]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
json_print: Add print_tv()
authorPetr Machata <petrm@nvidia.com>
Wed, 17 Mar 2021 12:54:31 +0000 (13:54 +0100)
committerDavid Ahern <dsahern@kernel.org>
Fri, 19 Mar 2021 15:00:08 +0000 (15:00 +0000)
Add a helper to dump a timeval. Print by first converting to double and
then dispatching to print_color_float().

Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
include/json_print.h
lib/json_print.c

index 6fcf9fd910ecc5d158ffa0f528b2780439813826..91b34571ceb00007ac35f5d171e7cecf65d7f93b 100644 (file)
@@ -81,6 +81,7 @@ _PRINT_FUNC(0xhex, unsigned long long)
 _PRINT_FUNC(luint, unsigned long)
 _PRINT_FUNC(lluint, unsigned long long)
 _PRINT_FUNC(float, double)
+_PRINT_FUNC(tv, const struct timeval *)
 #undef _PRINT_FUNC
 
 #define _PRINT_NAME_VALUE_FUNC(type_name, type, format_char)             \
index 994a2f8d6ae0e44e551d8217e1d799c2e2ef0738..e3a88375fe7c8a563e177e1390be8420a8db9716 100644 (file)
@@ -299,6 +299,19 @@ int print_color_null(enum output_type type,
        return ret;
 }
 
+int print_color_tv(enum output_type type,
+                  enum color_attr color,
+                  const char *key,
+                  const char *fmt,
+                  const struct timeval *tv)
+{
+       double usecs = tv->tv_usec;
+       double secs = tv->tv_sec;
+       double time = secs + usecs / 1000000;
+
+       return print_color_float(type, color, key, fmt, time);
+}
+
 /* Print line separator (if not in JSON mode) */
 void print_nl(void)
 {