summaryrefslogtreecommitdiffstats
path: root/web/api/queries/rrdr.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 11:08:07 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 11:08:07 +0000
commitc69cb8cc094cc916adbc516b09e944cd3d137c01 (patch)
treef2878ec41fb6d0e3613906c6722fc02b934eeb80 /web/api/queries/rrdr.c
parentInitial commit. (diff)
downloadnetdata-c69cb8cc094cc916adbc516b09e944cd3d137c01.tar.xz
netdata-c69cb8cc094cc916adbc516b09e944cd3d137c01.zip
Adding upstream version 1.29.3.upstream/1.29.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'web/api/queries/rrdr.c')
-rw-r--r--web/api/queries/rrdr.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/web/api/queries/rrdr.c b/web/api/queries/rrdr.c
new file mode 100644
index 0000000..ef237fa
--- /dev/null
+++ b/web/api/queries/rrdr.c
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "rrdr.h"
+
+/*
+static void rrdr_dump(RRDR *r)
+{
+ long c, i;
+ RRDDIM *d;
+
+ fprintf(stderr, "\nCHART %s (%s)\n", r->st->id, r->st->name);
+
+ for(c = 0, d = r->st->dimensions; d ;c++, d = d->next) {
+ fprintf(stderr, "DIMENSION %s (%s), %s%s%s%s\n"
+ , d->id
+ , d->name
+ , (r->od[c] & RRDR_EMPTY)?"EMPTY ":""
+ , (r->od[c] & RRDR_RESET)?"RESET ":""
+ , (r->od[c] & RRDR_DIMENSION_HIDDEN)?"HIDDEN ":""
+ , (r->od[c] & RRDR_DIMENSION_NONZERO)?"NONZERO ":""
+ );
+ }
+
+ if(r->rows <= 0) {
+ fprintf(stderr, "RRDR does not have any values in it.\n");
+ return;
+ }
+
+ fprintf(stderr, "RRDR includes %d values in it:\n", r->rows);
+
+ // for each line in the array
+ for(i = 0; i < r->rows ;i++) {
+ calculated_number *cn = &r->v[ i * r->d ];
+ RRDR_DIMENSION_FLAGS *co = &r->o[ i * r->d ];
+
+ // print the id and the timestamp of the line
+ fprintf(stderr, "%ld %ld ", i + 1, r->t[i]);
+
+ // for each dimension
+ for(c = 0, d = r->st->dimensions; d ;c++, d = d->next) {
+ if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
+ if(unlikely(!(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
+
+ if(co[c] & RRDR_EMPTY)
+ fprintf(stderr, "null ");
+ else
+ fprintf(stderr, CALCULATED_NUMBER_FORMAT " %s%s%s%s "
+ , cn[c]
+ , (co[c] & RRDR_EMPTY)?"E":" "
+ , (co[c] & RRDR_RESET)?"R":" "
+ , (co[c] & RRDR_DIMENSION_HIDDEN)?"H":" "
+ , (co[c] & RRDR_DIMENSION_NONZERO)?"N":" "
+ );
+ }
+
+ fprintf(stderr, "\n");
+ }
+}
+*/
+
+
+
+
+inline static void rrdr_lock_rrdset(RRDR *r) {
+ if(unlikely(!r)) {
+ error("NULL value given!");
+ return;
+ }
+
+ rrdset_rdlock(r->st);
+ r->has_st_lock = 1;
+}
+
+inline static void rrdr_unlock_rrdset(RRDR *r) {
+ if(unlikely(!r)) {
+ error("NULL value given!");
+ return;
+ }
+
+ if(likely(r->has_st_lock)) {
+ rrdset_unlock(r->st);
+ r->has_st_lock = 0;
+ }
+}
+
+inline void rrdr_free(RRDR *r)
+{
+ if(unlikely(!r)) {
+ error("NULL value given!");
+ return;
+ }
+
+ rrdr_unlock_rrdset(r);
+ freez(r->t);
+ freez(r->v);
+ freez(r->o);
+ freez(r->od);
+ freez(r);
+}
+
+RRDR *rrdr_create(struct rrdset *st, long n, struct context_param *context_param_list)
+{
+ if(unlikely(!st)) {
+ error("NULL value given!");
+ return NULL;
+ }
+
+ RRDR *r = callocz(1, sizeof(RRDR));
+ r->st = st;
+
+ rrdr_lock_rrdset(r);
+
+ RRDDIM *temp_rd = context_param_list ? context_param_list->rd : NULL;
+ RRDDIM *rd;
+ if (temp_rd) {
+ RRDDIM *t = temp_rd;
+ while (t) {
+ r->d++;
+ t = t->next;
+ }
+ } else
+ rrddim_foreach_read(rd, st) r->d++;
+
+ r->n = n;
+
+ r->t = callocz((size_t)n, sizeof(time_t));
+ r->v = mallocz(n * r->d * sizeof(calculated_number));
+ r->o = mallocz(n * r->d * sizeof(RRDR_VALUE_FLAGS));
+ r->od = mallocz(r->d * sizeof(RRDR_DIMENSION_FLAGS));
+
+ // set the hidden flag on hidden dimensions
+ int c;
+ for (c = 0, rd = temp_rd ? temp_rd : st->dimensions; rd; c++, rd = rd->next) {
+ if (unlikely(rrddim_flag_check(rd, RRDDIM_FLAG_HIDDEN)))
+ r->od[c] = RRDR_DIMENSION_HIDDEN;
+ else
+ r->od[c] = RRDR_DIMENSION_DEFAULT;
+ }
+
+ r->group = 1;
+ r->update_every = 1;
+
+ return r;
+}