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

Function scan_cgroups

engine/src/core/conversation_memory.cpp:258–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258bool scan_cgroups(const MemoryProbePaths& paths, CgroupScan& out) {
259 std::optional<std::string> v2_group, v1_group;
260 std::ifstream groups(paths.self_cgroup);
261 if (!groups) {
262 v2_group = "/"; // no /proc/self/cgroup: the mount's own top group is still readable
263 } else {
264 std::string line;
265 while (std::getline(groups, line)) {
266 const size_t c1 = line.find(':'), c2 = c1 == std::string::npos ? c1 : line.find(':', c1 + 1);
267 if (c2 == std::string::npos) continue;
268 const std::string controllers = line.substr(c1 + 1, c2 - c1 - 1), group = line.substr(c2 + 1);
269 if (line.compare(0, c1, "0") == 0 && controllers.empty()) { v2_group = group; continue; }
270 std::istringstream names(controllers);
271 for (std::string name; std::getline(names, name, ',');)
272 if (name == "memory") v1_group = group;
273 }
274 }
275 std::vector<fs::path> dirs;
276 if (v2_group) {
277 if (!group_dirs(paths.cgroup_root, *v2_group, dirs)) return false;
278 static const char* const names[] = {"memory.max", "memory.high"};
279 if (!scan_levels(dirs, names, 2, "memory.current", false, out)) return false;
280 }
281 if (!out.any_files && v1_group) { // cgroup v1: the memory controller's own tree
282 if (!group_dirs(fs::path(paths.cgroup_root) / "memory", *v1_group, dirs)) return false;
283 static const char* const names[] = {"memory.limit_in_bytes"};
284 if (!scan_levels(dirs, names, 1, "memory.usage_in_bytes", true, out)) return false;
285 }
286 return true;
287}
288
289std::optional<HostMemoryReading> combine(std::optional<uint64_t> available, std::optional<uint64_t> total,
290 const CgroupScan& cg, uint64_t explicit_limit, bool inactive_only,

Callers 1

sample_host_memoryFunction · 0.85

Calls 6

group_dirsFunction · 0.85
scan_levelsFunction · 0.85
pathFunction · 0.85
compareMethod · 0.80
findMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected