Commit 02abd6cd authored by Alessio Netti's avatar Alessio Netti
Browse files

Analytics: minor changes to QueryEngine

- querySensor does not return NULL pointers anymore, but always
the "buffer" input argument
- the previous implementation was more descriptive of error statuses,
but much more prone to leaking memory in case of improper usage
- Also fixed a warning in the MSR plugin
parent 4652717e
......@@ -189,6 +189,7 @@ public:
* @param rel If true, the input timestamps are considered to be relative offset against "now"
* @return Pointer to a vector containing readings for the given query
*/
//TODO: consider switching to a double pointer buffer input and boolean/int output
vector<reading_t>* querySensor(const string& name, const uint64_t startTs, const uint64_t endTs, vector<reading_t>* buffer, const bool rel=true) {
if(!_callback)
throw runtime_error("Query Engine: callback not set!");
......
......@@ -101,11 +101,11 @@ std::vector<qeJobData>* jobQueryCallback(const uint32_t jobId, const uint64_t st
uint64_t endTsInt = rel ? now - endTs : endTs;
DCDB::TimeStamp start(startTsInt), end(endTsInt);
err = myJobDataStore->getJobsInIntervalRunning(tempList, start, end);
if(err != JD_OK) return NULL;
if(err != JD_OK) return buffer;
} else {
// Getting a single job by id
err = myJobDataStore->getJobById(tempData, jobId);
if(err != JD_OK) return NULL;
if(err != JD_OK) return buffer;
tempList.push_back(tempData);
}
......@@ -129,7 +129,7 @@ std::vector<reading_t>* sensorQueryCallback(const string& name, const uint64_t s
try {
topic = queryEngine.getNavigator()->getNodeTopic(name);
} catch(const std::domain_error& e) {
return NULL;
return buffer;
}
std::vector <reading_t> *output = NULL;
DCDB::SensorId sid;
......@@ -169,7 +169,7 @@ std::vector<reading_t>* sensorQueryCallback(const string& name, const uint64_t s
}
catch(const std::exception& e) {
if(!buffer && output) delete output;
return NULL;
return buffer;
}
return output;
}
......
......@@ -78,14 +78,14 @@ boost::shared_ptr<boost::asio::io_service::work> keepAliveWork;
std::vector<reading_t>* sensorQueryCallback(const string& name, const uint64_t startTs, const uint64_t endTs, std::vector<reading_t>* buffer, const bool rel) {
// Returning NULL if the query engine is being updated
if(_queryEngine.updating.load()) return NULL;
if(_queryEngine.updating.load()) return buffer;
++_queryEngine.access;
std::vector<reading_t>* res = NULL;
std::vector<reading_t>* res = buffer;
shared_ptr<map<string, SBasePtr>> sensorMap = _queryEngine.getSensorMap();
if(sensorMap!=nullptr && sensorMap->count(name)>0) {
SBasePtr sensor = sensorMap->at(name);
res = sensor->isInit() ? sensor->getCache()->getView(startTs, endTs, buffer, rel) : NULL;
res = sensor->isInit() ? sensor->getCache()->getView(startTs, endTs, buffer, rel) : buffer;
}
--_queryEngine.access;
return res;
......
......@@ -102,7 +102,7 @@ private:
void program_fixed();
unsigned int _htAggregation; /**< Value for hyper-threading aggregation. Zero indicates disabled HT agg. */
int _number_metrics_per_cpu;
//int _number_metrics_per_cpu;
unsigned int _total_number_cpus;
std::vector<msrSensorBin> _sensorBins; /**< Bins to sort sensors according to their _cpu. */
int32_t msr_read(uint64_t msr_number, uint64_t *value, unsigned int cpu);
......
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