]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
format-table: add TABLE_TIMESPAN_MSEC
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 15 Jul 2019 15:09:39 +0000 (00:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 15 Jul 2019 15:09:39 +0000 (00:09 +0900)
src/shared/format-table.c
src/shared/format-table.h

index 54ca1972bde65cf0d1bfc9b382b795a655211691..90c80568ac43ec8d69c9a47b0ab9299cc8865ccf 100644 (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);
 
index ada59f34238d2827c5f85a452458ab5a30c63e2a..cd77ea02f0ca14f4b31fd07196c968d50df7be2e 100644 (file)
@@ -14,6 +14,7 @@ typedef enum TableDataType {
         TABLE_BOOLEAN,
         TABLE_TIMESTAMP,
         TABLE_TIMESPAN,
+        TABLE_TIMESPAN_MSEC,
         TABLE_SIZE,
         TABLE_BPS,
         TABLE_INT,