mirror of
https://github.com/netdata/netdata.git
synced 2025-05-16 06:11:38 +00:00

* split all API formatters in modules * added markdown formatting * updated csv readme * updated csv readme * more documentation * added more documentation * updated documentation * fixed typo * fixed typo
94 lines
2.3 KiB
C
94 lines
2.3 KiB
C
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include "value.h"
|
|
|
|
|
|
inline calculated_number rrdr2value(RRDR *r, long i, RRDR_OPTIONS options, int *all_values_are_null) {
|
|
rrdset_check_rdlock(r->st);
|
|
|
|
long c;
|
|
RRDDIM *d;
|
|
|
|
calculated_number *cn = &r->v[ i * r->d ];
|
|
RRDR_VALUE_FLAGS *co = &r->o[ i * r->d ];
|
|
|
|
calculated_number sum = 0, min = 0, max = 0, v;
|
|
int all_null = 1, init = 1;
|
|
|
|
calculated_number total = 1;
|
|
int set_min_max = 0;
|
|
if(unlikely(options & RRDR_OPTION_PERCENTAGE)) {
|
|
total = 0;
|
|
for(c = 0, d = r->st->dimensions; d && c < r->d ;c++, d = d->next) {
|
|
calculated_number n = cn[c];
|
|
|
|
if(likely((options & RRDR_OPTION_ABSOLUTE) && n < 0))
|
|
n = -n;
|
|
|
|
total += n;
|
|
}
|
|
// prevent a division by zero
|
|
if(total == 0) total = 1;
|
|
set_min_max = 1;
|
|
}
|
|
|
|
// for each dimension
|
|
for(c = 0, d = r->st->dimensions; d && c < r->d ;c++, d = d->next) {
|
|
if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
|
|
if(unlikely((options & RRDR_OPTION_NONZERO) && !(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
|
|
|
|
calculated_number n = cn[c];
|
|
|
|
if(likely((options & RRDR_OPTION_ABSOLUTE) && n < 0))
|
|
n = -n;
|
|
|
|
if(unlikely(options & RRDR_OPTION_PERCENTAGE)) {
|
|
n = n * 100 / total;
|
|
|
|
if(unlikely(set_min_max)) {
|
|
r->min = r->max = n;
|
|
set_min_max = 0;
|
|
}
|
|
|
|
if(n < r->min) r->min = n;
|
|
if(n > r->max) r->max = n;
|
|
}
|
|
|
|
if(unlikely(init)) {
|
|
if(n > 0) {
|
|
min = 0;
|
|
max = n;
|
|
}
|
|
else {
|
|
min = n;
|
|
max = 0;
|
|
}
|
|
init = 0;
|
|
}
|
|
|
|
if(likely(!(co[c] & RRDR_VALUE_EMPTY))) {
|
|
all_null = 0;
|
|
sum += n;
|
|
}
|
|
|
|
if(n < min) min = n;
|
|
if(n > max) max = n;
|
|
}
|
|
|
|
if(unlikely(all_null)) {
|
|
if(likely(all_values_are_null))
|
|
*all_values_are_null = 1;
|
|
return 0;
|
|
}
|
|
else {
|
|
if(likely(all_values_are_null))
|
|
*all_values_are_null = 0;
|
|
}
|
|
|
|
if(options & RRDR_OPTION_MIN2MAX)
|
|
v = max - min;
|
|
else
|
|
v = sum;
|
|
|
|
return v;
|
|
}
|