X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftarget_scale.c;h=b667ed13ed618ae243b0084ca6778452c42253a8;hb=1ebf2f31bd2e080e6f42de640f0a3899a61501c0;hp=b29a02bfa64801d9e967294ba4d1af7e6ce0cb48;hpb=fc6f1e3d33d646391adb5cedc62e7b3904c15003;p=collectd.git diff --git a/src/target_scale.c b/src/target_scale.c index b29a02bf..b667ed13 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); @@ -398,7 +387,7 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - data = (ts_data_t *) malloc (sizeof (*data)); + data = malloc (sizeof (*data)); if (data == NULL) { ERROR ("ts_create: malloc failed."); @@ -458,7 +447,7 @@ static int ts_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ notification_meta_t __attribute__((unused)) **meta, void **user_data) { ts_data_t *data; - int i; + size_t i; if ((ds == NULL) || (vl == NULL) || (user_data == NULL)) return (-EINVAL);