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) ...@@ -124,6 +124,5 @@ void ProcfsConfigurator::sensorGroup(ProcfsSensorGroup &sGroup, CFG_VAL config)
LOG(debug) << " Number of metrics found: " << numMetrics; LOG(debug) << " Number of metrics found: " << numMetrics;
// We assign the final sensor objects as parsed in the target file, and assign the parser object // We assign the final sensor objects as parsed in the target file, and assign the parser object
sGroup.replaceSensors(parser->getSensors());
sGroup.setParser(parser); sGroup.setParser(parser);
} }
...@@ -167,6 +167,7 @@ std::vector<ureading_t> *ProcfsParser::readSensors() { ...@@ -167,6 +167,7 @@ std::vector<ureading_t> *ProcfsParser::readSensors() {
* @return true if successful, false otherwise * @return true if successful, false otherwise
*/ */
bool MeminfoParser::_readNames(std::map<std::string, ProcfsSBPtr> *sensorMap, std::set<int> *cpuSet) { bool MeminfoParser::_readNames(std::map<std::string, ProcfsSBPtr> *sensorMap, std::set<int> *cpuSet) {
_foundCPUs.clear();
if (_sensors == NULL) { if (_sensors == NULL) {
bool memUsedEnabled = sensorMap != NULL && !sensorMap->empty() && sensorMap->find(_memUsedToken) != sensorMap->end(); bool memUsedEnabled = sensorMap != NULL && !sensorMap->empty() && sensorMap->find(_memUsedToken) != sensorMap->end();
_memFreeLine = -1; _memFreeLine = -1;
...@@ -333,6 +334,7 @@ bool MeminfoParser::_readMetrics() { ...@@ -333,6 +334,7 @@ bool MeminfoParser::_readMetrics() {
* @return true if successful, false otherwise * @return true if successful, false otherwise
*/ */
bool ProcstatParser::_readNames(std::map<std::string, ProcfsSBPtr> *sensorMap, std::set<int> *cpuSet) { bool ProcstatParser::_readNames(std::map<std::string, ProcfsSBPtr> *sensorMap, std::set<int> *cpuSet) {
_foundCPUs.clear();
if (_sensors == NULL) { if (_sensors == NULL) {
_numMetrics = 0; _numMetrics = 0;
_numInternalMetrics = 0; _numInternalMetrics = 0;
...@@ -419,6 +421,8 @@ bool ProcstatParser::_readNames(std::map<std::string, ProcfsSBPtr> *sensorMap, s ...@@ -419,6 +421,8 @@ bool ProcstatParser::_readNames(std::map<std::string, ProcfsSBPtr> *sensorMap, s
} }
colCtr++; 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 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 // - The cpu in said line is not part of the input CPU set
......
...@@ -65,6 +65,7 @@ class ProcfsParser { ...@@ -65,6 +65,7 @@ class ProcfsParser {
virtual void close(); virtual void close();
// Setters and getters // Setters and getters
std::set<int>& getFoundCPUs() {return _foundCPUs; }
std::string getPath() { return _path; } std::string getPath() { return _path; }
int getHtVal() { return _htVal; } int getHtVal() { return _htVal; }
unsigned int getNumMetrics() { return _numMetrics; } unsigned int getNumMetrics() { return _numMetrics; }
...@@ -104,6 +105,7 @@ class ProcfsParser { ...@@ -104,6 +105,7 @@ class ProcfsParser {
std::vector<char> _skipColumn; std::vector<char> _skipColumn;
// Internal variables // Internal variables
std::set<int> _foundCPUs;
bool _initialized; bool _initialized;
uint64_t _scalingFactor; uint64_t _scalingFactor;
unsigned int _cacheIndex; unsigned int _cacheIndex;
......
...@@ -54,21 +54,25 @@ ProcfsSensorGroup::~ProcfsSensorGroup() { ...@@ -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. * 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<std::string> sensorSet = std::set<std::string>();
std::set<int> effCpuSet; for (const auto &s_new : *parser->getSensors()) {
for (const auto &s_new : *newSensors) {
sensorSet.insert(s_new->getMetric()); sensorSet.insert(s_new->getMetric());
effCpuSet.insert(s_new->getCPUId());
} }
std::set<int> &effCpuSet = parser->getFoundCPUs();
for (const auto &s : _sensors) for (const auto &s : _sensors)
if (sensorSet.find(s->getMetric()) == sensorSet.end()) if (sensorSet.find(s->getMetric()) == sensorSet.end())
...@@ -81,7 +85,7 @@ void ProcfsSensorGroup::replaceSensors(std::vector<ProcfsSBPtr> *newSensors) { ...@@ -81,7 +85,7 @@ void ProcfsSensorGroup::replaceSensors(std::vector<ProcfsSBPtr> *newSensors) {
effCpuSet.clear(); effCpuSet.clear();
_sensors.clear(); _sensors.clear();
_baseSensors.clear(); _baseSensors.clear();
for (auto s : *newSensors) for (auto s : *parser->getSensors())
pushBackSensor(std::make_shared<ProcfsSensorBase>(*s)); pushBackSensor(std::make_shared<ProcfsSensorBase>(*s));
} }
......
...@@ -57,8 +57,8 @@ class ProcfsSensorGroup : public SensorGroupTemplate<ProcfsSensorBase> { ...@@ -57,8 +57,8 @@ class ProcfsSensorGroup : public SensorGroupTemplate<ProcfsSensorBase> {
bool execOnStart() final override; bool execOnStart() final override;
// Setters and getters // Setters and getters
void setParser(ProcfsParser *parser);
void setHtVal(int htVal) { this->_htVal = htVal; } void setHtVal(int htVal) { this->_htVal = htVal; }
void setParser(ProcfsParser *parser) { this->_parser = parser; }
void setType(std::string t) { this->_type = t; } void setType(std::string t) { this->_type = t; }
void setPath(std::string p) { this->_path = p; } void setPath(std::string p) { this->_path = p; }
void setCpuSet(std::set<int> s) { this->_cpuSet = s; } void setCpuSet(std::set<int> s) { this->_cpuSet = s; }
...@@ -74,8 +74,6 @@ class ProcfsSensorGroup : public SensorGroupTemplate<ProcfsSensorBase> { ...@@ -74,8 +74,6 @@ class ProcfsSensorGroup : public SensorGroupTemplate<ProcfsSensorBase> {
std::set<int> *getCpuSet() { return &this->_cpuSet; } std::set<int> *getCpuSet() { return &this->_cpuSet; }
uint64_t getScalingFactor() { return this->_scalingFactor; } uint64_t getScalingFactor() { return this->_scalingFactor; }
void replaceSensors(std::vector<ProcfsSBPtr> *newSensors);
void printGroupConfig(LOG_LEVEL ll, unsigned leadingSpaces = 16) final override; void printGroupConfig(LOG_LEVEL ll, unsigned leadingSpaces = 16) final override;
private: 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