MCPcopy Create free account
hub / github.com/Niko1221/Strata / read_cgroup_memory_stat

Function read_cgroup_memory_stat

engine/src/core/expert_source.cpp:388–425  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386
387#if defined(__linux__)
388bool read_cgroup_memory_stat(const std::filesystem::path& path, uint64_t current,
389 detail::CgroupMemoryStat& stat) {
390 std::ifstream input(path / "memory.stat");
391 if (!input) return false;
392
393 bool inactive_file = false, file_dirty = false, file_writeback = false, file = false;
394 std::string line;
395 while (std::getline(input, line)) {
396 std::istringstream fields(line);
397 std::string key;
398 uint64_t value = 0;
399 if (!(fields >> key >> value)) return false;
400 fields >> std::ws;
401 if (!fields.eof()) return false;
402
403 if (key == "inactive_file") {
404 if (inactive_file) return false;
405 inactive_file = true;
406 stat.inactive_file = value;
407 } else if (key == "file_dirty") {
408 if (file_dirty) return false;
409 file_dirty = true;
410 stat.file_dirty = value;
411 } else if (key == "file_writeback") {
412 if (file_writeback) return false;
413 file_writeback = true;
414 stat.file_writeback = value;
415 } else if (key == "file") { // 149: optional (every v2 kernel has it); 0 = inactive_file alone
416 if (file) return false;
417 file = true;
418 stat.file = value;
419 }
420 }
421 if (!input.eof() || !inactive_file || !file_dirty || !file_writeback) return false;
422 stat.current = current;
423 stat.valid = true;
424 return true;
425}
426#endif
427
428} // namespace

Callers 1

host_available_memoryFunction · 0.70

Calls 1

eofMethod · 0.80

Tested by

no test coverage detected