X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_latency.c;h=893bded3b9b387187adbab01eb55e6134001488e;hb=b8913bc047474aa0a3bfbf03ecbb3b5050605ed1;hp=cfe90e27ac97f8869d31cf68c33f32d37f3f55fb;hpb=85349dfd72e43a7dbeab8d8af2d77b779121203a;p=collectd.git diff --git a/src/utils_latency.c b/src/utils_latency.c index cfe90e27..893bded3 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -102,7 +102,7 @@ void change_bin_width (latency_counter_t *lc, size_t val) /* {{{ */ DEBUG("utils_latency: change_bin_width: fixed all bins"); } - DEBUG("utils_latency: change_bin_width: val-[%ld], oldBinWidth-[%d], " + DEBUG("utils_latency: change_bin_width: val-[%zu], oldBinWidth-[%d], " "newBinWidth-[%d], required_bin_width-[%f], " "required_bin_width_logbase2-[%f]", val, old_bin_width, new_bin_width, required_bin_width, @@ -117,6 +117,7 @@ latency_counter_t *latency_counter_create () /* {{{ */ lc = malloc (sizeof (*lc)); if (lc == NULL) return (NULL); + memset (lc, 0, sizeof (*lc)); latency_counter_reset (lc); lc->bin_width = HISTOGRAM_DEFAULT_BIN_WIDTH; @@ -209,7 +210,7 @@ cdtime_t latency_counter_get_average (latency_counter_t *lc) /* {{{ */ { double average; - if (lc == NULL) + if ((lc == NULL) || (lc->num == 0)) return (0); average = CDTIME_T_TO_DOUBLE (lc->sum) / ((double) lc->num); @@ -227,7 +228,7 @@ cdtime_t latency_counter_get_percentile (latency_counter_t *lc, int sum; size_t i; - if ((lc == NULL) || !((percent > 0.0) && (percent < 100.0))) + if ((lc == NULL) || (lc->num == 0) || !((percent > 0.0) && (percent < 100.0))) return (0); /* Find index i so that at least "percent" events are within i+1 ms. */