X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftarget_scale.c;h=74652ff81dbeeb6452f0fce8c2d01768e10d3836;hb=21ab7512825cf8177d5eee5101344b45d0854610;hp=bef03e58769cd147ee6fcf0efe8f15cf87f46c43;hpb=c1219a1c9db2e8400e2ee94b87f86ccd441485d5;p=collectd.git diff --git a/src/target_scale.c b/src/target_scale.c index bef03e58..74652ff8 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); @@ -334,7 +328,7 @@ static int ts_config_add_data_source(ts_data_t *data, /* {{{ */ /* Allocate space for the char pointers */ new_data_sources_num = data->data_sources_num + ((size_t) ci->values_num); - temp = (char **) realloc (data->data_sources, + temp = realloc (data->data_sources, new_data_sources_num * sizeof (char *)); if (temp == NULL) { @@ -393,13 +387,12 @@ static int ts_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ int status; int i; - data = (ts_data_t *) malloc (sizeof (*data)); + data = calloc (1, sizeof (*data)); if (data == NULL) { - ERROR ("ts_create: malloc failed."); + ERROR ("ts_create: calloc failed."); return (-ENOMEM); } - memset (data, 0, sizeof (*data)); data->factor = NAN; data->offset = NAN; @@ -453,7 +446,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);