]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/analyze/analyze-timespan.c
blockdev-util: "partscan" sysattr now directly shows the enabled state
[thirdparty/systemd.git] / src / analyze / analyze-timespan.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "analyze.h"
4 #include "analyze-timespan.h"
5 #include "calendarspec.h"
6 #include "format-table.h"
7 #include "glyph-util.h"
8 #include "strv.h"
9 #include "terminal-util.h"
10
11 int verb_timespan(int argc, char *argv[], void *userdata) {
12 STRV_FOREACH(input_timespan, strv_skip(argv, 1)) {
13 _cleanup_(table_unrefp) Table *table = NULL;
14 usec_t output_usecs;
15 TableCell *cell;
16 int r;
17
18 r = parse_time(*input_timespan, &output_usecs, USEC_PER_SEC);
19 if (r < 0) {
20 log_error_errno(r, "Failed to parse time span '%s': %m", *input_timespan);
21 time_parsing_hint(*input_timespan, /* calendar= */ true, /* timestamp= */ true, /* timespan= */ false);
22 return r;
23 }
24
25 table = table_new_vertical();
26 if (!table)
27 return log_oom();
28
29 assert_se(cell = table_get_cell(table, 0, 0));
30 r = table_set_ellipsize_percent(table, cell, 100);
31 if (r < 0)
32 return r;
33
34 assert_se(cell = table_get_cell(table, 0, 1));
35 r = table_set_ellipsize_percent(table, cell, 100);
36 if (r < 0)
37 return r;
38
39 r = table_add_many(table,
40 TABLE_FIELD, "Original",
41 TABLE_STRING, *input_timespan);
42 if (r < 0)
43 return table_log_add_error(r);
44
45 r = table_add_cell_stringf_full(table, NULL, TABLE_FIELD, "%ss", special_glyph(SPECIAL_GLYPH_MU));
46 if (r < 0)
47 return table_log_add_error(r);
48
49 r = table_add_many(table,
50 TABLE_UINT64, output_usecs,
51 TABLE_FIELD, "Human",
52 TABLE_TIMESPAN, output_usecs,
53 TABLE_SET_COLOR, ansi_highlight());
54 if (r < 0)
55 return table_log_add_error(r);
56
57 r = table_print(table, NULL);
58 if (r < 0)
59 return r;
60
61 if (input_timespan[1])
62 putchar('\n');
63 }
64
65 return 0;
66 }