From 43ead5e3d611e7d3a2e723f5a3cdbf1f8686cea0 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Fri, 12 Jan 2024 16:57:13 +0800 Subject: [PATCH 1/2] run: show accounting data of same type in the same line --- src/run/run.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/run/run.c b/src/run/run.c index c78d3c6a1d..e94ae2abbe 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -1822,23 +1822,36 @@ 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.memory_peak != UINT64_MAX) { + const char *swap; - if (c.memory_swap_peak != UINT64_MAX) - log_info("Memory swap peak: %s", FORMAT_BYTES(c.memory_swap_peak)); + if (c.memory_swap_peak != UINT64_MAX) + swap = strjoina(" (swap: %s)", FORMAT_BYTES(c.memory_swap_peak)); + else + swap = ""; + + log_info("Memory peak: %s%s", FORMAT_BYTES(c.memory_peak), swap); + } + + const char *ip_ingress = NULL, *ip_egress = NULL; if (c.ip_ingress_bytes != UINT64_MAX) - log_info("IP traffic received: %s", FORMAT_BYTES(c.ip_ingress_bytes)); - + ip_ingress = strjoina(" received: ", FORMAT_BYTES(c.ip_ingress_bytes)); if (c.ip_egress_bytes != UINT64_MAX) - log_info("IP traffic sent: %s", FORMAT_BYTES(c.ip_egress_bytes)); + ip_egress = strjoina(" sent: ", FORMAT_BYTES(c.ip_egress_bytes)); + + if (ip_ingress || ip_egress) + log_info("IP traffic%s%s", strempty(ip_ingress), strempty(ip_egress)); + + const char *io_read = NULL, *io_write = NULL; if (c.io_read_bytes != UINT64_MAX) - log_info("IO bytes read: %s", FORMAT_BYTES(c.io_read_bytes)); - + io_read = strjoina(" read: %s", FORMAT_BYTES(c.io_read_bytes)); if (c.io_write_bytes != UINT64_MAX) - log_info("IO bytes written: %s", FORMAT_BYTES(c.io_write_bytes)); + io_write = strjoina(" written: %s", FORMAT_BYTES(c.io_write_bytes)); + + if (io_read || io_write) + log_info("IO bytes%s%s", strempty(io_read), strempty(io_write)); } /* Try to propagate the service's return value. But if the service defines From 5447338b95813fa785f17811a5d083388446da63 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Fri, 12 Jan 2024 17:35:21 +0800 Subject: [PATCH 2/2] run: don't show IP/IO accounting data if 0 --- src/run/run.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/run/run.c b/src/run/run.c index e94ae2abbe..3f54bd5607 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -1835,9 +1835,9 @@ static int start_transient_service(sd_bus *bus) { const char *ip_ingress = NULL, *ip_egress = NULL; - if (c.ip_ingress_bytes != UINT64_MAX) + if (!IN_SET(c.ip_ingress_bytes, 0, UINT64_MAX)) ip_ingress = strjoina(" received: ", FORMAT_BYTES(c.ip_ingress_bytes)); - if (c.ip_egress_bytes != UINT64_MAX) + if (!IN_SET(c.ip_egress_bytes, 0, UINT64_MAX)) ip_egress = strjoina(" sent: ", FORMAT_BYTES(c.ip_egress_bytes)); if (ip_ingress || ip_egress) @@ -1845,9 +1845,9 @@ static int start_transient_service(sd_bus *bus) { const char *io_read = NULL, *io_write = NULL; - if (c.io_read_bytes != UINT64_MAX) + if (!IN_SET(c.io_read_bytes, 0, UINT64_MAX)) io_read = strjoina(" read: %s", FORMAT_BYTES(c.io_read_bytes)); - if (c.io_write_bytes != UINT64_MAX) + if (!IN_SET(c.io_write_bytes, 0, UINT64_MAX)) io_write = strjoina(" written: %s", FORMAT_BYTES(c.io_write_bytes)); if (io_read || io_write)