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() {
  std::string key,line;
  float value;
  float MemUtiUsed{0};
  float memtot{0},memfree{0};
 std::ifstream MemInfoFile(kProcDirectory+kMeminfoFilename);
  if(MemInfoFile.is_open())
  {
    while (std::getline(MemInfoFile,line))
    {
      std::istringstream myStream(line);
      myStream >> key >> value;
      if(key == "MemTotal:")
      {
        memtot = value;
      }
      else if (key == "MemFree:")
      {
        memfree = value;
        return static_cast<float> (1-(memfree/memtot));
      }
    }
  }
  return MemUtiUsed;
 }
float LinuxParser :: MemoryUtilization ( ) { std :: string key , line ; float value ; float MemUtiUsed { 0 } ; float memtot { 0 } , memfree { 0 } ; std :: ifstream MemInfoFile ( kProcDirectory + kMeminfoFilename ) ; if ( MemInfoFile . is_open ( ) ) { while ( std :: getline ( MemInfoFile , line ) ) { std :: istringstream myStream ( line ) ; myStream >> key >> value ; if ( key == " " ) { memtot = value ; } else if ( key == " " ) { memfree = value ; return static_cast < float > ( 1 - ( memfree / memtot ) ) ; } } } return MemUtiUsed ; }
Read and return the system memory utilization
Read and return the system memory utilization
// return 0.0;