14 bool memoryLoad::parseMemoryFile() {
15 if(timeStamp + std::chrono::milliseconds(10) > std::chrono::steady_clock::now()) {
18 std::ifstream memoryFile;
19 memoryFile.open(this->memInfoFile);
20 this->timeStamp = std::chrono::steady_clock::now();
21 if (!memoryFile.is_open()) {
26 while (std::getline(memoryFile, line)) {
27 sscanf(line.c_str(),
"MemTotal: %" PRIu64, &this->totalMemoryInKB);
28 sscanf(line.c_str(),
"MemAvailable: %" PRIu64, &this->currentMemoryUsageInKB);
35 this->parseMemoryFile();
36 return this->totalMemoryInKB;
40 this->parseMemoryFile();
45 this->parseMemoryFile();
51 return this->parseProcessMemoryFile(this->memInfoOfProcessFile);
55 return memoryLoad::parseProcessMemoryFile(
"/proc/" +
std::to_string(pid) +
"/status");
58 uint64_t memoryLoad::parseProcessMemoryFile(std::string fileToParse) {
60 std::ifstream memoryFile;
61 memoryFile.open(fileToParse);
63 while (std::getline(memoryFile, line)) {
64 sscanf(line.c_str(),
"VmSize: %" PRIu64, &MemFree);