From 0531bded79dcdde93f2b076f86c40d02b81a18b9 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 6 Nov 2023 17:24:14 +0100 Subject: [PATCH] core: include peak memory in unit_log_resources() Signed-off-by: Florian Schmaus --- src/core/unit.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/core/unit.c b/src/core/unit.c index 02c5cbd1020..d7e7da40c21 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2326,6 +2326,7 @@ static int unit_log_resources(Unit *u) { size_t n_message_parts = 0, n_iovec = 0; char* message_parts[1 + 2 + 2 + 1], *t; nsec_t nsec = NSEC_INFINITY; + uint64_t memory_peak = UINT64_MAX; int r; const char* const ip_fields[_CGROUP_IP_ACCOUNTING_METRIC_MAX] = { [CGROUP_IP_INGRESS_BYTES] = "IP_METRIC_INGRESS_BYTES", @@ -2369,6 +2370,24 @@ static int unit_log_resources(Unit *u) { nsec > NOTICEWORTHY_CPU_NSEC); } + (void) unit_get_memory_peak(u, &memory_peak); + if (memory_peak != UINT64_MAX) { + /* Format peak memory for inclusion in the structured log message */ + if (asprintf(&t, "MEMORY_PEAK=%" PRIu64, memory_peak) < 0) { + r = log_oom(); + goto finish; + } + iovec[n_iovec++] = IOVEC_MAKE_STRING(t); + + /* Format peak memory for inclusion in the human language message string */ + t = strjoin(FORMAT_BYTES(memory_peak), " memory peak"); + if (!t) { + r = log_oom(); + goto finish; + } + message_parts[n_message_parts++] = t; + } + for (CGroupIOAccountingMetric k = 0; k < _CGROUP_IO_ACCOUNTING_METRIC_MAX; k++) { uint64_t value = UINT64_MAX;