The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2491>

authored by

Jakob Bornecrantz and committed by
Marge Bot
befedee9 4d2cb296

+62 -53
+3 -53
src/xrt/auxiliary/util/u_live_stats.cpp
··· 14 14 15 15 /* 16 16 * 17 - * Helper functions. 18 - * 19 - */ 20 - 21 - static void 22 - print_as_ms(u_pp_delegate_t dg, uint64_t value_ns) 23 - { 24 - uint64_t in_us = value_ns / 1000; 25 - uint64_t in_ms = in_us / 1000; 26 - uint64_t in_1_000_ms = in_ms / 1000; 27 - uint64_t in_1_000_000_ms = in_1_000_ms / 1000; 28 - 29 - // Prints " M'TTT'###.FFFms" 30 - 31 - // " M'" 32 - if (in_1_000_000_ms >= 1) { 33 - u_pp(dg, " %" PRIu64 "'", in_1_000_000_ms); 34 - } else { 35 - // " M'" 36 - u_pp(dg, " "); 37 - } 38 - 39 - // "TTT'" 40 - if (in_1_000_ms >= 1000) { 41 - // Need to pad with zeros 42 - u_pp(dg, "%03" PRIu64 "'", in_1_000_ms % 1000); 43 - } else if (in_1_000_ms >= 1) { 44 - // Pad with spaces, we need to write a number. 45 - u_pp(dg, "%3" PRIu64 "'", in_1_000_ms); 46 - } else { 47 - // "TTT'" 48 - u_pp(dg, " "); 49 - } 50 - 51 - // "###" 52 - if (in_ms >= 1000) { 53 - // Need to pad with zeros 54 - u_pp(dg, "%03" PRIu64, in_ms % 1000); 55 - } else { 56 - // Pad with spaces, always need a numbere here. 57 - u_pp(dg, "%3" PRIu64, in_ms % 1000); 58 - } 59 - 60 - // ".FFFms" 61 - u_pp(dg, ".%03" PRIu64 "ms", in_us % 1000); 62 - } 63 - 64 - 65 - /* 66 - * 67 17 * 'Exported' functions. 68 18 * 69 19 */ ··· 110 60 u_ls_ns_get_and_reset(uls, &median, &mean, &worst); 111 61 112 62 u_pp(dg, "%16s", uls->name); 113 - print_as_ms(dg, median); 114 - print_as_ms(dg, mean); 115 - print_as_ms(dg, worst); 63 + u_pp_padded_pretty_ms(dg, median); 64 + u_pp_padded_pretty_ms(dg, mean); 65 + u_pp_padded_pretty_ms(dg, worst); 116 66 }
+44
src/xrt/auxiliary/util/u_pretty_print.c
··· 15 15 #include <string.h> 16 16 #include <stdarg.h> 17 17 #include <stdio.h> 18 + #include <inttypes.h> 18 19 19 20 20 21 /* ··· 262 263 case XRT_SPACE_REFERENCE_TYPE_INVALID: DG("XRT_SPACE_REFERENCE_TYPE_INVALID"); return; 263 264 default: u_pp(dg, "XRT_SPACE_REFERENCE_TYPE_0x%08x", type); return; 264 265 } 266 + } 267 + 268 + void 269 + u_pp_padded_pretty_ms(u_pp_delegate_t dg, uint64_t value_ns) 270 + { 271 + uint64_t in_us = value_ns / 1000; 272 + uint64_t in_ms = in_us / 1000; 273 + uint64_t in_1_000_ms = in_ms / 1000; 274 + uint64_t in_1_000_000_ms = in_1_000_ms / 1000; 275 + 276 + // Prints " M'TTT'###.FFFms" 277 + 278 + // " M'" 279 + if (in_1_000_000_ms >= 1) { 280 + u_pp(dg, " %" PRIu64 "'", in_1_000_000_ms); 281 + } else { 282 + // " M'" 283 + u_pp(dg, " "); 284 + } 285 + 286 + // "TTT'" 287 + if (in_1_000_ms >= 1000) { 288 + // Need to pad with zeros 289 + u_pp(dg, "%03" PRIu64 "'", in_1_000_ms % 1000); 290 + } else if (in_1_000_ms >= 1) { 291 + // Pad with spaces, we need to write a number. 292 + u_pp(dg, "%3" PRIu64 "'", in_1_000_ms); 293 + } else { 294 + // "TTT'" 295 + u_pp(dg, " "); 296 + } 297 + 298 + // "###" 299 + if (in_ms >= 1000) { 300 + // Need to pad with zeros 301 + u_pp(dg, "%03" PRIu64, in_ms % 1000); 302 + } else { 303 + // Pad with spaces, always need a numbere here. 304 + u_pp(dg, "%3" PRIu64, in_ms % 1000); 305 + } 306 + 307 + // ".FFFms" 308 + u_pp(dg, ".%03" PRIu64 "ms", in_us % 1000); 265 309 } 266 310 267 311
+15
src/xrt/auxiliary/util/u_pretty_print.h
··· 1 1 // Copyright 2022, Collabora, Ltd. 2 + // Copyright 2024-2025, NVIDIA CORPORATION. 2 3 // SPDX-License-Identifier: BSL-1.0 3 4 /*! 4 5 * @file ··· 100 101 */ 101 102 void 102 103 u_pp_xrt_reference_space_type(struct u_pp_delegate dg, enum xrt_reference_space_type type); 104 + 105 + 106 + /*! 107 + * Pretty prints a milliseconds padded to be at least 16 characters, the 108 + * formatting is meant to be human readable, does not use locale. 109 + * 110 + * Formatted as: " M'TTT'###.FFFms" 111 + * Zero: " 0.000ms" 112 + * 113 + * If the value is 10 seconds or larger (MM) then it will be longer then 16 114 + * characters. 115 + */ 116 + void 117 + u_pp_padded_pretty_ms(u_pp_delegate_t dg, uint64_t value_ns); 103 118 104 119 105 120 /*