OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 113 of file DataMgr.h.

Constructor & Destructor Documentation

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

Definition at line 119 of file DataMgr.h.

119  {}) {
120  if (text.empty()) {
121  std::ifstream f("/proc/buddyinfo");
122  std::stringstream ss;
123  ss << f.rdbuf();
124  text = ss.str();
125  }
126  inputText_ = text;
127 
128  const size_t skipped_columns = 4;
129  // NOTE(sy): For now this calculation ignores the first four buddyinfo columns,
130  // but in the future we could break out subscores by node and/or by zone.
131  size_t number_of_columns = 0;
132  for (const std::string& line : split(text, "\n")) {
133  if (line.empty()) {
134  continue;
135  }
136  const auto columns = split(line);
137  CHECK_GT(columns.size(), skipped_columns) << "unexpected line format: " << line;
138  if (number_of_columns != 0) {
139  CHECK_EQ(columns.size(), number_of_columns)
140  << "expected line to have " << number_of_columns << " columns: " << line;
141  } else {
142  number_of_columns = columns.size();
143  orders_.resize(number_of_columns - skipped_columns, 0);
144  }
145  for (size_t i = skipped_columns; i < number_of_columns; ++i) {
146  orders_[i - skipped_columns] += strtoull(columns[i].c_str(), NULL, 10);
147  }
148  }
149 #ifdef __linux__
150  const long page_size =
151  sysconf(_SC_PAGE_SIZE); // in case x86-64 is configured to use 2MB pages
152 #else
153  const long page_size = heavyai::get_page_size();
154 #endif
155  size_t scaled = 0;
156  size_t total = 0;
157  for (size_t order = 0; order < orders_.size(); ++order) {
158  const size_t bytes = orders_[order] * (size_t(1) << order) * page_size;
159  scaled += (bytes * (orders_.size() - 1 - order)) / (orders_.size() - 1);
160  total += bytes;
161  }
162 
163  CHECK_GT(total, size_t(0)) << "failed to parse:\n" << text;
164  fragmentationPercent_ = (scaled * 100) / total;
165  }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
#define CHECK_GT(x, y)
Definition: Logger.h:234
constexpr double f
Definition: Utm.h:31
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
tuple line
Definition: parse_ast.py:10
std::vector< size_t > orders_
Definition: DataMgr.h:115
int get_page_size()
Definition: heavyai_fs.cpp:29

Member Function Documentation

auto Data_Namespace::ProcBuddyinfoParser::begin ( )
inline

Definition at line 168 of file DataMgr.h.

References orders_.

168 { return orders_.begin(); }
std::vector< size_t > orders_
Definition: DataMgr.h:115
auto Data_Namespace::ProcBuddyinfoParser::end ( )
inline

Definition at line 169 of file DataMgr.h.

References orders_.

169 { return orders_.end(); }
std::vector< size_t > orders_
Definition: DataMgr.h:115
auto Data_Namespace::ProcBuddyinfoParser::getFragmentationPercent ( )
inline

Definition at line 170 of file DataMgr.h.

References fragmentationPercent_.

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

+ Here is the caller graph for this function:

auto Data_Namespace::ProcBuddyinfoParser::getInputText ( )
inline

Definition at line 171 of file DataMgr.h.

References inputText_.

171 { return inputText_; }
auto Data_Namespace::ProcBuddyinfoParser::operator[] ( size_t  order)
inline

Definition at line 167 of file DataMgr.h.

References orders_.

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

Member Data Documentation

size_t Data_Namespace::ProcBuddyinfoParser::fragmentationPercent_
private

Definition at line 116 of file DataMgr.h.

Referenced by getFragmentationPercent().

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

Definition at line 114 of file DataMgr.h.

Referenced by getInputText().

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

Definition at line 115 of file DataMgr.h.

Referenced by begin(), end(), and operator[]().


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