]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: Show how long a service ran for after it exited in status output
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 22 Feb 2022 11:06:00 +0000 (11:06 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 23 Feb 2022 20:09:50 +0000 (20:09 +0000)
src/systemctl/systemctl-show.c

index 76418196c6ace918d0ea3afaa7126f0c88f817d2..c1298ce75831e1a46ad7d0f3b58385c9bf122e21 100644 (file)
@@ -433,6 +433,18 @@ static void print_status_info(
                                FORMAT_TIMESTAMP_STYLE(until_timestamp, arg_timestamp_style),
                                FORMAT_TIMESTAMP_RELATIVE(until_timestamp));
                 }
+
+                if (!endswith(i->id, ".target") &&
+                        STRPTR_IN_SET(i->active_state, "inactive", "failed") &&
+                        timestamp_is_set(i->active_enter_timestamp) &&
+                        timestamp_is_set(i->active_exit_timestamp) &&
+                        i->active_exit_timestamp >= i->active_enter_timestamp) {
+
+                        usec_t duration;
+
+                        duration = i->active_exit_timestamp - i->active_enter_timestamp;
+                        printf("   Duration: %s\n", FORMAT_TIMESPAN(duration, MSEC_PER_SEC));
+                }
         } else
                 printf("\n");