X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Futils_latency.c;h=7699f570721aa747240869f54a53a7144d081598;hb=cadc1d5581d3024f4c5ebb940cd49a0dec45c9d4;hp=4a250c33a4143730f1609da50af3ac428855c79a;hpb=9c7fee6fa1c83bd76b39d16fe5376cfb6ef192e4;p=collectd.git diff --git a/src/utils_latency.c b/src/utils_latency.c index 4a250c33..7699f570 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -117,11 +117,18 @@ cdtime_t latency_counter_get_sum (latency_counter_t *lc) /* {{{ */ return (lc->sum); } /* }}} cdtime_t latency_counter_get_sum */ +size_t latency_counter_get_num (latency_counter_t *lc) /* {{{ */ +{ + if (lc == NULL) + return (0); + return (lc->num); +} /* }}} size_t latency_counter_get_num */ + 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); @@ -139,7 +146,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. */