summaryrefslogtreecommitdiffstats
path: root/src/analyze
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2019-07-15 18:07:31 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2019-07-15 18:07:31 +0200
commit7503c6e80e7ea7da03632d408f884cc4a74da37d (patch)
treed209907974f1794b5ae204b70eafe6eb94e82faa /src/analyze
parentanalyze: format output of 'systemd-analyze calendar' by using Table (diff)
downloadsystemd-7503c6e80e7ea7da03632d408f884cc4a74da37d.tar.xz
systemd-7503c6e80e7ea7da03632d408f884cc4a74da37d.zip
analyze: format output of 'systemd-analyze timespan' by using Table
Diffstat (limited to 'src/analyze')
-rw-r--r--src/analyze/analyze.c62
1 files changed, 54 insertions, 8 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 68917003c1..84eb8794cd 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -1721,9 +1721,10 @@ static int dump_timespan(int argc, char *argv[], void *userdata) {
char **input_timespan;
STRV_FOREACH(input_timespan, strv_skip(argv, 1)) {
+ _cleanup_(table_unrefp) Table *table = NULL;
+ usec_t output_usecs;
+ TableCell *cell;
int r;
- usec_t usec_magnitude = 1, output_usecs;
- char ft_buf[FORMAT_TIMESPAN_MAX];
r = parse_time(*input_timespan, &output_usecs, USEC_PER_SEC);
if (r < 0) {
@@ -1732,12 +1733,57 @@ static int dump_timespan(int argc, char *argv[], void *userdata) {
return r;
}
- printf("Original: %s\n", *input_timespan);
- printf(" %ss: %" PRIu64 "\n", special_glyph(SPECIAL_GLYPH_MU), output_usecs);
- printf(" Human: %s%s%s\n",
- ansi_highlight(),
- format_timespan(ft_buf, sizeof(ft_buf), output_usecs, usec_magnitude),
- ansi_normal());
+ table = table_new("NAME", "VALUE");
+ if (!table)
+ return log_oom();
+
+ 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_add_cell(table, NULL, TABLE_STRING, "Original:");
+ if (r < 0)
+ return r;
+
+ r = table_add_cell(table, NULL, TABLE_STRING, *input_timespan);
+ if (r < 0)
+ return r;
+
+ r = table_add_cell_stringf(table, NULL, "%ss:", special_glyph(SPECIAL_GLYPH_MU));
+ if (r < 0)
+ return r;
+
+ r = table_add_cell(table, NULL, TABLE_UINT64, &output_usecs);
+ if (r < 0)
+ return r;
+
+ r = table_add_cell(table, NULL, TABLE_STRING, "Human:");
+ if (r < 0)
+ return r;
+
+ r = table_add_cell(table, &cell, TABLE_TIMESPAN, &output_usecs);
+ if (r < 0)
+ return r;
+
+ r = table_set_color(table, cell, ansi_highlight());
+ if (r < 0)
+ return r;
+
+ r = table_print(table, NULL);
+ if (r < 0)
+ return r;
if (input_timespan[1])
putchar('\n');