Message ID | ef15d0e8dc8b58f93537116dd2a43f7d188a8fb6.1615889875.git.petrm@nvidia.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | David Ahern |
Headers | show |
Series | ip: nexthop: Support resilient groups | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
On Tue, 16 Mar 2021 11:20:12 +0100 Petr Machata <petrm@nvidia.com> wrote: > 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> > --- > include/json_print.h | 1 + > lib/json_print.c | 13 +++++++++++++ > 2 files changed, 14 insertions(+) > > diff --git a/include/json_print.h b/include/json_print.h > index 6fcf9fd910ec..63eee3823fe4 100644 > --- a/include/json_print.h > +++ b/include/json_print.h > @@ -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, struct timeval *) This Make it const please?
Stephen Hemminger <stephen@networkplumber.org> writes: >> +_PRINT_FUNC(tv, struct timeval *) > > This > > Make it const please? OK
diff --git a/include/json_print.h b/include/json_print.h index 6fcf9fd910ec..63eee3823fe4 100644 --- a/include/json_print.h +++ b/include/json_print.h @@ -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, struct timeval *) #undef _PRINT_FUNC #define _PRINT_NAME_VALUE_FUNC(type_name, type, format_char) \ diff --git a/lib/json_print.c b/lib/json_print.c index 994a2f8d6ae0..1018bfb36d94 100644 --- a/lib/json_print.c +++ b/lib/json_print.c @@ -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, + 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) {
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> --- include/json_print.h | 1 + lib/json_print.c | 13 +++++++++++++ 2 files changed, 14 insertions(+)