OmniSciDB  72c90bc290
 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 112 of file DataMgr.h.

Constructor & Destructor Documentation

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

Definition at line 118 of file DataMgr.h.

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

Member Function Documentation

auto Data_Namespace::ProcBuddyinfoParser::begin ( )
inline

Definition at line 169 of file DataMgr.h.

References orders_.

169  {
170  return orders_.begin();
171  }
std::vector< size_t > orders_
Definition: DataMgr.h:114
auto Data_Namespace::ProcBuddyinfoParser::end ( )
inline

Definition at line 172 of file DataMgr.h.

References orders_.

172  {
173  return orders_.end();
174  }
std::vector< size_t > orders_
Definition: DataMgr.h:114
auto Data_Namespace::ProcBuddyinfoParser::getFragmentationPercent ( )
inline

Definition at line 175 of file DataMgr.h.

References fragmentationPercent_.

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

175  {
176  return fragmentationPercent_;
177  }

+ Here is the caller graph for this function:

auto Data_Namespace::ProcBuddyinfoParser::getInputText ( )
inline

Definition at line 178 of file DataMgr.h.

References inputText_.

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

Definition at line 166 of file DataMgr.h.

References orders_.

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

Member Data Documentation

size_t Data_Namespace::ProcBuddyinfoParser::fragmentationPercent_
private

Definition at line 115 of file DataMgr.h.

Referenced by getFragmentationPercent().

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

Definition at line 113 of file DataMgr.h.

Referenced by getInputText().

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

Definition at line 114 of file DataMgr.h.

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


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