Commit f8b30b59 authored by Micha Mueller's avatar Micha Mueller
Browse files

Rename PerfCounter --> PerfSensor

parent 381100b8
...@@ -75,7 +75,7 @@ src/sensors/%.o: CXXFLAGS+= $(PLUGINFLAGS) -I$(DCDBDEPSPATH)/bacnet-stack-$(BACN ...@@ -75,7 +75,7 @@ src/sensors/%.o: CXXFLAGS+= $(PLUGINFLAGS) -I$(DCDBDEPSPATH)/bacnet-stack-$(BACN
libdcdbplugin_sysfs.$(LIBEXT): src/Sensor.o src/sensors/sysfs/SysfsSensor.o src/sensors/sysfs/SysfsConfigurator.o libdcdbplugin_sysfs.$(LIBEXT): src/Sensor.o src/sensors/sysfs/SysfsSensor.o src/sensors/sysfs/SysfsConfigurator.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system $(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
libdcdbplugin_perfevent.$(LIBEXT): src/sensors/perfevent/PerfCounter.o src/sensors/perfevent/PerfeventConfigurator.o src/sensors/perfevent/PerfCounterGroup.o libdcdbplugin_perfevent.$(LIBEXT): src/sensors/perfevent/PerfSensor.o src/sensors/perfevent/PerfeventConfigurator.o src/sensors/perfevent/PerfSensorGroup.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system $(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
libdcdbplugin_ipmi.$(LIBEXT): src/Sensor.o src/sensors/ipmi/IPMISensor.o src/sensors/ipmi/IPMIHost.o src/sensors/ipmi/IPMIConfigurator.o libdcdbplugin_ipmi.$(LIBEXT): src/Sensor.o src/sensors/ipmi/IPMISensor.o src/sensors/ipmi/IPMIHost.o src/sensors/ipmi/IPMIConfigurator.o
......
/* /*
* PerfCounter.cpp * PerfSensor.cpp
* *
* Created on: 11.12.2017 * Created on: 11.12.2017
* Author: Micha Mueller * Author: Micha Mueller
*/ */
#include "PerfCounter.h" #include "PerfSensor.h"
#include "timestamp.h" #include "timestamp.h"
#include <unistd.h> #include <unistd.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
...@@ -15,12 +16,12 @@ ...@@ -15,12 +16,12 @@
#include <functional> #include <functional>
#include <limits.h> #include <limits.h>
PerfCounter::PerfCounter(const std::string& name) : PerfSensor::PerfSensor(const std::string& name) :
SensorBase(name), PerfSensorBase(name), SingleSensor(name) {} SensorBase(name), PerfSensorBase(name), SingleSensor(name) {}
PerfCounter::~PerfCounter() {} PerfSensor::~PerfSensor() {}
void PerfCounter::start() { void PerfSensor::start() {
if (_keepRunning) { if (_keepRunning) {
//we have been started already //we have been started already
LOG(info) << "Sensor " << _name << " already running."; LOG(info) << "Sensor " << _name << " already running.";
...@@ -51,11 +52,11 @@ void PerfCounter::start() { ...@@ -51,11 +52,11 @@ void PerfCounter::start() {
_keepRunning = 1; _keepRunning = 1;
_pendingTasks++; _pendingTasks++;
_timer->async_wait(std::bind(&PerfCounter::readAsync, this)); _timer->async_wait(std::bind(&PerfSensor::readAsync, this));
LOG(info) << "Sensor " << _name << " started."; LOG(info) << "Sensor " << _name << " started.";
} }
void PerfCounter::stop() { void PerfSensor::stop() {
_keepRunning = 0; _keepRunning = 0;
if(_fd != -1) { if(_fd != -1) {
close(_fd); close(_fd);
...@@ -64,7 +65,7 @@ void PerfCounter::stop() { ...@@ -64,7 +65,7 @@ void PerfCounter::stop() {
LOG(info) << "Sensor " << _name << " stopped."; LOG(info) << "Sensor " << _name << " stopped.";
} }
void PerfCounter::storeReading(reading_t reading, unsigned cacheIndex) { void PerfSensor::storeReading(reading_t reading, unsigned cacheIndex) {
_readingQueue->push(reading); _readingQueue->push(reading);
_cache[_cacheIndex] = reading; _cache[_cacheIndex] = reading;
_cacheIndex = (_cacheIndex + 1) % _cacheSize; _cacheIndex = (_cacheIndex + 1) % _cacheSize;
...@@ -77,7 +78,7 @@ void PerfCounter::storeReading(reading_t reading, unsigned cacheIndex) { ...@@ -77,7 +78,7 @@ void PerfCounter::storeReading(reading_t reading, unsigned cacheIndex) {
_latestValue.timestamp = reading.timestamp; _latestValue.timestamp = reading.timestamp;
} }
void PerfCounter::read() { void PerfSensor::read() {
reading_t reading; reading_t reading;
reading.timestamp = getTimestamp(); reading.timestamp = getTimestamp();
...@@ -101,14 +102,14 @@ void PerfCounter::read() { ...@@ -101,14 +102,14 @@ void PerfCounter::read() {
storeReading(reading, _cacheIndex); storeReading(reading, _cacheIndex);
} }
void PerfCounter::readAsync() { void PerfSensor::readAsync() {
uint64_t now = getTimestamp(); uint64_t now = getTimestamp();
read(); read();
if (_timer != NULL && _keepRunning) { if (_timer != NULL && _keepRunning) {
uint64_t next = now + MS_TO_NS(_interval); uint64_t next = now + MS_TO_NS(_interval);
_timer->expires_at(timestamp2ptime(next)); _timer->expires_at(timestamp2ptime(next));
_pendingTasks++; _pendingTasks++;
_timer->async_wait(std::bind(&PerfCounter::readAsync, this)); _timer->async_wait(std::bind(&PerfSensor::readAsync, this));
} }
_pendingTasks--; _pendingTasks--;
} }
/* /*
* PerfCounter.h * PerfSensor.h
* *
* Created on: 11.12.2017 * Created on: 11.12.2017
* Author: Micha Mueller * Author: Micha Mueller
*/ */
#ifndef PERFCOUNTER_H_ #ifndef PERFSENSOR_H_
#define PERFCOUNTER_H_ #define PERFSENSOR_H_
#include "PerfSensorBase.h" #include "PerfSensorBase.h"
#include "../../headers/SingleSensor.h" #include "../../headers/SingleSensor.h"
class PerfCounter : public PerfSensorBase, public PerfAttributes, public SingleSensor { class PerfSensor : public PerfSensorBase, public PerfAttributes, public SingleSensor {
public: public:
PerfCounter(const std::string& name); PerfSensor(const std::string& name);
virtual ~PerfCounter(); virtual ~PerfSensor();
void start() override; void start() override;
void stop() override; void stop() override;
...@@ -26,4 +26,4 @@ private: ...@@ -26,4 +26,4 @@ private:
void readAsync() override; void readAsync() override;
}; };
#endif /* PERFCOUNTER_H_ */ #endif /* PERFSENSOR_H_ */
/* /*
* PerfCounterGroup.cpp * PerfSensorGroup.cpp
* *
* Created on: 04.08.2018 * Created on: 04.08.2018
* Author: Micha Mueller * Author: Micha Mueller
*/ */
#include "PerfCounterGroup.h" #include "PerfSensorGroup.h"
#include "timestamp.h" #include "timestamp.h"
#include <unistd.h> #include <unistd.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
...@@ -24,20 +25,20 @@ struct read_format { ...@@ -24,20 +25,20 @@ struct read_format {
} values[]; } values[];
}; };
PerfCounterGroup::PerfCounterGroup(const std::string name) : PerfSensorGroup::PerfSensorGroup(const std::string name) :
SensorGroupTemplate(name) { SensorGroupTemplate(name) {
_bufSize = 0; _bufSize = 0;
_buf = NULL; _buf = NULL;
} }
PerfCounterGroup::~PerfCounterGroup() { PerfSensorGroup::~PerfSensorGroup() {
if (_buf) { if (_buf) {
delete[] _buf; delete[] _buf;
} }
} }
void PerfCounterGroup::init(boost::asio::io_service& io) { void PerfSensorGroup::init(boost::asio::io_service& io) {
_cacheSize = _cacheInterval / _interval + 1; _cacheSize = _cacheInterval / _interval + 1;
if (!_timer) { if (!_timer) {
_timer = new boost::asio::deadline_timer(io, boost::posix_time::seconds(0)); _timer = new boost::asio::deadline_timer(io, boost::posix_time::seconds(0));
...@@ -58,10 +59,10 @@ void PerfCounterGroup::init(boost::asio::io_service& io) { ...@@ -58,10 +59,10 @@ void PerfCounterGroup::init(boost::asio::io_service& io) {
} }
} }
void PerfCounterGroup::start() { void PerfSensorGroup::start() {
if (_keepRunning) { if (_keepRunning) {
//we have been started already //we have been started already
LOG(info) << "Countergroup " << _groupName << " already running."; LOG(info) << "Sensorgroup " << _groupName << " already running.";
return; return;
} }
...@@ -112,20 +113,20 @@ void PerfCounterGroup::start() { ...@@ -112,20 +113,20 @@ void PerfCounterGroup::start() {
_keepRunning = 1; _keepRunning = 1;
_pendingTasks++; _pendingTasks++;
_timer->async_wait(std::bind(&PerfCounterGroup::readAsync, this)); _timer->async_wait(std::bind(&PerfSensorGroup::readAsync, this));
LOG(info) << "Countergroup " << _groupName << " started."; LOG(info) << "Sensorgroup " << _groupName << " started.";
} }
void PerfCounterGroup::stop() { void PerfSensorGroup::stop() {
_keepRunning = 0; _keepRunning = 0;
if(_fd != -1) { if(_fd != -1) {
close(_fd); close(_fd);
_fd = -1; _fd = -1;
} }
LOG(info) << "Countergroup " << _groupName << " stopped."; LOG(info) << "Sensorgroup " << _groupName << " stopped.";
} }
void PerfCounterGroup::read() { void PerfSensorGroup::read() {
reading_t reading; reading_t reading;
reading.timestamp = getTimestamp(); reading.timestamp = getTimestamp();
...@@ -133,7 +134,7 @@ void PerfCounterGroup::read() { ...@@ -133,7 +134,7 @@ void PerfCounterGroup::read() {
unsigned long long count; unsigned long long count;
if (::read(_fd, _buf, _bufSize) < 0) { if (::read(_fd, _buf, _bufSize) < 0) {
LOG(error) << "Countergroup" << _groupName << " could not read value"; LOG(error) << "Sensorgroup" << _groupName << " could not read value";
return; return;
} }
...@@ -163,14 +164,14 @@ void PerfCounterGroup::read() { ...@@ -163,14 +164,14 @@ void PerfCounterGroup::read() {
_cacheIndex = (_cacheIndex + 1) % _cacheSize; _cacheIndex = (_cacheIndex + 1) % _cacheSize;
} }
void PerfCounterGroup::readAsync() { void PerfSensorGroup::readAsync() {
uint64_t now = getTimestamp(); uint64_t now = getTimestamp();
read(); read();
if (_timer != NULL && _keepRunning) { if (_timer != NULL && _keepRunning) {
uint64_t next = now + MS_TO_NS(_interval); uint64_t next = now + MS_TO_NS(_interval);
_timer->expires_at(timestamp2ptime(next)); _timer->expires_at(timestamp2ptime(next));
_pendingTasks++; _pendingTasks++;
_timer->async_wait(std::bind(&PerfCounterGroup::readAsync, this)); _timer->async_wait(std::bind(&PerfSensorGroup::readAsync, this));
} }
_pendingTasks--; _pendingTasks--;
} }
/* /*
* PerfCounterGroup.h * PerfSensorGroup.h
* *
* Created on: 04.08.2018 * Created on: 04.08.2018
* Author: Micha Mueller * Author: Micha Mueller
*/ */
#ifndef PERFCOUNTERGROUP_H_ #ifndef PERFSENSORGROUP_H_
#define PERFCOUNTERGROUP_H_ #define PERFSENSORGROUP_H_
#include "../../headers/SensorGroupTemplate.h" #include "../../headers/SensorGroupTemplate.h"
#include "PerfSensor.h"
#include "PerfSensorBase.h" #include "PerfSensorBase.h"
#include "PerfCounter.h"
class PerfCounterGroup : public SensorGroupTemplate<PerfSensorBase>, public PerfAttributes { class PerfSensorGroup : public SensorGroupTemplate<PerfSensorBase>, public PerfAttributes {
public: public:
PerfCounterGroup(const std::string name); PerfSensorGroup(const std::string name);
virtual ~PerfCounterGroup(); virtual ~PerfSensorGroup();
void init(boost::asio::io_service& io) override; void init(boost::asio::io_service& io) override;
void start() override; void start() override;
...@@ -31,4 +31,4 @@ private: ...@@ -31,4 +31,4 @@ private:
std::vector<uint64_t> _ids; std::vector<uint64_t> _ids;
}; };
#endif /* PERFCOUNTERGROUP_H_ */ #endif /* PERFSENSORGROUP_H_ */
...@@ -75,7 +75,7 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) ...@@ -75,7 +75,7 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
if (STRCMP(sensor, "sensor")) { if (STRCMP(sensor, "sensor")) {
LOG(debug) << "Sensor \"" << sensor.second.data() << "\""; LOG(debug) << "Sensor \"" << sensor.second.data() << "\"";
if (!sensor.second.empty()) { if (!sensor.second.empty()) {
PerfCounter perfCounter(sensor.second.data()); PerfSensor perfSensor(sensor.second.data());
//first check if default counter is given //first check if default counter is given
boost::optional<boost::property_tree::iptree&> defaultC = sensor.second.get_child_optional("default"); boost::optional<boost::property_tree::iptree&> defaultC = sensor.second.get_child_optional("default");
...@@ -83,8 +83,8 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) ...@@ -83,8 +83,8 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
LOG(debug) << " Using \"" << defaultC.get().data() << "\" as default."; LOG(debug) << " Using \"" << defaultC.get().data() << "\" as default.";
sensorMap_t::iterator it = _templateSensors.find(defaultC.get().data()); sensorMap_t::iterator it = _templateSensors.find(defaultC.get().data());
if(it != _templateSensors.end()) { if(it != _templateSensors.end()) {
perfCounter = it->second; perfSensor = it->second;
perfCounter.setName(sensor.second.data()); perfSensor.setName(sensor.second.data());
} else { } else {
LOG(warning) << " Template sensor \"" << defaultC.get().data() << "\" not found! Using standard values."; LOG(warning) << " Template sensor \"" << defaultC.get().data() << "\" not found! Using standard values.";
} }
...@@ -108,22 +108,22 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) ...@@ -108,22 +108,22 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
} }
//read remaining values //read remaining values
if(readSingleSensor(perfCounter, sensor.second)) { if(readSingleSensor(perfSensor, sensor.second)) {
//create distinct perfCounter and mqttSuffix per CPU //create distinct perfCounter and mqttSuffix per CPU
string startMqtt = perfCounter.getMqtt(); string startMqtt = perfSensor.getMqtt();
//customize perfCounter for every CPU //customize perfCounter for every CPU
for (auto i : cpuSet) { for (auto i : cpuSet) {
PerfCounter* perfCC = new PerfCounter(sensor.second.data()); PerfSensor* perfS = new PerfSensor(sensor.second.data());
*perfCC = perfCounter; *perfS = perfSensor;
string incMqtt = increaseMqtt(startMqtt, i); string incMqtt = increaseMqtt(startMqtt, i);
perfCC->setName(perfCC->getName() + std::to_string(i)); perfS->setName(perfS->getName() + std::to_string(i));
perfCC->setCpuId(i); perfS->setCpuId(i);
perfCC->setMqtt(_mqttPrefix + incMqtt); perfS->setMqtt(_mqttPrefix + incMqtt);
LOG(debug) << " CPU " << perfCC->getCpuId() << " using MQTT-Topic " << perfCC->getMqtt(); LOG(debug) << " CPU " << perfS->getCpuId() << " using MQTT-Topic " << perfS->getMqtt();
_sensors.push_back(perfCC); _sensors.push_back(perfS);
} }
} else { } else {
LOG(warning) << " Sensor \"" << sensor.second.data() << "\" has bad values! Ignoring..."; LOG(warning) << " Sensor \"" << sensor.second.data() << "\" has bad values! Ignoring...";
...@@ -137,7 +137,7 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) ...@@ -137,7 +137,7 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
if (STRCMP(group, "group")) { if (STRCMP(group, "group")) {
LOG(debug) << "Group \"" << group.second.data() << "\""; LOG(debug) << "Group \"" << group.second.data() << "\"";
if (!group.second.empty()) { if (!group.second.empty()) {
PerfCounterGroup perfGroup(group.second.data()); PerfSensorGroup perfGroup(group.second.data());
//initialize set with cpuIDs //initialize set with cpuIDs
//default cpuSet: contains all cpuIDs //default cpuSet: contains all cpuIDs
...@@ -164,10 +164,10 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) ...@@ -164,10 +164,10 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
//customize perfGroup for every CPU //customize perfGroup for every CPU
for (auto i : cpuSet) { for (auto i : cpuSet) {
PerfCounterGroup* perfCG = new PerfCounterGroup(group.second.data()); PerfSensorGroup* perfSG = new PerfSensorGroup(group.second.data());
*perfCG = perfGroup; *perfSG = perfGroup;
perfCG->setGroupName(perfCG->getGroupName() + std::to_string(i)); perfSG->setGroupName(perfSG->getGroupName() + std::to_string(i));
perfCG->setCpuId(i); perfSG->setCpuId(i);
//read counters //read counters
BOOST_FOREACH(boost::property_tree::iptree::value_type &val, group.second) { BOOST_FOREACH(boost::property_tree::iptree::value_type &val, group.second) {
...@@ -176,14 +176,14 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg) ...@@ -176,14 +176,14 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
PerfSensorBase* perfSB = new PerfSensorBase(val.second.data() + std::to_string(i)); PerfSensorBase* perfSB = new PerfSensorBase(val.second.data() + std::to_string(i));
if(readSensorBase(*perfSB, val.second)) { if(readSensorBase(*perfSB, val.second)) {
perfSB->setMqtt(_mqttPrefix + mqttPart + increaseMqtt(perfSB->getMqtt(), i)); perfSB->setMqtt(_mqttPrefix + mqttPart + increaseMqtt(perfSB->getMqtt(), i));
LOG(debug) << " Counter " << perfSB->getName() << " on CPU " << perfCG->getCpuId() << " using MQTT-Topic " << perfSB->getMqtt(); LOG(debug) << " Sensor " << perfSB->getName() << " on CPU " << perfSG->getCpuId() << " using MQTT-Topic " << perfSB->getMqtt();
perfCG->pushBackSensor(perfSB); perfSG->pushBackSensor(perfSB);
} else { } else {
LOG(warning) << " Counter \"" << val.second.data() << "\" has bad values! Ignoring..."; LOG(warning) << " Sensor \"" << val.second.data() << "\" has bad values! Ignoring...";
} }
} }
} }
_sensorGroups.push_back(perfCG); _sensorGroups.push_back(perfSG);
} }
} }
} }
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include <set> #include <set>
#include "PerfCounter.h"
#include "PerfCounterGroup.h"
#include "../../ConfiguratorTemplate.h" #include "../../ConfiguratorTemplate.h"
#include "PerfSensor.h"
#include "PerfSensorGroup.h"
class PerfeventConfigurator : public ConfiguratorTemplate<PerfSensorBase, PerfCounter> { class PerfeventConfigurator : public ConfiguratorTemplate<PerfSensorBase, PerfSensor> {
typedef std::map<std::string, std::set<int>> templateCpuMap_t; typedef std::map<std::string, std::set<int>> templateCpuMap_t;
typedef std::map<std::string, unsigned int> enumMap_t; typedef std::map<std::string, unsigned int> enumMap_t;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment