diff options
author | Emanuel Haupt <ehaupt@FreeBSD.org> | 2008-02-27 10:12:56 +0000 |
---|---|---|
committer | Emanuel Haupt <ehaupt@FreeBSD.org> | 2008-02-27 10:12:56 +0000 |
commit | 35f2cdab6f2741c5f5f29c912f5fd2f86b99014a (patch) | |
tree | 9cf4c236efbd33dde5bcb170e29ace1e71f815a4 /sysutils/wmbluecpu | |
parent | 5127ab5e03cfa525e7daf616c42d496289a2b82e (diff) | |
download | ports-35f2cdab6f2741c5f5f29c912f5fd2f86b99014a.tar.gz ports-35f2cdab6f2741c5f5f29c912f5fd2f86b99014a.zip |
Notes
Diffstat (limited to 'sysutils/wmbluecpu')
-rw-r--r-- | sysutils/wmbluecpu/Makefile | 4 | ||||
-rw-r--r-- | sysutils/wmbluecpu/files/cpu_freebsd.c | 36 |
2 files changed, 22 insertions, 18 deletions
diff --git a/sysutils/wmbluecpu/Makefile b/sysutils/wmbluecpu/Makefile index 46a1ac3463b9..386634bdb03d 100644 --- a/sysutils/wmbluecpu/Makefile +++ b/sysutils/wmbluecpu/Makefile @@ -7,12 +7,12 @@ PORTNAME= wmbluecpu PORTVERSION= 0.4 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= sysutils windowmaker MASTER_SITES= ${MASTER_SITE_SUNSITE} MASTER_SITE_SUBDIR= X11/xutils -MAINTAINER= ports@FreeBSD.org +MAINTAINER= benjsc@FreeBSD.org COMMENT= A CPU monitoring dockapp USE_BZIP2= yes diff --git a/sysutils/wmbluecpu/files/cpu_freebsd.c b/sysutils/wmbluecpu/files/cpu_freebsd.c index 36440aea422a..62fb2a8fc7b7 100644 --- a/sysutils/wmbluecpu/files/cpu_freebsd.c +++ b/sysutils/wmbluecpu/files/cpu_freebsd.c @@ -35,23 +35,17 @@ #include <unistd.h> static kvm_t *kd; -static struct nlist nlst[] = { {"_cp_time"}, {0} }; +static int cp_time_mib[2]; +static struct nlist nlst[] = { + {"_cp_time"}, {0}}; void cpu_init(void) { - if (!(kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open"))) - { - perror("kvm_open"); - exit(1); - } - - kvm_nlist(kd, nlst); - - if (!nlst[0].n_type) - { - perror("kvm_nlist"); - exit(1); + size_t len = 2; + sysctlnametomib("kern.cp_time", cp_time_mib, &len); + if((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) != NULL ){ + kvm_nlist(kd, nlst); } seteuid(getuid()); @@ -73,13 +67,23 @@ int history[17]; void cpu_getusage() { long cpu, nice, system, idle, used, total; - long cpu_time[CPUSTATES]; + long cpu_time[CPUSTATES], cpu_time_len=sizeof(cpu_time); + int error; - if (kvm_read(kd, nlst[0].n_value, &cpu_time, sizeof(cpu_time)) + if( cp_time_mib[0] != 0 ){ + error = sysctl(cp_time_mib, 2, cpu_time, &cpu_time_len, NULL, 0 ); + if ( error ){ + perror("sysctl, cpu_time_mib"); + exit(1); + } + } + else { + if (kvm_read(kd, nlst[0].n_value, &cpu_time, sizeof(cpu_time)) != sizeof(cpu_time)) - { + { perror("kvm_read"); exit(1); + } } cpu = cpu_time[CP_USER]; |