analyze: format output of 'systemd-analyze timestamp' by using Table
This commit is contained in:
parent
7503c6e80e
commit
af2d6d477c
|
@ -1793,8 +1793,9 @@ static int dump_timespan(int argc, char *argv[], void *userdata) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_timestamp_one(const char *p) {
|
static int test_timestamp_one(const char *p) {
|
||||||
|
_cleanup_(table_unrefp) Table *table = NULL;
|
||||||
|
TableCell *cell;
|
||||||
usec_t usec;
|
usec_t usec;
|
||||||
char buf[FORMAT_TIMESTAMP_MAX];
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = parse_timestamp(p, &usec);
|
r = parse_timestamp(p, &usec);
|
||||||
|
@ -1804,24 +1805,77 @@ static int test_timestamp_one(const char *p) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(" Original form: %s\n", p);
|
table = table_new("NAME", "VALUE");
|
||||||
printf("Normalized form: %s%s%s\n",
|
if (!table)
|
||||||
ansi_highlight_blue(),
|
return log_oom();
|
||||||
format_timestamp(buf, sizeof buf, usec),
|
|
||||||
ansi_normal());
|
|
||||||
|
|
||||||
if (!in_utc_timezone())
|
table_set_header(table, false);
|
||||||
printf(" (in UTC): %s\n", format_timestamp_utc(buf, sizeof buf, usec));
|
|
||||||
|
|
||||||
printf(" UNIX seconds: @%"PRI_USEC"%s%0*"PRI_USEC"\n",
|
assert_se(cell = table_get_cell(table, 0, 0));
|
||||||
usec / USEC_PER_SEC,
|
r = table_set_ellipsize_percent(table, cell, 100);
|
||||||
usec % USEC_PER_SEC ? "." : "",
|
if (r < 0)
|
||||||
usec % USEC_PER_SEC ? 6 : 0,
|
return r;
|
||||||
usec % USEC_PER_SEC);
|
|
||||||
|
|
||||||
printf(" From now: %s\n", format_timestamp_relative(buf, sizeof buf, usec));
|
r = table_set_align_percent(table, cell, 100);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
return 0;
|
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 form:");
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = table_add_cell(table, NULL, TABLE_STRING, p);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = table_add_cell(table, NULL, TABLE_STRING, "Normalized form:");
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = table_add_cell(table, &cell, TABLE_TIMESTAMP, &usec);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = table_set_color(table, cell, ansi_highlight_blue());
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
if (!in_utc_timezone()) {
|
||||||
|
r = table_add_cell(table, NULL, TABLE_STRING, "(in UTC):");
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = table_add_cell(table, &cell, TABLE_TIMESTAMP_UTC, &usec);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = table_add_cell(table, NULL, TABLE_STRING, "UNIX seconds:");
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = table_add_cell_stringf(table, &cell, "@%"PRI_USEC"%s%0*"PRI_USEC"",
|
||||||
|
usec / USEC_PER_SEC,
|
||||||
|
usec % USEC_PER_SEC ? "." : "",
|
||||||
|
usec % USEC_PER_SEC ? 6 : 0,
|
||||||
|
usec % USEC_PER_SEC);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = table_add_cell(table, NULL, TABLE_STRING, "From now:");
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
r = table_add_cell(table, &cell, TABLE_TIMESTAMP_RELATIVE, &usec);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
return table_print(table, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_timestamp(int argc, char *argv[], void *userdata) {
|
static int test_timestamp(int argc, char *argv[], void *userdata) {
|
||||||
|
|
Loading…
Reference in a new issue