]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: include peak memory in unit_log_resources()
authorFlorian Schmaus <flo@geekplace.eu>
Mon, 6 Nov 2023 16:24:14 +0000 (17:24 +0100)
committerFlorian Schmaus <flo@geekplace.eu>
Mon, 6 Nov 2023 17:08:33 +0000 (18:08 +0100)
Signed-off-by: Florian Schmaus <flo@geekplace.eu>
src/core/unit.c

index 02c5cbd102077796cfe6b076ecefb6803e412fd2..d7e7da40c215c113d38c9638448ffc6a0daa9ba4 100644 (file)
@@ -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;