Commit 9a0cf496 authored by Micha Mueller's avatar Micha Mueller
Browse files

Resolve issue #1: Perf plugin uses custom delta computation which uses uint64_t internally

parent 4db1e2f6
......@@ -80,7 +80,6 @@ public:
void setName(const std::string& name, int cpuID=-1) { _name = formatName(name, cpuID); }
void setMqtt(const std::string& mqtt) { _mqtt = mqtt; }
void setCacheInterval(unsigned cacheInterval) { _cacheInterval = cacheInterval; }
void setLastRawValue(int64_t value) { _lastRawValue.value = value; }
const std::size_t getSizeOfReadingQueue() const { return _readingQueue->read_available(); }
std::size_t popReadingQueue(reading_t *reads, std::size_t max) const { return _readingQueue->pop(reads, max); }
......@@ -99,7 +98,7 @@ public:
}
}
virtual void storeReading(reading_t reading, double factor=1.0, unsigned long long maxValue=ULLONG_MAX) {
void storeReading(reading_t reading, double factor=1.0, unsigned long long maxValue=ULLONG_MAX) {
_latestValue.timestamp = reading.timestamp;
if( _delta ) {
if (reading.value < _lastRawValue.value)
......
......@@ -18,7 +18,8 @@ public:
PerfSensorBase(const std::string& name) :
SensorBase(name),
_type(0),
_config(0) {}
_config(0),
_lastRawPerf(0) {}
virtual ~PerfSensorBase() {}
......@@ -27,10 +28,29 @@ public:
void setType(unsigned type) { _type = type; }
void setConfig(unsigned config) { _config = config; }
void setLastRaw(uint64_t raw) { _lastRawPerf = raw; }
void storeReading(uint64_t value, uint64_t timestamp, double factor=1.0, unsigned long long maxValue=ULLONG_MAX) {
_latestValue.timestamp = timestamp;
if( _delta ) {
if (value < _lastRawPerf)
_latestValue.value = (value + (maxValue - _lastRawPerf)) * factor;
else
_latestValue.value = (value - _lastRawPerf) * factor;
_lastRawPerf = value;
}
else
_latestValue.value = value * factor;
_readingQueue->push(_latestValue);
_cache[_cacheIndex] = _latestValue;
_cacheIndex = (_cacheIndex + 1) % _cacheSize;
}
protected:
unsigned int _type;
unsigned int _config;
uint64_t _lastRawPerf;
};
using PerfSBPtr = std::shared_ptr<PerfSensorBase>;
......
......@@ -62,7 +62,6 @@ void PerfSensorGroup::init(boost::asio::io_service& io) {
*
* Therefore we require 16 byte per sensor plus an additional 8*3 byte
*/
//requires
std::size_t bufSize = _sensors.size() * 16 + 24;
if (!_buf) {
_buf = new char[bufSize];
......@@ -155,8 +154,7 @@ void PerfSensorGroup::stop() {
}
void PerfSensorGroup::read() {
reading_t reading;
reading.timestamp = getTimestamp();
uint64_t timestamp = getTimestamp();
struct read_format* rf = (struct read_format*) _buf;
unsigned long long count;
......@@ -192,22 +190,20 @@ void PerfSensorGroup::read() {
}
//iterate over all values returned by ::read()
for (unsigned i = 0; i < rf->nr; i++) {
//TODO Perfcounter use unsigned 64bit. What happens with values > 63bit ?
int64_t val = rf->values[i].value;
uint64_t val = rf->values[i].value;
//iterate over all counters and find the one with matching id
for (unsigned j = 0; j < _sensors.size(); j++) {
if (rf->values[i].id == _ids[j]) {
reading.value = val;
#ifdef DEBUG
LOG(debug) << _groupName << "::" << _sensors[j]->getName() << ": \"" << reading.value << "\"";
LOG(debug) << _groupName << "::" << _sensors[j]->getName() << ": \"" << val << "\"";
#endif
if(_lastValid){
//storeReading takes care of delta computation and applies correction value on the result
_sensors[j]->storeReading(reading, correction, PerfSensorBase::MAXCOUNTERVALUE);
_sensors[j]->storeReading(val, timestamp, correction, PerfSensorBase::MAXCOUNTERVALUE);
} else {
//Before we can compute correct values again after an invalid reading we have to update the lastRawValue first
_sensors[j]->setLastRawValue(val);
_sensors[j]->setLastRaw(val);
}
break;
}
......
......@@ -113,7 +113,7 @@ public:
*
* @return The requested value
*/
uint64_t issueGet(const oid* const OID, size_t OIDLen);
int64_t issueGet(const oid* const OID, size_t OIDLen);
private:
bool _isInitialized;
......
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