diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-30 14:47:41 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-30 14:47:41 +0000 |
commit | 98ebab8b768d4651d8db2f46a0cd6bd53012c8e6 (patch) | |
tree | 2f491e67f1f49a31b0cfeeaabb032b646b8d808c /procps/top.c | |
parent | 8b1409896d3224fec477bc372c4dceaebe6d6351 (diff) | |
download | busybox-w32-98ebab8b768d4651d8db2f46a0cd6bd53012c8e6.tar.gz busybox-w32-98ebab8b768d4651d8db2f46a0cd6bd53012c8e6.tar.bz2 busybox-w32-98ebab8b768d4651d8db2f46a0cd6bd53012c8e6.zip |
top,ps: improve /proc/PID/cmdinfo reading code
function old new delta
display_status - 1231 +1231
read_cmdline - 101 +101
parse_conf 1284 1303 +19
arith 2033 2042 +9
collect_blk 467 474 +7
fsck_main 1909 1911 +2
dhcprelay_main 1125 1122 -3
singlemount 4555 4547 -8
read_close 50 36 -14
get_lcm 123 105 -18
ed_main 3111 3084 -27
func_args 73 28 -45
procps_scan 732 658 -74
top_main 2187 899 -1288
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/8 up/down: 1369/-1477) Total: -108 bytes
text data bss dec hex filename
676048 2744 13968 692760 a9218 busybox_old
675940 2744 13968 692652 a91ac busybox_unstripped
Diffstat (limited to 'procps/top.c')
-rw-r--r-- | procps/top.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/procps/top.c b/procps/top.c index 136f1404a..a37a0d07f 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -40,11 +40,10 @@ typedef struct top_status_t { | |||
40 | unsigned pid, ppid; | 40 | unsigned pid, ppid; |
41 | unsigned uid; | 41 | unsigned uid; |
42 | char state[4]; | 42 | char state[4]; |
43 | /* TODO: read /proc/$PID/cmdline only for processes which are displayed */ | 43 | char comm[COMM_LEN]; |
44 | char cmd[64]; | ||
45 | } top_status_t; | 44 | } top_status_t; |
46 | 45 | ||
47 | typedef struct jiffy_counts_t{ | 46 | typedef struct jiffy_counts_t { |
48 | unsigned long long usr,nic,sys,idle,iowait,irq,softirq,steal; | 47 | unsigned long long usr,nic,sys,idle,iowait,irq,softirq,steal; |
49 | unsigned long long total; | 48 | unsigned long long total; |
50 | unsigned long long busy; | 49 | unsigned long long busy; |
@@ -421,7 +420,7 @@ static void display_status(int count, int scr_width) | |||
421 | 420 | ||
422 | /* Ok, all prelim data is ready, go thru the list */ | 421 | /* Ok, all prelim data is ready, go thru the list */ |
423 | while (count-- > 0) { | 422 | while (count-- > 0) { |
424 | int col = scr_width+1; | 423 | int col = scr_width; |
425 | CALC_STAT(pmem, (s->vsz*pmem_scale + pmem_half) >> pmem_shift); | 424 | CALC_STAT(pmem, (s->vsz*pmem_scale + pmem_half) >> pmem_shift); |
426 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE | 425 | #if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE |
427 | CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift); | 426 | CALC_STAT(pcpu, (s->pcpu*pcpu_scale + pcpu_half) >> pcpu_shift); |
@@ -444,8 +443,11 @@ static void display_status(int count, int scr_width) | |||
444 | , SHOW_STAT(pcpu) | 443 | , SHOW_STAT(pcpu) |
445 | #endif | 444 | #endif |
446 | ); | 445 | ); |
447 | if (col > 0) | 446 | if (col > 0) { |
448 | printf("%.*s", col, s->cmd); | 447 | char buf[col + 1]; |
448 | read_cmdline(buf, col, s->pid, s->comm); | ||
449 | fputs(buf, stdout); | ||
450 | } | ||
449 | /* printf(" %d/%d %lld/%lld", s->pcpu, total_pcpu, | 451 | /* printf(" %d/%d %lld/%lld", s->pcpu, total_pcpu, |
450 | jif.busy - prev_jif.busy, jif.total - prev_jif.total); */ | 452 | jif.busy - prev_jif.busy, jif.total - prev_jif.total); */ |
451 | s++; | 453 | s++; |
@@ -560,12 +562,11 @@ int top_main(int argc, char **argv) | |||
560 | | PSSCAN_UTIME | 562 | | PSSCAN_UTIME |
561 | | PSSCAN_STATE | 563 | | PSSCAN_STATE |
562 | | PSSCAN_COMM | 564 | | PSSCAN_COMM |
563 | | PSSCAN_CMD | ||
564 | | PSSCAN_SID | 565 | | PSSCAN_SID |
565 | | PSSCAN_UIDGID | 566 | | PSSCAN_UIDGID |
566 | ))) { | 567 | ))) { |
567 | int n = ntop; | 568 | int n = ntop; |
568 | top = xrealloc(top, (++ntop)*sizeof(top_status_t)); | 569 | top = xrealloc(top, (++ntop) * sizeof(*top)); |
569 | top[n].pid = p->pid; | 570 | top[n].pid = p->pid; |
570 | top[n].ppid = p->ppid; | 571 | top[n].ppid = p->ppid; |
571 | top[n].vsz = p->vsz; | 572 | top[n].vsz = p->vsz; |
@@ -574,10 +575,7 @@ int top_main(int argc, char **argv) | |||
574 | #endif | 575 | #endif |
575 | top[n].uid = p->uid; | 576 | top[n].uid = p->uid; |
576 | strcpy(top[n].state, p->state); | 577 | strcpy(top[n].state, p->state); |
577 | if (p->cmd) | 578 | strcpy(top[n].comm, p->comm); |
578 | safe_strncpy(top[n].cmd, p->cmd, sizeof(top[n].cmd)); | ||
579 | else /* mimic ps */ | ||
580 | sprintf(top[n].cmd, "[%s]", p->comm); | ||
581 | } | 579 | } |
582 | if (ntop == 0) { | 580 | if (ntop == 0) { |
583 | bb_error_msg_and_die("no process info in /proc"); | 581 | bb_error_msg_and_die("no process info in /proc"); |