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