u/pp: Move pretty printer for miliseconds to shared code

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2491>
This commit is contained in:
Jakob Bornecrantz authored and Marge Bot committed 2025-06-26 17:33:56 +00:00
1 parent 4d2cb296ea
commit befedee962
3 files changed
+62 -53

No files matched your search

+3 -53
View File
@@ -12,56 +12,6 @@
#include <algorithm>
/*
*
* Helper functions.
*
*/
static void
print_as_ms(u_pp_delegate_t dg, uint64_t value_ns)
{
uint64_t in_us = value_ns / 1000;
uint64_t in_ms = in_us / 1000;
uint64_t in_1_000_ms = in_ms / 1000;
uint64_t in_1_000_000_ms = in_1_000_ms / 1000;
// Prints " M'TTT'###.FFFms"
// " M'"
if (in_1_000_000_ms >= 1) {
u_pp(dg, " %" PRIu64 "'", in_1_000_000_ms);
} else {
// " M'"
u_pp(dg, " ");
}
// "TTT'"
if (in_1_000_ms >= 1000) {
// Need to pad with zeros
u_pp(dg, "%03" PRIu64 "'", in_1_000_ms % 1000);
} else if (in_1_000_ms >= 1) {
// Pad with spaces, we need to write a number.
u_pp(dg, "%3" PRIu64 "'", in_1_000_ms);
} else {
// "TTT'"
u_pp(dg, " ");
}
// "###"
if (in_ms >= 1000) {
// Need to pad with zeros
u_pp(dg, "%03" PRIu64, in_ms % 1000);
} else {
// Pad with spaces, always need a numbere here.
u_pp(dg, "%3" PRIu64, in_ms % 1000);
}
// ".FFFms"
u_pp(dg, ".%03" PRIu64 "ms", in_us % 1000);
}
/*
*
* 'Exported' functions.
@@ -110,7 +60,7 @@ u_ls_ns_print_and_reset(struct u_live_stats_ns *uls, u_pp_delegate_t dg)
u_ls_ns_get_and_reset(uls, &median, &mean, &worst);
u_pp(dg, "%16s", uls->name);
print_as_ms(dg, median);
print_as_ms(dg, mean);
print_as_ms(dg, worst);
u_pp_padded_pretty_ms(dg, median);
u_pp_padded_pretty_ms(dg, mean);
u_pp_padded_pretty_ms(dg, worst);
}
+44
View File
@@ -15,6 +15,7 @@
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <inttypes.h>
/*
@@ -264,6 +265,49 @@ u_pp_xrt_reference_space_type(struct u_pp_delegate dg, enum xrt_reference_space_
}
}
void
u_pp_padded_pretty_ms(u_pp_delegate_t dg, uint64_t value_ns)
{
uint64_t in_us = value_ns / 1000;
uint64_t in_ms = in_us / 1000;
uint64_t in_1_000_ms = in_ms / 1000;
uint64_t in_1_000_000_ms = in_1_000_ms / 1000;
// Prints " M'TTT'###.FFFms"
// " M'"
if (in_1_000_000_ms >= 1) {
u_pp(dg, " %" PRIu64 "'", in_1_000_000_ms);
} else {
// " M'"
u_pp(dg, " ");
}
// "TTT'"
if (in_1_000_ms >= 1000) {
// Need to pad with zeros
u_pp(dg, "%03" PRIu64 "'", in_1_000_ms % 1000);
} else if (in_1_000_ms >= 1) {
// Pad with spaces, we need to write a number.
u_pp(dg, "%3" PRIu64 "'", in_1_000_ms);
} else {
// "TTT'"
u_pp(dg, " ");
}
// "###"
if (in_ms >= 1000) {
// Need to pad with zeros
u_pp(dg, "%03" PRIu64, in_ms % 1000);
} else {
// Pad with spaces, always need a numbere here.
u_pp(dg, "%3" PRIu64, in_ms % 1000);
}
// ".FFFms"
u_pp(dg, ".%03" PRIu64 "ms", in_us % 1000);
}
/*
*
+15
View File
@@ -1,4 +1,5 @@
// Copyright 2022, Collabora, Ltd.
// Copyright 2024-2025, NVIDIA CORPORATION.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
@@ -102,6 +103,20 @@ void
u_pp_xrt_reference_space_type(struct u_pp_delegate dg, enum xrt_reference_space_type type);
/*!
* Pretty prints a milliseconds padded to be at least 16 characters, the
* formatting is meant to be human readable, does not use locale.
*
* Formatted as: " M'TTT'###.FFFms"
* Zero: " 0.000ms"
*
* If the value is 10 seconds or larger (MM) then it will be longer then 16
* characters.
*/
void
u_pp_padded_pretty_ms(u_pp_delegate_t dg, uint64_t value_ns);
/*
*
* Math struct printers.