FreeBSD Bugzilla – Attachment 102752 Details for
Bug 142577
sysutils/conky does not display information for each core CPU is more than one
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 3.99 KB, created by
Ivan Klymenko
on 2010-01-10 17:00:16 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
Ivan Klymenko
Created:
2010-01-10 17:00:16 UTC
Size:
3.99 KB
patch
obsolete
>diff -u freebsd.c.orig freebsd.c >--- freebsd.c.orig 2010-01-09 21:49:10.000000000 +0200 >+++ freebsd.c 2010-01-10 10:21:22.000000000 +0200 >@@ -289,22 +289,22 @@ > }; > > struct cpu_load_struct fresh = { {0, 0, 0, 0, 0} }; >-long cpu_used, oldtotal, oldused; >+long cpu_used;//, oldtotal, oldused; >+extern long * g_oldtotal, * g_oldused; > > void get_cpu_count(void) > { >- /* int cpu_count = 0; */ >+ int cpu_count = 0; >+ size_t cpu_count_len = sizeof(cpu_count); > >- /* XXX: FreeBSD doesn't allow to get per CPU load stats on SMP machines. >- * It's possible to get a CPU count, but as we fulfill only >- * info.cpu_usage[0], it's better to report there's only one CPU. >- * It should fix some bugs (e.g. cpugraph) */ >-#if 0 >- if (GETSYSCTL("hw.ncpu", cpu_count) == 0) { >- info.cpu_count = cpu_count; >+ if (sysctlbyname("hw.ncpu", &cpu_count, &cpu_count_len, NULL, 0) < 0) { >+ fprintf(stderr, "Cannot get hw.ncpu"); >+ info.cpu_count = 1; >+ } >+ else >+ { >+ info.cpu_count = cpu_count; > } >-#endif >- info.cpu_count = 1; > > info.cpu_usage = malloc(info.cpu_count * sizeof(float)); > if (info.cpu_usage == NULL) { >@@ -315,9 +315,11 @@ > /* XXX: SMP support */ > void update_cpu_usage(void) > { >- long used, total; >- long cp_time[CPUSTATES]; >- size_t cp_len = sizeof(cp_time); >+ int i, j = 0; >+ long *used, *total; >+ static long *cp_time_per_cpu; >+ size_t cp_len = info.cpu_count * CPUSTATES * sizeof(long); >+ size_t len = info.cpu_count * sizeof(long); > > /* add check for !info.cpu_usage since that mem is freed on a SIGUSR1 */ > if ((cpu_setup == 0) || (!info.cpu_usage)) { >@@ -325,28 +327,41 @@ > cpu_setup = 1; > } > >- if (sysctlbyname("kern.cp_time", &cp_time, &cp_len, NULL, 0) < 0) { >- fprintf(stderr, "Cannot get kern.cp_time"); >- } >- >- fresh.load[0] = cp_time[CP_USER]; >- fresh.load[1] = cp_time[CP_NICE]; >- fresh.load[2] = cp_time[CP_SYS]; >- fresh.load[3] = cp_time[CP_IDLE]; >- fresh.load[4] = cp_time[CP_IDLE]; >- >- used = fresh.load[0] + fresh.load[1] + fresh.load[2]; >- total = fresh.load[0] + fresh.load[1] + fresh.load[2] + fresh.load[3]; >- >- if ((total - oldtotal) != 0) { >- info.cpu_usage[0] = ((double) (used - oldused)) / >- (double) (total - oldtotal); >- } else { >- info.cpu_usage[0] = 0; >- } >- >- oldused = used; >- oldtotal = total; >+ cp_time_per_cpu = malloc(cp_len); >+ used = malloc(len); >+ total = malloc(len); >+ >+ if (sysctlbyname("kern.cp_times", cp_time_per_cpu, &cp_len, NULL, 0) < 0) { >+ fprintf(stderr, "Cannot get kern.cp_times"); >+ } >+ >+ for (i=0; i<info.cpu_count; i++) >+ { >+ fresh.load[0] = cp_time_per_cpu[CP_USER+j]; >+ fresh.load[1] = cp_time_per_cpu[CP_NICE+j]; >+ fresh.load[2] = cp_time_per_cpu[CP_SYS+j]; >+ fresh.load[3] = cp_time_per_cpu[CP_IDLE+j]; >+ fresh.load[4] = cp_time_per_cpu[CP_IDLE+j]; >+ >+ j+=CPUSTATES; >+ >+ used[i] = fresh.load[0] + fresh.load[1] + fresh.load[2]; >+ total[i] = fresh.load[0] + fresh.load[1] + fresh.load[2] + fresh.load[3]; >+ >+ if ((total[i] - g_oldtotal[i]) != 0) { >+ info.cpu_usage[i] = ((double) (used[i] - g_oldused[i])) / >+ (double) (total[i] - g_oldtotal[i]); >+ } else { >+ info.cpu_usage[i] = 0; >+ } >+ >+ g_oldused[i] = used[i]; >+ g_oldtotal[i] = total[i]; >+ } >+ >+ free(cp_time_per_cpu); >+ free(used); >+ free(total); > } > > void update_load_average(void) >diff -u conky.c.orig conky.c >--- conky.c.orig2010-01-10 00:49:54.000000000 +0200 >+++ conky.c2010-01-10 01:04:44.000000000 +0200 >@@ -151,6 +151,10 @@ > double update_interval; > void *global_cpu = NULL; > >+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) >+long *g_oldused, *g_oldtotal; >+#endif >+ > int argc_copy; > char** argv_copy; > >@@ -3485,6 +3489,10 @@ > > obj = construct_text_object(buf, arg, > line, &ifblock_opaque, orig_p); >+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) >+g_oldused = malloc((size_t)info.cpu_count * sizeof(long)); >+ g_oldtotal = malloc((size_t)info.cpu_count * sizeof(long)); >+#endif > if (obj != NULL) { > append_object(retval, obj); > } >@@ -9386,6 +9394,9 @@ > main_loop(); > > #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) >+free(g_oldused); >+free(g_oldtotal); >+ > kvm_close(kd); > #endif
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 142577
: 102752