From 3f935f49aee0ad81255a5f0d18648fd414ccea48 Mon Sep 17 00:00:00 2001
From: wang--ge <wang__ge@126.com>
Date: Thu, 4 Jan 2024 09:50:15 +0800
Subject: [PATCH] trim dbengine test frequency

---
 daemon/unit_test.c   | 99 +-------------------------------------------
 libnetdata/inlined.h |  2 +
 2 files changed, 4 insertions(+), 97 deletions(-)

diff --git a/daemon/unit_test.c b/daemon/unit_test.c
index fa3fa84..b4e93c6 100644
--- a/daemon/unit_test.c
+++ b/daemon/unit_test.c
@@ -2139,102 +2139,7 @@ int test_dbengine(void)
 
     errors += test_dbengine_check_metrics(st, rd, current_region, time_start[current_region]);
 
-    current_region = 1; //this is the second region of data
-    update_every = REGION_UPDATE_EVERY[current_region]; // set data collection frequency to 3 seconds
-    // Align pages for frequency change
-    for (i = 0 ; i < CHARTS ; ++i) {
-        st[i]->update_every = update_every;
-        for (j = 0; j < DIMS; ++j) {
-            rrdeng_store_metric_flush_current_page((rd[i][j])->tiers[0].db_collection_handle);
-        }
-    }
-
-    time_start[current_region] = time_end[current_region - 1] + update_every;
-    if (0 != time_start[current_region] % update_every) // align to update_every
-        time_start[current_region] += update_every - time_start[current_region] % update_every;
-    time_end[current_region] = test_dbengine_create_metrics(st,rd, current_region, time_start[current_region]);
-
-    errors += test_dbengine_check_metrics(st, rd, current_region, time_start[current_region]);
-
-    current_region = 2; //this is the third region of data
-    update_every = REGION_UPDATE_EVERY[current_region]; // set data collection frequency to 1 seconds
-    // Align pages for frequency change
-    for (i = 0 ; i < CHARTS ; ++i) {
-        st[i]->update_every = update_every;
-        for (j = 0; j < DIMS; ++j) {
-            rrdeng_store_metric_flush_current_page((rd[i][j])->tiers[0].db_collection_handle);
-        }
-    }
-
-    time_start[current_region] = time_end[current_region - 1] + update_every;
-    if (0 != time_start[current_region] % update_every) // align to update_every
-        time_start[current_region] += update_every - time_start[current_region] % update_every;
-    time_end[current_region] = test_dbengine_create_metrics(st,rd, current_region, time_start[current_region]);
-
-    errors += test_dbengine_check_metrics(st, rd, current_region, time_start[current_region]);
-
-    for (current_region = 0 ; current_region < REGIONS ; ++current_region) {
-        errors += test_dbengine_check_rrdr(st, rd, current_region, time_start[current_region], time_end[current_region]);
-    }
-
-    current_region = 1;
-    update_every = REGION_UPDATE_EVERY[current_region]; // use the maximum update_every = 3
-    long points = (time_end[REGIONS - 1] - time_start[0]) / update_every; // cover all time regions with RRDR
-    long point_offset = (time_start[current_region] - time_start[0]) / update_every;
-    for (i = 0 ; i < CHARTS ; ++i) {
-        ONEWAYALLOC *owa = onewayalloc_create(0);
-        RRDR *r = rrd2rrdr_legacy(owa, st[i], points, time_start[0] + update_every,
-                                  time_end[REGIONS - 1], RRDR_GROUPING_AVERAGE, 0,
-                                  RRDR_OPTION_NATURAL_POINTS, NULL, NULL, 0, 0,
-                                  QUERY_SOURCE_UNITTEST, STORAGE_PRIORITY_NORMAL);
-
-        if (!r) {
-            fprintf(stderr, "    DB-engine unittest %s: empty RRDR ### E R R O R ###\n", rrdset_name(st[i]));
-            ++errors;
-        } else {
-            long c;
-
-            assert(r->internal.qt->request.st == st[i]);
-            // test current region values only, since they must be left unchanged
-            for (c = point_offset ; c < (long)(point_offset + rrdr_rows(r) / REGIONS / 2) ; ++c) {
-                RRDDIM *d;
-                time_t time_now = time_start[current_region] + (c - point_offset + 2) * update_every;
-                time_t time_retrieved = r->t[c];
-
-                // for each dimension
-                rrddim_foreach_read(d, r->internal.qt->request.st) {
-                    if(unlikely(d_dfe.counter >= r->d)) break; // d_counter is provided by the dictionary dfe
-
-                    j = (int)d_dfe.counter;
-
-                    NETDATA_DOUBLE *cn = &r->v[ c * r->d ];
-                    NETDATA_DOUBLE value = cn[j];
-                    assert(rd[i][j] == d);
-
-                    collected_number last = i * DIMS * REGION_POINTS[current_region] + j * REGION_POINTS[current_region] + c - point_offset + 1;
-                    NETDATA_DOUBLE expected = unpack_storage_number(pack_storage_number((NETDATA_DOUBLE)last, SN_DEFAULT_FLAGS));
-
-                    uint8_t same = (roundndd(value) == roundndd(expected)) ? 1 : 0;
-                    if(!same) {
-                        if(!value_errors)
-                            fprintf(stderr, "    DB-engine unittest %s/%s: at %lu secs, expecting value " NETDATA_DOUBLE_FORMAT
-                                ", RRDR found " NETDATA_DOUBLE_FORMAT ", ### E R R O R ###\n",
-                                    rrdset_name(st[i]), rrddim_name(rd[i][j]), (unsigned long)time_now, expected, value);
-                        value_errors++;
-                    }
-                    if(time_retrieved != time_now) {
-                        if(!time_errors)
-                            fprintf(stderr, "    DB-engine unittest %s/%s: at %lu secs, found RRDR timestamp %lu ### E R R O R ###\n",
-                                    rrdset_name(st[i]), rrddim_name(rd[i][j]), (unsigned long)time_now, (unsigned long)time_retrieved);
-                        time_errors++;
-                    }
-                }
-                rrddim_foreach_done(d);
-            }
-            rrdr_free(owa, r);
-        }
-        onewayalloc_destroy(owa);
-    }
+    errors += test_dbengine_check_rrdr(st, rd, current_region, time_start[current_region], time_end[current_region]);
 
     rrd_wrlock();
     rrdeng_prepare_exit((struct rrdengine_instance *)host->db[0].instance);
