json_print: Add print_tv()
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>
This commit is contained in:
parent
a5b355c08c
commit
e757f741e9
|
|
@ -81,6 +81,7 @@ _PRINT_FUNC(0xhex, unsigned long long)
|
||||||
_PRINT_FUNC(luint, unsigned long)
|
_PRINT_FUNC(luint, unsigned long)
|
||||||
_PRINT_FUNC(lluint, unsigned long long)
|
_PRINT_FUNC(lluint, unsigned long long)
|
||||||
_PRINT_FUNC(float, double)
|
_PRINT_FUNC(float, double)
|
||||||
|
_PRINT_FUNC(tv, const struct timeval *)
|
||||||
#undef _PRINT_FUNC
|
#undef _PRINT_FUNC
|
||||||
|
|
||||||
#define _PRINT_NAME_VALUE_FUNC(type_name, type, format_char) \
|
#define _PRINT_NAME_VALUE_FUNC(type_name, type, format_char) \
|
||||||
|
|
|
||||||
|
|
@ -299,6 +299,19 @@ int print_color_null(enum output_type type,
|
||||||
return ret;
|
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) */
|
/* Print line separator (if not in JSON mode) */
|
||||||
void print_nl(void)
|
void print_nl(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue