summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0eebd26)
raw | patch | inline | side by side (parent: 0eebd26)
author | Florian Forster <octo@collectd.org> | |
Sun, 12 Jul 2015 10:58:20 +0000 (12:58 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 13 Jul 2015 09:55:58 +0000 (11:55 +0200) |
A missing cast when calculating "width_change_ratio" caused all metrics to
be moved to bucket #0.
be moved to bucket #0.
src/utils_latency.c | patch | blob | history |
diff --git a/src/utils_latency.c b/src/utils_latency.c
index c6a1ff6669185746d9ea1da8e0e56553946f10d9..5d3b1468544134ddfdb3a7c235d2985fb5a6ad08 100644 (file)
--- a/src/utils_latency.c
+++ b/src/utils_latency.c
*
* So, if the required bin width is 300, then new bin width will be 512 as it is
* the next nearest power of 2.
-*
*/
void change_bin_width (latency_counter_t *lc, size_t val) /* {{{ */
{
- int i=0;
/* This function is called because the new value is above histogram's range.
* First find the required bin width:
* requiredBinWidth = (value + 1) / numBins
double required_bin_width_logbase2 = log(required_bin_width) / log(2.0);
int new_bin_width = (int)(pow(2.0, ceil( required_bin_width_logbase2)));
int old_bin_width = lc->bin_width;
+
lc->bin_width = new_bin_width;
/*
*/
if (lc->num > 0) // if the histogram has data then iterate else skip
{
- double width_change_ratio = old_bin_width / new_bin_width;
- for (i=0; i<HISTOGRAM_NUM_BINS; i++)
+ double width_change_ratio = ((double) old_bin_width) / ((double) new_bin_width);
+ size_t i;
+
+ for (i = 0; i < HISTOGRAM_NUM_BINS; i++)
{
- int new_bin = (int)(i * width_change_ratio);
+ size_t new_bin = (size_t) (((double) i) * width_change_ratio);
if (i == new_bin)
continue;
+ assert (new_bin < i);
+
+ if (lc->histogram[i] != 0) {
+ DEBUG ("utils_latency: moving %d from %zu to %zu.", lc->histogram[i], i, new_bin);
+ }
lc->histogram[new_bin] += lc->histogram[i];
lc->histogram[i] = 0;
}
- DEBUG("utils_latency: change_bin_width: fixed all bins");
}
DEBUG("utils_latency: change_bin_width: val-[%zu], oldBinWidth-[%d], "
"required_bin_width_logbase2-[%f]",
val, old_bin_width, new_bin_width, required_bin_width,
required_bin_width_logbase2);
-
} /* }}} void change_bin_width */
latency_counter_t *latency_counter_create () /* {{{ */