From bd07d3d0b401b0c837a9b37a9a6aedf0f769fe22 Mon Sep 17 00:00:00 2001 From: Boucman Date: Tue, 5 Dec 2017 10:20:40 +0100 Subject: [PATCH] Print the time to reach default.target in systemd-analyze time (#7383) Example output (last line is new): $ systemd-analyze time Startup finished in 12.879s (firmware) + 36.999s (loader) + 1.313s (kernel) + 22.672s (initrd) + 3min 1.755s (userspace) = 4min 15.619s graphical.target reached after 1min 39.377s in userspace --- src/analyze/analyze.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 5229b3a082f..8b220d19782 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -491,11 +491,40 @@ static int pretty_boot_time(sd_bus *bus, char **_buf) { size_t size; char *ptr; int r; + usec_t activated_time = USEC_INFINITY; + _cleanup_free_ char* path = NULL, *unit_id = NULL; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; r = acquire_boot_times(bus, &t); if (r < 0) return r; + path = unit_dbus_path_from_name(SPECIAL_DEFAULT_TARGET); + if (!path) + return log_oom(); + + r = sd_bus_get_property_string( + bus, + "org.freedesktop.systemd1", + path, + "org.freedesktop.systemd1.Unit", + "Id", + &error, + &unit_id); + if (r < 0) { + log_error_errno(r, "default.target doesn't seem to exist: %s", bus_error_message(&error, r)); + unit_id = NULL; + } + + r = bus_get_uint64_property(bus, path, + "org.freedesktop.systemd1.Unit", + "ActiveEnterTimestampMonotonic", + &activated_time); + if (r < 0) { + log_info_errno(r, "default.target seems not to be started. Continuing..."); + activated_time = USEC_INFINITY; + } + ptr = buf; size = sizeof(buf); @@ -512,6 +541,9 @@ static int pretty_boot_time(sd_bus *bus, char **_buf) { size = strpcpyf(&ptr, size, "%s (userspace) ", format_timespan(ts, sizeof(ts), t->finish_time - t->userspace_time, USEC_PER_MSEC)); strpcpyf(&ptr, size, "= %s", format_timespan(ts, sizeof(ts), t->firmware_time + t->finish_time, USEC_PER_MSEC)); + if (unit_id && activated_time != USEC_INFINITY) + size = strpcpyf(&ptr, size, "\n%s reached after %s in userspace", unit_id, format_timespan(ts, sizeof(ts), activated_time - t->userspace_time, USEC_PER_MSEC)); + ptr = strdup(buf); if (!ptr) return log_oom();