Skip to content

Commit

Permalink
reaper/CgroupAccounting: read "pids_peak"
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Feb 21, 2025
1 parent e998b78 commit 957bad2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cm4all-spawn (0.19) unstable; urgency=low

*
* reaper: read "pids.peak"

--

Expand Down
2 changes: 2 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ The following attributes of the ``cgroup`` parameter can be queried:

* ``memory_peak``: the peak memory usage [in bytes].

* ``pids_peak``: the peak number of processes.


libsodium
^^^^^^^^^
Expand Down
10 changes: 10 additions & 0 deletions src/reaper/CgroupAccounting.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,15 @@ ReadCgroupResourceUsage(FileDescriptor cgroup_fd) noexcept
} catch (...) {
}

try {
WithSmallTextFile<64>(FileAt{cgroup_fd, "pids.peak"}, [&result](std::string_view contents){
if (auto value = ParseInteger<uint_least32_t>(StripRight(contents))) {
result.pids_peak = *value;
result.have_pids_peak = true;
}
});
} catch (...) {
}

return result;
}
4 changes: 4 additions & 0 deletions src/reaper/CgroupAccounting.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ struct CgroupResourceUsage {

uint_least64_t memory_peak;

uint_least32_t pids_peak;

bool have_memory_peak = false;

bool have_pids_peak = false;
};

[[gnu::pure]]
Expand Down
4 changes: 4 additions & 0 deletions src/reaper/LAccounting.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ Push(lua_State *L, Lua::AutoCloseList &auto_close,
SetField(L, RelativeStackIndex{-1}, "memory_peak",
(lua_Integer)usage.memory_peak);

if (usage.have_pids_peak)
SetField(L, RelativeStackIndex{-1}, "pids_peak",
(lua_Integer)usage.pids_peak);

lua_pop(L, 1);
}

Expand Down
3 changes: 3 additions & 0 deletions src/reaper/Released.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ CollectCgroupStats(const char *suffix,
(u.memory_peak + MEGA / 2 - 1) / MEGA);
}

if (u.have_pids_peak)
p = fmt::format_to(p, " procs={}", u.pids_peak);

if (p > buffer)
fmt::print(stderr, "{}:{}\n", suffix,
std::string_view{buffer, p});
Expand Down

0 comments on commit 957bad2

Please sign in to comment.