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 Title, Num, KB;
  float MemTotal, MemFree, MemUsed;  
  string line;
  std::ifstream stream(kProcDirectory + kMeminfoFilename);
  if (stream.is_open()){
    while (std::getline(stream, line)){
      std::replace(line.begin(), line.end(), ':',' ');
      std::istringstream linestream(line);
      while (linestream>>Title>>Num>>KB){
        if (Title == "MemTotal"){MemTotal = std::stof(Num);}
        else if (Title == "MemFree"){MemFree = std::stof(Num);}
      }
    }
  }
  MemUsed = ((MemTotal-MemFree)/MemTotal);
  return MemUsed; }
float LinuxParser :: MemoryUtilization ( ) { string Title , Num , KB ; float MemTotal , MemFree , MemUsed ; string line ; std :: ifstream stream ( kProcDirectory + kMeminfoFilename ) ; if ( stream . is_open ( ) ) { while ( std :: getline ( stream , line ) ) { std :: replace ( line . begin ( ) , line . end ( ) , ' ' , ' ' ) ; std :: istringstream linestream ( line ) ; while ( linestream >> Title >> Num >> KB ) { if ( Title == " " ) { MemTotal = std :: stof ( Num ) ; } else if ( Title == " " ) { MemFree = std :: stof ( Num ) ; } } } } MemUsed = ( ( MemTotal - MemFree ) / MemTotal ) ; return MemUsed ; }
TODO: Read and return the system memory utilization
TODO : Read and return the system memory utilization
// std::cout<< "I am here \n"; //MemAval, Buffers, // else if (Title == "MemAvailable"){MemAval = std::stof(Num);} // else if (Title == "Buffers"){Buffers = std::stof(Num);} // std::cout<< MemTotal << "  " << MemFree<<"  "<< MemAval << "  "<< Buffers << "\n";