From 80f335963477233836ed7f6430f0fe314eb8da5c Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sun, 22 Aug 2010 12:24:26 +0200 Subject: [PATCH] make cpu_avg_samples a lua setting --- src/conky.cc | 16 ++-------------- src/conky.h | 3 ++- src/linux.cc | 18 +++++------------- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 45c5f548..61bff535 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -354,7 +354,8 @@ static conky::simple_config_setting fork_to_background("background", false * first forking */ static int first_pass = 1; -static int cpu_avg_samples, net_avg_samples, diskio_avg_samples; +static int net_avg_samples, diskio_avg_samples; +conky::range_config_setting cpu_avg_samples("cpu_avg_samples", 1, 14, 2, true); /* filenames for output */ char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL; @@ -2594,7 +2595,6 @@ static void set_default_configurations(void) { update_uname(); total_run_times = 0; - info.cpu_avg_samples = 2; info.net_avg_samples = 2; info.diskio_avg_samples = 2; info.memmax = 0; @@ -2877,18 +2877,6 @@ char load_config_file(const char *f) } } #endif - CONF("cpu_avg_samples") { - if (value) { - cpu_avg_samples = strtol(value, 0, 0); - if (cpu_avg_samples < 1 || cpu_avg_samples > 14) { - CONF_ERR; - } else { - info.cpu_avg_samples = cpu_avg_samples; - } - } else { - CONF_ERR; - } - } CONF("net_avg_samples") { if (value) { net_avg_samples = strtol(value, 0, 0); diff --git a/src/conky.h b/src/conky.h index 65258349..c971bb59 100644 --- a/src/conky.h +++ b/src/conky.h @@ -212,7 +212,6 @@ struct information { float *cpu_usage; /* struct cpu_stat cpu_summed; what the hell is this? */ int cpu_count; - int cpu_avg_samples; int net_avg_samples; @@ -247,6 +246,8 @@ struct information { short kflags; /* kernel settings, see enum KFLAG */ }; +extern conky::range_config_setting cpu_avg_samples; + /* needed by linux.c and top.c -> outsource somewhere */ enum { /* set to true if kernel uses "long" format for /proc/stats */ diff --git a/src/linux.cc b/src/linux.cc index c7026e64..2018162e 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -788,30 +788,22 @@ int update_stat(void) cpu[idx].cpu_last_active_total) / (float) (cpu[idx].cpu_total - cpu[idx].cpu_last_total); curtmp = 0; + + int samples = cpu_avg_samples.get(*state); #ifdef HAVE_OPENMP #pragma omp parallel for reduction(+:curtmp) schedule(dynamic,10) #endif /* HAVE_OPENMP */ - for (i = 0; i < info.cpu_avg_samples; i++) { + for (i = 0; i < samples; i++) { curtmp = curtmp + cpu[idx].cpu_val[i]; } - /* TESTING -- I've removed this, because I don't think it is right. - * You shouldn't divide by the cpu count here ... - * removing for testing */ - /* if (idx == 0) { - info.cpu_usage[idx] = curtmp / info.cpu_avg_samples / - info.cpu_count; - } else { - info.cpu_usage[idx] = curtmp / info.cpu_avg_samples; - } */ - /* TESTING -- this line replaces the prev. "suspect" if/else */ - info.cpu_usage[idx] = curtmp / info.cpu_avg_samples; + info.cpu_usage[idx] = curtmp / samples; cpu[idx].cpu_last_total = cpu[idx].cpu_total; cpu[idx].cpu_last_active_total = cpu[idx].cpu_active_total; #ifdef HAVE_OPENMP #pragma omp parallel for schedule(dynamic,10) #endif /* HAVE_OPENMP */ - for (i = info.cpu_avg_samples - 1; i > 0; i--) { + for (i = samples - 1; i > 0; i--) { cpu[idx].cpu_val[i] = cpu[idx].cpu_val[i - 1]; } }