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() { 
  string line, key, value, kB;
  float MemTotal, MemFree;
  bool bMemTotal = false;
  bool bMemFree = false;
  std::ifstream filestream(kProcDirectory + kMeminfoFilename);
  if (filestream.is_open()) {
    while (std::getline(filestream, line)) {
      std::replace(line.begin(), line.end(), ':', ' ');
      std::istringstream linestream(line);
      while (linestream >> key >> value >> kB) {
        if (key == "MemTotal") {MemTotal =  std::stof(value); bMemTotal = true;}
        if (key == "MemFree") {MemFree =  std::stof(value); bMemFree = true;}
        if(bMemTotal && bMemFree) {break;}
      }
    }
  }
  return (MemTotal - MemFree) / MemTotal;
}
float LinuxParser :: MemoryUtilization ( ) { string line , key , value , kB ; float MemTotal , MemFree ; bool bMemTotal = false ; bool bMemFree = false ; std :: ifstream filestream ( kProcDirectory + kMeminfoFilename ) ; if ( filestream . is_open ( ) ) { while ( std :: getline ( filestream , line ) ) { std :: replace ( line . begin ( ) , line . end ( ) , ' ' , ' ' ) ; std :: istringstream linestream ( line ) ; while ( linestream >> key >> value >> kB ) { if ( key == " " ) { MemTotal = std :: stof ( value ) ; bMemTotal = true ; } if ( key == " " ) { MemFree = std :: stof ( value ) ; bMemFree = true ; } if ( bMemTotal && bMemFree ) { break ; } } } } return ( MemTotal - MemFree ) / MemTotal ; }
TODO: Read and return the system memory utilization
TODO : Read and return the system memory utilization
//std::replace(line.begin(), line.end(), 'kB', ' ');