X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_latency.c;h=91ddd5fd92485c0a02d6642b56ce346334f40b50;hb=7cea19815ba24735e91dde1c08a889960b299b62;hp=01c8b5c22ea6c9a5f5952a9a5248e055562cc800;hpb=ba0be16485d017e2060bc3a1fef2cb0587a5336d;p=collectd.git diff --git a/src/utils_latency.c b/src/utils_latency.c index 01c8b5c2..91ddd5fd 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -1,6 +1,6 @@ /** * collectd - src/utils_latency.c - * Copyright (C) 2013 Florian Forster + * Copyright (C) 2013 Florian Forster * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -110,11 +110,25 @@ cdtime_t latency_counter_get_max (latency_counter_t *lc) /* {{{ */ return (lc->max); } /* }}} cdtime_t latency_counter_get_max */ +cdtime_t latency_counter_get_sum (latency_counter_t *lc) /* {{{ */ +{ + if (lc == NULL) + return (0); + 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); @@ -132,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. */