analyze: use bus_map_all_properties()
This commit is contained in:
parent
97cec9ba5e
commit
cc0eb780bd
|
@ -225,106 +225,48 @@ static void subtract_timestamp(usec_t *a, usec_t b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int acquire_boot_times(sd_bus *bus, struct boot_times **bt) {
|
static int acquire_boot_times(sd_bus *bus, struct boot_times **bt) {
|
||||||
|
static const struct bus_properties_map property_map[] = {
|
||||||
|
{ "FirmwareTimestampMonotonic", "t", NULL, offsetof(struct boot_times, firmware_time) },
|
||||||
|
{ "LoaderTimestampMonotonic", "t", NULL, offsetof(struct boot_times, loader_time) },
|
||||||
|
{ "KernelTimestamp", "t", NULL, offsetof(struct boot_times, kernel_time) },
|
||||||
|
{ "InitRDTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_time) },
|
||||||
|
{ "UserspaceTimestampMonotonic", "t", NULL, offsetof(struct boot_times, userspace_time) },
|
||||||
|
{ "FinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, finish_time) },
|
||||||
|
{ "SecurityStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, security_start_time) },
|
||||||
|
{ "SecurityFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, security_finish_time) },
|
||||||
|
{ "GeneratorsStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, generators_start_time) },
|
||||||
|
{ "GeneratorsFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, generators_finish_time) },
|
||||||
|
{ "UnitsLoadStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, unitsload_start_time) },
|
||||||
|
{ "UnitsLoadFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, unitsload_finish_time) },
|
||||||
|
{ "InitRDSecurityStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_security_start_time) },
|
||||||
|
{ "InitRDSecurityFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_security_finish_time) },
|
||||||
|
{ "InitRDGeneratorsStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_generators_start_time) },
|
||||||
|
{ "InitRDGeneratorsFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_generators_finish_time) },
|
||||||
|
{ "InitRDUnitsLoadStartTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_unitsload_start_time) },
|
||||||
|
{ "InitRDUnitsLoadFinishTimestampMonotonic", "t", NULL, offsetof(struct boot_times, initrd_unitsload_finish_time) },
|
||||||
|
{},
|
||||||
|
};
|
||||||
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
static struct boot_times times;
|
static struct boot_times times;
|
||||||
static bool cached = false;
|
static bool cached = false;
|
||||||
|
int r;
|
||||||
|
|
||||||
if (cached)
|
if (cached)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
assert_cc(sizeof(usec_t) == sizeof(uint64_t));
|
assert_cc(sizeof(usec_t) == sizeof(uint64_t));
|
||||||
|
|
||||||
if (bus_get_uint64_property(bus,
|
r = bus_map_all_properties(
|
||||||
"/org/freedesktop/systemd1",
|
bus,
|
||||||
"org.freedesktop.systemd1.Manager",
|
"org.freedesktop.systemd1",
|
||||||
"FirmwareTimestampMonotonic",
|
"/org/freedesktop/systemd1",
|
||||||
×.firmware_time) < 0 ||
|
property_map,
|
||||||
bus_get_uint64_property(bus,
|
BUS_MAP_STRDUP,
|
||||||
"/org/freedesktop/systemd1",
|
&error,
|
||||||
"org.freedesktop.systemd1.Manager",
|
NULL,
|
||||||
"LoaderTimestampMonotonic",
|
×);
|
||||||
×.loader_time) < 0 ||
|
if (r < 0)
|
||||||
bus_get_uint64_property(bus,
|
return log_error_errno(r, "Failed to get timestamp properties: %s", bus_error_message(&error, r));
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"KernelTimestamp",
|
|
||||||
×.kernel_time) < 0 ||
|
|
||||||
bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"InitRDTimestampMonotonic",
|
|
||||||
×.initrd_time) < 0 ||
|
|
||||||
bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"UserspaceTimestampMonotonic",
|
|
||||||
×.userspace_time) < 0 ||
|
|
||||||
bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"FinishTimestampMonotonic",
|
|
||||||
×.finish_time) < 0 ||
|
|
||||||
bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"SecurityStartTimestampMonotonic",
|
|
||||||
×.security_start_time) < 0 ||
|
|
||||||
bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"SecurityFinishTimestampMonotonic",
|
|
||||||
×.security_finish_time) < 0 ||
|
|
||||||
bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"GeneratorsStartTimestampMonotonic",
|
|
||||||
×.generators_start_time) < 0 ||
|
|
||||||
bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"GeneratorsFinishTimestampMonotonic",
|
|
||||||
×.generators_finish_time) < 0 ||
|
|
||||||
bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"UnitsLoadStartTimestampMonotonic",
|
|
||||||
×.unitsload_start_time) < 0 ||
|
|
||||||
bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"UnitsLoadFinishTimestampMonotonic",
|
|
||||||
×.unitsload_finish_time) < 0)
|
|
||||||
return -EIO;
|
|
||||||
|
|
||||||
(void) bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"InitRDSecurityStartTimestampMonotonic",
|
|
||||||
×.initrd_security_start_time);
|
|
||||||
(void) bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"InitRDSecurityFinishTimestampMonotonic",
|
|
||||||
×.initrd_security_finish_time);
|
|
||||||
(void) bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"InitRDGeneratorsStartTimestampMonotonic",
|
|
||||||
×.initrd_generators_start_time);
|
|
||||||
(void) bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"InitRDGeneratorsFinishTimestampMonotonic",
|
|
||||||
×.initrd_generators_finish_time);
|
|
||||||
(void) bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"InitRDUnitsLoadStartTimestampMonotonic",
|
|
||||||
×.initrd_unitsload_start_time);
|
|
||||||
(void) bus_get_uint64_property(bus,
|
|
||||||
"/org/freedesktop/systemd1",
|
|
||||||
"org.freedesktop.systemd1.Manager",
|
|
||||||
"InitRDUnitsLoadFinishTimestampMonotonic",
|
|
||||||
×.initrd_unitsload_finish_time);
|
|
||||||
|
|
||||||
if (times.finish_time <= 0) {
|
if (times.finish_time <= 0) {
|
||||||
log_error("Bootup is not yet finished (org.freedesktop.systemd1.Manager.FinishTimestampMonotonic=%"PRIu64").\n"
|
log_error("Bootup is not yet finished (org.freedesktop.systemd1.Manager.FinishTimestampMonotonic=%"PRIu64").\n"
|
||||||
|
@ -385,6 +327,13 @@ static void free_host_info(struct host_info *hi) {
|
||||||
DEFINE_TRIVIAL_CLEANUP_FUNC(struct host_info*, free_host_info);
|
DEFINE_TRIVIAL_CLEANUP_FUNC(struct host_info*, free_host_info);
|
||||||
|
|
||||||
static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
|
static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
|
||||||
|
static const struct bus_properties_map property_map[] = {
|
||||||
|
{ "InactiveExitTimestampMonotonic", "t", NULL, offsetof(struct unit_times, activating) },
|
||||||
|
{ "ActiveEnterTimestampMonotonic", "t", NULL, offsetof(struct unit_times, activated) },
|
||||||
|
{ "ActiveExitTimestampMonotonic", "t", NULL, offsetof(struct unit_times, deactivating) },
|
||||||
|
{ "InactiveEnterTimestampMonotonic", "t", NULL, offsetof(struct unit_times, deactivated) },
|
||||||
|
{},
|
||||||
|
};
|
||||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
_cleanup_(unit_times_freep) struct unit_times *unit_times = NULL;
|
_cleanup_(unit_times_freep) struct unit_times *unit_times = NULL;
|
||||||
|
@ -426,23 +375,17 @@ static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
|
||||||
|
|
||||||
assert_cc(sizeof(usec_t) == sizeof(uint64_t));
|
assert_cc(sizeof(usec_t) == sizeof(uint64_t));
|
||||||
|
|
||||||
if (bus_get_uint64_property(bus, u.unit_path,
|
r = bus_map_all_properties(
|
||||||
"org.freedesktop.systemd1.Unit",
|
bus,
|
||||||
"InactiveExitTimestampMonotonic",
|
"org.freedesktop.systemd1",
|
||||||
&t->activating) < 0 ||
|
u.unit_path,
|
||||||
bus_get_uint64_property(bus, u.unit_path,
|
property_map,
|
||||||
"org.freedesktop.systemd1.Unit",
|
BUS_MAP_STRDUP,
|
||||||
"ActiveEnterTimestampMonotonic",
|
&error,
|
||||||
&t->activated) < 0 ||
|
NULL,
|
||||||
bus_get_uint64_property(bus, u.unit_path,
|
t);
|
||||||
"org.freedesktop.systemd1.Unit",
|
if (r < 0)
|
||||||
"ActiveExitTimestampMonotonic",
|
return log_error_errno(r, "Failed to get timestamp properties of unit %s: %s", u.id, bus_error_message(&error, r));
|
||||||
&t->deactivating) < 0 ||
|
|
||||||
bus_get_uint64_property(bus, u.unit_path,
|
|
||||||
"org.freedesktop.systemd1.Unit",
|
|
||||||
"InactiveEnterTimestampMonotonic",
|
|
||||||
&t->deactivated) < 0)
|
|
||||||
return -EIO;
|
|
||||||
|
|
||||||
subtract_timestamp(&t->activating, boot_times->reverse_offset);
|
subtract_timestamp(&t->activating, boot_times->reverse_offset);
|
||||||
subtract_timestamp(&t->activated, boot_times->reverse_offset);
|
subtract_timestamp(&t->activated, boot_times->reverse_offset);
|
||||||
|
|
Loading…
Reference in a new issue