Commit d7c31f24 authored by Alessio Netti's avatar Alessio Netti
Browse files

ProcFS: better logging when checking CPU sets

parent 87ef2d25
......@@ -124,6 +124,5 @@ void ProcfsConfigurator::sensorGroup(ProcfsSensorGroup &sGroup, CFG_VAL config)
LOG(debug) << " Number of metrics found: " << numMetrics;
// We assign the final sensor objects as parsed in the target file, and assign the parser object
sGroup.replaceSensors(parser->getSensors());
sGroup.setParser(parser);
}
......@@ -167,6 +167,7 @@ std::vector<ureading_t> *ProcfsParser::readSensors() {
* @return true if successful, false otherwise
*/
bool MeminfoParser::_readNames(std::map<std::string, ProcfsSBPtr> *sensorMap, std::set<int> *cpuSet) {
_foundCPUs.clear();
if (_sensors == NULL) {
bool memUsedEnabled = sensorMap != NULL && !sensorMap->empty() && sensorMap->find(_memUsedToken) != sensorMap->end();
_memFreeLine = -1;
......@@ -333,6 +334,7 @@ bool MeminfoParser::_readMetrics() {
* @return true if successful, false otherwise
*/
bool ProcstatParser::_readNames(std::map<std::string, ProcfsSBPtr> *sensorMap, std::set<int> *cpuSet) {
_foundCPUs.clear();
if (_sensors == NULL) {
_numMetrics = 0;
_numInternalMetrics = 0;
......@@ -419,6 +421,8 @@ bool ProcstatParser::_readNames(std::map<std::string, ProcfsSBPtr> *sensorMap, s
}
colCtr++;
}
if(currCPU!=-1)
_foundCPUs.insert(currCPU);
}
// The line is flagged as skippable if no columns should be read from it. This can happen in two cases:
// - The cpu in said line is not part of the input CPU set
......
......@@ -65,6 +65,7 @@ class ProcfsParser {
virtual void close();
// Setters and getters
std::set<int>& getFoundCPUs() {return _foundCPUs; }
std::string getPath() { return _path; }
int getHtVal() { return _htVal; }
unsigned int getNumMetrics() { return _numMetrics; }
......@@ -104,6 +105,7 @@ class ProcfsParser {
std::vector<char> _skipColumn;
// Internal variables
std::set<int> _foundCPUs;
bool _initialized;
uint64_t _scalingFactor;
unsigned int _cacheIndex;
......
......@@ -54,21 +54,25 @@ ProcfsSensorGroup::~ProcfsSensorGroup() {
}
/**
* Replaces all sensor objects stored in the group with those contained in newSensors
* Assigns a new parser and replaces the internal sensor objects
*
* Old sensors are deleted and cleared, therefore make sure that newSensors does not contain any object previously used
* Old sensors are deleted and cleared, therefore make sure the parser does not contain any object previously used
* by the sensor group.
*
* @param newSensors: Vector of ProcfsSensorBase objects to replace the old set
* @param parser: Pointer to a ProcfsParser object
*
*/
void ProcfsSensorGroup::replaceSensors(std::vector<ProcfsSBPtr> *newSensors) {
void ProcfsSensorGroup::setParser(ProcfsParser *parser) {
if(parser)
_parser = parser;
else
return;
std::set<std::string> sensorSet = std::set<std::string>();
std::set<int> effCpuSet;
for (const auto &s_new : *newSensors) {
for (const auto &s_new : *parser->getSensors()) {
sensorSet.insert(s_new->getMetric());
effCpuSet.insert(s_new->getCPUId());
}
std::set<int> &effCpuSet = parser->getFoundCPUs();
for (const auto &s : _sensors)
if (sensorSet.find(s->getMetric()) == sensorSet.end())
......@@ -81,7 +85,7 @@ void ProcfsSensorGroup::replaceSensors(std::vector<ProcfsSBPtr> *newSensors) {
effCpuSet.clear();
_sensors.clear();
_baseSensors.clear();
for (auto s : *newSensors)
for (auto s : *parser->getSensors())
pushBackSensor(std::make_shared<ProcfsSensorBase>(*s));
}
......
......@@ -57,8 +57,8 @@ class ProcfsSensorGroup : public SensorGroupTemplate<ProcfsSensorBase> {
bool execOnStart() final override;
// Setters and getters
void setParser(ProcfsParser *parser);
void setHtVal(int htVal) { this->_htVal = htVal; }
void setParser(ProcfsParser *parser) { this->_parser = parser; }
void setType(std::string t) { this->_type = t; }
void setPath(std::string p) { this->_path = p; }
void setCpuSet(std::set<int> s) { this->_cpuSet = s; }
......@@ -74,8 +74,6 @@ class ProcfsSensorGroup : public SensorGroupTemplate<ProcfsSensorBase> {
std::set<int> *getCpuSet() { return &this->_cpuSet; }
uint64_t getScalingFactor() { return this->_scalingFactor; }
void replaceSensors(std::vector<ProcfsSBPtr> *newSensors);
void printGroupConfig(LOG_LEVEL ll, unsigned leadingSpaces = 16) final override;
private:
......
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