summaryrefslogtreecommitdiffstats
path: root/web/api/queries
diff options
context:
space:
mode:
Diffstat (limited to 'web/api/queries')
-rw-r--r--web/api/queries/average/average.c13
-rw-r--r--web/api/queries/average/average.h2
-rw-r--r--web/api/queries/des/des.c40
-rw-r--r--web/api/queries/des/des.h2
-rw-r--r--web/api/queries/incremental_sum/incremental_sum.c23
-rw-r--r--web/api/queries/incremental_sum/incremental_sum.h2
-rw-r--r--web/api/queries/max/max.c15
-rw-r--r--web/api/queries/max/max.h2
-rw-r--r--web/api/queries/median/median.c10
-rw-r--r--web/api/queries/median/median.h2
-rw-r--r--web/api/queries/min/min.c15
-rw-r--r--web/api/queries/min/min.h2
-rw-r--r--web/api/queries/query.c134
-rw-r--r--web/api/queries/rrdr.c26
-rw-r--r--web/api/queries/rrdr.h7
-rw-r--r--web/api/queries/ses/ses.c14
-rw-r--r--web/api/queries/ses/ses.h2
-rw-r--r--web/api/queries/stddev/stddev.c31
-rw-r--r--web/api/queries/stddev/stddev.h2
-rw-r--r--web/api/queries/sum/sum.c13
-rw-r--r--web/api/queries/sum/sum.h2
21 files changed, 186 insertions, 173 deletions
diff --git a/web/api/queries/average/average.c b/web/api/queries/average/average.c
index 2c64358e..2ed33da5 100644
--- a/web/api/queries/average/average.c
+++ b/web/api/queries/average/average.c
@@ -10,9 +10,8 @@ struct grouping_average {
size_t count;
};
-void *grouping_create_average(RRDR *r) {
- (void)r;
- return callocz(1, sizeof(struct grouping_average));
+void grouping_create_average(RRDR *r) {
+ r->internal.grouping_data = callocz(1, sizeof(struct grouping_average));
}
// resets when switches dimensions
@@ -29,11 +28,9 @@ void grouping_free_average(RRDR *r) {
}
void grouping_add_average(RRDR *r, calculated_number value) {
- if(!isnan(value)) {
- struct grouping_average *g = (struct grouping_average *)r->internal.grouping_data;
- g->sum += value;
- g->count++;
- }
+ struct grouping_average *g = (struct grouping_average *)r->internal.grouping_data;
+ g->sum += value;
+ g->count++;
}
calculated_number grouping_flush_average(RRDR *r, RRDR_VALUE_FLAGS *rrdr_value_options_ptr) {
diff --git a/web/api/queries/average/average.h b/web/api/queries/average/average.h
index 9fb7de21..23ecfac6 100644
--- a/web/api/queries/average/average.h
+++ b/web/api/queries/average/average.h
@@ -6,7 +6,7 @@
#include "../query.h"
#include "../rrdr.h"
-extern void *grouping_create_average(RRDR *r);
+extern void grouping_create_average(RRDR *r);
extern void grouping_reset_average(RRDR *r);
extern void grouping_free_average(RRDR *r);
extern void grouping_add_average(RRDR *r, calculated_number value);
diff --git a/web/api/queries/des/des.c b/web/api/queries/des/des.c
index c6236f31..8e4ca4bd 100644
--- a/web/api/queries/des/des.c
+++ b/web/api/queries/des/des.c
@@ -69,14 +69,14 @@ static inline void set_beta(RRDR *r, struct grouping_des *g) {
//info("beta for chart '%s' is " CALCULATED_NUMBER_FORMAT, r->st->name, g->beta);
}
-void *grouping_create_des(RRDR *r) {
- struct grouping_des *g = (struct grouping_des *)malloc(sizeof(struct grouping_des));
+void grouping_create_des(RRDR *r) {
+ struct grouping_des *g = (struct grouping_des *)mallocz(sizeof(struct grouping_des));
set_alpha(r, g);
set_beta(r, g);
g->level = 0.0;
g->trend = 0.0;
g->count = 0;
- return g;
+ r->internal.grouping_data = g;
}
// resets when switches dimensions
@@ -99,28 +99,26 @@ void grouping_free_des(RRDR *r) {
void grouping_add_des(RRDR *r, calculated_number value) {
struct grouping_des *g = (struct grouping_des *)r->internal.grouping_data;
- if(calculated_number_isnumber(value)) {
- if(likely(g->count > 0)) {
- // we have at least a number so far
+ if(likely(g->count > 0)) {
+ // we have at least a number so far
- if(unlikely(g->count == 1)) {
- // the second value we got
- g->trend = value - g->trend;
- g->level = value;
- }
-
- // for the values, except the first
- calculated_number last_level = g->level;
- g->level = (g->alpha * value) + (g->alpha_other * (g->level + g->trend));
- g->trend = (g->beta * (g->level - last_level)) + (g->beta_other * g->trend);
- }
- else {
- // the first value we got
- g->level = g->trend = value;
+ if(unlikely(g->count == 1)) {
+ // the second value we got
+ g->trend = value - g->trend;
+ g->level = value;
}
- g->count++;
+ // for the values, except the first
+ calculated_number last_level = g->level;
+ g->level = (g->alpha * value) + (g->alpha_other * (g->level + g->trend));
+ g->trend = (g->beta * (g->level - last_level)) + (g->beta_other * g->trend);
}
+ else {
+ // the first value we got
+ g->level = g->trend = value;
+ }
+
+ g->count++;
//fprintf(stderr, "value: " CALCULATED_NUMBER_FORMAT ", level: " CALCULATED_NUMBER_FORMAT ", trend: " CALCULATED_NUMBER_FORMAT "\n", value, g->level, g->trend);
}
diff --git a/web/api/queries/des/des.h b/web/api/queries/des/des.h
index 360513e9..bd361b86 100644
--- a/web/api/queries/des/des.h
+++ b/web/api/queries/des/des.h
@@ -8,7 +8,7 @@
extern void grouping_init_des(void);
-extern void *grouping_create_des(RRDR *r);
+extern void grouping_create_des(RRDR *r);
extern void grouping_reset_des(RRDR *r);
extern void grouping_free_des(RRDR *r);
extern void grouping_add_des(RRDR *r, calculated_number value);
diff --git a/web/api/queries/incremental_sum/incremental_sum.c b/web/api/queries/incremental_sum/incremental_sum.c
index 131d85d7..304d9aa7 100644
--- a/web/api/queries/incremental_sum/incremental_sum.c
+++ b/web/api/queries/incremental_sum/incremental_sum.c
@@ -11,9 +11,8 @@ struct grouping_incremental_sum {
size_t count;
};
-void *grouping_create_incremental_sum(RRDR *r) {
- (void)r;
- return callocz(1, sizeof(struct grouping_incremental_sum));
+void grouping_create_incremental_sum(RRDR *r) {
+ r->internal.grouping_data = callocz(1, sizeof(struct grouping_incremental_sum));
}
// resets when switches dimensions
@@ -31,17 +30,15 @@ void grouping_free_incremental_sum(RRDR *r) {
}
void grouping_add_incremental_sum(RRDR *r, calculated_number value) {
- if(!isnan(value)) {
- struct grouping_incremental_sum *g = (struct grouping_incremental_sum *)r->internal.grouping_data;
+ struct grouping_incremental_sum *g = (struct grouping_incremental_sum *)r->internal.grouping_data;
- if(unlikely(!g->count)) {
- g->first = value;
- g->count++;
- }
- else {
- g->last = value;
- g->count++;
- }
+ if(unlikely(!g->count)) {
+ g->first = value;
+ g->count++;
+ }
+ else {
+ g->last = value;
+ g->count++;
}
}
diff --git a/web/api/queries/incremental_sum/incremental_sum.h b/web/api/queries/incremental_sum/incremental_sum.h
index 990a2ac4..5b55ad3c 100644
--- a/web/api/queries/incremental_sum/incremental_sum.h
+++ b/web/api/queries/incremental_sum/incremental_sum.h
@@ -6,7 +6,7 @@
#include "../query.h"
#include "../rrdr.h"
-extern void *grouping_create_incremental_sum(RRDR *r);
+extern void grouping_create_incremental_sum(RRDR *r);
extern void grouping_reset_incremental_sum(RRDR *r);
extern void grouping_free_incremental_sum(RRDR *r);
extern void grouping_add_incremental_sum(RRDR *r, calculated_number value);
diff --git a/web/api/queries/max/max.c b/web/api/queries/max/max.c
index a4be36ad..b6e72331 100644
--- a/web/api/queries/max/max.c
+++ b/web/api/queries/max/max.c
@@ -10,9 +10,8 @@ struct grouping_max {
size_t count;
};
-void *grouping_create_max(RRDR *r) {
- (void)r;
- return callocz(1, sizeof(struct grouping_max));
+void grouping_create_max(RRDR *r) {
+ r->internal.grouping_data = callocz(1, sizeof(struct grouping_max));
}
// resets when switches dimensions
@@ -29,13 +28,11 @@ void grouping_free_max(RRDR *r) {
}
void grouping_add_max(RRDR *r, calculated_number value) {
- if(!isnan(value)) {
- struct grouping_max *g = (struct grouping_max *)r->internal.grouping_data;
+ struct grouping_max *g = (struct grouping_max *)r->internal.grouping_data;
- if(!g->count || calculated_number_fabs(value) > calculated_number_fabs(g->max)) {
- g->max = value;
- g->count++;
- }
+ if(!g->count || calculated_number_fabs(value) > calculated_number_fabs(g->max)) {
+ g->max = value;
+ g->count++;
}
}
diff --git a/web/api/queries/max/max.h b/web/api/queries/max/max.h
index d839fe3f..7b606ce3 100644
--- a/web/api/queries/max/max.h
+++ b/web/api/queries/max/max.h
@@ -6,7 +6,7 @@
#include "../query.h"
#include "../rrdr.h"
-extern void *grouping_create_max(RRDR *r);
+extern void grouping_create_max(RRDR *r);
extern void grouping_reset_max(RRDR *r);
extern void grouping_free_max(RRDR *r);
extern void grouping_add_max(RRDR *r, calculated_number value);
diff --git a/web/api/queries/median/median.c b/web/api/queries/median/median.c
index 31916c54..bffcee12 100644
--- a/web/api/queries/median/median.c
+++ b/web/api/queries/median/median.c
@@ -13,14 +13,14 @@ struct grouping_median {
LONG_DOUBLE series[];
};
-void *grouping_create_median(RRDR *r) {
+void grouping_create_median(RRDR *r) {
long entries = r->group;
if(entries < 0) entries = 0;
struct grouping_median *g = (struct grouping_median *)callocz(1, sizeof(struct grouping_median) + entries * sizeof(LONG_DOUBLE));
g->series_size = (size_t)entries;
- return g;
+ r->internal.grouping_data = g;
}
// resets when switches dimensions
@@ -41,10 +41,8 @@ void grouping_add_median(RRDR *r, calculated_number value) {
if(unlikely(g->next_pos >= g->series_size)) {
error("INTERNAL ERROR: median buffer overflow on chart '%s' - next_pos = %zu, series_size = %zu, r->group = %ld.", r->st->name, g->next_pos, g->series_size, r->group);
}
- else {
- if(calculated_number_isnumber(value))
- g->series[g->next_pos++] = (LONG_DOUBLE)value;
- }
+ else
+ g->series[g->next_pos++] = (LONG_DOUBLE)value;
}
calculated_number grouping_flush_median(RRDR *r, RRDR_VALUE_FLAGS *rrdr_value_options_ptr) {
diff --git a/web/api/queries/median/median.h b/web/api/queries/median/median.h
index dd2c1ffc..28d52b31 100644
--- a/web/api/queries/median/median.h
+++ b/web/api/queries/median/median.h
@@ -6,7 +6,7 @@
#include "../query.h"
#include "../rrdr.h"
-extern void *grouping_create_median(RRDR *r);
+extern void grouping_create_median(RRDR *r);
extern void grouping_reset_median(RRDR *r);
extern void grouping_free_median(RRDR *r);
extern void grouping_add_median(RRDR *r, calculated_number value);
diff --git a/web/api/queries/min/min.c b/web/api/queries/min/min.c
index 9bd7460e..497bae04 100644
--- a/web/api/queries/min/min.c
+++ b/web/api/queries/min/min.c
@@ -10,9 +10,8 @@ struct grouping_min {
size_t count;
};
-void *grouping_create_min(RRDR *r) {
- (void)r;
- return callocz(1, sizeof(struct grouping_min));
+void grouping_create_min(RRDR *r) {
+ r->internal.grouping_data = callocz(1, sizeof(struct grouping_min));
}
// resets when switches dimensions
@@ -29,13 +28,11 @@ void grouping_free_min(RRDR *r) {
}
void grouping_add_min(RRDR *r, calculated_number value) {
- if(!isnan(value)) {
- struct grouping_min *g = (struct grouping_min *)r->internal.grouping_data;
+ struct grouping_min *g = (struct grouping_min *)r->internal.grouping_data;
- if(!g->count || calculated_number_fabs(value) < calculated_number_fabs(g->min)) {
- g->min = value;
- g->count++;
- }
+ if(!g->count || calculated_number_fabs(value) < calculated_number_fabs(g->min)) {
+ g->min = value;
+ g->count++;
}
}
diff --git a/web/api/queries/min/min.h b/web/api/queries/min/min.h
index 74703605..9207c74f 100644
--- a/web/api/queries/min/min.h
+++ b/web/api/queries/min/min.h
@@ -6,7 +6,7 @@
#include "../query.h"
#include "../rrdr.h"
-extern void *grouping_create_min(RRDR *r);
+extern void grouping_create_min(RRDR *r);
extern void grouping_reset_min(RRDR *r);
extern void grouping_free_min(RRDR *r);
extern void grouping_add_min(RRDR *r, calculated_number value);
diff --git a/web/api/queries/query.c b/web/api/queries/query.c
index c55a9706..5c6c7041 100644
--- a/web/api/queries/query.c
+++ b/web/api/queries/query.c
@@ -3,6 +3,7 @@
#include "query.h"
#include "web/api/formatters/rrd2json.h"
#include "rrdr.h"
+#include "database/ram/rrddim_mem.h"
#include "average/average.h"
#include "incremental_sum/incremental_sum.h"
@@ -27,7 +28,7 @@ static struct {
// Allocate all required structures for a query.
// This is called once for each netdata query.
- void *(*create)(struct rrdresult *r);
+ void (*create)(struct rrdresult *r);
// Cleanup collected values, but don't destroy the structures.
// This is called when the query engine switches dimensions,
@@ -464,7 +465,9 @@ static inline void do_dimension_variablestep(
}
}
// add this value to grouping
- r->internal.grouping_add(r, value);
+ if(likely(!isnan(value)))
+ r->internal.grouping_add(r, value);
+
values_in_group++;
db_points_read++;
}
@@ -537,25 +540,18 @@ static inline void do_dimension_fixedstep(
, time_t before_wanted
, uint32_t options
){
-#ifdef NETDATA_INTERNAL_CHECKS
- RRDSET *st = r->st;
-#endif
-
- time_t
- now = after_wanted,
+ time_t now = after_wanted,
dt = r->update_every / r->group, /* usually is st->update_every */
max_date = 0,
min_date = 0;
- long
- group_size = r->group,
+ long group_size = r->group,
points_added = 0,
values_in_group = 0,
values_in_group_non_zero = 0,
rrdr_line = -1;
- RRDR_VALUE_FLAGS
- group_value_flags = RRDR_VALUE_NOTHING;
+ RRDR_VALUE_FLAGS group_value_flags = RRDR_VALUE_NOTHING;
struct rrddim_query_handle handle;
@@ -563,6 +559,13 @@ static inline void do_dimension_fixedstep(
size_t db_points_read = 0;
time_t db_now = now;
time_t first_time_t = rrddim_first_entry_t(rd);
+
+ // cache the function pointers we need in the loop
+ storage_number (*next_metric)(struct rrddim_query_handle *handle, time_t *current_time) = rd->state->query_ops.next_metric;
+ void (*grouping_add)(struct rrdresult *r, calculated_number value) = r->internal.grouping_add;
+ calculated_number (*grouping_flush)(struct rrdresult *r, RRDR_VALUE_FLAGS *rrdr_value_options_ptr) = r->internal.grouping_flush;
+ RRD_MEMORY_MODE rrd_memory_mode = rd->rrd_memory_mode;
+
for(rd->state->query_ops.init(rd, &handle, now, before_wanted) ; points_added < points_wanted ; now += dt) {
// make sure we return data in the proper time range
if(unlikely(now > before_wanted)) {
@@ -571,44 +574,74 @@ static inline void do_dimension_fixedstep(
#endif
break;
}
+
if(unlikely(now < after_wanted)) {
#ifdef NETDATA_INTERNAL_CHECKS
r->internal.log = "skipped, because attempted to access the db before 'wanted after'";
#endif
continue;
}
+
// read the value from the database
//storage_number n = rd->values[slot];
+
#ifdef NETDATA_INTERNAL_CHECKS
- if ((rd->rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE) &&
- (rrdset_time2slot(st, now) != (long unsigned)handle.slotted.slot)) {
- error("INTERNAL CHECK: Unaligned query for %s, database slot: %lu, expected slot: %lu", rd->id, (long unsigned)handle.slotted.slot, rrdset_time2slot(st, now));
+ struct mem_query_handle* mem_handle = (struct mem_query_handle*)handle.handle;
+ if ((rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE) &&
+ (rrdset_time2slot(r->st, now) != (long unsigned)(mem_handle->slot))) {
+ error("INTERNAL CHECK: Unaligned query for %s, database slot: %lu, expected slot: %lu", rd->id, (long unsigned)mem_handle->slot, rrdset_time2slot(r->st, now));
}
#endif
+
db_now = now; // this is needed to set db_now in case the next_metric implementation does not set it
+
storage_number n;
- if (rd->rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE && now <= first_time_t)
+ calculated_number value;
+
+ if (unlikely(rrd_memory_mode != RRD_MEMORY_MODE_DBENGINE && now <= first_time_t)) {
n = SN_EMPTY_SLOT;
- else
- n = rd->state->query_ops.next_metric(&handle, &db_now);
+ value = NAN;
+ }
+ else {
+ // load the metric value
+ n = next_metric(&handle, &db_now);
+ db_points_read++;
+
+ // and unpack it
+ if(likely(does_storage_number_exist(n))) {
+ if (options & RRDR_OPTION_ANOMALY_BIT)
+ value = (n & SN_ANOMALY_BIT) ? 0.0 : 100.0;
+ else
+ value = unpack_storage_number(n);
+ }
+ else
+ value = NAN;
+ }
+
if(unlikely(db_now > before_wanted)) {
#ifdef NETDATA_INTERNAL_CHECKS
r->internal.log = "stopped, because attempted to access the db after 'wanted before'";
#endif
break;
}
- for ( ; now <= db_now ; now += dt) {
- calculated_number value = NAN;
- if(likely(now >= db_now && does_storage_number_exist(n))) {
+
+ // this loop exists only to fill nulls
+ // so, if there is a value already, we use it for the first iteration
+ // but the following iterations will just fill nulls to the destination
+ for ( ; now <= db_now ; now += dt, value = NAN, n = SN_EMPTY_SLOT) {
+ if(likely(does_storage_number_exist(n))) {
+
#if defined(NETDATA_INTERNAL_CHECKS) && defined(ENABLE_DBENGINE)
- if ((rd->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) && (now != handle.rrdeng.now)) {
- error("INTERNAL CHECK: Unaligned query for %s, database time: %ld, expected time: %ld", rd->id, (long)handle.rrdeng.now, (long)now);
+ if(now >= db_now) {
+ struct rrdeng_query_handle *rrd_handle = (struct rrdeng_query_handle *)handle.handle;
+ if ((rd->rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) && (now != rrd_handle->now))
+ error(
+ "INTERNAL CHECK: Unaligned query for %s, database time: %ld, expected time: %ld",
+ rd->id,
+ (long)rrd_handle->now,
+ (long)now);
}
#endif
- if (options & RRDR_OPTION_ANOMALY_BIT)
- value = (n & SN_ANOMALY_BIT) ? 0.0 : 100.0;
- else
- value = unpack_storage_number(n);
if(likely(value != 0.0))
values_in_group_non_zero++;
@@ -616,21 +649,21 @@ static inline void do_dimension_fixedstep(
if(unlikely(did_storage_number_reset(n)))
group_value_flags |= RRDR_VALUE_RESET;
+ grouping_add(r, value);
}
// add this value for grouping
- r->internal.grouping_add(r, value);
values_in_group++;
- db_points_read++;
if(unlikely(values_in_group == group_size)) {
rrdr_line = rrdr_line_init(r, now, rrdr_line);
+ size_t rrdr_o_v_index = rrdr_line * r->d + dim_id_in_rrdr;
if(unlikely(!min_date)) min_date = now;
max_date = now;
// find the place to store our values
- RRDR_VALUE_FLAGS *rrdr_value_options_ptr = &r->o[rrdr_line * r->d + dim_id_in_rrdr];
+ RRDR_VALUE_FLAGS *rrdr_value_options_ptr = &r->o[rrdr_o_v_index];
// update the dimension options
if(likely(values_in_group_non_zero))
@@ -639,21 +672,21 @@ static inline void do_dimension_fixedstep(
// store the specific point options
*rrdr_value_options_ptr = group_value_flags;
- // store the value
- calculated_number value = r->internal.grouping_flush(r, rrdr_value_options_ptr);
- r->v[rrdr_line * r->d + dim_id_in_rrdr] = value;
+ // store the group value
+ calculated_number group_value = grouping_flush(r, rrdr_value_options_ptr);
+ r->v[rrdr_o_v_index] = group_value;
if(likely(points_added || dim_id_in_rrdr)) {
// find the min/max across all dimensions
- if(unlikely(value < min)) min = value;
- if(unlikely(value > max)) max = value;
+ if(unlikely(group_value < min)) min = group_value;
+ if(unlikely(group_value > max)) max = group_value;
}
else {
// runs only when dim_id_in_rrdr == 0 && points_added == 0
// so, on the first point added for the query.
- min = max = value;
+ min = max = group_value;
}
points_added++;
@@ -831,7 +864,8 @@ static int rrdr_convert_before_after_to_absolute(
}
static RRDR *rrd2rrdr_fixedstep(
- RRDSET *st
+ ONEWAYALLOC *owa
+ , RRDSET *st
, long points_requested
, long long after_requested
, long long before_requested
@@ -855,7 +889,7 @@ static RRDR *rrd2rrdr_fixedstep(
RRDDIM *temp_rd = context_param_list ? context_param_list->rd : NULL;
if(duration <= 0 || available_points <= 0)
- return rrdr_create(st, 1, context_param_list);
+ return rrdr_create(owa, st, 1, context_param_list);
// check the number of wanted points in the result
if(unlikely(points_requested < 0)) points_requested = -points_requested;
@@ -1013,7 +1047,7 @@ static RRDR *rrd2rrdr_fixedstep(
// initialize our result set
// this also locks the chart for us
- RRDR *r = rrdr_create(st, points_wanted, context_param_list);
+ RRDR *r = rrdr_create(owa, st, points_wanted, context_param_list);
if(unlikely(!r)) {
#ifdef NETDATA_INTERNAL_CHECKS
error("INTERNAL CHECK: Cannot create RRDR for %s, after=%u, before=%u, duration=%u, points=%ld", st->id, (uint32_t)after_wanted, (uint32_t)before_wanted, (uint32_t)duration, points_wanted);
@@ -1077,7 +1111,7 @@ static RRDR *rrd2rrdr_fixedstep(
}
// allocate any memory required by the grouping method
- r->internal.grouping_data = r->internal.grouping_create(r);
+ r->internal.grouping_create(r);
// -------------------------------------------------------------------------
@@ -1216,7 +1250,8 @@ static RRDR *rrd2rrdr_fixedstep(
#ifdef ENABLE_DBENGINE
static RRDR *rrd2rrdr_variablestep(
- RRDSET *st
+ ONEWAYALLOC *owa
+ , RRDSET *st
, long points_requested
, long long after_requested
, long long before_requested
@@ -1242,7 +1277,7 @@ static RRDR *rrd2rrdr_variablestep(
if(duration <= 0 || available_points <= 0) {
freez(region_info_array);
- return rrdr_create(st, 1, context_param_list);
+ return rrdr_create(owa, st, 1, context_param_list);
}
// check the number of wanted points in the result
@@ -1401,7 +1436,7 @@ static RRDR *rrd2rrdr_variablestep(
// initialize our result set
// this also locks the chart for us
- RRDR *r = rrdr_create(st, points_wanted, context_param_list);
+ RRDR *r = rrdr_create(owa, st, points_wanted, context_param_list);
if(unlikely(!r)) {
#ifdef NETDATA_INTERNAL_CHECKS
error("INTERNAL CHECK: Cannot create RRDR for %s, after=%u, before=%u, duration=%u, points=%ld", st->id, (uint32_t)after_wanted, (uint32_t)before_wanted, (uint32_t)duration, points_wanted);
@@ -1468,7 +1503,7 @@ static RRDR *rrd2rrdr_variablestep(
}
// allocate any memory required by the grouping method
- r->internal.grouping_data = r->internal.grouping_create(r);
+ r->internal.grouping_create(r);
// -------------------------------------------------------------------------
@@ -1608,7 +1643,8 @@ static RRDR *rrd2rrdr_variablestep(
#endif //#ifdef ENABLE_DBENGINE
RRDR *rrd2rrdr(
- RRDSET *st
+ ONEWAYALLOC *owa
+ , RRDSET *st
, long points_requested
, long long after_requested
, long long before_requested
@@ -1644,7 +1680,7 @@ RRDR *rrd2rrdr(
first_entry_t = after_requested;
if (context_param_list && !(context_param_list->flags & CONTEXT_FLAGS_ARCHIVE)) {
- rebuild_context_param_list(context_param_list, after_requested);
+ rebuild_context_param_list(owa, context_param_list, after_requested);
st = context_param_list->rd ? context_param_list->rd->rrdset : NULL;
if (unlikely(!st))
return NULL;
@@ -1669,7 +1705,7 @@ RRDR *rrd2rrdr(
}
freez(region_info_array);
}
- return rrd2rrdr_fixedstep(st, points_requested, after_requested, before_requested, group_method,
+ return rrd2rrdr_fixedstep(owa, st, points_requested, after_requested, before_requested, group_method,
resampling_time_requested, options, dimensions, rrd_update_every,
first_entry_t, last_entry_t, absolute_period_requested, context_param_list, timeout);
} else {
@@ -1680,13 +1716,13 @@ RRDR *rrd2rrdr(
rrd_update_every, first_entry_t,
last_entry_t, options);
}
- return rrd2rrdr_variablestep(st, points_requested, after_requested, before_requested, group_method,
+ return rrd2rrdr_variablestep(owa, st, points_requested, after_requested, before_requested, group_method,
resampling_time_requested, options, dimensions, rrd_update_every,
first_entry_t, last_entry_t, absolute_period_requested, region_info_array, context_param_list, timeout);
}
}
#endif
- return rrd2rrdr_fixedstep(st, points_requested, after_requested, before_requested, group_method,
+ return rrd2rrdr_fixedstep(owa, st, points_requested, after_requested, before_requested, group_method,
resampling_time_requested, options, dimensions,
rrd_update_every, first_entry_t, last_entry_t, absolute_period_requested, context_param_list, timeout);
}
diff --git a/web/api/queries/rrdr.c b/web/api/queries/rrdr.c
index b6486822..4d05778c 100644
--- a/web/api/queries/rrdr.c
+++ b/web/api/queries/rrdr.c
@@ -78,12 +78,12 @@ inline static void rrdr_unlock_rrdset(RRDR *r) {
}
if(likely(r->has_st_lock)) {
- rrdset_unlock(r->st);
r->has_st_lock = 0;
+ rrdset_unlock(r->st);
}
}
-inline void rrdr_free(RRDR *r)
+inline void rrdr_free(ONEWAYALLOC *owa, RRDR *r)
{
if(unlikely(!r)) {
error("NULL value given!");
@@ -91,21 +91,21 @@ inline void rrdr_free(RRDR *r)
}
rrdr_unlock_rrdset(r);
- freez(r->t);
- freez(r->v);
- freez(r->o);
- freez(r->od);
- freez(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);
}
-RRDR *rrdr_create(struct rrdset *st, long n, struct context_param *context_param_list)
+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 *r = callocz(1, sizeof(RRDR));
+ RRDR *r = onewayalloc_callocz(owa, 1, sizeof(RRDR));
r->st = st;
if (!context_param_list || !(context_param_list->flags & CONTEXT_FLAGS_ARCHIVE)) {
@@ -126,10 +126,10 @@ RRDR *rrdr_create(struct rrdset *st, long n, struct context_param *context_param
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));
+ 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));
// set the hidden flag on hidden dimensions
int c;
diff --git a/web/api/queries/rrdr.h b/web/api/queries/rrdr.h
index bd94e56e..87ba6c86 100644
--- a/web/api/queries/rrdr.h
+++ b/web/api/queries/rrdr.h
@@ -83,7 +83,7 @@ typedef struct rrdresult {
long resampling_group;
calculated_number resampling_divisor;
- void *(*grouping_create)(struct rrdresult *r);
+ void (*grouping_create)(struct rrdresult *r);
void (*grouping_reset)(struct rrdresult *r);
void (*grouping_free)(struct rrdresult *r);
void (*grouping_add)(struct rrdresult *r, calculated_number value);
@@ -102,13 +102,14 @@ typedef struct rrdresult {
#define rrdr_rows(r) ((r)->rows)
#include "database/rrd.h"
-extern void rrdr_free(RRDR *r);
-extern RRDR *rrdr_create(struct rrdset *st, long n, struct context_param *context_param_list);
+extern void rrdr_free(ONEWAYALLOC *owa, RRDR *r);
+extern RRDR *rrdr_create(ONEWAYALLOC *owa, struct rrdset *st, long n, struct context_param *context_param_list);
#include "../web_api_v1.h"
#include "web/api/queries/query.h"
extern RRDR *rrd2rrdr(
+ ONEWAYALLOC *owa,
RRDSET *st, long points_requested, long long after_requested, long long before_requested,
RRDR_GROUPING group_method, long resampling_time_requested, RRDR_OPTIONS options, const char *dimensions,
struct context_param *context_param_list, int timeout);
diff --git a/web/api/queries/ses/ses.c b/web/api/queries/ses/ses.c
index 772505f9..ae4a0fa0 100644
--- a/web/api/queries/ses/ses.c
+++ b/web/api/queries/ses/ses.c
@@ -48,11 +48,11 @@ static inline void set_alpha(RRDR *r, struct grouping_ses *g) {
g->alpha_other = 1.0 - g->alpha;
}
-void *grouping_create_ses(RRDR *r) {
+void grouping_create_ses(RRDR *r) {
struct grouping_ses *g = (struct grouping_ses *)callocz(1, sizeof(struct grouping_ses));
set_alpha(r, g);
g->level = 0.0;
- return g;
+ r->internal.grouping_data = g;
}
// resets when switches dimensions
@@ -71,13 +71,11 @@ void grouping_free_ses(RRDR *r) {
void grouping_add_ses(RRDR *r, calculated_number value) {
struct grouping_ses *g = (struct grouping_ses *)r->internal.grouping_data;
- if(calculated_number_isnumber(value)) {
- if(unlikely(!g->count))
- g->level = value;
+ if(unlikely(!g->count))
+ g->level = value;
- g->level = g->alpha * value + g->alpha_other * g->level;
- g->count++;
- }
+ g->level = g->alpha * value + g->alpha_other * g->level;
+ g->count++;
}
calculated_number grouping_flush_ses(RRDR *r, RRDR_VALUE_FLAGS *rrdr_value_options_ptr) {
diff --git a/web/api/queries/ses/ses.h b/web/api/queries/ses/ses.h
index 603fdb57..c05f208f 100644
--- a/web/api/queries/ses/ses.h
+++ b/web/api/queries/ses/ses.h
@@ -8,7 +8,7 @@
extern void grouping_init_ses(void);
-extern void *grouping_create_ses(RRDR *r);
+extern void grouping_create_ses(RRDR *r);
extern void grouping_reset_ses(RRDR *r);
extern void grouping_free_ses(RRDR *r);
extern void grouping_add_ses(RRDR *r, calculated_number value);
diff --git a/web/api/queries/stddev/stddev.c b/web/api/queries/stddev/stddev.c
index 16258445..ffe7a47c 100644
--- a/web/api/queries/stddev/stddev.c
+++ b/web/api/queries/stddev/stddev.c
@@ -14,9 +14,8 @@ struct grouping_stddev {
calculated_number m_oldM, m_newM, m_oldS, m_newS;
};
-void *grouping_create_stddev(RRDR *r) {
- UNUSED (r);
- return callocz(1, sizeof(struct grouping_stddev));
+void grouping_create_stddev(RRDR *r) {
+ r->internal.grouping_data = callocz(1, sizeof(struct grouping_stddev));
}
// resets when switches dimensions
@@ -34,22 +33,20 @@ void grouping_free_stddev(RRDR *r) {
void grouping_add_stddev(RRDR *r, calculated_number value) {
struct grouping_stddev *g = (struct grouping_stddev *)r->internal.grouping_data;
- if(calculated_number_isnumber(value)) {
- g->count++;
+ g->count++;
- // See Knuth TAOCP vol 2, 3rd edition, page 232
- if (g->count == 1) {
- g->m_oldM = g->m_newM = value;
- g->m_oldS = 0.0;
- }
- else {
- g->m_newM = g->m_oldM + (value - g->m_oldM) / g->count;
- g->m_newS = g->m_oldS + (value - g->m_oldM) * (value - g->m_newM);
+ // See Knuth TAOCP vol 2, 3rd edition, page 232
+ if (g->count == 1) {
+ g->m_oldM = g->m_newM = value;
+ g->m_oldS = 0.0;
+ }
+ else {
+ g->m_newM = g->m_oldM + (value - g->m_oldM) / g->count;
+ g->m_newS = g->m_oldS + (value - g->m_oldM) * (value - g->m_newM);
- // set up for next iteration
- g->m_oldM = g->m_newM;
- g->m_oldS = g->m_newS;
- }
+ // set up for next iteration
+ g->m_oldM = g->m_newM;
+ g->m_oldS = g->m_newS;
}
}
diff --git a/web/api/queries/stddev/stddev.h b/web/api/queries/stddev/stddev.h
index 7a469757..ab58fbe5 100644
--- a/web/api/queries/stddev/stddev.h
+++ b/web/api/queries/stddev/stddev.h
@@ -6,7 +6,7 @@
#include "../query.h"
#include "../rrdr.h"
-extern void *grouping_create_stddev(RRDR *r);
+extern void grouping_create_stddev(RRDR *r);
extern void grouping_reset_stddev(RRDR *r);
extern void grouping_free_stddev(RRDR *r);
extern void grouping_add_stddev(RRDR *r, calculated_number value);
diff --git a/web/api/queries/sum/sum.c b/web/api/queries/sum/sum.c
index 0da9937a..6bb012bb 100644
--- a/web/api/queries/sum/sum.c
+++ b/web/api/queries/sum/sum.c
@@ -10,9 +10,8 @@ struct grouping_sum {
size_t count;
};
-void *grouping_create_sum(RRDR *r) {
- (void)r;
- return callocz(1, sizeof(struct grouping_sum));
+void grouping_create_sum(RRDR *r) {
+ r->internal.grouping_data = callocz(1, sizeof(struct grouping_sum));
}
// resets when switches dimensions
@@ -29,11 +28,9 @@ void grouping_free_sum(RRDR *r) {
}
void grouping_add_sum(RRDR *r, calculated_number value) {
- if(!isnan(value)) {
- struct grouping_sum *g = (struct grouping_sum *)r->internal.grouping_data;
- g->sum += value;
- g->count++;
- }
+ struct grouping_sum *g = (struct grouping_sum *)r->internal.grouping_data;
+ g->sum += value;
+ g->count++;
}
calculated_number grouping_flush_sum(RRDR *r, RRDR_VALUE_FLAGS *rrdr_value_options_ptr) {
diff --git a/web/api/queries/sum/sum.h b/web/api/queries/sum/sum.h
index 9dc8d209..05cb6185 100644
--- a/web/api/queries/sum/sum.h
+++ b/web/api/queries/sum/sum.h
@@ -6,7 +6,7 @@
#include "../query.h"
#include "../rrdr.h"
-extern void *grouping_create_sum(RRDR *r);
+extern void grouping_create_sum(RRDR *r);
extern void grouping_reset_sum(RRDR *r);
extern void grouping_free_sum(RRDR *r);
extern void grouping_add_sum(RRDR *r, calculated_number value);