Skip to content

Commit 61d2e33

Browse files
committed
1 parent 76edc79 commit 61d2e33

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

debian/changelog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cm4all-spawn (0.21) unstable; urgency=low
22

3-
*
3+
* reaper: support cgroup btime
44

55
--
66

meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ libcommon_require_sodium = get_option('sodium')
121121
libcommon_enable_libsystemd = libsystemd.found()
122122

123123
subdir('libcommon/src/util')
124+
subdir('libcommon/src/time')
124125
subdir('libcommon/src/lib/cap')
125126
subdir('libcommon/src/lib/fmt')
126127
subdir('libcommon/src/lib/sodium')
@@ -206,6 +207,7 @@ executable('cm4all-spawn-reaper',
206207
pg_dep,
207208
lua_sodium_dep,
208209
util_dep,
210+
time_dep,
209211
fmt_dep,
210212
],
211213
install: true,

src/reaper/Released.cxx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include "Scopes.hxx"
77
#include "CgroupAccounting.hxx"
88
#include "LAccounting.hxx"
9+
#include "time/ISO8601.hxx"
10+
#include "time/StatxCast.hxx"
11+
#include "util/StringBuffer.hxx"
912
#include "util/StringCompare.hxx"
1013

1114
#include <fmt/format.h>
@@ -14,6 +17,7 @@
1417
#include <stdio.h>
1518
#include <unistd.h>
1619
#include <errno.h>
20+
#include <sys/stat.h>
1721

1822
using std::string_view_literals::operator""sv;
1923

@@ -31,10 +35,14 @@ GetManagedSuffix(const char *path)
3135

3236
static void
3337
CollectCgroupStats(const char *suffix,
38+
const std::chrono::system_clock::time_point btime,
3439
const CgroupResourceUsage &u)
3540
{
3641
char buffer[4096], *p = buffer;
3742

43+
if (btime != std::chrono::system_clock::time_point{})
44+
p = fmt::format_to(p, " since={}"sv, FormatISO8601(btime).c_str());
45+
3846
if (u.cpu.user.count() >= 0 || u.cpu.system.count() >= 0) {
3947
const auto user = std::max(u.cpu.user.count(), 0.);
4048
const auto system = std::max(u.cpu.system.count(), 0.);
@@ -106,12 +114,23 @@ Instance::OnCgroupEmpty(const char *path) noexcept
106114
UniqueFileDescriptor cgroup_fd;
107115
(void)cgroup_fd.Open(root_cgroup, path + 1, O_DIRECTORY|O_RDONLY);
108116

117+
std::chrono::system_clock::time_point btime;
118+
119+
if (cgroup_fd.IsDefined()) {
120+
struct statx stx;
121+
if (statx(cgroup_fd.Get(), "", AT_EMPTY_PATH|AT_STATX_FORCE_SYNC,
122+
STATX_BTIME, &stx) == 0) {
123+
if (stx.stx_mask & STATX_BTIME)
124+
btime = ToSystemTimePoint(stx.stx_btime);
125+
}
126+
}
127+
109128
// TODO read resource usage right before the cgroup actually gets deleted
110129
const auto u = cgroup_fd.IsDefined()
111130
? ReadCgroupResourceUsage(cgroup_fd)
112131
: CgroupResourceUsage{};
113132

114-
CollectCgroupStats(suffix, u);
133+
CollectCgroupStats(suffix, btime, u);
115134

116135
if (lua_accounting)
117136
lua_accounting->InvokeCgroupReleased(std::move(cgroup_fd), path, u);

0 commit comments

Comments
 (0)