summaryrefslogtreecommitdiff
path: root/util/qdist.c
AgeCommit message (Collapse)AuthorFilesLines
2016-08-03qdist: return "(empty)" instead of NULL when printing an empty distEmilio G. Cota1-2/+4
Printf'ing a NULL string is undefined behaviour. Avoid it. Reported-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Emilio G. Cota <cota@braap.org> Message-Id: <1469459025-23606-4-git-send-email-cota@braap.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-08-03qdist: use g_renew and g_new instead of g_realloc and g_malloc.Emilio G. Cota1-4/+3
This is safer against overflow. g_renew is available in all version of glib, while g_realloc_n is only available in 2.24. Signed-off-by: Emilio G. Cota <cota@braap.org> Message-Id: <1469459025-23606-3-git-send-email-cota@braap.org> [Rewritten to use g_new/g_renew. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-08-02qdist: fix memory leak during binningEmilio G. Cota1-1/+1
In qdist_bin__internal(), to->entries is initialized to a 1-element array, which we then leak when n == from->n. Fix it. Signed-off-by: Emilio G. Cota <cota@braap.org> Message-Id: <1469459025-23606-2-git-send-email-cota@braap.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-06-16clean-includes: run it once morePaolo Bonzini1-0/+1
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-06-11qdist: add module to represent frequency distributions of dataEmilio G. Cota1-0/+395
Sometimes it is useful to have a quick histogram to represent a certain distribution -- for example, when investigating a performance regression in a hash table due to inadequate hashing. The appended allows us to easily represent a distribution using Unicode characters. Further, the data structure keeping track of the distribution is so simple that obtaining its values for off-line processing is trivial. Example, taking the last 10 commits to QEMU: Characters in commit title Count ----------------------------------- 39 1 48 1 53 1 54 2 57 1 61 1 67 1 78 1 80 1 qdist_init(&dist); qdist_inc(&dist, 39); [...] qdist_inc(&dist, 80); char *str = qdist_pr(&dist, 9, QDIST_PR_LABELS); // -> [39.0,43.6)▂▂ █▂ ▂ ▄[75.4,80.0] g_free(str); char *str = qdist_pr(&dist, 4, QDIST_PR_LABELS); // -> [39.0,49.2)▁█▁▁[69.8,80.0] g_free(str); Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Emilio G. Cota <cota@braap.org> Message-Id: <1465412133-3029-9-git-send-email-cota@braap.org> Signed-off-by: Richard Henderson <rth@twiddle.net>