1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-24 11:55:43 +00:00

smp support?

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@207 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2005-08-27 09:29:24 +00:00
parent 8d30811f6f
commit 5a179ffde2
3 changed files with 84 additions and 41 deletions

View File

@ -851,7 +851,7 @@ struct text_object {
struct fs_stat *fs;
unsigned char loadavg[3];
//unsigned int diskio;
int cpu_index;
struct {
struct fs_stat *fs;
int w, h;
@ -1038,6 +1038,13 @@ if (s[0] == '#') {
END OBJ(buffers, INFO_BUFFERS)
END OBJ(cached, INFO_BUFFERS)
END OBJ(cpu, INFO_CPU)
if (arg) {
if (sscanf(arg, "%i", &obj->data.cpu_index) < 1) {
ERR("$cpu takes an int as an arg");
} else {
obj->data.cpu_index = 1;
}
}
END OBJ(cpubar, INFO_CPU)
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
END OBJ(cpugraph, INFO_CPU)
@ -1772,23 +1779,23 @@ static void generate_text()
OBJ(cpu) {
if (!use_spacer)
snprintf(p, n, "%*d", pad_percents,
(int) (cur->cpu_usage *
(int) (cur->cpu_usage[obj->data.cpu_index] *
100.0));
else
snprintf(p, 4, "%*d ",
pad_percents,
(int) (cur->cpu_usage *
(int) (cur->cpu_usage[obj->data.cpu_index] *
100.0));
}
OBJ(cpubar) {
new_bar(p, obj->data.pair.a,
obj->data.pair.b,
(int) (cur->cpu_usage * 255.0));
(int) (cur->cpu_usage[0] * 255.0));
}
OBJ(cpugraph) {
new_graph(p, obj->a,
obj->b, obj->c, obj->d,
(unsigned int) (cur->cpu_usage *
(unsigned int) (cur->cpu_usage[0] *
100), 100, 1);
}
OBJ(color) {

View File

@ -81,10 +81,10 @@ struct fs_stat {
long long avail;
};
struct cpu_stat {
/*struct cpu_stat {
unsigned int user, nice, system, idle, iowait, irq, softirq;
int cpu_avg_samples;
};
};*/
#ifdef MPD
struct mpd_s {
@ -129,7 +129,7 @@ enum {
#endif
INFO_WIFI = 19,
INFO_DISKIO = 20,
INFO_I8K = 21
INFO_I8K = 21,
};
@ -153,8 +153,8 @@ struct information {
unsigned int procs;
unsigned int run_procs;
float cpu_usage;
struct cpu_stat cpu_summed;
float *cpu_usage;
/* struct cpu_stat cpu_summed; what the hell is this? */
unsigned int cpu_count;
unsigned int cpu_avg_samples;

View File

@ -320,23 +320,25 @@ void update_total_processes()
update_sysinfo();
}
static unsigned int cpu_user, cpu_system, cpu_nice;
static double last_cpu_sum;
static int clock_ticks;
struct cpu_info {
unsigned int cpu_user;
unsigned int cpu_system;
unsigned int cpu_nice;
double last_cpu_sum;
int clock_ticks;
double cpu_val[15];
};
static short cpu_setup = 0;
static int rep;
static FILE *stat_fp;
inline static void update_stat()
void get_cpu_count()
{
// FIXME: arbitrary size?
static double cpu_val[15];
static int rep;
char buf[256];
unsigned int i;
double curtmp;
if (stat_fp == NULL)
stat_fp = open_file("/proc/stat", &rep);
stat_fp = open_file("/tmp/testcpu", &rep);
else
fseek(stat_fp, 0, SEEK_SET);
if (stat_fp == NULL)
@ -348,37 +350,71 @@ inline static void update_stat()
if (fgets(buf, 255, stat_fp) == NULL)
break;
if (strncmp(buf, "procs_running ", 14) == 0) {
sscanf(buf, "%*s %d", &info.run_procs);
info.mask |= (1 << INFO_RUN_PROCS);
} else if (strncmp(buf, "cpu ", 4) == 0) {
sscanf(buf, "%*s %u %u %u", &cpu_user, &cpu_nice,
&cpu_system);
info.mask |= (1 << INFO_CPU);
} else if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
info.cpu_count++;
}
}
info.cpu_usage = malloc(info.cpu_count * sizeof(float));
printf("cpu count is %i\n", info.cpu_count);
}
inline static void update_stat()
{
// FIXME: arbitrary size?
static struct cpu_info *cpu = NULL;
char buf[256];
unsigned int i;
unsigned int index;
double curtmp;
if (!cpu_setup) {
get_cpu_count();
cpu_setup = 1;
}
if (cpu == NULL) {
cpu = malloc(info.cpu_count * sizeof(struct cpu_info));
}
if (stat_fp == NULL)
stat_fp = open_file("/tmp/testcpu", &rep);
else
fseek(stat_fp, 0, SEEK_SET);
if (stat_fp == NULL)
return;
index = 0;
while (!feof(stat_fp) && index < info.cpu_count) {
if (fgets(buf, 255, stat_fp) == NULL)
break;
if (strncmp(buf, "procs_running ", 14) == 0) {
sscanf(buf, "%*s %d", &info.run_procs);
info.mask |= (1 << INFO_RUN_PROCS);
} else if (strncmp(buf, "cpu", 3) == 0 && isdigit(buf[3])) {
sscanf(buf, "%*s %u %u %u", &(cpu[index].cpu_user), &(cpu[index].cpu_nice),
&(cpu[index].cpu_system));
index++;
info.mask |= (1 << INFO_CPU);
}
}
for (index = 0; index < info.cpu_count; index++) {
double delta;
delta = current_update_time - last_update_time;
if (delta <= 0.001)
return;
if (clock_ticks == 0)
clock_ticks = sysconf(_SC_CLK_TCK);
if (cpu[index].clock_ticks == 0)
cpu[index].clock_ticks = sysconf(_SC_CLK_TCK);
curtmp = 0;
cpu_val[0] =
(cpu_user + cpu_nice + cpu_system -
last_cpu_sum) / delta / (double) clock_ticks /
info.cpu_count;
cpu[index].cpu_val[0] =
(cpu[index].cpu_user + cpu[index].cpu_nice + cpu[index].cpu_system -
cpu[index].last_cpu_sum) / delta / (double) cpu[index].clock_ticks;
for (i = 0; i < info.cpu_avg_samples; i++)
curtmp += cpu_val[i];
info.cpu_usage = curtmp / info.cpu_avg_samples;
last_cpu_sum = cpu_user + cpu_nice + cpu_system;
curtmp += cpu[index].cpu_val[i];
printf("setting usage to %f\n", curtmp / info.cpu_avg_samples);
info.cpu_usage[index] = curtmp / info.cpu_avg_samples;
cpu[index].last_cpu_sum = cpu[index].cpu_user + cpu[index].cpu_nice + cpu[index].cpu_system;
for (i = info.cpu_avg_samples; i > 1; i--)
cpu_val[i - 1] = cpu_val[i - 2];
cpu[index].cpu_val[i - 1] = cpu[index].cpu_val[i - 2];
}