summaryrefslogtreecommitdiffstats
path: root/web/api/queries/rrdr.c
diff options
context:
space:
mode:
Diffstat (limited to 'web/api/queries/rrdr.c')
-rw-r--r--web/api/queries/rrdr.c90
1 files changed, 37 insertions, 53 deletions
diff --git a/web/api/queries/rrdr.c b/web/api/queries/rrdr.c
index 4d05778c1..ecf4ca2ac 100644
--- a/web/api/queries/rrdr.c
+++ b/web/api/queries/rrdr.c
@@ -30,7 +30,7 @@ static void rrdr_dump(RRDR *r)
// for each line in the array
for(i = 0; i < r->rows ;i++) {
- calculated_number *cn = &r->v[ i * r->d ];
+ NETDATA_DOUBLE *cn = &r->v[ i * r->d ];
RRDR_DIMENSION_FLAGS *co = &r->o[ i * r->d ];
// print the id and the timestamp of the line
@@ -44,7 +44,7 @@ static void rrdr_dump(RRDR *r)
if(co[c] & RRDR_EMPTY)
fprintf(stderr, "null ");
else
- fprintf(stderr, CALCULATED_NUMBER_FORMAT " %s%s%s%s "
+ fprintf(stderr, NETDATA_DOUBLE_FORMAT " %s%s%s%s "
, cn[c]
, (co[c] & RRDR_EMPTY)?"E":" "
, (co[c] & RRDR_RESET)?"R":" "
@@ -58,78 +58,65 @@ static void rrdr_dump(RRDR *r)
}
*/
+inline void rrdr_free(ONEWAYALLOC *owa, RRDR *r) {
+ if(unlikely(!r)) return;
-
-
-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)) {
- r->has_st_lock = 0;
+ if(likely(r->st_locked_by_rrdr_create))
rrdset_unlock(r->st);
- }
-}
-
-inline void rrdr_free(ONEWAYALLOC *owa, RRDR *r)
-{
- if(unlikely(!r)) {
- error("NULL value given!");
- return;
- }
- rrdr_unlock_rrdset(r);
onewayalloc_freez(owa, r->t);
onewayalloc_freez(owa, r->v);
onewayalloc_freez(owa, r->o);
onewayalloc_freez(owa, r->od);
+ onewayalloc_freez(owa, r->ar);
onewayalloc_freez(owa, r);
}
-RRDR *rrdr_create(ONEWAYALLOC *owa, struct rrdset *st, long n, struct context_param *context_param_list)
-{
- if (unlikely(!st)) {
- error("NULL value given!");
- return NULL;
- }
-
+RRDR *rrdr_create_for_x_dimensions(ONEWAYALLOC *owa, int dimensions, long points) {
RRDR *r = onewayalloc_callocz(owa, 1, sizeof(RRDR));
- r->st = st;
+ r->internal.owa = owa;
+
+ r->d = dimensions;
+ r->n = points;
+
+ r->t = onewayalloc_callocz(owa, points, sizeof(time_t));
+ r->v = onewayalloc_mallocz(owa, points * dimensions * sizeof(NETDATA_DOUBLE));
+ r->o = onewayalloc_mallocz(owa, points * dimensions * sizeof(RRDR_VALUE_FLAGS));
+ r->ar = onewayalloc_mallocz(owa, points * dimensions * sizeof(NETDATA_DOUBLE));
+ r->od = onewayalloc_mallocz(owa, dimensions * sizeof(RRDR_DIMENSION_FLAGS));
+ r->group = 1;
+ r->update_every = 1;
+
+ return r;
+}
+
+RRDR *rrdr_create(ONEWAYALLOC *owa, struct rrdset *st, long n, struct context_param *context_param_list) {
+ if (unlikely(!st)) return NULL;
+
+ bool st_locked_by_rrdr_create = false;
if (!context_param_list || !(context_param_list->flags & CONTEXT_FLAGS_ARCHIVE)) {
- rrdr_lock_rrdset(r);
- r->st_needs_lock = 1;
+ rrdset_rdlock(st);
+ st_locked_by_rrdr_create = true;
}
+ // count the number of dimensions
+ int dimensions = 0;
RRDDIM *temp_rd = context_param_list ? context_param_list->rd : NULL;
RRDDIM *rd;
if (temp_rd) {
RRDDIM *t = temp_rd;
while (t) {
- r->d++;
+ dimensions++;
t = t->next;
}
} else
- rrddim_foreach_read(rd, st) r->d++;
-
- r->n = n;
+ rrddim_foreach_read(rd, st) dimensions++;
- r->t = onewayalloc_callocz(owa, (size_t)n, sizeof(time_t));
- r->v = onewayalloc_mallocz(owa, n * r->d * sizeof(calculated_number));
- r->o = onewayalloc_mallocz(owa, n * r->d * sizeof(RRDR_VALUE_FLAGS));
- r->od = onewayalloc_mallocz(owa, r->d * sizeof(RRDR_DIMENSION_FLAGS));
+ // create the rrdr
+ RRDR *r = rrdr_create_for_x_dimensions(owa, dimensions, n);
+ r->st = st;
+ r->st_locked_by_rrdr_create = st_locked_by_rrdr_create;
// set the hidden flag on hidden dimensions
int c;
@@ -140,8 +127,5 @@ RRDR *rrdr_create(ONEWAYALLOC *owa, struct rrdset *st, long n, struct context_pa
r->od[c] = RRDR_DIMENSION_DEFAULT;
}
- r->group = 1;
- r->update_every = 1;
-
return r;
}