X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftarget_scale.c;h=6169fa05d585ce4c7a97abc6c882b80dbbeb78db;hb=8eb05d21637cd1eb3b6c4c4d3ed519cc2fd3ebf6;hp=bef03e58769cd147ee6fcf0efe8f15cf87f46c43;hpb=a60550f0b85d413957654546a87f00a95e59a26c;p=collectd.git diff --git a/src/target_scale.c b/src/target_scale.c index bef03e58..6169fa05 100644 --- a/src/target_scale.c +++ b/src/target_scale.c @@ -2,21 +2,26 @@ * collectd - src/target_scale.c * Copyright (C) 2008-2009 Florian Forster * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; only version 2 of the License is applicable. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: - * Florian Forster + * Florian Forster **/ #include "collectd.h" @@ -84,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)) @@ -109,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); @@ -453,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);