Commit 3f8b1935 authored by Alessio Netti's avatar Alessio Netti
Browse files

ProcFS plugin optimization

- Most metric name checks in the procstat parser now use plain C string
    matching instead of regular expressions
- Overhead has been reduced to 1.09% for a full vmstat + meminfo +
    procstat instantiation on a CoolMUC3 node (2700+ metrics each sec)
- Overhead for a minimal meminfo instantiation is 0.05% (44 metrics)
- We can safely assume linear scaling of the plugin in function of the
    number of metrics
parent 886a0016
......@@ -7,6 +7,7 @@
//
#include "ProcfsParser.h"
#include <iostream>
// Definitions for the ProcfsParser abstract class
......@@ -220,7 +221,7 @@ std::vector<std::string> *ProcstatParser::_readNames() {
}
// We check whether the line is cpu core-related or not through a regular expression
// If the name contains the "cpu" keyword, then it is cpu-related
if( boost::regex_search(lineToken, this->_match, this->reg_exp) ) {
if( strncmp(lineToken, this->_cpu_prefix, this->_cpu_prefix_len) == 0 ) {
// If a match to an integer number is found within the name, the metric is related to a specific core. Otherwise,
// it is considered as a system-wide metric
try { currCPU = !boost::regex_search(lineToken, this->_match, reg_exp_num) ? -1 : (short)std::stol(this->_match.str(0)); }
......@@ -273,7 +274,7 @@ std::vector<reading_t> *ProcstatParser::_readMetrics() {
// First token is discarded, represents the metric's name
if(lineToken == NULL) return NULL;
// We check whether the line is CPU core-related or not (see _readNames)
if( boost::regex_search(lineToken, this->_match, this->reg_exp) ) {
if( strncmp(lineToken, this->_cpu_prefix, this->_cpu_prefix_len) == 0 ) {
ctrInner = 0;
// We iterate over the line and capture all of the CPU core-related metrics
while( (lineToken = strtok_r(NULL, this->LINE_SEP, &savePtr)) != NULL ) {
......
......@@ -118,7 +118,10 @@ protected:
enum { DEFAULTMETRICS = 10 };
const std::string DEFAULT_NAMES[DEFAULTMETRICS] = {"user", "nice", "system", "idle", "iowait", "irq", "softirq", "steal", "guest", "guest_nice"};
// Regex to match strings beginning with the "cpu" keyword
const boost::regex reg_exp = boost::regex("^cpu");
// C strings that encode the prefixes of cpu-related lines
const char *_cpu_prefix = "cpu";
const short _cpu_prefix_len = strlen(this->_cpu_prefix);
// Regex to match strings ending with integer numbers (in this case, CPU core IDs)
const boost::regex reg_exp_num = boost::regex("[0-9]+$");
};
......
Supports Markdown
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