properties: Skip found set building for nominal case
bus_message_print_all_properties() inserts every name it walks into the found-properties set, but the set is only used to report missing requested properties at debug level. Request the set from systemctl only when properties were specified and debug logging is enabled, avoiding the unnecessary work in normal operation. In my tests with `systemctl show` over 160 units this brings the instructions retired from 1167.8M down to 992.6M, a reduction of 15.0%. The output is unchanged.
This commit is contained in:
@@ -2336,6 +2336,7 @@ static int show_one(
|
||||
.io_read_bytes = UINT64_MAX,
|
||||
.io_write_bytes = UINT64_MAX,
|
||||
};
|
||||
bool collect_found_properties;
|
||||
int r;
|
||||
|
||||
assert(path);
|
||||
@@ -2387,13 +2388,18 @@ static int show_one(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to rewind: %s", bus_error_message(&error, r));
|
||||
|
||||
r = bus_message_print_all_properties(reply, print_property, arg_properties, arg_print_flags, &found_properties);
|
||||
/* The found properties set is expensive and only used for debug logging, so collect it only when needed. */
|
||||
collect_found_properties = DEBUG_LOGGING && !strv_isempty(arg_properties);
|
||||
|
||||
r = bus_message_print_all_properties(reply, print_property, arg_properties, arg_print_flags,
|
||||
collect_found_properties ? &found_properties : NULL);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
STRV_FOREACH(pp, arg_properties)
|
||||
if (!set_contains(found_properties, *pp))
|
||||
log_debug("Property %s does not exist.", *pp);
|
||||
if (collect_found_properties)
|
||||
STRV_FOREACH(pp, arg_properties)
|
||||
if (!set_contains(found_properties, *pp))
|
||||
log_debug("Property %s does not exist.", *pp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user