diff options
author | 2022-06-02 09:29:04 -0400 | |
---|---|---|
committer | 2022-06-02 09:29:04 -0400 | |
commit | 4f592ed011d0678c459b166c854b9e9247cd1b26 (patch) | |
tree | 09a880063fe5dcb79617f84ff34b41db70a5e4c2 /src | |
parent | Merge pull request #5170 from kmk3/ids-add-sh-paths (diff) | |
download | firejail-4f592ed011d0678c459b166c854b9e9247cd1b26.tar.gz firejail-4f592ed011d0678c459b166c854b9e9247cd1b26.tar.zst firejail-4f592ed011d0678c459b166c854b9e9247cd1b26.zip |
speed up firemon
Diffstat (limited to 'src')
-rw-r--r-- | src/firemon/netstats.c | 2 | ||||
-rw-r--r-- | src/firemon/top.c | 2 | ||||
-rw-r--r-- | src/lib/pid.c | 6 |
3 files changed, 6 insertions, 4 deletions
diff --git a/src/firemon/netstats.c b/src/firemon/netstats.c index 7d86ca45e..31abd5471 100644 --- a/src/firemon/netstats.c +++ b/src/firemon/netstats.c | |||
@@ -205,7 +205,7 @@ void netstats(void) { | |||
205 | while (1) { | 205 | while (1) { |
206 | // set pid table | 206 | // set pid table |
207 | int i; | 207 | int i; |
208 | int itv = 1; // 1 second interval | 208 | int itv = 3; // 3 second interval |
209 | pid_read(0); | 209 | pid_read(0); |
210 | 210 | ||
211 | // start rx/tx measurements | 211 | // start rx/tx measurements |
diff --git a/src/firemon/top.c b/src/firemon/top.c index 0633370ac..3e7323ded 100644 --- a/src/firemon/top.c +++ b/src/firemon/top.c | |||
@@ -267,7 +267,7 @@ void top(void) { | |||
267 | 267 | ||
268 | // set pid table | 268 | // set pid table |
269 | int i; | 269 | int i; |
270 | int itv = 1; // 1 second interval | 270 | int itv = 3; // 3 second interval |
271 | pid_read(0); | 271 | pid_read(0); |
272 | 272 | ||
273 | // start cpu measurements | 273 | // start cpu measurements |
diff --git a/src/lib/pid.c b/src/lib/pid.c index 3cf0df909..2cc72bce0 100644 --- a/src/lib/pid.c +++ b/src/lib/pid.c | |||
@@ -303,6 +303,7 @@ void pid_store_cpu(unsigned index, unsigned parent, unsigned *utime, unsigned *s | |||
303 | 303 | ||
304 | // mon_pid: pid of sandbox to be monitored, 0 if all sandboxes are included | 304 | // mon_pid: pid of sandbox to be monitored, 0 if all sandboxes are included |
305 | void pid_read(pid_t mon_pid) { | 305 | void pid_read(pid_t mon_pid) { |
306 | unsigned old_max_pids = max_pids; | ||
306 | FILE *fp = fopen("/proc/sys/kernel/pid_max", "r"); | 307 | FILE *fp = fopen("/proc/sys/kernel/pid_max", "r"); |
307 | if (fp) { | 308 | if (fp) { |
308 | int val; | 309 | int val; |
@@ -314,12 +315,13 @@ void pid_read(pid_t mon_pid) { | |||
314 | } | 315 | } |
315 | 316 | ||
316 | if (pids == NULL) { | 317 | if (pids == NULL) { |
318 | old_max_pids = max_pids; | ||
317 | pids = malloc(sizeof(Process) * max_pids); | 319 | pids = malloc(sizeof(Process) * max_pids); |
318 | if (pids == NULL) | 320 | if (pids == NULL) |
319 | errExit("malloc"); | 321 | errExit("malloc"); |
320 | } | 322 | } |
321 | 323 | ||
322 | memset(pids, 0, sizeof(Process) * max_pids); | 324 | memset(pids, 0, sizeof(Process) * old_max_pids); |
323 | pid_t mypid = getpid(); | 325 | pid_t mypid = getpid(); |
324 | 326 | ||
325 | DIR *dir; | 327 | DIR *dir; |
@@ -424,7 +426,7 @@ void pid_read(pid_t mon_pid) { | |||
424 | closedir(dir); | 426 | closedir(dir); |
425 | 427 | ||
426 | // update max_pid | 428 | // update max_pid |
427 | max_pids = new_max_pids; | 429 | max_pids = new_max_pids + 1; |
428 | 430 | ||
429 | pid_t pid; | 431 | pid_t pid; |
430 | for (pid = 0; pid < max_pids; pid++) { | 432 | for (pid = 0; pid < max_pids; pid++) { |