From aa95dfdd5e7e95e4c2f23a53c76afb49beca442d Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sun, 7 Mar 2010 13:29:30 +0100 Subject: [PATCH] make top_cpu_separate a lua setting --- src/common.cc | 2 +- src/conky.cc | 5 ----- src/conky.h | 3 --- src/top.cc | 15 ++++++++------- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/common.cc b/src/common.cc index 146fb2b2..98168526 100644 --- a/src/common.cc +++ b/src/common.cc @@ -373,7 +373,7 @@ static void *run_update_callback(void *data) } } -conky::simple_config_setting no_buffers("no_buffers", true, false); +conky::simple_config_setting no_buffers("no_buffers", true, true); void update_stuff(void) { diff --git a/src/conky.cc b/src/conky.cc index 76cde498..0cb46b00 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -156,7 +156,6 @@ static conky::simple_config_setting use_spacer("use_spacer", NO_SP /* variables holding various config settings */ int short_units; int format_human_readable; -int cpu_separate; int top_cpu, top_mem, top_time; #ifdef BUILD_IOSTATS int top_io; @@ -2492,7 +2491,6 @@ static void set_default_configurations(void) info.diskio_avg_samples = 2; info.memmax = 0; top_cpu = 0; - cpu_separate = 0; short_units = 0; format_human_readable = 1; top_mem = 0; @@ -3117,9 +3115,6 @@ char load_config_file(const char *f) CONF_ERR; } #endif /* __linux__ */ - CONF("top_cpu_separate") { - cpu_separate = string_to_bool(value); - } CONF("short_units") { short_units = string_to_bool(value); } diff --git a/src/conky.h b/src/conky.h index d9d7ce80..1f9bc8b9 100644 --- a/src/conky.h +++ b/src/conky.h @@ -271,9 +271,6 @@ extern int top_io; #endif /* BUILD_IOSTATS */ extern int top_running; -/* defined in conky.c, needed by top.c */ -extern int cpu_separate; - /* struct that has all info to be shared between * instances of the same text object */ extern struct information info; diff --git a/src/top.cc b/src/top.cc index 19f030bf..98d7404f 100644 --- a/src/top.cc +++ b/src/top.cc @@ -32,6 +32,7 @@ #include "prioqueue.h" #include "top.h" #include "logging.h" +#include "setting.hh" /* hash table size - always a power of 2 */ #define HTABSIZE 256 @@ -40,6 +41,8 @@ static unsigned long g_time = 0; static unsigned long long previous_total = 0; static struct process *first_process = 0; +static conky::simple_config_setting top_cpu_separate("top_cpu_separate", false, true); + /* a simple hash table to speed up find_process() */ struct proc_hash_entry { struct proc_hash_entry *next; @@ -560,14 +563,12 @@ static unsigned long long calc_cpu_total(void) inline static void calc_cpu_each(unsigned long long total) { - struct process *p = first_process; + float mul = 100.0; + if(top_cpu_separate.get(*state)) + mul *= info.cpu_count; - while (p) { - p->amount = 100.0 * (cpu_separate ? info.cpu_count : 1) * - (p->user_time + p->kernel_time) / (float) total; - - p = p->next; - } + for(struct process *p = first_process; p; p = p->next) + p->amount = mul * (p->user_time + p->kernel_time) / (float) total; } #ifdef BUILD_IOSTATS