OmniSciDB  8a228a1076
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 69 of file DataMgr.h.

Constructor & Destructor Documentation

◆ ProcMeminfoParser()

Data_Namespace::ProcMeminfoParser::ProcMeminfoParser ( )
inline

Definition at line 73 of file DataMgr.h.

References CHECK, split(), strip(), and to_lower().

73  {
74  std::ifstream f("/proc/meminfo");
75  std::stringstream ss;
76  ss << f.rdbuf();
77 
78  for (const std::string& line : split(ss.str(), "\n")) {
79  if (line.empty()) {
80  continue;
81  }
82  const auto nv = split(line, ":", 1);
83  CHECK(nv.size() == 2) << "unexpected line format in /proc/meminfo: " << line;
84  const auto name = strip(nv[0]), value = to_lower(strip(nv[1]));
85  auto v = split(value);
86  CHECK(v.size() == 1 || v.size() == 2)
87  << "unexpected line format in /proc/meminfo: " << line;
88  items_[name] = std::atoll(v[0].c_str());
89  if (v.size() == 2) {
90  CHECK(v[1] == "kb") << "unexpected unit suffix in /proc/meminfo: " << line;
91  items_[name] *= 1024;
92  }
93  }
94  }
std::string to_lower(const std::string &str)
std::unordered_map< std::string, size_t > items_
Definition: DataMgr.h:70
std::string strip(std::string_view str)
trim any whitespace from the left and right ends of a string
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
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:

Member Function Documentation

◆ begin()

auto Data_Namespace::ProcMeminfoParser::begin ( )
inline

Definition at line 97 of file DataMgr.h.

97 { return items_.begin(); }
std::unordered_map< std::string, size_t > items_
Definition: DataMgr.h:70

◆ end()

auto Data_Namespace::ProcMeminfoParser::end ( )
inline

Definition at line 98 of file DataMgr.h.

98 { return items_.end(); }
std::unordered_map< std::string, size_t > items_
Definition: DataMgr.h:70

◆ operator[]()

auto Data_Namespace::ProcMeminfoParser::operator[] ( const std::string &  name)
inline

Definition at line 96 of file DataMgr.h.

96 { return items_[name]; }
std::unordered_map< std::string, size_t > items_
Definition: DataMgr.h:70

Member Data Documentation

◆ items_

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

Definition at line 70 of file DataMgr.h.


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