Commit bd2959b3 authored by Aurélien Delrieu's avatar Aurélien Delrieu

Adapt probe sending to JSON format of Collect Agent

parent 2a4bf3c2
......@@ -156,7 +156,7 @@ bool OutputOpenbach::sendRegister(OutputLog *log)
void OutputOpenbach::sendProbes(void)
{
std::unordered_map<string, string> stats;
json::JSON stats;
long double timestamp;
......@@ -169,15 +169,47 @@ void OutputOpenbach::sendProbes(void)
for(size_t i = 0 ; i < this->probes.size() ; i++)
{
BaseProbe *probe = this->probes[i];
if(this->getValueCount(probe) != 0)
if(this->getValueCount(probe) == 0)
{
stats[probe->getName()] = probe->getStrData();
probe->reset();
continue;
}
switch(probe->getDataType())
{
case INT32_TYPE:
{
Probe<int32_t> *iprobe = dynamic_cast<Probe<int32_t> *>(probe);
if(iprobe != NULL)
{
stats[probe->getName()] = iprobe->get();
}
break;
}
case FLOAT_TYPE:
{
Probe<float> *fprobe = dynamic_cast<Probe<float> *>(probe);
if(fprobe != NULL)
{
stats[probe->getName()] = fprobe->get();
}
break;
}
case DOUBLE_TYPE:
{
Probe<double> *dprobe = dynamic_cast<Probe<double> *>(probe);
if(dprobe != NULL)
{
stats[probe->getName()] = dprobe->get();
}
break;
}
}
probe->reset();
}
this->mutex.releaseLock();
if(stats.empty())
if(stats.size() <= 0)
{
return;
}
......
......@@ -55,6 +55,12 @@ enum sample_type_t
SAMPLE_SUM /*!< Calculate the sum */
};
enum datatype_t {
INT32_TYPE = 0,
FLOAT_TYPE = 1,
DOUBLE_TYPE = 2
};
/**
* @class the probe representation
*/
......@@ -63,6 +69,7 @@ class BaseProbe
friend class OutputInternal;
public:
virtual ~BaseProbe();
/**
......@@ -101,30 +108,23 @@ public:
virtual bool getData(unsigned char* buffer, size_t len) const = 0;
/**
* @brief get data in string
* @brief get data type
*
* @return data
**/
virtual string getStrData() const = 0;
* @return data type
*/
virtual datatype_t getDataType() const = 0;
/**
* @brief reset values count
*
**/
void reset();
protected:
BaseProbe(uint8_t id, const string &name,
const string &unit,
bool enabled, sample_type_t type);
/**
* @brief get the storage type ID
*
* @return the sorage type ID
*/
virtual uint8_t storageTypeId() = 0;
/// the probe ID
uint8_t id;
/// the probe name
......
......@@ -157,7 +157,7 @@ uint8_t OutputInternal::getBaseProbeId(BaseProbe *probe) const
uint8_t OutputInternal::getStorageTypeId(BaseProbe *probe) const
{
return probe->storageTypeId();
return (uint8_t)probe->getDataType();
}
string OutputInternal::getLogName(const OutputLog *log) const
......
......@@ -39,21 +39,21 @@
template<>
uint8_t Probe<int32_t>::storageTypeId()
datatype_t Probe<int32_t>::getDataType() const
{
return 0;
return INT32_TYPE;
}
template<>
uint8_t Probe<float>::storageTypeId()
datatype_t Probe<float>::getDataType() const
{
return 1;
return FLOAT_TYPE;
}
template<>
uint8_t Probe<double>::storageTypeId()
datatype_t Probe<double>::getDataType() const
{
return 2;
return DOUBLE_TYPE;
}
template<>
......@@ -90,30 +90,6 @@ bool Probe<float>::getData(unsigned char* buffer, size_t len) const
return true;
}
template<>
string Probe<float>::getStrData() const
{
std::stringstream strs;
strs.setf(std::ios_base::fixed);
strs.precision(12);
float val = this->get();
strs << val;
return strs.str();
}
template<>
string Probe<double>::getStrData() const
{
std::stringstream strs;
strs.setf(std::ios_base::fixed);
strs.precision(12);
float val = this->get();
strs << val;
return strs.str();
}
template<>
bool Probe<double>::getData(unsigned char* buffer, size_t len) const
{
......
......@@ -72,14 +72,12 @@ public:
bool getData(unsigned char* buffer, size_t len) const;
string getStrData() const;
datatype_t getDataType() const;
private:
Probe(uint8_t id, const string &name,
const string &unit,
bool enabled, sample_type_t type);
virtual uint8_t storageTypeId();
/// the concatenation of all values
T accumulator;
......@@ -152,16 +150,6 @@ T Probe<T>::get() const
return value;
}
template<typename T>
string Probe<T>::getStrData() const
{
std::stringstream strs;
T val = this->get();
strs << val;
return strs.str();
}
template<typename T>
size_t Probe<T>::getDataSize() const
{
......@@ -169,13 +157,13 @@ size_t Probe<T>::getDataSize() const
}
template<>
uint8_t Probe<int32_t>::storageTypeId();
datatype_t Probe<int32_t>::getDataType() const;
template<>
uint8_t Probe<float>::storageTypeId();
datatype_t Probe<float>::getDataType() const;
template<>
uint8_t Probe<double>::storageTypeId();
datatype_t Probe<double>::getDataType() const;
template<>
bool Probe<int32_t>::getData(unsigned char* buffer, size_t len) const;
......@@ -186,11 +174,5 @@ bool Probe<float>::getData(unsigned char* buffer, size_t len) const;
template<>
bool Probe<double>::getData(unsigned char* buffer, size_t len) const;
template<>
string Probe<float>::getStrData() const;
template<>
string Probe<double>::getStrData() const;
#endif
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