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() {
  float memTotal, memUt, memFree, buffers, cached;
  std::string key, value, line;
  std::ifstream filestream(kProcDirectory + kMeminfoFilename);
  if (filestream.is_open()) {
    while (std::getline(filestream, line)) {
      std::replace(line.begin(), line.end(), ':', ' ');
      std::istringstream stringstream(line);
      while (stringstream >> key >> value) {
        if (key == "MemTotal") memTotal = std::stof(value);
        if (key == "MemFree") memFree = std::stof(value);
        if (key == "Buffers") buffers = std::stof(value);
        if (key == "Cached") cached = std::stof(value);
      }
    }
    memUt = (memFree + buffers + cached) / memTotal;
    return memUt;
  }
  return 0.0;
}
float LinuxParser :: MemoryUtilization ( ) { float memTotal , memUt , memFree , buffers , cached ; std :: string key , value , line ; std :: ifstream filestream ( kProcDirectory + kMeminfoFilename ) ; if ( filestream . is_open ( ) ) { while ( std :: getline ( filestream , line ) ) { std :: replace ( line . begin ( ) , line . end ( ) , ' ' , ' ' ) ; std :: istringstream stringstream ( line ) ; while ( stringstream >> key >> value ) { if ( key == " " ) memTotal = std :: stof ( value ) ; if ( key == " " ) memFree = std :: stof ( value ) ; if ( key == " " ) buffers = std :: stof ( value ) ; if ( key == " " ) cached = std :: stof ( value ) ; } } memUt = ( memFree + buffers + cached ) / memTotal ; return memUt ; } return 0.0 ; }
TODO: Read and return the system memory utilization
TODO : Read and return the system memory utilization
// memUt = 100 - (((memFree + buffers + cached) * 100) / memTotal);