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