src/linux_parser.cpp
// TODO: Read and return the system memory utilization
Read and return the system memory utilization
Read and return the system memory utilization
float LinuxParser::MemoryUtilization() 
{
  int memTotal = 0;
  int memFree = 0;
  std::string key;
  float value = 0; 
  std::string line;
  std::ifstream fileStream(kProcDirectory + kMeminfoFilename);
  if(fileStream.is_open())
  {
    while(std::getline(fileStream, line))
    {
      std::istringstream linestream(line);
      linestream >> key >> value;
      if(key == "MemTotal:")
      {
        memTotal = value;
      }else if(key == "MemFree:")
      {
        memFree = value;
      }
    }
  }
  if(memTotal == 0)
  {
    return 0.0;
  }else{
    return float(memTotal-memFree)/memTotal;
  } 
}
float LinuxParser :: MemoryUtilization ( ) { int memTotal = 0 ; int memFree = 0 ; std :: string key ; float value = 0 ; std :: string line ; std :: ifstream fileStream ( kProcDirectory + kMeminfoFilename ) ; if ( fileStream . is_open ( ) ) { while ( std :: getline ( fileStream , line ) ) { std :: istringstream linestream ( line ) ; linestream >> key >> value ; if ( key == " " ) { memTotal = value ; } else if ( key == " " ) { memFree = value ; } } } if ( memTotal == 0 ) { return 0.0 ; } else { return float ( memTotal - memFree ) / memTotal ; } }
TODO: Read and return the system memory utilization
TODO : Read and return the system memory utilization