OmniSciDB  91042dcc5b
 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 111 of file DataMgr.h.

Constructor & Destructor Documentation

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

Definition at line 117 of file DataMgr.h.

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

Member Function Documentation

auto Data_Namespace::ProcBuddyinfoParser::begin ( )
inline

Definition at line 166 of file DataMgr.h.

References orders_.

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

Definition at line 167 of file DataMgr.h.

References orders_.

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

Definition at line 168 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 169 of file DataMgr.h.

References inputText_.

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

Definition at line 165 of file DataMgr.h.

References orders_.

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

Member Data Documentation

size_t Data_Namespace::ProcBuddyinfoParser::fragmentationPercent_
private

Definition at line 114 of file DataMgr.h.

Referenced by getFragmentationPercent().

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

Definition at line 112 of file DataMgr.h.

Referenced by getInputText().

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

Definition at line 113 of file DataMgr.h.

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


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