src/linux_parser.cpp
// Read and return the system memory utilization
Read and return the system memory utilization
Read and return the system memory utilization
float LinuxParser::MemoryUtilization() { 
  string mem_total, mem_free;
  string line, label;
  std::ifstream stream(kProcDirectory + kMeminfoFilename);
  if (stream.is_open()) {
    std::getline(stream,line);
    std::istringstream linestream1(line);
    linestream1 >> label >> mem_total;
    std::getline(stream,line);
    std::istringstream linestream2(line);
    linestream2 >> label >> mem_free;
  }
  return (stof(mem_total) - stof(mem_free)) / stof(mem_total); 
}
float LinuxParser :: MemoryUtilization ( ) { string mem_total , mem_free ; string line , label ; std :: ifstream stream ( kProcDirectory + kMeminfoFilename ) ; if ( stream . is_open ( ) ) { std :: getline ( stream , line ) ; std :: istringstream linestream1 ( line ) ; linestream1 >> label >> mem_total ; std :: getline ( stream , line ) ; std :: istringstream linestream2 ( line ) ; linestream2 >> label >> mem_free ; } return ( stof ( mem_total ) - stof ( mem_free ) ) / stof ( mem_total ) ; }
Read and return the system memory utilization
Read and return the system memory utilization
// Get first line and pop off the value under the MemTotal label // Get second line and pop off the value under the MemFree label // Return the memory used based on formula % MemUsed == (MemTotal - MemFree) / MemTotal