OmniSciDB  8a228a1076
Data_Namespace::ProcBuddyinfoParser Class Reference

Parse /proc/buddyinfo into a Fragmentation health score. More...

#include <DataMgr.h>

+ Collaboration diagram for Data_Namespace::ProcBuddyinfoParser:

Public Member Functions

 ProcBuddyinfoParser (std::string text={})
 
auto operator[] (size_t order)
 
auto begin ()
 
auto end ()
 
auto getFragmentationPercent ()
 
auto getInputText ()
 

Private Attributes

std::string inputText_
 
std::vector< size_t > orders_
 
size_t fragmentationPercent_
 

Detailed Description

Parse /proc/buddyinfo into a Fragmentation health score.

Definition at line 102 of file DataMgr.h.

Constructor & Destructor Documentation

◆ ProcBuddyinfoParser()

Data_Namespace::ProcBuddyinfoParser::ProcBuddyinfoParser ( std::string  text = {})
inline

Definition at line 108 of file DataMgr.h.

References CHECK_EQ, CHECK_GT, and split().

108  {}) {
109  if (text.empty()) {
110  std::ifstream f("/proc/buddyinfo");
111  std::stringstream ss;
112  ss << f.rdbuf();
113  text = ss.str();
114  }
115  inputText_ = text;
116 
117  const size_t skipped_columns = 4;
118  // NOTE(sy): For now this calculation ignores the first four buddyinfo columns,
119  // but in the future we could break out subscores by node and/or by zone.
120  size_t number_of_columns = 0;
121  for (const std::string& line : split(text, "\n")) {
122  if (line.empty()) {
123  continue;
124  }
125  const auto columns = split(line);
126  CHECK_GT(columns.size(), skipped_columns) << "unexpected line format: " << line;
127  if (number_of_columns != 0) {
128  CHECK_EQ(columns.size(), number_of_columns)
129  << "expected line to have " << number_of_columns << " columns: " << line;
130  } else {
131  number_of_columns = columns.size();
132  orders_.resize(number_of_columns - skipped_columns, 0);
133  }
134  for (size_t i = skipped_columns; i < number_of_columns; ++i) {
135  orders_[i - skipped_columns] += strtoull(columns[i].c_str(), NULL, 10);
136  }
137  }
138 
139  const long page_size =
140  sysconf(_SC_PAGE_SIZE); // in case x86-64 is configured to use 2MB pages
141  size_t scaled = 0;
142  size_t total = 0;
143  for (size_t order = 0; order < orders_.size(); ++order) {
144  const size_t bytes = orders_[order] * (size_t(1) << order) * page_size;
145  scaled += (bytes * (orders_.size() - 1 - order)) / (orders_.size() - 1);
146  total += bytes;
147  }
148 
149  CHECK_GT(total, size_t(0)) << "failed to parse:\n" << text;
150  fragmentationPercent_ = (scaled * 100) / total;
151  }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
#define CHECK_GT(x, y)
Definition: Logger.h:209
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings
std::vector< size_t > orders_
Definition: DataMgr.h:104
+ Here is the call graph for this function:

Member Function Documentation

◆ begin()

auto Data_Namespace::ProcBuddyinfoParser::begin ( )
inline

Definition at line 154 of file DataMgr.h.

154 { return orders_.begin(); }
std::vector< size_t > orders_
Definition: DataMgr.h:104

◆ end()

auto Data_Namespace::ProcBuddyinfoParser::end ( )
inline

Definition at line 155 of file DataMgr.h.

155 { return orders_.end(); }
std::vector< size_t > orders_
Definition: DataMgr.h:104

◆ getFragmentationPercent()

auto Data_Namespace::ProcBuddyinfoParser::getFragmentationPercent ( )
inline

Definition at line 156 of file DataMgr.h.

Referenced by Data_Namespace::DataMgr::getSystemMemoryUsage().

+ Here is the caller graph for this function:

◆ getInputText()

auto Data_Namespace::ProcBuddyinfoParser::getInputText ( )
inline

Definition at line 157 of file DataMgr.h.

157 { return inputText_; }

◆ operator[]()

auto Data_Namespace::ProcBuddyinfoParser::operator[] ( size_t  order)
inline

Definition at line 153 of file DataMgr.h.

153 { return orders_[order]; }
std::vector< size_t > orders_
Definition: DataMgr.h:104

Member Data Documentation

◆ fragmentationPercent_

size_t Data_Namespace::ProcBuddyinfoParser::fragmentationPercent_
private

Definition at line 105 of file DataMgr.h.

◆ inputText_

std::string Data_Namespace::ProcBuddyinfoParser::inputText_
private

Definition at line 103 of file DataMgr.h.

◆ orders_

std::vector<size_t> Data_Namespace::ProcBuddyinfoParser::orders_
private

Definition at line 104 of file DataMgr.h.


The documentation for this class was generated from the following file: