594167
From b07519fd5241eacfdb735917eca4ccbf441b5a8a Mon Sep 17 00:00:00 2001
594167
From: Daan De Meyer <daan.j.demeyer@gmail.com>
594167
Date: Tue, 22 Feb 2022 11:06:00 +0000
594167
Subject: [PATCH] systemctl: Show how long a service ran for after it exited in
594167
 status output
594167
594167
(cherry picked from commit 0802f62efc1d1c67d5be67223b529c93536cf2ed)
594167
594167
Related: #2017035
594167
---
594167
 src/systemctl/systemctl-show.c | 12 ++++++++++++
594167
 1 file changed, 12 insertions(+)
594167
594167
diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c
594167
index 37c898f313..9b23471990 100644
594167
--- a/src/systemctl/systemctl-show.c
594167
+++ b/src/systemctl/systemctl-show.c
594167
@@ -433,6 +433,18 @@ static void print_status_info(
594167
                                FORMAT_TIMESTAMP_STYLE(until_timestamp, arg_timestamp_style),
594167
                                FORMAT_TIMESTAMP_RELATIVE(until_timestamp));
594167
                 }
594167
+
594167
+                if (!endswith(i->id, ".target") &&
594167
+                        STRPTR_IN_SET(i->active_state, "inactive", "failed") &&
594167
+                        timestamp_is_set(i->active_enter_timestamp) &&
594167
+                        timestamp_is_set(i->active_exit_timestamp) &&
594167
+                        i->active_exit_timestamp >= i->active_enter_timestamp) {
594167
+
594167
+                        usec_t duration;
594167
+
594167
+                        duration = i->active_exit_timestamp - i->active_enter_timestamp;
594167
+                        printf("   Duration: %s\n", FORMAT_TIMESPAN(duration, MSEC_PER_SEC));
594167
+                }
594167
         } else
594167
                 printf("\n");
594167