Line 0
Link Here
|
|
|
1 |
--- wmtop.c.orig Wed Mar 7 05:30:56 2001 |
2 |
+++ wmtop.c Fri Feb 25 22:34:36 2005 |
3 |
@@ -70,6 +70,13 @@ |
4 |
#include "xpm/wmtop-neon2.xpm" |
5 |
#include "xpm/wmtop-rainbow.xpm" |
6 |
|
7 |
+#ifdef NO_PROCFS |
8 |
+#include <kvm.h> |
9 |
+#include <sys/sysctl.h> |
10 |
+#include <sys/user.h> |
11 |
+#include <sys/resource.h> |
12 |
+#endif |
13 |
+ |
14 |
/******************************************/ |
15 |
/* Defines */ |
16 |
/******************************************/ |
17 |
@@ -191,6 +198,9 @@ |
18 |
int rss; |
19 |
int time_stamp; |
20 |
int counted; |
21 |
+#ifdef NO_PROCFS |
22 |
+ struct kinfo_proc *kp; |
23 |
+#endif |
24 |
}; |
25 |
|
26 |
/******************************************/ |
27 |
@@ -455,17 +465,19 @@ |
28 |
* Anyone hoping to port wmtop should look here first. |
29 |
*/ |
30 |
int process_parse_procfs(struct process *process) { |
31 |
+#if !defined(NO_PROCFS) |
32 |
char line[WMTOP_BUFLENGTH],filename[WMTOP_BUFLENGTH],procname[WMTOP_BUFLENGTH]; |
33 |
int ps; |
34 |
struct stat sbuf; |
35 |
- int user_time,kernel_time; |
36 |
int rc; |
37 |
+#endif |
38 |
+ int user_time,kernel_time; |
39 |
#if defined(LINUX) |
40 |
char *r,*q; |
41 |
char deparenthesised_name[WMTOP_BUFLENGTH]; |
42 |
int endl; |
43 |
#endif /* defined(LINUX) */ |
44 |
-#if defined(FREEBSD) |
45 |
+#if defined(FREEBSD) && !defined(NO_PROCFS) |
46 |
int us,um,ks,km; |
47 |
#endif /* defined(FREEBSD) */ |
48 |
|
49 |
@@ -473,6 +485,15 @@ |
50 |
assert(process->id==0x0badfeed); |
51 |
#endif /* defined(PARANOID) */ |
52 |
|
53 |
+#if defined(NO_PROCFS) |
54 |
+#define GETV(u) ((u).tv_sec * 1000 + (u).tv_usec / 1000) |
55 |
+ process->time_stamp = g_time; |
56 |
+ if(process->name) |
57 |
+ wmtop_free(process->name); |
58 |
+ process->name = wmtop_strdup(process->kp->ki_comm); |
59 |
+ process->user_time = GETV(process->kp->ki_rusage.ru_utime); |
60 |
+ process->kernel_time = GETV(process->kp->ki_rusage.ru_stime); |
61 |
+#else |
62 |
sprintf(filename,PROCFS_TEMPLATE,process->pid); |
63 |
|
64 |
/* |
65 |
@@ -582,6 +603,7 @@ |
66 |
process->user_time = us*1000+um/1000; |
67 |
process->kernel_time = ks*1000+km/1000; |
68 |
#endif /* defined(FREEBSD) */ |
69 |
+#endif /* defined(NO_PROCFS) */ |
70 |
|
71 |
process->rss *= getpagesize(); |
72 |
|
73 |
@@ -607,6 +629,39 @@ |
74 |
/******************************************/ |
75 |
|
76 |
int update_process_table() { |
77 |
+#if defined(NO_PROCFS) |
78 |
+ kvm_t *kd; |
79 |
+ int n; |
80 |
+ struct kinfo_proc *p; |
81 |
+ |
82 |
+ if((kd = kvm_open(NULL, "/dev/null", NULL, O_RDONLY, "wmtop")) == NULL) |
83 |
+ return 1; |
84 |
+ |
85 |
+ if((p = kvm_getprocs(kd, KERN_PROC_ALL, 0, &n)) == NULL) |
86 |
+ return 1; |
87 |
+ |
88 |
+ for(; n > 0; n --, p ++) |
89 |
+ { |
90 |
+ char **argv; |
91 |
+ struct process *pp; |
92 |
+ |
93 |
+ if((argv = kvm_getargv(kd, p, 0)) == NULL || |
94 |
+ argv[0] == NULL) |
95 |
+ continue; |
96 |
+ |
97 |
+ pp = find_process(p->ki_pid); |
98 |
+ if(!pp) |
99 |
+ pp = new_process(p->ki_pid); |
100 |
+ |
101 |
+ pp->kp = p; |
102 |
+ calculate_cpu(pp); |
103 |
+ } |
104 |
+ |
105 |
+ if(kvm_close(kd) != 0) |
106 |
+ return 1; |
107 |
+ |
108 |
+ return 0; |
109 |
+#else |
110 |
DIR *dir; |
111 |
struct dirent *entry; |
112 |
|
113 |
@@ -640,6 +695,7 @@ |
114 |
closedir(dir); |
115 |
|
116 |
return 0; |
117 |
+#endif /* defined(NO_PROCFS) */ |
118 |
} |
119 |
|
120 |
/******************************************/ |