diff options
Diffstat (limited to 'src/core/unit.c')
-rw-r--r-- | src/core/unit.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/core/unit.c b/src/core/unit.c index 4ac8d0adc0..924828d2d8 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -115,6 +115,7 @@ Unit* unit_new(Manager *m, size_t size) { u->ref_gid = GID_INVALID; u->cpu_usage_last = NSEC_INFINITY; u->memory_peak_last = UINT64_MAX; + u->memory_swap_peak_last = UINT64_MAX; u->cgroup_invalidated_mask |= CGROUP_MASK_BPF_FIREWALL; u->failure_action_exit_status = u->success_action_exit_status = -1; @@ -2319,14 +2320,14 @@ static int raise_level(int log_level, bool condition_info, bool condition_notice } static int unit_log_resources(Unit *u) { - struct iovec iovec[1 + 1 + _CGROUP_IP_ACCOUNTING_METRIC_MAX + _CGROUP_IO_ACCOUNTING_METRIC_MAX + 4]; + struct iovec iovec[1 + 2 + _CGROUP_IP_ACCOUNTING_METRIC_MAX + _CGROUP_IO_ACCOUNTING_METRIC_MAX + 4]; bool any_traffic = false, have_ip_accounting = false, any_io = false, have_io_accounting = false; _cleanup_free_ char *igress = NULL, *egress = NULL, *rr = NULL, *wr = NULL; int log_level = LOG_DEBUG; /* May be raised if resources consumed over a threshold */ size_t n_message_parts = 0, n_iovec = 0; - char* message_parts[1 + 1 + 2 + 2 + 1], *t; + char* message_parts[1 + 2 + 2 + 2 + 1], *t; nsec_t nsec = NSEC_INFINITY; - uint64_t memory_peak = UINT64_MAX; + uint64_t memory_peak = UINT64_MAX, memory_swap_peak = UINT64_MAX; int r; const char* const ip_fields[_CGROUP_IP_ACCOUNTING_METRIC_MAX] = { [CGROUP_IP_INGRESS_BYTES] = "IP_METRIC_INGRESS_BYTES", @@ -2388,6 +2389,24 @@ static int unit_log_resources(Unit *u) { message_parts[n_message_parts++] = t; } + (void) unit_get_memory_swap_peak(u, &memory_swap_peak); + if (memory_swap_peak != UINT64_MAX) { + /* Format peak swap memory for inclusion in the structured log message */ + if (asprintf(&t, "MEMORY_SWAP_PEAK=%" PRIu64, memory_swap_peak) < 0) { + r = log_oom(); + goto finish; + } + iovec[n_iovec++] = IOVEC_MAKE_STRING(t); + + /* Format peak swap memory for inclusion in the human language message string */ + t = strjoin(FORMAT_BYTES(memory_swap_peak), " memory swap 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; |