The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit aa93ef6e authored by Daniele Tafani's avatar Daniele Tafani
Browse files

Introduced sensor operations in dcdblib. Optimized printout of operations in dcdbquery.

parent 2e60dcb7
......@@ -2,7 +2,7 @@
* Sensor.h
*
* Created on: 28 Apr 2017
* Author: ottmi
* Author: Michael Ott, Daniele Tafani
*/
#ifndef LIB_INCLUDE_DCDB_SENSOR_H_
......@@ -15,26 +15,18 @@
#include "dcdb/timestamp.h"
namespace DCDB {
class Sensor {
public:
Sensor(DCDB::Connection* connection, std::string publicName);
virtual ~Sensor();
void query(std::list<SensorDataStoreReading>& reading, TimeStamp& start, TimeStamp& end, QueryAggregate aggregate = AGGREGATE_NONE);
double getScalingFactor() const {
return scalingFactor;
}
void setScalingFactor(double scalingFactor) {
this->scalingFactor = scalingFactor;
}
private:
Connection* connection;
PublicSensor publicSensor;
SensorConfig* sensorConfig;
double scalingFactor;
};
} /* namespace DCDB */
......
//
// sensoroperations.hpp
// dcdb
//
// Created by Tafani, Daniele on 13.04.18.
// Copyright © 2018 LRZ. All rights reserved.
//
#include <stdio.h>
#include <cstdint>
#include <cinttypes>
#include <cstdlib>
#ifndef sensoroperations_h
#define sensoroperations_h
namespace DCDB {
typedef enum {
DCDB_OP_SUCCESS,
DCDB_OP_OVERFLOW,
DCDB_OP_DIVISION_BY_ZERO,
DCDB_OP_UNKNOWN,
} DCDB_OP_RESULT;
DCDB_OP_RESULT safeAdd(int64_t lh, int64_t rh, int64_t* result);
DCDB_OP_RESULT safeMult(int64_t lh, int64_t rh, int64_t* result);
DCDB_OP_RESULT safeMult(double lh, double rh, int64_t* result);
DCDB_OP_RESULT scale(int64_t* result, double scalingFactor, double baseScalingFactor);
DCDB_OP_RESULT delta(int64_t lh, int64_t rh, int64_t* result);
DCDB_OP_RESULT derivative(int64_t lhx, int64_t rhx, uint64_t lht, uint64_t rht, int64_t* result);
DCDB_OP_RESULT integral(int64_t lhx, int64_t rhx, uint64_t lht, uint64_t rht, int64_t* result);
} /* End of namespace DCDB */
#endif /* sensoroperations_h */
......@@ -2,7 +2,7 @@
* Sensor.cpp
*
* Created on: 28 Apr 2017
* Author: ottmi
* Author: Michael Ott, Daniele Tafani
*/
#include <iostream>
......@@ -16,9 +16,8 @@ namespace DCDB {
sensorConfig = new SensorConfig(connection);
this->connection = connection;
scalingFactor = 1;
/* Retrieve publicSensor ifno */
/* Retrieve publicSensor info */
switch (sensorConfig->getPublicSensorByName(publicSensor, publicName.c_str())) {
case DCDB::SC_OK:
break;
......@@ -63,12 +62,6 @@ namespace DCDB {
for (std::list<SensorId>::iterator sit = sensorIds.begin(); sit != sensorIds.end(); sit++) {
sensorDataStore.query(result, *sit, start, end, aggregate);
}
if (scalingFactor != 1.0 || publicSensor.scaling_factor != 1.0) {
for (std::list<SensorDataStoreReading>::iterator reading = result.begin(); reading != result.end(); reading++) {
reading->value = ((double) reading->value) * scalingFactor * publicSensor.scaling_factor;
}
}
}
}
......
//
// sensoroperations.cpp
// dcdb
//
// Created by Tafani, Daniele on 13.04.18.
// Copyright © 2018 LRZ. All rights reserved.
//
#include <limits>
#include <cmath>
#include "dcdb/sensoroperations.h"
namespace DCDB {
void doubleToFraction(int64_t* num, int64_t* den, double number) {
*den = 1;
while((std::abs(number) - std::abs(floor(number)))) {
number *= 10;
*den *= 10;
}
*num = number;
}
/* Safe implementation of addition between 64-bit integers */
DCDB_OP_RESULT safeAdd(int64_t lh, int64_t rh, int64_t* result) {
if ( (lh < 0.0) == (rh < 0.0)
&& std::abs(lh) > std::numeric_limits<int64_t>::max() - std::abs(rh) )
return DCDB_OP_OVERFLOW;
*result = (int64_t) lh + rh;
return DCDB_OP_SUCCESS;
}
/* Safe multiplication for 64-bit integers */
DCDB_OP_RESULT safeMult(int64_t lh, int64_t rh, int64_t* result) {
if (lh > 0 && rh > 0 && lh > std::numeric_limits<int64_t>::max() / rh) {
*result = std::numeric_limits<int64_t>::max();
return DCDB_OP_OVERFLOW;
}
if (lh < 0 && rh > 0 && lh < std::numeric_limits<int64_t>::min() / rh) {
*result = std::numeric_limits<int64_t>::min();
return DCDB_OP_OVERFLOW;
}
if (lh > 0 && rh < 0 && rh < std::numeric_limits<int64_t>::min() / lh) {
*result = std::numeric_limits<int64_t>::min();
return DCDB_OP_OVERFLOW;
}
if (lh < 0 && rh < 0 && (lh <= std::numeric_limits<int64_t>::min()
|| rh <= std::numeric_limits<int64_t>::min()
|| -lh > std::numeric_limits<int64_t>::max() / -rh)) {
*result = std::numeric_limits<int64_t>::max();
return DCDB_OP_OVERFLOW;
}
*result = lh*rh;
return DCDB_OP_SUCCESS;
}
/* Scale function for double */
DCDB_OP_RESULT scale(int64_t* result, double scalingFactor, double baseScalingFactor) {
double factor = scalingFactor * baseScalingFactor;
int64_t product = *result;
if(std::abs(factor) - std::abs(floor(factor))) {
int64_t num = 0;
int64_t denom = 0;
doubleToFraction(&num, &denom, factor);
DCDB_OP_RESULT multResult = safeMult(num, *result, &product);
if(multResult != DCDB_OP_SUCCESS) {
*result = product;
return multResult;
}
*result = product / denom;
return DCDB_OP_SUCCESS;
}
return safeMult((int64_t) factor, product, result);
};
/* Safe delta function */
DCDB_OP_RESULT delta(int64_t lh, int64_t rh, int64_t* result) {
//TODO: Need to address overflow for monothonic sensor data, e.g., energy reaching max value.
//Maybe need to add another field to sensorconfig ("monothonic")?
//Or need to pass the maximum value detectable by the sensor?
*result = lh - rh;
return DCDB_OP_SUCCESS;
};
/* Safe implementation of a derivative */
DCDB_OP_RESULT derivative(int64_t lhx, int64_t rhx, uint64_t lht, uint64_t rht, int64_t* result) {
int64_t dx = 0;
uint64_t dt = 0;
DCDB_OP_RESULT deltaResult = delta(lhx, rhx, &dx);
if(deltaResult != DCDB_OP_SUCCESS) {
*result = dx;
return deltaResult;
}
dt = (int64_t) lht - rht;
if(dt == 0)
return DCDB_OP_DIVISION_BY_ZERO; //Presumably it's always != 0...
*result = dx / dt;
return DCDB_OP_SUCCESS;
};
/* Safe implementation of an integral */
DCDB_OP_RESULT integral(int64_t lhx, int64_t rhx, uint64_t lht, uint64_t rht, int64_t* result) {
int64_t dx = 0;
int64_t dt = 0;
DCDB_OP_RESULT deltaResult = delta(lhx, rhx, &dx);
if(deltaResult != DCDB_OP_SUCCESS) {
*result = dx;
return deltaResult;
}
dt = (int64_t) lht - rht;
return safeMult(dx, dt, result);
};
} /* end DCDB namespace */
//================================================================================
// Name : dcdbquery.cpp
// Author : Axel Auweter
// Author : Axel Auweter, Daniele Tafani
// Copyright : Leibniz Supercomputing Centre
// Description : Main file of the dcdbquery command line utility
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2011-2016 Leibniz Supercomputing Centre
// Copyright (C) 2011-2018 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
......@@ -124,9 +124,6 @@ int main(int argc, char * const argv[])
case 'l':
myQuery->setLocalTimeEnabled(true);
break;
case 'f':
myQuery->setFloatOutputEnabled(true);
break;
default:
usage();
exit(EXIT_FAILURE);
......
This diff is collapsed.
//================================================================================
// Name : query.h
// Author : Axel Auweter
// Author : Axel Auweter, Daniele Tafani
// Copyright : Leibniz Supercomputing Centre
// Description : Header of query class of dcdbquery
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2011-2016 Leibniz Supercomputing Centre
// Copyright (C) 2011-2018 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
......@@ -42,33 +42,47 @@
class DCDBQuery
{
struct outputFormat {
bool printValue;
double scalingFactor;
std::string unit;
};
typedef enum {
CONVERT_OK,
CONVERT_ERR,
} CONVERT_RESULT;
protected:
DCDB::Connection* connection;
bool useLocalTime;
bool useRawOutput;
bool useFloatOutput;
std::string sensorName;
bool scale;
double scalingFactor;
bool unitConvert;
bool printValue;
bool calculateDelta;
bool calculateDeltaT;
bool calculateDerivative;
bool calculateIntegral;
std::string unit;
double baseScalingFactor;
DCDB::Unit baseUnit;
DCDB::Unit targetUnit;
outputFormat valueFormat;
outputFormat deltaFormat;
outputFormat deltaTFormat;
outputFormat derivativeFormat;
outputFormat integralFormat;
bool notifyOverflow;
public:
void setLocalTimeEnabled(bool enable);
bool getLocalTimeEnabled();
void setRawOutputEnabled(bool enable);
bool getRawOutputEnabled();
void setFloatOutputEnabled(bool enable);
bool getFloatOutputEnabled();
void genOutput(std::list<DCDB::SensorDataStoreReading> &results);
void check(std::list<std::string>::iterator it , double* scalingFactor);
void checkModifier(std::list<std::string>::iterator it, double* scalingFactor, std::string* unit);
void doQuery(const char* hostname, std::list<std::string> sensors, DCDB::TimeStamp start, DCDB::TimeStamp end);
......
  • Added:

    1. Sensor operations in DCDBLib with checks on numerical problems like overflows, division by zero etc.
    2. Reworked dcdbquery to exploit sensor operations for printing interesting ops like deltas, derivatives, integrals, etc.
    3. Removed scaling factor in sensor.cpp. It's now defined as a sensor operation. The public sensor scaling factor is untouched.
    4. Removed float output from dcdbquery...we really never used it...
    5. Precision is 64-bit integer for all operations besides scaling factors (double).

    Next:

    1. Fix unit conversion! At the moment it only makes sense for normal sensor readings, not for sensor operations (e.g., need to add units like Ws, Joules, l/h, etc.).
    2. Update output on dcdbquery -h
    3. Fix overflow for monotonic sensor readings (e.g., energy will overflow at some point).
    4. Add unit conversion for timestamps (useful for sensor operations).
    Edited by Daniele Tafani
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