xref: /openbmc/qemu/include/qemu/qdist.h (revision 709395f8)
1 /*
2  * Copyright (C) 2016, Emilio G. Cota <cota@braap.org>
3  *
4  * License: GNU GPL, version 2 or later.
5  *   See the COPYING file in the top-level directory.
6  */
7 #ifndef QEMU_QDIST_H
8 #define QEMU_QDIST_H
9 
10 #include "qemu-common.h"
11 #include "qemu/bitops.h"
12 
13 /*
14  * Samples with the same 'x value' end up in the same qdist_entry,
15  * e.g. inc(0.1) and inc(0.1) end up as {x=0.1, count=2}.
16  *
17  * Binning happens only at print time, so that we retain the flexibility to
18  * choose the binning. This might not be ideal for workloads that do not care
19  * much about precision and insert many samples all with different x values;
20  * in that case, pre-binning (e.g. entering both 0.115 and 0.097 as 0.1)
21  * should be considered.
22  */
23 struct qdist_entry {
24     double x;
25     unsigned long count;
26 };
27 
28 struct qdist {
29     struct qdist_entry *entries;
30     size_t n;
31     size_t size;
32 };
33 
34 #define QDIST_PR_BORDER     BIT(0)
35 #define QDIST_PR_LABELS     BIT(1)
36 /* the remaining options only work if PR_LABELS is set */
37 #define QDIST_PR_NODECIMAL  BIT(2)
38 #define QDIST_PR_PERCENT    BIT(3)
39 #define QDIST_PR_100X       BIT(4)
40 #define QDIST_PR_NOBINRANGE BIT(5)
41 
42 void qdist_init(struct qdist *dist);
43 void qdist_destroy(struct qdist *dist);
44 
45 void qdist_add(struct qdist *dist, double x, long count);
46 void qdist_inc(struct qdist *dist, double x);
47 double qdist_xmin(const struct qdist *dist);
48 double qdist_xmax(const struct qdist *dist);
49 double qdist_avg(const struct qdist *dist);
50 unsigned long qdist_sample_count(const struct qdist *dist);
51 size_t qdist_unique_entries(const struct qdist *dist);
52 
53 /* callers must free the returned string with g_free() */
54 char *qdist_pr_plain(const struct qdist *dist, size_t n_groups);
55 
56 /* callers must free the returned string with g_free() */
57 char *qdist_pr(const struct qdist *dist, size_t n_groups, uint32_t opt);
58 
59 /* Only qdist code and test code should ever call this function */
60 void qdist_bin__internal(struct qdist *to, const struct qdist *from, size_t n);
61 
62 #endif /* QEMU_QDIST_H */
63