diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/firemon/netstats.c | 16 | ||||
-rw-r--r-- | src/firemon/procevent.c | 31 | ||||
-rw-r--r-- | src/firemon/top.c | 32 | ||||
-rw-r--r-- | src/include/pid.h | 26 | ||||
-rw-r--r-- | src/lib/pid.c | 28 |
5 files changed, 74 insertions, 59 deletions
diff --git a/src/firemon/netstats.c b/src/firemon/netstats.c index 31abd5471..156efe67d 100644 --- a/src/firemon/netstats.c +++ b/src/firemon/netstats.c | |||
@@ -106,10 +106,8 @@ void get_stats(int parent) { | |||
106 | } | 106 | } |
107 | 107 | ||
108 | // store data | 108 | // store data |
109 | pids[parent].rx_delta = rx - pids[parent].rx; | 109 | pids[parent].option.netstats.rx = rx - pids[parent].option.netstats.rx; |
110 | pids[parent].rx = rx; | 110 | pids[parent].option.netstats.tx = tx - pids[parent].option.netstats.tx; |
111 | pids[parent].tx_delta = tx - pids[parent].tx; | ||
112 | pids[parent].tx = tx; | ||
113 | 111 | ||
114 | 112 | ||
115 | free(fname); | 113 | free(fname); |
@@ -117,10 +115,8 @@ void get_stats(int parent) { | |||
117 | return; | 115 | return; |
118 | 116 | ||
119 | errexit: | 117 | errexit: |
120 | pids[parent].rx = 0; | 118 | pids[parent].option.netstats.rx = 0; |
121 | pids[parent].tx = 0; | 119 | pids[parent].option.netstats.tx = 0; |
122 | pids[parent].rx_delta = 0; | ||
123 | pids[parent].tx_delta = 0; | ||
124 | } | 120 | } |
125 | 121 | ||
126 | 122 | ||
@@ -174,11 +170,11 @@ static void print_proc(int index, int itv, int col) { | |||
174 | ptruser = ""; | 170 | ptruser = ""; |
175 | 171 | ||
176 | 172 | ||
177 | float rx_kbps = ((float) pids[index].rx_delta / 1000) / itv; | 173 | float rx_kbps = ((float) pids[index].option.netstats.rx / 1000) / itv; |
178 | char ptrrx[15]; | 174 | char ptrrx[15]; |
179 | sprintf(ptrrx, "%.03f", rx_kbps); | 175 | sprintf(ptrrx, "%.03f", rx_kbps); |
180 | 176 | ||
181 | float tx_kbps = ((float) pids[index].tx_delta / 1000) / itv; | 177 | float tx_kbps = ((float) pids[index].option.netstats.tx / 1000) / itv; |
182 | char ptrtx[15]; | 178 | char ptrtx[15]; |
183 | sprintf(ptrtx, "%.03f", tx_kbps); | 179 | sprintf(ptrtx, "%.03f", tx_kbps); |
184 | 180 | ||
diff --git a/src/firemon/procevent.c b/src/firemon/procevent.c index ccc1ba1c6..4edbaab07 100644 --- a/src/firemon/procevent.c +++ b/src/firemon/procevent.c | |||
@@ -417,18 +417,18 @@ static void __attribute__((noreturn)) procevent_monitor(const int sock, pid_t my | |||
417 | sprintf(lineptr, " %u", pid); | 417 | sprintf(lineptr, " %u", pid); |
418 | lineptr += strlen(lineptr); | 418 | lineptr += strlen(lineptr); |
419 | 419 | ||
420 | char *user = pids[pid].user; | 420 | char *user = pids[pid].option.event.user; |
421 | if (!user) | 421 | if (!user) |
422 | user = pid_get_user_name(pids[pid].uid); | 422 | user = pid_get_user_name(pids[pid].uid); |
423 | if (user) { | 423 | if (user) { |
424 | pids[pid].user = user; | 424 | pids[pid].option.event.user = user; |
425 | sprintf(lineptr, " (%s)", user); | 425 | sprintf(lineptr, " (%s)", user); |
426 | lineptr += strlen(lineptr); | 426 | lineptr += strlen(lineptr); |
427 | } | 427 | } |
428 | 428 | ||
429 | 429 | ||
430 | int sandbox_closed = 0; // exit sandbox flag | 430 | int sandbox_closed = 0; // exit sandbox flag |
431 | char *cmd = pids[pid].cmd; | 431 | char *cmd = pids[pid].option.event.cmd; |
432 | if (!cmd) { | 432 | if (!cmd) { |
433 | cmd = pid_proc_cmdline(pid); | 433 | cmd = pid_proc_cmdline(pid); |
434 | } | 434 | } |
@@ -465,10 +465,10 @@ static void __attribute__((noreturn)) procevent_monitor(const int sock, pid_t my | |||
465 | 465 | ||
466 | // unflag pid for exit events | 466 | // unflag pid for exit events |
467 | if (remove_pid) { | 467 | if (remove_pid) { |
468 | if (pids[pid].user) | 468 | if (pids[pid].option.event.user) |
469 | free(pids[pid].user); | 469 | free(pids[pid].option.event.user); |
470 | if (pids[pid].cmd) | 470 | if (pids[pid].option.event.cmd) |
471 | free(pids[pid].cmd); | 471 | free(pids[pid].option.event.cmd); |
472 | memset(&pids[pid], 0, sizeof(Process)); | 472 | memset(&pids[pid], 0, sizeof(Process)); |
473 | } | 473 | } |
474 | 474 | ||
@@ -485,9 +485,9 @@ static void __attribute__((noreturn)) procevent_monitor(const int sock, pid_t my | |||
485 | 485 | ||
486 | // on uid events the uid is changing | 486 | // on uid events the uid is changing |
487 | if (proc_ev->what == PROC_EVENT_UID) { | 487 | if (proc_ev->what == PROC_EVENT_UID) { |
488 | if (pids[pid].user) | 488 | if (pids[pid].option.event.user) |
489 | free(pids[pid].user); | 489 | free(pids[pid].option.event.user); |
490 | pids[pid].user = 0; | 490 | pids[pid].option.event.user = 0; |
491 | pids[pid].uid = pid_get_uid(pid); | 491 | pids[pid].uid = pid_get_uid(pid); |
492 | } | 492 | } |
493 | 493 | ||
@@ -505,6 +505,17 @@ void procevent(pid_t pid) { | |||
505 | exit(1); | 505 | exit(1); |
506 | } | 506 | } |
507 | 507 | ||
508 | // set max_pids to the max value allowed by the kernel | ||
509 | FILE *fp = fopen("/proc/sys/kernel/pid_max", "r"); | ||
510 | if (fp) { | ||
511 | int val; | ||
512 | if (fscanf(fp, "%d", &val) == 1) { | ||
513 | if (val >= max_pids) | ||
514 | max_pids = val + 1; | ||
515 | } | ||
516 | fclose(fp); | ||
517 | } | ||
518 | |||
508 | // monitor using netlink | 519 | // monitor using netlink |
509 | int sock = procevent_netlink_setup(); | 520 | int sock = procevent_netlink_setup(); |
510 | if (sock < 0) { | 521 | if (sock < 0) { |
diff --git a/src/firemon/top.c b/src/firemon/top.c index 3e7323ded..56f171f5b 100644 --- a/src/firemon/top.c +++ b/src/firemon/top.c | |||
@@ -154,8 +154,8 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne | |||
154 | 154 | ||
155 | // cpu | 155 | // cpu |
156 | itv *= clocktick; | 156 | itv *= clocktick; |
157 | float ud = (float) (*utime - pids[index].utime) / itv * 100; | 157 | float ud = (float) (*utime - pids[index].option.top.utime) / itv * 100; |
158 | float sd = (float) (*stime - pids[index].stime) / itv * 100; | 158 | float sd = (float) (*stime - pids[index].option.top.stime) / itv * 100; |
159 | float cd = ud + sd; | 159 | float cd = ud + sd; |
160 | *cpu = cd; | 160 | *cpu = cd; |
161 | char cpu_str[10]; | 161 | char cpu_str[10]; |
@@ -179,6 +179,34 @@ static char *print_top(unsigned index, unsigned parent, unsigned *utime, unsigne | |||
179 | return rv; | 179 | return rv; |
180 | } | 180 | } |
181 | 181 | ||
182 | // recursivity!!! | ||
183 | void pid_store_cpu(unsigned index, unsigned parent, unsigned *utime, unsigned *stime) { | ||
184 | if (pids[index].level == 1) { | ||
185 | *utime = 0; | ||
186 | *stime = 0; | ||
187 | } | ||
188 | |||
189 | // Remove unused parameter warning | ||
190 | (void)parent; | ||
191 | |||
192 | unsigned utmp = 0; | ||
193 | unsigned stmp = 0; | ||
194 | pid_get_cpu_time(index, &utmp, &stmp); | ||
195 | *utime += utmp; | ||
196 | *stime += stmp; | ||
197 | |||
198 | unsigned i; | ||
199 | for (i = index + 1; i < (unsigned)max_pids; i++) { | ||
200 | if (pids[i].parent == (pid_t)index) | ||
201 | pid_store_cpu(i, index, utime, stime); | ||
202 | } | ||
203 | |||
204 | if (pids[index].level == 1) { | ||
205 | pids[index].option.top.utime = *utime; | ||
206 | pids[index].option.top.stime = *stime; | ||
207 | } | ||
208 | } | ||
209 | |||
182 | 210 | ||
183 | typedef struct node_t { | 211 | typedef struct node_t { |
184 | struct node_t *next; | 212 | struct node_t *next; |
diff --git a/src/include/pid.h b/src/include/pid.h index 7e235b713..d2f912b2a 100644 --- a/src/include/pid.h +++ b/src/include/pid.h | |||
@@ -31,14 +31,23 @@ typedef struct { | |||
31 | unsigned char zombie; | 31 | unsigned char zombie; |
32 | pid_t parent; | 32 | pid_t parent; |
33 | uid_t uid; | 33 | uid_t uid; |
34 | char *user; | 34 | |
35 | char *cmd; | 35 | union { |
36 | unsigned utime; | 36 | struct event_t { |
37 | unsigned stime; | 37 | char *user; |
38 | unsigned long long rx; // network rx, bytes | 38 | char *cmd; |
39 | unsigned long long tx; // networking tx, bytes | 39 | } event; |
40 | unsigned rx_delta; | 40 | |
41 | unsigned tx_delta; | 41 | struct top_t { |
42 | unsigned utime; | ||
43 | unsigned stime; | ||
44 | } top; | ||
45 | |||
46 | struct netstats_t { | ||
47 | unsigned long long rx; // network rx, bytes | ||
48 | unsigned long long tx; // networking tx, bytes | ||
49 | } netstats; | ||
50 | } option; | ||
42 | } Process; | 51 | } Process; |
43 | //extern Process pids[max_pids]; | 52 | //extern Process pids[max_pids]; |
44 | extern Process *pids; | 53 | extern Process *pids; |
@@ -52,7 +61,6 @@ char *pid_get_user_name(uid_t uid); | |||
52 | // print functions | 61 | // print functions |
53 | void pid_print_tree(unsigned index, unsigned parent, int nowrap); | 62 | void pid_print_tree(unsigned index, unsigned parent, int nowrap); |
54 | void pid_print_list(unsigned index, int nowrap); | 63 | void pid_print_list(unsigned index, int nowrap); |
55 | void pid_store_cpu(unsigned index, unsigned parent, unsigned *utime, unsigned *stime); | ||
56 | void pid_read(pid_t mon_pid); | 64 | void pid_read(pid_t mon_pid); |
57 | 65 | ||
58 | #endif | 66 | #endif |
diff --git a/src/lib/pid.c b/src/lib/pid.c index 2cc72bce0..8b2a9b0f5 100644 --- a/src/lib/pid.c +++ b/src/lib/pid.c | |||
@@ -273,34 +273,6 @@ void pid_print_list(unsigned index, int nowrap) { | |||
273 | print_elem(index, nowrap); | 273 | print_elem(index, nowrap); |
274 | } | 274 | } |
275 | 275 | ||
276 | // recursivity!!! | ||
277 | void pid_store_cpu(unsigned index, unsigned parent, unsigned *utime, unsigned *stime) { | ||
278 | if (pids[index].level == 1) { | ||
279 | *utime = 0; | ||
280 | *stime = 0; | ||
281 | } | ||
282 | |||
283 | // Remove unused parameter warning | ||
284 | (void)parent; | ||
285 | |||
286 | unsigned utmp = 0; | ||
287 | unsigned stmp = 0; | ||
288 | pid_get_cpu_time(index, &utmp, &stmp); | ||
289 | *utime += utmp; | ||
290 | *stime += stmp; | ||
291 | |||
292 | unsigned i; | ||
293 | for (i = index + 1; i < (unsigned)max_pids; i++) { | ||
294 | if (pids[i].parent == (pid_t)index) | ||
295 | pid_store_cpu(i, index, utime, stime); | ||
296 | } | ||
297 | |||
298 | if (pids[index].level == 1) { | ||
299 | pids[index].utime = *utime; | ||
300 | pids[index].stime = *stime; | ||
301 | } | ||
302 | } | ||
303 | |||
304 | // mon_pid: pid of sandbox to be monitored, 0 if all sandboxes are included | 276 | // mon_pid: pid of sandbox to be monitored, 0 if all sandboxes are included |
305 | void pid_read(pid_t mon_pid) { | 277 | void pid_read(pid_t mon_pid) { |
306 | unsigned old_max_pids = max_pids; | 278 | unsigned old_max_pids = max_pids; |