From a21eeeba55a434a689bed3a4f5554361b6a19d1f Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 12 Oct 2016 17:25:13 +0200 Subject: [PATCH 1/1] src/utils_latency{,_config}.[ch]: Reformat new code with clang-format. --- src/utils_latency.c | 20 ++++++++-------- src/utils_latency_config.c | 60 +++++++++++++++++----------------------------- src/utils_latency_config.h | 19 +++++++-------- 3 files changed, 41 insertions(+), 58 deletions(-) diff --git a/src/utils_latency.c b/src/utils_latency.c index f5a51e25..5749f10d 100644 --- a/src/utils_latency.c +++ b/src/utils_latency.c @@ -290,9 +290,9 @@ cdtime_t latency_counter_get_percentile (latency_counter_t *lc, /* {{{ */ return (latency_interpolated); } /* }}} cdtime_t latency_counter_get_percentile */ -double latency_counter_get_rate (const latency_counter_t *lc, /* {{{ */ - cdtime_t lower, cdtime_t upper, const cdtime_t now) -{ +double latency_counter_get_rate(const latency_counter_t *lc, /* {{{ */ + cdtime_t lower, cdtime_t upper, + const cdtime_t now) { if ((lc == NULL) || (lc->num == 0)) return (NAN); @@ -308,7 +308,7 @@ double latency_counter_get_rate (const latency_counter_t *lc, /* {{{ */ cdtime_t lower_bin = 0; if (lower) /* lower is *exclusive* => determine bucket for lower+1 */ - lower_bin = ((lower+1) - 1) / lc->bin_width; + lower_bin = ((lower + 1) - 1) / lc->bin_width; /* lower is greater than the longest latency observed => rate is zero. */ if (lower_bin >= HISTOGRAM_NUM_BINS) @@ -332,22 +332,22 @@ double latency_counter_get_rate (const latency_counter_t *lc, /* {{{ */ * lower_bin_boundary and lower. This ratio is then subtracted from sum to * increase accuracy. */ cdtime_t lower_bin_boundary = lower_bin * lc->bin_width; - assert (lower >= lower_bin_boundary); - double lower_ratio = (double)(lower - lower_bin_boundary) / ((double) lc->bin_width); + assert(lower >= lower_bin_boundary); + double lower_ratio = + (double)(lower - lower_bin_boundary) / ((double)lc->bin_width); sum -= lower_ratio * lc->histogram[lower_bin]; } - if (upper) - { + if (upper) { /* As above: approximate ratio of requests in upper_bin, that fall between * upper and upper_bin_boundary. */ cdtime_t upper_bin_boundary = (upper_bin + 1) * lc->bin_width; - assert (upper <= upper_bin_boundary); + assert(upper <= upper_bin_boundary); double ratio = (double)(upper_bin_boundary - upper) / (double)lc->bin_width; sum -= ratio * lc->histogram[upper_bin]; } - return sum / (CDTIME_T_TO_DOUBLE (now - lc->start_time)); + return sum / (CDTIME_T_TO_DOUBLE(now - lc->start_time)); } /* }}} double latency_counter_get_rate */ /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/utils_latency_config.c b/src/utils_latency_config.c index 2121e546..f99fe583 100644 --- a/src/utils_latency_config.c +++ b/src/utils_latency_config.c @@ -30,10 +30,8 @@ #include "utils_latency_config.h" int latency_config_add_percentile(const char *plugin, latency_config_t *cl, - oconfig_item_t *ci) -{ - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) - { + oconfig_item_t *ci) { + if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) { ERROR("%s plugin: \"%s\" requires exactly one numeric argument.", plugin, ci->key); return (-1); @@ -42,8 +40,7 @@ int latency_config_add_percentile(const char *plugin, latency_config_t *cl, double percent = ci->values[0].value.number; double *tmp; - if ((percent <= 0.0) || (percent >= 100)) - { + if ((percent <= 0.0) || (percent >= 100)) { ERROR("%s plugin: The value for \"%s\" must be between 0 and 100, " "exclusively.", plugin, ci->key); @@ -52,8 +49,7 @@ int latency_config_add_percentile(const char *plugin, latency_config_t *cl, tmp = realloc(cl->percentile, sizeof(*cl->percentile) * (cl->percentile_num + 1)); - if (tmp == NULL) - { + if (tmp == NULL) { ERROR("%s plugin: realloc failed.", plugin); return (ENOMEM); } @@ -65,26 +61,21 @@ int latency_config_add_percentile(const char *plugin, latency_config_t *cl, } /* int latency_config_add_percentile */ int latency_config_add_rate(const char *plugin, latency_config_t *cl, - oconfig_item_t *ci) -{ - if ((ci->values_num != 2) - || (ci->values[0].type != OCONFIG_TYPE_NUMBER) - || (ci->values[1].type != OCONFIG_TYPE_NUMBER)) - { + oconfig_item_t *ci) { + if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_NUMBER) || + (ci->values[1].type != OCONFIG_TYPE_NUMBER)) { ERROR("%s plugin: \"%s\" requires exactly two numeric arguments.", plugin, ci->key); return (-1); } if (ci->values[1].value.number && - ci->values[1].value.number <= ci->values[0].value.number) - { + ci->values[1].value.number <= ci->values[0].value.number) { ERROR("%s plugin: MIN must be less than MAX in \"%s\".", plugin, ci->key); return (-1); } - if (ci->values[0].value.number < 0.001) - { + if (ci->values[0].value.number < 0.001) { ERROR("%s plugin: MIN must be greater or equal to 0.001 in \"%s\".", plugin, ci->key); return (-1); @@ -95,8 +86,7 @@ int latency_config_add_rate(const char *plugin, latency_config_t *cl, cdtime_t *tmp; tmp = realloc(cl->rates, sizeof(*cl->rates) * (cl->rates_num + 1) * 2); - if (tmp == NULL) - { + if (tmp == NULL) { ERROR("%s plugin: realloc failed.", plugin); return (ENOMEM); } @@ -108,15 +98,14 @@ int latency_config_add_rate(const char *plugin, latency_config_t *cl, return (0); } /* int latency_config_add_rate */ -int latency_config_copy(latency_config_t *dst, const latency_config_t src) -{ +int latency_config_copy(latency_config_t *dst, const latency_config_t src) { *dst = (latency_config_t){ - .rates = NULL, - .rates_num = src.rates_num, - .rates_type = NULL, - .percentile = NULL, - .percentile_num = src.percentile_num, - .percentile_type = NULL, + .rates = NULL, + .rates_num = src.rates_num, + .rates_type = NULL, + .percentile = NULL, + .percentile_num = src.percentile_num, + .percentile_type = NULL, }; /* Copy percentiles configuration */ @@ -128,11 +117,9 @@ int latency_config_copy(latency_config_t *dst, const latency_config_t src) memcpy(dst->percentile, src.percentile, (sizeof(*dst->percentile) * (src.percentile_num))); - if (src.percentile_type != NULL) - { + if (src.percentile_type != NULL) { dst->percentile_type = strdup(src.percentile_type); - if (dst->percentile_type == NULL) - { + if (dst->percentile_type == NULL) { latency_config_free(*dst); return (-1); } @@ -141,19 +128,16 @@ int latency_config_copy(latency_config_t *dst, const latency_config_t src) /* Copy rates configuration */ dst->rates_num = src.rates_num; dst->rates = calloc(src.rates_num * 2, sizeof(*dst->rates)); - if (dst->rates == NULL) - { + if (dst->rates == NULL) { latency_config_free(*dst); return (-1); } memcpy(dst->rates, src.rates, (sizeof(*dst->rates) * (src.rates_num) * 2)); - if (src.rates_type != NULL) - { + if (src.rates_type != NULL) { dst->rates_type = strdup(src.rates_type); - if (dst->rates_type == NULL) - { + if (dst->rates_type == NULL) { latency_config_free(*dst); return (-1); } diff --git a/src/utils_latency_config.h b/src/utils_latency_config.h index aad8914c..a5354960 100644 --- a/src/utils_latency_config.h +++ b/src/utils_latency_config.h @@ -31,18 +31,17 @@ #include "collectd.h" #include "utils_time.h" -struct latency_config_s -{ - double *percentile; - size_t percentile_num; - char *percentile_type; +struct latency_config_s { + double *percentile; + size_t percentile_num; + char *percentile_type; cdtime_t *rates; - size_t rates_num; - char *rates_type; - _Bool lower; - _Bool upper; + size_t rates_num; + char *rates_type; + _Bool lower; + _Bool upper; //_Bool sum; - _Bool avg; + _Bool avg; //_Bool count; }; typedef struct latency_config_s latency_config_t; -- 2.11.0