@@ -2242,7 +2147,7 @@ int test_dbengine(void)
     rrdeng_exit((struct rrdengine_instance *)host->db[0].instance);
     rrd_unlock();
 
-    return errors + value_errors + time_errors;
+    return errors;
 }
 
 struct dbengine_chart_thread {
diff --git a/libnetdata/inlined.h b/libnetdata/inlined.h
index 2697b9a..906b0dd 100644
--- a/libnetdata/inlined.h
+++ b/libnetdata/inlined.h
@@ -236,6 +236,7 @@ static inline uint64_t str2uint64_base64(const char *src, char **endptr) {
     return num;
 }
 
+static NETDATA_DOUBLE str2ndd_parse_double_decimal_digits_internal(const char *src, int *digits) __attribute__((optimize(0)));
 static inline NETDATA_DOUBLE str2ndd_parse_double_decimal_digits_internal(const char *src, int *digits) {
     const char *s = src;
     NETDATA_DOUBLE n = 0.0;
@@ -257,6 +258,7 @@ static inline NETDATA_DOUBLE str2ndd_parse_double_decimal_digits_internal(const
     return n;
 }
 
+static NETDATA_DOUBLE str2ndd(const char *src, char **endptr) __attribute__((optimize(0)));
 static inline NETDATA_DOUBLE str2ndd(const char *src, char **endptr) {
     const char *s = src;
 
-- 
2.33.0

