From: Florian Forster Date: Fri, 3 Jul 2015 06:23:29 +0000 (+0200) Subject: utils_cache.c, scale target: Don't re-implement counter wrap-around logic. X-Git-Tag: collectd-5.6.0~658 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=881d288ab29676f19afd886730ab550c7d15c8fc;p=collectd.git utils_cache.c, scale target: Don't re-implement counter wrap-around logic. --- diff --git a/src/daemon/utils_cache.c b/src/daemon/utils_cache.c index 129cbb07..4fc96c2b 100644 --- a/src/daemon/utils_cache.c +++ b/src/daemon/utils_cache.c @@ -411,23 +411,7 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) { case DS_TYPE_COUNTER: { - counter_t diff; - - /* check if the counter has wrapped around */ - if (vl->values[i].counter < ce->values_raw[i].counter) - { - if (ce->values_raw[i].counter <= 4294967295U) - diff = (4294967295U - ce->values_raw[i].counter) - + vl->values[i].counter; - else - diff = (18446744073709551615ULL - ce->values_raw[i].counter) - + vl->values[i].counter; - } - else /* counter has NOT wrapped around */ - { - diff = vl->values[i].counter - ce->values_raw[i].counter; - } - + counter_t diff = counter_diff (ce->values_raw[i].counter, vl->values[i].counter); ce->values_gauge[i] = ((double) diff) / (CDTIME_T_TO_DOUBLE (vl->time - ce->last_time)); ce->values_raw[i].counter = vl->values[i].counter; @@ -441,9 +425,7 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) case DS_TYPE_DERIVE: { - derive_t diff; - - diff = vl->values[i].derive - ce->values_raw[i].derive; + derive_t diff = vl->values[i].derive - ce->values_raw[i].derive; ce->values_gauge[i] = ((double) diff) / (CDTIME_T_TO_DOUBLE (vl->time - ce->last_time)); diff --git a/src/target_scale.c b/src/target_scale.c index 33a2ba5e..6169fa05 100644 --- a/src/target_scale.c +++ b/src/target_scale.c @@ -89,22 +89,11 @@ static int ts_invoke_counter (const data_set_t *ds, value_list_t *vl, /* {{{ */ if (failure == 0) { - uint64_t difference; + uint64_t diff; double rate; - /* Calcualte the rate */ - if (prev_counter > curr_counter) /* => counter overflow */ - { - if (prev_counter <= 4294967295UL) /* 32 bit overflow */ - difference = (4294967295UL - prev_counter) + curr_counter; - else /* 64 bit overflow */ - difference = (18446744073709551615ULL - prev_counter) + curr_counter; - } - else /* no overflow */ - { - difference = curr_counter - prev_counter; - } - rate = ((double) difference) / CDTIME_T_TO_DOUBLE (vl->interval); + diff = (uint64_t) counter_diff (prev_counter, curr_counter); + rate = ((double) diff) / CDTIME_T_TO_DOUBLE (vl->interval); /* Modify the rate. */ if (!isnan (data->factor)) @@ -114,9 +103,9 @@ static int ts_invoke_counter (const data_set_t *ds, value_list_t *vl, /* {{{ */ /* Calculate the internal counter. */ int_fraction += (rate * CDTIME_T_TO_DOUBLE (vl->interval)); - difference = (uint64_t) int_fraction; - int_fraction -= ((double) difference); - int_counter += difference; + diff = (uint64_t) int_fraction; + int_fraction -= ((double) diff); + int_counter += diff; assert (int_fraction >= 0.0); assert (int_fraction < 1.0);