format-table: add TABLE_TIMESPAN_MSEC

This commit is contained in:
Yu Watanabe 2019-07-16 00:09:39 +09:00
parent 8eb0cafeb0
commit ba99f19c0d
2 changed files with 9 additions and 2 deletions

View File

@ -231,6 +231,7 @@ static size_t table_data_size(TableDataType type, const void *data) {
case TABLE_TIMESTAMP:
case TABLE_TIMESPAN:
case TABLE_TIMESPAN_MSEC:
return sizeof(usec_t);
case TABLE_SIZE:
@ -720,6 +721,7 @@ int table_add_many_internal(Table *t, TableDataType first_type, ...) {
case TABLE_TIMESTAMP:
case TABLE_TIMESPAN:
case TABLE_TIMESPAN_MSEC:
buffer.usec = va_arg(ap, usec_t);
data = &buffer.usec;
break;
@ -885,6 +887,7 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
return CMP(a->timestamp, b->timestamp);
case TABLE_TIMESPAN:
case TABLE_TIMESPAN_MSEC:
return CMP(a->timespan, b->timespan);
case TABLE_SIZE:
@ -999,14 +1002,16 @@ static const char *table_data_format(TableData *d) {
break;
}
case TABLE_TIMESPAN: {
case TABLE_TIMESPAN:
case TABLE_TIMESPAN_MSEC: {
_cleanup_free_ char *p;
p = new(char, FORMAT_TIMESPAN_MAX);
if (!p)
return NULL;
if (!format_timespan(p, FORMAT_TIMESPAN_MAX, d->timespan, 0))
if (!format_timespan(p, FORMAT_TIMESPAN_MAX, d->timespan,
d->type == TABLE_TIMESPAN ? 0 : USEC_PER_MSEC))
return "n/a";
d->formatted = TAKE_PTR(p);
@ -1638,6 +1643,7 @@ static int table_data_to_json(TableData *d, JsonVariant **ret) {
return json_variant_new_unsigned(ret, d->timestamp);
case TABLE_TIMESPAN:
case TABLE_TIMESPAN_MSEC:
if (d->timespan == USEC_INFINITY)
return json_variant_new_null(ret);

View File

@ -14,6 +14,7 @@ typedef enum TableDataType {
TABLE_BOOLEAN,
TABLE_TIMESTAMP,
TABLE_TIMESPAN,
TABLE_TIMESPAN_MSEC,
TABLE_SIZE,
TABLE_BPS,
TABLE_INT,