| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-bus.h" |
| 4 |
|
| 5 |
#include "analyze.h" |
| 6 |
#include "analyze-blame.h" |
| 7 |
#include "analyze-time-data.h" |
| 8 |
#include "bus-util.h" |
| 9 |
#include "format-table.h" |
| 10 |
#include "runtime-scope.h" |
| 11 |
|
| 12 |
int verb_blame(int argc, char *argv[], uintptr_t _data, void *userdata) { |
| 13 |
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; |
| 14 |
_cleanup_(unit_times_free_arrayp) UnitTimes *times = NULL; |
| 15 |
_cleanup_(table_unrefp) Table *table = NULL; |
| 16 |
TableCell *cell; |
| 17 |
int n, r; |
| 18 |
|
| 19 |
r = acquire_bus(&bus, NULL); |
| 20 |
if (r < 0) |
| 21 |
return bus_log_connect_error(r, arg_transport, arg_runtime_scope); |
| 22 |
|
| 23 |
n = acquire_time_data(bus, /* require_finished= */ false, ×); |
| 24 |
if (n <= 0) |
| 25 |
return n; |
| 26 |
|
| 27 |
table = table_new("time", "unit"); |
| 28 |
if (!table) |
| 29 |
return log_oom(); |
| 30 |
|
| 31 |
assert_se(cell = table_get_cell(table, 0, 0)); |
| 32 |
(void) table_set_ellipsize_percent(table, cell, 100); |
| 33 |
|
| 34 |
(void) table_set_align_percent(table, cell, 100); |
| 35 |
|
| 36 |
assert_se(cell = table_get_cell(table, 0, 1)); |
| 37 |
(void) table_set_ellipsize_percent(table, cell, 100); |
| 38 |
|
| 39 |
r = table_set_sort(table, (size_t) 0); |
| 40 |
if (r < 0) |
| 41 |
return table_log_sort_error(r); |
| 42 |
|
| 43 |
r = table_set_reverse(table, 0, true); |
| 44 |
if (r < 0) |
| 45 |
return table_log_sort_error(r); |
| 46 |
|
| 47 |
for (UnitTimes *u = times; u->has_data; u++) { |
| 48 |
if (u->time <= 0) |
| 49 |
continue; |
| 50 |
|
| 51 |
r = table_add_many(table, |
| 52 |
TABLE_TIMESPAN_MSEC, u->time, |
| 53 |
TABLE_STRING, u->name); |
| 54 |
if (r < 0) |
| 55 |
return table_log_add_error(r); |
| 56 |
} |
| 57 |
|
| 58 |
return table_print_with_pager(table, arg_json_format_flags, arg_pager_flags, /* show_header= */ false); |
| 59 |
} |