OmniSciDB  a5dc49c757
 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 79 of file DataMgr.h.

Constructor & Destructor Documentation

Data_Namespace::ProcMeminfoParser::ProcMeminfoParser ( )
inline

Definition at line 83 of file DataMgr.h.

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

83  {
84  std::ifstream f("/proc/meminfo");
85  std::stringstream ss;
86  ss << f.rdbuf();
87 
88  for (const std::string& line : split(ss.str(), "\n")) {
89  if (line.empty()) {
90  continue;
91  }
92  const auto nv = split(line, ":", 1);
93  CHECK(nv.size() == 2) << "unexpected line format in /proc/meminfo: " << line;
94  const auto name = strip(nv[0]), value = to_lower(strip(nv[1]));
95  auto v = split(value);
96  CHECK(v.size() == 1 || v.size() == 2)
97  << "unexpected line format in /proc/meminfo: " << line;
98  items_[name] = std::atoll(v[0].c_str());
99  if (v.size() == 2) {
100  CHECK(v[1] == "kb") << "unexpected unit suffix in /proc/meminfo: " << line;
101  items_[name] *= 1024;
102  }
103  }
104  }
std::string to_lower(const std::string &str)
std::unordered_map< std::string, size_t > items_
Definition: DataMgr.h:80
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
tuple line
Definition: parse_ast.py:10
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
#define CHECK(condition)
Definition: Logger.h:291
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

Member Function Documentation

auto Data_Namespace::ProcMeminfoParser::begin ( )
inline

Definition at line 107 of file DataMgr.h.

References items_.

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

Definition at line 108 of file DataMgr.h.

References items_.

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

Definition at line 106 of file DataMgr.h.

References items_, and setup::name.

106 { return items_[name]; }
std::unordered_map< std::string, size_t > items_
Definition: DataMgr.h:80
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 80 of file DataMgr.h.

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


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