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 */ 23struct qdist_entry { 24 double x; 25 unsigned long count; 26}; 27 28struct 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 42void qdist_init(struct qdist *dist); 43void qdist_destroy(struct qdist *dist); 44 45void qdist_add(struct qdist *dist, double x, long count); 46void qdist_inc(struct qdist *dist, double x); 47double qdist_xmin(const struct qdist *dist); 48double qdist_xmax(const struct qdist *dist); 49double qdist_avg(const struct qdist *dist); 50unsigned long qdist_sample_count(const struct qdist *dist); 51size_t qdist_unique_entries(const struct qdist *dist); 52 53/* callers must free the returned string with g_free() */ 54char *qdist_pr_plain(const struct qdist *dist, size_t n_groups); 55 56/* callers must free the returned string with g_free() */ 57char *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 */ 60void qdist_bin__internal(struct qdist *to, const struct qdist *from, size_t n); 61 62#endif /* QEMU_QDIST_H */ 63