OmniSciDB  91042dcc5b
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data_Namespace::ProcMeminfoParser Class Reference

Parse /proc/meminfo into key/value pairs. More...

#include <DataMgr.h>

Public Member Functions

 ProcMeminfoParser ()
 
auto operator[] (const std::string &name)
 
auto begin ()
 
auto end ()
 

Private Attributes

std::unordered_map
< std::string, size_t > 
items_
 

Detailed Description

Parse /proc/meminfo into key/value pairs.

Definition at line 78 of file DataMgr.h.

Constructor & Destructor Documentation

Data_Namespace::ProcMeminfoParser::ProcMeminfoParser ( )
inline

Definition at line 82 of file DataMgr.h.

References CHECK, f, items_, parse_ast::line, setup::name, split(), strip(), and to_lower().

82  {
83  std::ifstream f("/proc/meminfo");
84  std::stringstream ss;
85  ss << f.rdbuf();
86 
87  for (const std::string& line : split(ss.str(), "\n")) {
88  if (line.empty()) {
89  continue;
90  }
91  const auto nv = split(line, ":", 1);
92  CHECK(nv.size() == 2) << "unexpected line format in /proc/meminfo: " << line;
93  const auto name = strip(nv[0]), value = to_lower(strip(nv[1]));
94  auto v = split(value);
95  CHECK(v.size() == 1 || v.size() == 2)
96  << "unexpected line format in /proc/meminfo: " << line;
97  items_[name] = std::atoll(v[0].c_str());
98  if (v.size() == 2) {
99  CHECK(v[1] == "kb") << "unexpected unit suffix in /proc/meminfo: " << line;
100  items_[name] *= 1024;
101  }
102  }
103  }
std::string to_lower(const std::string &str)
std::unordered_map< std::string, size_t > items_
Definition: DataMgr.h:79
std::string strip(std::string_view str)
trim any whitespace from the left and right ends of a string
string name
Definition: setup.in.py:72
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
#define CHECK(condition)
Definition: Logger.h:211
char * f

+ Here is the call graph for this function:

Member Function Documentation

auto Data_Namespace::ProcMeminfoParser::begin ( )
inline

Definition at line 106 of file DataMgr.h.

References items_.

106 { return items_.begin(); }
std::unordered_map< std::string, size_t > items_
Definition: DataMgr.h:79
auto Data_Namespace::ProcMeminfoParser::end ( )
inline

Definition at line 107 of file DataMgr.h.

References items_.

107 { return items_.end(); }
std::unordered_map< std::string, size_t > items_
Definition: DataMgr.h:79
auto Data_Namespace::ProcMeminfoParser::operator[] ( const std::string &  name)
inline

Definition at line 105 of file DataMgr.h.

References items_, and setup::name.

105 { return items_[name]; }
std::unordered_map< std::string, size_t > items_
Definition: DataMgr.h:79
string name
Definition: setup.in.py:72

Member Data Documentation

std::unordered_map<std::string, size_t> Data_Namespace::ProcMeminfoParser::items_
private

Definition at line 79 of file DataMgr.h.

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


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