Browse Source

netdata doubles (#13217)

* netdata doubles

* fix cmocka test

* fix cmocka test again

* fix left-overs of long double to NETDATA_DOUBLE

* RRDDIM detached from disk representation; db settings in [db] section of netdata.conf

* update the memory before saving

* rrdset is now detached from file structures too

* on memory mode map, update the memory mapped structures on every iteration

* allow RRD_ID_LENGTH_MAX to be changed

* granularity secs, back to update every

* fix formatting

* more formatting
Costa Tsaousis 2 years ago
parent
commit
c3dfbe52a6

+ 4 - 4
aclk/aclk_rx_msgs.c

@@ -55,19 +55,19 @@ static int cloud_to_agent_parse(JSON_ENTRY *e)
             break;
         case JSON_NUMBER:
             if (!strcmp(e->name, "version")) {
-                data->version = e->data.number;
+                data->version = (int)e->data.number;
                 break;
             }
             if (!strcmp(e->name, "timeout")) {
-                data->timeout = e->data.number;
+                data->timeout = (int)e->data.number;
                 break;
             }
             if (!strcmp(e->name, "min-version")) {
-                data->min_version = e->data.number;
+                data->min_version = (int)e->data.number;
                 break;
             }
             if (!strcmp(e->name, "max-version")) {
-                data->max_version = e->data.number;
+                data->max_version = (int)e->data.number;
                 break;
             }
 

+ 1 - 1
cli/README.md

@@ -20,7 +20,7 @@ reload-health
 reload-labels
     Reload all labels.
 save-database
-    Save internal DB to disk for memory mode save.
+    Save internal DB to disk for database mode save.
 reopen-logs
     Close and reopen log files.
 shutdown-agent

+ 10 - 8
collectors/apps.plugin/apps_plugin.c

@@ -173,7 +173,8 @@ static kernel_uint_t
         global_gtime = 0;
 
 // the normalization ratios, as calculated by normalize_utilization()
-double  utime_fix_ratio = 1.0,
+NETDATA_DOUBLE
+        utime_fix_ratio = 1.0,
         stime_fix_ratio = 1.0,
         gtime_fix_ratio = 1.0,
         minflt_fix_ratio = 1.0,
@@ -501,7 +502,8 @@ struct file_descriptor {
 static int
         all_files_len = 0,
         all_files_size = 0;
-        long double currentmaxfds = 0;
+
+long currentmaxfds = 0;
 
 // ----------------------------------------------------------------------------
 // read users and groups from files
@@ -3021,7 +3023,7 @@ static inline void aggregate_pid_fds_on_targets(struct pid_stat *p) {
     reallocate_target_fds(u);
     reallocate_target_fds(g);
 
-    long double currentfds = 0;
+    long currentfds = 0;
     size_t c, size = p->fds_size;
     struct pid_fd *fds = p->fds;
     for(c = 0; c < size ;c++) {
@@ -3373,7 +3375,7 @@ static void normalize_utilization(struct target *root) {
             gtime_fix_ratio  =
             cutime_fix_ratio =
             cstime_fix_ratio =
-            cgtime_fix_ratio = 1.0; //(double)(global_utime + global_stime) / (double)(utime + cutime + stime + cstime);
+            cgtime_fix_ratio = 1.0; //(NETDATA_DOUBLE)(global_utime + global_stime) / (NETDATA_DOUBLE)(utime + cutime + stime + cstime);
         }
         else if((global_utime + global_stime > utime + stime) && (cutime || cstime)) {
             // children resources are too high
@@ -3383,7 +3385,7 @@ static void normalize_utilization(struct target *root) {
             gtime_fix_ratio  = 1.0;
             cutime_fix_ratio =
             cstime_fix_ratio =
-            cgtime_fix_ratio = (double)((global_utime + global_stime) - (utime + stime)) / (double)(cutime + cstime);
+            cgtime_fix_ratio = (NETDATA_DOUBLE)((global_utime + global_stime) - (utime + stime)) / (NETDATA_DOUBLE)(cutime + cstime);
         }
         else if(utime || stime) {
             // even running processes are unrealistic
@@ -3391,7 +3393,7 @@ static void normalize_utilization(struct target *root) {
             // lower the running processes resources
             utime_fix_ratio  =
             stime_fix_ratio  =
-            gtime_fix_ratio  = (double)(global_utime + global_stime) / (double)(utime + stime);
+            gtime_fix_ratio  = (NETDATA_DOUBLE)(global_utime + global_stime) / (NETDATA_DOUBLE)(utime + stime);
             cutime_fix_ratio =
             cstime_fix_ratio =
             cgtime_fix_ratio = 0.0;
@@ -3439,14 +3441,14 @@ static void normalize_utilization(struct target *root) {
 
     if(utime || stime || gtime)
         majflt_fix_ratio =
-        minflt_fix_ratio = (double)(utime * utime_fix_ratio + stime * stime_fix_ratio + gtime * gtime_fix_ratio) / (double)(utime + stime + gtime);
+        minflt_fix_ratio = (NETDATA_DOUBLE)(utime * utime_fix_ratio + stime * stime_fix_ratio + gtime * gtime_fix_ratio) / (NETDATA_DOUBLE)(utime + stime + gtime);
     else
         minflt_fix_ratio =
         majflt_fix_ratio = 1.0;
 
     if(cutime || cstime || cgtime)
         cmajflt_fix_ratio =
-        cminflt_fix_ratio = (double)(cutime * cutime_fix_ratio + cstime * cstime_fix_ratio + cgtime * cgtime_fix_ratio) / (double)(cutime + cstime + cgtime);
+        cminflt_fix_ratio = (NETDATA_DOUBLE)(cutime * cutime_fix_ratio + cstime * cstime_fix_ratio + cgtime * cgtime_fix_ratio) / (NETDATA_DOUBLE)(cutime + cstime + cgtime);
     else
         cminflt_fix_ratio =
         cmajflt_fix_ratio = 1.0;

+ 12 - 12
collectors/cgroups.plugin/sys_fs_cgroup.c

@@ -835,7 +835,7 @@ struct cgroup {
     unsigned long long cpu_cfs_quota;
 
     RRDSETVAR *chart_var_cpu_limit;
-    calculated_number prev_cpu_usage;
+    NETDATA_DOUBLE prev_cpu_usage;
 
     char *filename_memory_limit;
     unsigned long long memory_limit;
@@ -1012,7 +1012,7 @@ static unsigned long long calc_percentage(unsigned long long value, unsigned lon
     if (total == 0) {
         return 0;
     }
-    return (calculated_number)value / (calculated_number)total * 100;
+    return (NETDATA_DOUBLE)value / (NETDATA_DOUBLE)total * 100;
 }
 
 static int calc_cgroup_depth(const char *id) {
@@ -3686,7 +3686,7 @@ static inline int update_memory_limits(char **filename, RRDSETVAR **chart_var, u
                     *filename = NULL;
                 }
                 else {
-                    rrdsetvar_custom_chart_variable_set(*chart_var, (calculated_number)(*value / (1024 * 1024)));
+                    rrdsetvar_custom_chart_variable_set(*chart_var, (NETDATA_DOUBLE)(*value / (1024 * 1024)));
                     return 1;
                 }
             } else {
@@ -3701,11 +3701,11 @@ static inline int update_memory_limits(char **filename, RRDSETVAR **chart_var, u
                 char *s = "max\n\0";
                 if(strcmp(s, buffer) == 0){
                     *value = UINT64_MAX;
-                    rrdsetvar_custom_chart_variable_set(*chart_var, (calculated_number)(*value / (1024 * 1024)));
+                    rrdsetvar_custom_chart_variable_set(*chart_var, (NETDATA_DOUBLE)(*value / (1024 * 1024)));
                     return 1;
                 }
                 *value = str2ull(buffer);
-                rrdsetvar_custom_chart_variable_set(*chart_var, (calculated_number)(*value / (1024 * 1024)));
+                rrdsetvar_custom_chart_variable_set(*chart_var, (NETDATA_DOUBLE)(*value / (1024 * 1024)));
                 return 1;
             }
         }
@@ -3814,17 +3814,17 @@ void update_cgroup_charts(int update_every) {
                     }
                 }
                 else {
-                    calculated_number value = 0, quota = 0;
+                    NETDATA_DOUBLE value = 0, quota = 0;
 
                     if(likely( ((!(cg->options & CGROUP_OPTIONS_IS_UNIFIED)) && (cg->filename_cpuset_cpus || (cg->filename_cpu_cfs_period && cg->filename_cpu_cfs_quota)))
                             || ((cg->options & CGROUP_OPTIONS_IS_UNIFIED) && cg->filename_cpu_cfs_quota))) {
                         if(unlikely(cg->cpu_cfs_quota > 0))
-                            quota = (calculated_number)cg->cpu_cfs_quota / (calculated_number)cg->cpu_cfs_period;
+                            quota = (NETDATA_DOUBLE)cg->cpu_cfs_quota / (NETDATA_DOUBLE)cg->cpu_cfs_period;
 
                         if(unlikely(quota > 0 && quota < cg->cpuset_cpus))
                             value = quota * 100;
                         else
-                            value = (calculated_number)cg->cpuset_cpus * 100;
+                            value = (NETDATA_DOUBLE)cg->cpuset_cpus * 100;
                     }
                     if(likely(value)) {
                         rrdsetvar_custom_chart_variable_set(cg->chart_var_cpu_limit, value);
@@ -3853,14 +3853,14 @@ void update_cgroup_charts(int update_every) {
                                 rrddim_add(cg->st_cpu_limit, "used", NULL, 1, system_hz, RRD_ALGORITHM_ABSOLUTE);
                             else
                                 rrddim_add(cg->st_cpu_limit, "used", NULL, 1, 1000000, RRD_ALGORITHM_ABSOLUTE);
-                            cg->prev_cpu_usage = (calculated_number)(cg->cpuacct_stat.user + cg->cpuacct_stat.system) * 100;
+                            cg->prev_cpu_usage = (NETDATA_DOUBLE)(cg->cpuacct_stat.user + cg->cpuacct_stat.system) * 100;
                         }
                         else
                             rrdset_next(cg->st_cpu_limit);
 
-                        calculated_number cpu_usage = 0;
-                        cpu_usage = (calculated_number)(cg->cpuacct_stat.user + cg->cpuacct_stat.system) * 100;
-                        calculated_number cpu_used = 100 * (cpu_usage - cg->prev_cpu_usage) / (value * update_every);
+                        NETDATA_DOUBLE cpu_usage = 0;
+                        cpu_usage = (NETDATA_DOUBLE)(cg->cpuacct_stat.user + cg->cpuacct_stat.system) * 100;
+                        NETDATA_DOUBLE cpu_used = 100 * (cpu_usage - cg->prev_cpu_usage) / (value * update_every);
 
                         rrdset_isnot_obsolete(cg->st_cpu_limit);
 

+ 1 - 1
collectors/cgroups.plugin/tests/test_doubles.c

@@ -109,7 +109,7 @@ RRDSETVAR *rrdsetvar_custom_chart_variable_create(RRDSET *st, const char *name)
     return NULL;
 }
 
-void rrdsetvar_custom_chart_variable_set(RRDSETVAR *rs, calculated_number value)
+void rrdsetvar_custom_chart_variable_set(RRDSETVAR *rs, NETDATA_DOUBLE value)
 {
     UNUSED(rs);
     UNUSED(value);

+ 4 - 4
collectors/ebpf.plugin/ebpf_cachestat.c

@@ -367,23 +367,23 @@ void cachestat_update_publish(netdata_publish_cachestat_t *out, uint64_t mpa, ui
                               uint64_t apcl, uint64_t apd)
 {
     // Adapted algorithm from https://github.com/iovisor/bcc/blob/master/tools/cachestat.py#L126-L138
-    calculated_number total = (calculated_number) (((long long)mpa) - ((long long)mbd));
+    NETDATA_DOUBLE total = (NETDATA_DOUBLE) (((long long)mpa) - ((long long)mbd));
     if (total < 0)
         total = 0;
 
-    calculated_number misses = (calculated_number) ( ((long long) apcl) - ((long long) apd) );
+    NETDATA_DOUBLE misses = (NETDATA_DOUBLE) ( ((long long) apcl) - ((long long) apd) );
     if (misses < 0)
         misses = 0;
 
     // If hits are < 0, then its possible misses are overestimate due to possibly page cache read ahead adding
     // more pages than needed. In this case just assume misses as total and reset hits.
-    calculated_number hits = total - misses;
+    NETDATA_DOUBLE hits = total - misses;
     if (hits < 0 ) {
         misses = total;
         hits = 0;
     }
 
-    calculated_number ratio = (total > 0) ? hits/total : 1;
+    NETDATA_DOUBLE ratio = (total > 0) ? hits/total : 1;
 
     out->ratio = (long long )(ratio*100);
     out->hit = (long long)hits;

+ 2 - 2
collectors/ebpf.plugin/ebpf_dcstat.c

@@ -239,8 +239,8 @@ static inline int ebpf_dc_load_and_attach(struct dc_bpf *obj, ebpf_module_t *em)
  */
 void dcstat_update_publish(netdata_publish_dcstat_t *out, uint64_t cache_access, uint64_t not_found)
 {
-    calculated_number successful_access = (calculated_number) (((long long)cache_access) - ((long long)not_found));
-    calculated_number ratio = (cache_access) ? successful_access/(calculated_number)cache_access : 0;
+    NETDATA_DOUBLE successful_access = (NETDATA_DOUBLE) (((long long)cache_access) - ((long long)not_found));
+    NETDATA_DOUBLE ratio = (cache_access) ? successful_access/(NETDATA_DOUBLE)cache_access : 0;
 
     out->ratio = (long long )(ratio*100);
 }

+ 2 - 2
collectors/perf.plugin/perf_plugin.c

@@ -520,8 +520,8 @@ static void perf_send_metrics() {
                , "instructions_per_cycle"
                );
 
-        calculated_number result = ((calculated_number)perf_events[EV_ID_INSTRUCTIONS].value /
-                                    (calculated_number)perf_events[EV_ID_CPU_CYCLES].value) * 100.0;
+        NETDATA_DOUBLE result = ((NETDATA_DOUBLE)perf_events[EV_ID_INSTRUCTIONS].value /
+                                    (NETDATA_DOUBLE)perf_events[EV_ID_CPU_CYCLES].value) * 100.0;
         printf("SET %s = %lld\n"
                , "ipc"
                , (collected_number) result

+ 3 - 3
collectors/plugins.d/pluginsd_parser.c

@@ -96,7 +96,7 @@ PARSER_RC pluginsd_disable_action(void *user)
 }
 
 
-PARSER_RC pluginsd_variable_action(void *user, RRDHOST *host, RRDSET *st, char *name, int global, calculated_number value)
+PARSER_RC pluginsd_variable_action(void *user, RRDHOST *host, RRDSET *st, char *name, int global, NETDATA_DOUBLE value)
 {
     UNUSED(user);
 
@@ -473,7 +473,7 @@ PARSER_RC pluginsd_variable(char **words, void *user, PLUGINSD_ACTION  *plugins_
 {
     char *name = words[1];
     char *value = words[2];
-    calculated_number v;
+    NETDATA_DOUBLE v;
 
     RRDSET *st = ((PARSER_USER_OBJECT *) user)->st;
     RRDHOST *host = ((PARSER_USER_OBJECT *) user)->host;
@@ -513,7 +513,7 @@ PARSER_RC pluginsd_variable(char **words, void *user, PLUGINSD_ACTION  *plugins_
     }
 
     char *endptr = NULL;
-    v = (calculated_number)str2ld(value, &endptr);
+    v = (NETDATA_DOUBLE)str2ndd(value, &endptr);
     if (unlikely(endptr && *endptr)) {
         if (endptr == value)
             error(

+ 1 - 2
collectors/plugins.d/pluginsd_parser.h

@@ -30,8 +30,7 @@ extern PARSER_RC pluginsd_chart_action(void *user, char *type, char *id, char *n
                                        char *title, char *units, char *plugin, char *module, int priority,
                                        int update_every, RRDSET_TYPE chart_type, char *options);
 extern PARSER_RC pluginsd_disable_action(void *user);
-extern PARSER_RC pluginsd_variable_action(void *user, RRDHOST *host, RRDSET *st, char *name, int global,
-                                          calculated_number value);
+extern PARSER_RC pluginsd_variable_action(void *user, RRDHOST *host, RRDSET *st, char *name, int global, NETDATA_DOUBLE value);
 extern PARSER_RC pluginsd_dimension_action(void *user, RRDSET *st, char *id, char *name, char *algorithm,
                                            long multiplier, long divisor, char *options, RRD_ALGORITHM algorithm_type);
 extern PARSER_RC pluginsd_label_action(void *user, char *key, char *value, RRDLABEL_SRC source);

Some files were not shown because too many files changed in this diff