OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data_Namespace::ProcBuddyinfoParser Class Reference

Parse /proc/buddyinfo into a few fragmentation-related data. More...

#include <DataMgr.h>

Public Member Functions

void parseBuddyinfo ()
 
double getFragmentationPercent () const
 
size_t getSumAvailPages () const
 
size_t getSumHighestBlocks () const
 

Private Attributes

double frag_percent_ {0}
 
size_t sum_avail_pages_ {0}
 
size_t sum_highest_blocks_ {0}
 

Detailed Description

Parse /proc/buddyinfo into a few fragmentation-related data.

Definition at line 112 of file DataMgr.h.

Member Function Documentation

double Data_Namespace::ProcBuddyinfoParser::getFragmentationPercent ( ) const
inline

Definition at line 115 of file DataMgr.h.

References frag_percent_.

115 { return frag_percent_; }
size_t Data_Namespace::ProcBuddyinfoParser::getSumAvailPages ( ) const
inline

Definition at line 116 of file DataMgr.h.

References sum_avail_pages_.

116 { return sum_avail_pages_; }
size_t Data_Namespace::ProcBuddyinfoParser::getSumHighestBlocks ( ) const
inline

Definition at line 117 of file DataMgr.h.

References sum_highest_blocks_.

void Data_Namespace::ProcBuddyinfoParser::parseBuddyinfo ( )

Definition at line 846 of file DataMgr.cpp.

References frag_percent_, Data_Namespace::anonymous_namespace{DataMgr.cpp}::kErrorCodeUnableToOpenFile, parse_ast::line, sum_avail_pages_, sum_highest_blocks_, and Data_Namespace::anonymous_namespace{DataMgr.cpp}::tokenize().

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

846  {
847  std::ifstream file("/proc/buddyinfo");
848  if (!file.is_open()) {
851  return;
852  }
853 
854  constexpr unsigned max_line_size = 256;
855  char line[max_line_size];
856 
857  BuddyinfoBlocks frag; // Used to calculate frag_percent_.
858 
859  // Example: line = "Node 0, zone Normal 1 2 3 4 5 6 7 8 9 10 11"
860  // No CHECKs are done, and no exceptions are thrown. The worst that can happen is
861  // bad logs, which is not worth crashing the server or showing an error to the user.
862  while (file.getline(line, max_line_size)) {
863  auto tokens = tokenize(line); // Split on spaces.
864  // Sanity check on tokens.size() and known tokens.
865  if (5u <= tokens.size() && tokens[0] == "Node" && tokens[2] == "zone") {
866  BuddyinfoBlocks row(tokens.data() + 4, tokens.size() - 4);
867 
868  // Calculate member variables
869  frag.addBlocks(row);
870  if (tokens[3].substr(0, 3) != "DMA") {
871  sum_avail_pages_ += row.sumAvailPages();
872  sum_highest_blocks_ += row.highestBlock();
873  }
874  }
875  }
876  frag_percent_ = frag.fragPercent();
877 }
small_vector< std::string_view, kMaxBuddyinfoTokens > tokenize(std::string_view const str)
Definition: DataMgr.cpp:824
tuple line
Definition: parse_ast.py:10

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

double Data_Namespace::ProcBuddyinfoParser::frag_percent_ {0}
private

Definition at line 120 of file DataMgr.h.

Referenced by getFragmentationPercent(), and parseBuddyinfo().

size_t Data_Namespace::ProcBuddyinfoParser::sum_avail_pages_ {0}
private

Definition at line 121 of file DataMgr.h.

Referenced by getSumAvailPages(), and parseBuddyinfo().

size_t Data_Namespace::ProcBuddyinfoParser::sum_highest_blocks_ {0}
private

Definition at line 122 of file DataMgr.h.

Referenced by getSumHighestBlocks(), and parseBuddyinfo().


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