1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 09:21:26 +03:00

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
This commit is contained in:
Boucman 2017-12-05 10:20:40 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent fc11a1a204
commit bd07d3d0b4

View File

@ -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();