mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-15 19:56:55 +00:00
make cpu_avg_samples a lua setting
This commit is contained in:
parent
663e99ee53
commit
80f3359634
16
src/conky.cc
16
src/conky.cc
@ -354,7 +354,8 @@ static conky::simple_config_setting<bool> 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<int> 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);
|
||||
|
@ -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<int> cpu_avg_samples;
|
||||
|
||||
/* needed by linux.c and top.c -> outsource somewhere */
|
||||
enum {
|
||||
/* set to true if kernel uses "long" format for /proc/stats */
|
||||
|
18
src/linux.cc
18
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];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user