diff options
Diffstat (limited to 'src/firemon')
-rw-r--r-- | src/firemon/netstats.c | 18 | ||||
-rw-r--r-- | src/firemon/procevent.c | 31 | ||||
-rw-r--r-- | src/firemon/top.c | 34 |
3 files changed, 59 insertions, 24 deletions
diff --git a/src/firemon/netstats.c b/src/firemon/netstats.c index 7d86ca45e..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 | ||
@@ -205,7 +201,7 @@ void netstats(void) { | |||
205 | while (1) { | 201 | while (1) { |
206 | // set pid table | 202 | // set pid table |
207 | int i; | 203 | int i; |
208 | int itv = 1; // 1 second interval | 204 | int itv = 3; // 3 second interval |
209 | pid_read(0); | 205 | pid_read(0); |
210 | 206 | ||
211 | // start rx/tx measurements | 207 | // start rx/tx measurements |
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 0633370ac..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; |
@@ -267,7 +295,7 @@ void top(void) { | |||
267 | 295 | ||
268 | // set pid table | 296 | // set pid table |
269 | int i; | 297 | int i; |
270 | int itv = 1; // 1 second interval | 298 | int itv = 3; // 3 second interval |
271 | pid_read(0); | 299 | pid_read(0); |
272 | 300 | ||
273 | // start cpu measurements | 301 | // start cpu measurements |