diff --git a/src/xrt/auxiliary/util/u_live_stats.cpp b/src/xrt/auxiliary/util/u_live_stats.cpp index 817debcaf..1c82e126f 100644 --- a/src/xrt/auxiliary/util/u_live_stats.cpp +++ b/src/xrt/auxiliary/util/u_live_stats.cpp @@ -12,56 +12,6 @@ #include -/* - * - * 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); } diff --git a/src/xrt/auxiliary/util/u_pretty_print.c b/src/xrt/auxiliary/util/u_pretty_print.c index fb487578d..287aea62d 100644 --- a/src/xrt/auxiliary/util/u_pretty_print.c +++ b/src/xrt/auxiliary/util/u_pretty_print.c @@ -15,6 +15,7 @@ #include #include #include +#include /* @@ -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); +} + /* * diff --git a/src/xrt/auxiliary/util/u_pretty_print.h b/src/xrt/auxiliary/util/u_pretty_print.h index 9804dc587..5e0f44b4d 100644 --- a/src/xrt/auxiliary/util/u_pretty_print.h +++ b/src/xrt/auxiliary/util/u_pretty_print.h @@ -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.