Monado OpenXR Runtime
u_live_stats.h
Go to the documentation of this file.
1// Copyright 2024, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Live stats tracking and printing.
6 * @author Jakob Bornecrantz <jakob@collabora.com>
7 * @ingroup aux_util
8 */
9#pragma once
10
11#include "xrt/xrt_compiler.h"
12
13#include "util/u_pretty_print.h"
14
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/*!
21 * Number of chars for the name of the live stats.
22 *
23 * @ingroup aux_util
24 */
25#define U_LIVE_STATS_NAME_COUNT (16)
26
27/*!
28 * Max number of values that can be put into the trackers.
29 *
30 * @ingroup aux_util
31 */
32#define U_LIVE_STATS_VALUE_COUNT (1024)
33
34/*!
35 * Struct to do live statistic tracking and printing of nano-seconds values,
36 * used by amongst other the compositor pacing code.
37 *
38 * @ingroup aux_util
39 */
41{
42 //! Small name used for printing.
44
45 //! Number of values currently in struct.
46 uint32_t value_count;
47
48 //! The values that will be used to calculate statistics.
50};
51
52/*!
53 * Add a value to the live stats struct, returns true if the struct is full
54 * either before or after adding the value.
55 *
56 * @public @memberof u_live_stats_ns
57 * @ingroup aux_util
58 */
59static inline bool
60u_ls_ns_add(struct u_live_stats_ns *uls, uint64_t value)
61{
62 if (uls->value_count >= ARRAY_SIZE(uls->values)) {
63 return true;
64 }
65
66 uls->values[uls->value_count++] = value;
67
68 if (uls->value_count >= ARRAY_SIZE(uls->values)) {
69 return true;
70 }
71
72 return false;
73}
74
75/*!
76 * Get the median, mean and worst of the current set of values,
77 * then reset the struct.
78 *
79 * @public @memberof u_live_stats_ns
80 */
81void
82u_ls_ns_get_and_reset(struct u_live_stats_ns *uls, uint64_t *out_median, uint64_t *out_mean, uint64_t *out_worst);
83
84/*!
85 * Prints a header that looks nice before @ref u_ls_ns_print_and_reset,
86 * adding details about columns. Doesn't include any newlines.
87 *
88 * @public @memberof u_live_stats_ns
89 */
90void
92
93/*!
94 * Prints the calculated values and resets the struct, can be used with
95 * @ref u_ls_ns_print_header to get a nice header to the values. Doesn't
96 * include any newlines.
97 *
98 * @public @memberof u_live_stats_ns
99 */
100void
102
103
104#ifdef __cplusplus
105}
106#endif
#define U_LIVE_STATS_NAME_COUNT
Number of chars for the name of the live stats.
Definition: u_live_stats.h:25
#define U_LIVE_STATS_VALUE_COUNT
Max number of values that can be put into the trackers.
Definition: u_live_stats.h:32
static bool u_ls_ns_add(struct u_live_stats_ns *uls, uint64_t value)
Add a value to the live stats struct, returns true if the struct is full either before or after addin...
Definition: u_live_stats.h:60
Struct to do live statistic tracking and printing of nano-seconds values, used by amongst other the c...
Definition: u_live_stats.h:41
uint32_t value_count
Number of values currently in struct.
Definition: u_live_stats.h:46
void u_ls_ns_get_and_reset(struct u_live_stats_ns *uls, uint64_t *out_median, uint64_t *out_mean, uint64_t *out_worst)
Get the median, mean and worst of the current set of values, then reset the struct.
Definition: u_live_stats.cpp:72
void u_ls_ns_print_header(u_pp_delegate_t dg)
Prints a header that looks nice before u_ls_ns_print_and_reset, adding details about columns.
Definition: u_live_stats.cpp:100
char name[(16)]
Small name used for printing.
Definition: u_live_stats.h:43
void u_ls_ns_print_and_reset(struct u_live_stats_ns *uls, u_pp_delegate_t dg)
Prints the calculated values and resets the struct, can be used with u_ls_ns_print_header to get a ni...
Definition: u_live_stats.cpp:107
uint64_t values[(1024)]
The values that will be used to calculate statistics.
Definition: u_live_stats.h:49
Helper struct to hold a function pointer and data pointer.
Definition: u_pretty_print.h:49
Pretty printing various Monado things.
Header holding common defines.
#define ARRAY_SIZE(a)
Array size helper.
Definition: xrt_compiler.h:30