]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: include peak memory in output 29879/head
authorFlorian Schmaus <flo@geekplace.eu>
Mon, 6 Nov 2023 16:28:41 +0000 (17:28 +0100)
committerFlorian Schmaus <flo@geekplace.eu>
Mon, 6 Nov 2023 17:10:06 +0000 (18:10 +0100)
Fixes #28542.

Signed-off-by: Florian Schmaus <flo@geekplace.eu>
NEWS
src/run/run.c

diff --git a/NEWS b/NEWS
index 38b94ad42be5cd951cc5140b2f5bc918ced8910f..a83efb5f9cf677c78556e2cb82017f4abd2e4823 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -436,7 +436,7 @@ CHANGES WITH 255 in spe:
         * systemd-sysupdate now accepts directories in the MatchPattern= option.
 
         * systemd-run will now output the invocation ID of the launched
-          transient unit.
+          transient unit and its peak memory usage.
 
         * systemd-analyze, systemd-tmpfiles, systemd-sysusers, systemd-sysctl,
           and systemd-binfmt gained a new --tldr option that can be used instead
index edafd4956734081095cb650778d1035003a64294..1b20a8f4591176e644bd573ab6ca0e99c0b819cf 100644 (file)
@@ -1049,6 +1049,7 @@ typedef struct RunContext {
         uint64_t inactive_enter_usec;
         char *result;
         uint64_t cpu_usage_nsec;
+        uint64_t memory_peak;
         uint64_t ip_ingress_bytes;
         uint64_t ip_egress_bytes;
         uint64_t io_read_bytes;
@@ -1110,6 +1111,7 @@ static int run_context_update(RunContext *c, const char *path) {
                 { "ExecMainCode",                    "i",    NULL,    offsetof(RunContext, exit_code)           },
                 { "ExecMainStatus",                  "i",    NULL,    offsetof(RunContext, exit_status)         },
                 { "CPUUsageNSec",                    "t",    NULL,    offsetof(RunContext, cpu_usage_nsec)      },
+                { "MemoryPeak",                      "t",    NULL,    offsetof(RunContext, memory_peak)         },
                 { "IPIngressBytes",                  "t",    NULL,    offsetof(RunContext, ip_ingress_bytes)    },
                 { "IPEgressBytes",                   "t",    NULL,    offsetof(RunContext, ip_egress_bytes)     },
                 { "IOReadBytes",                     "t",    NULL,    offsetof(RunContext, io_read_bytes)       },
@@ -1391,6 +1393,7 @@ static int start_transient_service(sd_bus *bus) {
         if (arg_wait || arg_stdio != ARG_STDIO_NONE) {
                 _cleanup_(run_context_free) RunContext c = {
                         .cpu_usage_nsec = NSEC_INFINITY,
+                        .memory_peak = UINT64_MAX,
                         .ip_ingress_bytes = UINT64_MAX,
                         .ip_egress_bytes = UINT64_MAX,
                         .io_read_bytes = UINT64_MAX,
@@ -1486,6 +1489,9 @@ static int start_transient_service(sd_bus *bus) {
                                 log_info("CPU time consumed: %s",
                                          FORMAT_TIMESPAN(DIV_ROUND_UP(c.cpu_usage_nsec, NSEC_PER_USEC), USEC_PER_MSEC));
 
+                        if (c.memory_peak != UINT64_MAX)
+                                log_info("Memory peak: %s", FORMAT_BYTES(c.memory_peak));
+
                         if (c.ip_ingress_bytes != UINT64_MAX)
                                 log_info("IP traffic received: %s", FORMAT_BYTES(c.ip_ingress_bytes));