allow overwriting the storage type of calculated_number and related functions
Costa Tsaousis (ktsaou) committed
Sep 9, 2017 at 21:47 UTC
334cd30cf5e4ee0d94fd0bb2762ae8698bdb13f1
5 files changed
+14
-11
src/rrd2json.c
+5
-5
@@ -213,14 +213,14 @@ void rrd_stats_api_v1_charts_allmetrics_shell(RRDHOST *host, BUFFER *wb) {
213
buffer_sprintf(wb, "NETDATA_%s_%s=\"\" # %s\n", chart, dimension, st->units);
214
else {
215
if(rd->multiplier < 0 || rd->divisor < 0) n = -n;
216
- n = roundl(n);
216
+ n = calculated_number_round(n);
217
if(!rrddim_flag_check(rd, RRDDIM_FLAG_HIDDEN)) total += n;
218
buffer_sprintf(wb, "NETDATA_%s_%s=\"%0.0Lf\" # %s\n", chart, dimension, n, st->units);
219
}
220
}
221
}
222
223
- total = roundl(total);
223
+ total = calculated_number_round(total);
224
buffer_sprintf(wb, "NETDATA_%s_VISIBLETOTAL=\"%0.0Lf\" # %s\n", chart, total, st->units);
225
rrdset_unlock(st);
226
}
@@ -243,7 +243,7 @@ void rrd_stats_api_v1_charts_allmetrics_shell(RRDHOST *host, BUFFER *wb) {
243
if(isnan(n) || isinf(n))
244
buffer_sprintf(wb, "NETDATA_ALARM_%s_%s_VALUE=\"\" # %s\n", chart, alarm, rc->units);
245
else {
246
- n = roundl(n);
246
+ n = calculated_number_round(n);
247
buffer_sprintf(wb, "NETDATA_ALARM_%s_%s_VALUE=\"%0.0Lf\" # %s\n", chart, alarm, n, rc->units);
248
}
249
@@ -1573,13 +1573,13 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1573
switch(group_method) {
1574
case GROUP_MIN:
1575
if(unlikely(isnan(group_values[c])) ||
1576
- fabsl(value) < fabsl(group_values[c]))
1576
+ calculated_number_fabs(value) < calculated_number_fabs(group_values[c]))
1577
group_values[c] = value;
1578
break;
1579
1580
case GROUP_MAX:
1581
if(unlikely(isnan(group_values[c])) ||
1582
- fabsl(value) > fabsl(group_values[c]))
1582
+ calculated_number_fabs(value) > calculated_number_fabs(group_values[c]))
1583
group_values[c] = value;
1584
break;
1585
src/statsd.c
+1
-1
@@ -445,7 +445,7 @@ static inline void statsd_process_counter(STATSD_METRIC *m, const char *value, c
445
446
if(unlikely(m->reset)) statsd_reset_metric(m);
447
448
- m->counter.value += roundl((long double)statsd_parse_int(value, 1) / statsd_parse_float(sampling, 1.0));
448
+ m->counter.value += llrintl((long double)statsd_parse_int(value, 1) / statsd_parse_float(sampling, 1.0));
449
450
m->events++;
451
m->count++;
src/storage_number.c
+1
-1
@@ -199,7 +199,7 @@ int print_calculated_number(char *str, calculated_number value) {
199
*wstr++ = '.';
200
201
// convert the fractional part to string (reversed)
202
- char *fstre = print_number_llu_r_smart(fractional_str, (unsigned long long)llrintl(fractional));
202
+ char *fstre = print_number_llu_r_smart(fractional_str, (unsigned long long)calculated_number_llrint(fractional));
203
204
// prepend zeros to reach 7 digits length
205
int decimal = 7;
src/storage_number.h
+4
@@ -14,6 +14,10 @@ typedef long double collected_number;
14
#define COLLECTED_NUMBER_FORMAT "%0.7Lf"
15
*/
16
17
+#define calculated_number_llrint(x) llrintl(x)
18
+#define calculated_number_round(x) roundl(x)
19
+#define calculated_number_fabs(x) fabsl(x)
20
+
21
typedef uint32_t storage_number;
22
#define STORAGE_NUMBER_FORMAT "%u"
23
src/unit_test.c
+3
-4
@@ -1037,7 +1037,7 @@ int run_test(struct test *test)
1037
for(c = 0 ; c < max ; c++) {
1038
calculated_number v = unpack_storage_number(rd->values[c]);
1039
calculated_number n = test->results[c];
1040
- int same = (roundl(v * 10000000.0) == roundl(n * 10000000.0))?1:0;
1040
+ int same = (calculated_number_round(v * 10000000.0) == calculated_number_round(n * 10000000.0))?1:0;
1041
fprintf(stderr, " %s/%s: checking position %lu (at %lu secs), expecting value " CALCULATED_NUMBER_FORMAT ", found " CALCULATED_NUMBER_FORMAT ", %s\n",
1042
test->name, rd->name, c+1,
1043
(rrdset_first_entry_t(st) + c * st->update_every) - time_start,
@@ -1048,7 +1048,7 @@ int run_test(struct test *test)
1048
if(rd2) {
1049
v = unpack_storage_number(rd2->values[c]);
1050
n = test->results2[c];
1051
- same = (roundl(v * 10000000.0) == roundl(n * 10000000.0))?1:0;
1051
+ same = (calculated_number_round(v * 10000000.0) == calculated_number_round(n * 10000000.0))?1:0;
1052
fprintf(stderr, " %s/%s: checking position %lu (at %lu secs), expecting value " CALCULATED_NUMBER_FORMAT ", found " CALCULATED_NUMBER_FORMAT ", %s\n",
1053
test->name, rd2->name, c+1,
1054
(rrdset_first_entry_t(st) + c * st->update_every) - time_start,
@@ -1062,8 +1062,7 @@ int run_test(struct test *test)
1062
1063
static int test_variable_renames(void) {
1064
fprintf(stderr, "Creating chart\n");
1065
- RRDSET *st = rrdset_create_localhost("chart", "ID", NULL, "family", "context", "Unit Testing", "a value", 1, 1
1066
- , RRDSET_TYPE_LINE);
1065
+ RRDSET *st = rrdset_create_localhost("chart", "ID", NULL, "family", "context", "Unit Testing", "a value", 1, 1, RRDSET_TYPE_LINE);
1066
fprintf(stderr, "Created chart with id '%s', name '%s'\n", st->id, st->name);
1067
1068
fprintf(stderr, "Creating dimension DIM1\n");