diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 14:31:17 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 14:31:17 +0000 |
commit | 8020f71afd34d7696d7933659df2d763ab05542f (patch) | |
tree | 2fdf1b5447ffd8bdd61e702ca183e814afdcb4fc /ml/Query.h | |
parent | Initial commit. (diff) | |
download | netdata-upstream.tar.xz netdata-upstream.zip |
Adding upstream version 1.37.1.upstream/1.37.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ml/Query.h')
-rw-r--r-- | ml/Query.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/ml/Query.h b/ml/Query.h new file mode 100644 index 0000000..78d1170 --- /dev/null +++ b/ml/Query.h @@ -0,0 +1,57 @@ +#ifndef QUERY_H +#define QUERY_H + +#include "ml-private.h" + +namespace ml { + +class Query { +public: + Query(RRDDIM *RD) : RD(RD), Initialized(false) { + Ops = RD->tiers[0]->query_ops; + } + + time_t latestTime() { + return Ops->latest_time(RD->tiers[0]->db_metric_handle); + } + + time_t oldestTime() { + return Ops->oldest_time(RD->tiers[0]->db_metric_handle); + } + + void init(time_t AfterT, time_t BeforeT) { + Ops->init(RD->tiers[0]->db_metric_handle, &Handle, AfterT, BeforeT); + Initialized = true; + points_read = 0; + } + + bool isFinished() { + return Ops->is_finished(&Handle); + } + + ~Query() { + if (Initialized) { + Ops->finalize(&Handle); + global_statistics_ml_query_completed(points_read); + points_read = 0; + } + } + + std::pair<time_t, CalculatedNumber> nextMetric() { + points_read++; + STORAGE_POINT sp = Ops->next_metric(&Handle); + return { sp.start_time, sp.sum / sp.count }; + } + +private: + RRDDIM *RD; + bool Initialized; + size_t points_read; + + struct storage_engine_query_ops *Ops; + struct storage_engine_query_handle Handle; +}; + +} // namespace ml + +#endif /* QUERY_H */ |