#include "def.h"
#include "fd-util.h"
#include "fileio.h"
+#include "format-table.h"
#include "glob-util.h"
#include "hashmap.h"
#include "locale-util.h"
return 0;
}
-static int compare_unit_time(const struct unit_times *a, const struct unit_times *b) {
- return CMP(b->time, a->time);
-}
-
static int compare_unit_start(const struct unit_times *a, const struct unit_times *b) {
return CMP(a->activating, b->activating);
}
static int analyze_blame(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_(unit_times_freep) struct unit_times *times = NULL;
+ _cleanup_(table_unrefp) Table *table = NULL;
struct unit_times *u;
+ TableCell *cell;
int n, r;
r = acquire_bus(&bus, NULL);
if (n <= 0)
return n;
- typesafe_qsort(times, n, compare_unit_time);
+ table = table_new("TIME", "UNIT");
+ if (!table)
+ return log_oom();
- (void) pager_open(arg_pager_flags);
+ table_set_header(table, false);
+
+ assert_se(cell = table_get_cell(table, 0, 0));
+ r = table_set_ellipsize_percent(table, cell, 100);
+ if (r < 0)
+ return r;
+
+ r = table_set_align_percent(table, cell, 100);
+ if (r < 0)
+ return r;
+
+ assert_se(cell = table_get_cell(table, 0, 1));
+ r = table_set_ellipsize_percent(table, cell, 100);
+ if (r < 0)
+ return r;
+
+ r = table_set_sort(table, 0, SIZE_MAX);
+ if (r < 0)
+ return r;
+
+ r = table_set_reverse(table, 0, true);
+ if (r < 0)
+ return r;
for (u = times; u->has_data; u++) {
- char ts[FORMAT_TIMESPAN_MAX];
+ if (u->time <= 0)
+ continue;
+
+ r = table_add_cell(table, NULL, TABLE_TIMESPAN_MSEC, &u->time);
+ if (r < 0)
+ return r;
- if (u->time > 0)
- printf("%16s %s\n", format_timespan(ts, sizeof(ts), u->time, USEC_PER_MSEC), u->name);
+ r = table_add_cell(table, NULL, TABLE_STRING, u->name);
+ if (r < 0)
+ return r;
}
- return 0;
+ (void) pager_open(arg_pager_flags);
+
+ return table_print(table, NULL);
}
static int analyze_time(int argc, char *argv[], void *userdata) {