Commit 4e2daf27 authored by Micha Mueller's avatar Micha Mueller
Browse files

Rename PerfSensor --> PerfSingleSensor. Make PerfAttributes own file

parent f8b30b59
......@@ -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/PerfSensor.o src/sensors/perfevent/PerfeventConfigurator.o src/sensors/perfevent/PerfSensorGroup.o
libdcdbplugin_perfevent.$(LIBEXT): src/sensors/perfevent/PerfSingleSensor.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
......
/*
* PerfAttributes.h
*
* Created on: 13.08.2018
* Author: Micha Mueller
*/
#ifndef PERFEVENT_PERFATTRIBUTES_H_
#define PERFEVENT_PERFATTRIBUTES_H_
class PerfAttributes {
public:
PerfAttributes() :
_cpuId(0),
_fd(-1) {}
virtual ~PerfAttributes() {}
int getCpuId() const { return _cpuId; }
void setCpuId(int cpuId) { _cpuId = cpuId; }
protected:
int _cpuId;
int _fd;
};
#endif /* PERFEVENT_PERFATTRIBUTES_H_ */
......@@ -43,22 +43,4 @@ protected:
unsigned int _config;
};
class PerfAttributes {
public:
PerfAttributes() :
_cpuId(0),
_fd(-1) {}
virtual ~PerfAttributes() {}
int getCpuId() const { return _cpuId; }
void setCpuId(int cpuId) { _cpuId = cpuId; }
protected:
int _cpuId;
int _fd;
};
#endif /* PERFEVENT_PERFSENSORBASE_H_ */
......@@ -9,8 +9,8 @@
#define PERFSENSORGROUP_H_
#include "../../headers/SensorGroupTemplate.h"
#include "PerfSensor.h"
#include "PerfAttributes.h"
#include "PerfSensorBase.h"
class PerfSensorGroup : public SensorGroupTemplate<PerfSensorBase>, public PerfAttributes {
......
/*
* PerfSensor.cpp
* PerfSingleSensor.cpp
*
* Created on: 11.12.2017
* Author: Micha Mueller
*/
#include "PerfSensor.h"
#include "PerfSingleSensor.h"
#include "timestamp.h"
#include <unistd.h>
......@@ -16,12 +16,12 @@
#include <functional>
#include <limits.h>
PerfSensor::PerfSensor(const std::string& name) :
PerfSingleSensor::PerfSingleSensor(const std::string& name) :
SensorBase(name), PerfSensorBase(name), SingleSensor(name) {}
PerfSensor::~PerfSensor() {}
PerfSingleSensor::~PerfSingleSensor() {}
void PerfSensor::start() {
void PerfSingleSensor::start() {
if (_keepRunning) {
//we have been started already
LOG(info) << "Sensor " << _name << " already running.";
......@@ -52,11 +52,11 @@ void PerfSensor::start() {
_keepRunning = 1;
_pendingTasks++;
_timer->async_wait(std::bind(&PerfSensor::readAsync, this));
_timer->async_wait(std::bind(&PerfSingleSensor::readAsync, this));
LOG(info) << "Sensor " << _name << " started.";
}
void PerfSensor::stop() {
void PerfSingleSensor::stop() {
_keepRunning = 0;
if(_fd != -1) {
close(_fd);
......@@ -65,7 +65,7 @@ void PerfSensor::stop() {
LOG(info) << "Sensor " << _name << " stopped.";
}
void PerfSensor::storeReading(reading_t reading, unsigned cacheIndex) {
void PerfSingleSensor::storeReading(reading_t reading, unsigned cacheIndex) {
_readingQueue->push(reading);
_cache[_cacheIndex] = reading;
_cacheIndex = (_cacheIndex + 1) % _cacheSize;
......@@ -78,7 +78,7 @@ void PerfSensor::storeReading(reading_t reading, unsigned cacheIndex) {
_latestValue.timestamp = reading.timestamp;
}
void PerfSensor::read() {
void PerfSingleSensor::read() {
reading_t reading;
reading.timestamp = getTimestamp();
......@@ -102,14 +102,14 @@ void PerfSensor::read() {
storeReading(reading, _cacheIndex);
}
void PerfSensor::readAsync() {
void PerfSingleSensor::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(&PerfSensor::readAsync, this));
_timer->async_wait(std::bind(&PerfSingleSensor::readAsync, this));
}
_pendingTasks--;
}
/*
* PerfSensor.h
* PerfSingleSensor.h
*
* Created on: 11.12.2017
* Author: Micha Mueller
*/
#ifndef PERFSENSOR_H_
#define PERFSENSOR_H_
#ifndef PERFSINGLESENSOR_H_
#define PERFSINGLESENSOR_H_
#include "PerfAttributes.h"
#include "PerfSensorBase.h"
#include "../../headers/SingleSensor.h"
class PerfSensor : public PerfSensorBase, public PerfAttributes, public SingleSensor {
class PerfSingleSensor : public PerfSensorBase, public PerfAttributes, public SingleSensor {
public:
PerfSensor(const std::string& name);
virtual ~PerfSensor();
PerfSingleSensor(const std::string& name);
virtual ~PerfSingleSensor();
void start() override;
void stop() override;
......@@ -26,4 +27,4 @@ private:
void readAsync() override;
};
#endif /* PERFSENSOR_H_ */
#endif /* PERFSINGLESENSOR_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()) {
PerfSensor perfSensor(sensor.second.data());
PerfSingleSensor perfSensor(sensor.second.data());
//first check if default counter is given
boost::optional<boost::property_tree::iptree&> defaultC = sensor.second.get_child_optional("default");
......@@ -115,7 +115,7 @@ bool PerfeventConfigurator::derivedReadConfig(boost::property_tree::iptree& cfg)
//customize perfCounter for every CPU
for (auto i : cpuSet) {
PerfSensor* perfS = new PerfSensor(sensor.second.data());
PerfSingleSensor* perfS = new PerfSingleSensor(sensor.second.data());
*perfS = perfSensor;
string incMqtt = increaseMqtt(startMqtt, i);
......
......@@ -11,10 +11,10 @@
#include <set>
#include "../../ConfiguratorTemplate.h"
#include "PerfSensor.h"
#include "PerfSensorGroup.h"
#include "PerfSingleSensor.h"
class PerfeventConfigurator : public ConfiguratorTemplate<PerfSensorBase, PerfSensor> {
class PerfeventConfigurator : public ConfiguratorTemplate<PerfSensorBase, PerfSingleSensor> {
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