aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-19 14:43:17 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-19 14:43:17 +0000
commit31789a81d5751acaaf373e8ede2932208161f869 (patch)
tree8b3fe7e25ca247fc8d4e44102cef8b23a92f0354
parent362c6ec6941c774992abcf008459616dbce0e7af (diff)
downloadbusybox-w32-31789a81d5751acaaf373e8ede2932208161f869.tar.gz
busybox-w32-31789a81d5751acaaf373e8ede2932208161f869.tar.bz2
busybox-w32-31789a81d5751acaaf373e8ede2932208161f869.zip
top,ps: 'stringify' tty only when needed. -60 bytes.
-rw-r--r--include/libbb.h5
-rw-r--r--libbb/procps.c24
-rw-r--r--procps/ps.c5
3 files changed, 12 insertions, 22 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 999caae0c..9ca565348 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -847,10 +847,9 @@ typedef struct {
847 unsigned sid; 847 unsigned sid;
848 unsigned uid; 848 unsigned uid;
849 unsigned gid; 849 unsigned gid;
850 unsigned tty_major,tty_minor;
850 char state[4]; 851 char state[4];
851 char tty_str[8]; /* "maj,min" or "?" */ 852 /* basename of executable in exec(2), read from /proc/N/stat */
852 /* basename of executable in exec(2), read from /proc/N/stat, */
853 /* size from sizeof(task_struct.comm) in /usr/include/linux/sched.h */
854 char comm[COMM_LEN]; 853 char comm[COMM_LEN];
855 /* user/group? - use passwd/group parsing functions */ 854 /* user/group? - use passwd/group parsing functions */
856} procps_status_t; 855} procps_status_t;
diff --git a/libbb/procps.c b/libbb/procps.c
index e04ff34ff..10ddabf94 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -225,30 +225,18 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags)
225 break; 225 break;
226 sp->vsz = vsz >> 10; /* vsize is in bytes and we want kb */ 226 sp->vsz = vsz >> 10; /* vsize is in bytes and we want kb */
227 sp->rss = rss >> 10; 227 sp->rss = rss >> 10;
228 228 sp->tty_major = (tty >> 8) & 0xfff;
229 sp->tty_str[0] = '?'; 229 sp->tty_minor = (tty & 0xff) | ((tty >> 12) & 0xfff00));
230 /* sp->tty_str[1] = '\0'; - done by memset */
231 if (tty) /* tty field of "0" means "no tty" */
232 snprintf(sp->tty_str, sizeof(sp->tty_str), "%u,%u",
233 (tty >> 8) & 0xfff, /* major */
234 (tty & 0xff) | ((tty >> 12) & 0xfff00));
235#else 230#else
236/* This costs ~100 bytes more but makes top faster by 20% 231/* This costs ~100 bytes more but makes top faster by 20%
237 * If you run 10000 processes, this may be important for you */ 232 * If you run 10000 processes, this may be important for you */
238 cp += 2; 233 sp->state[0] = cp[2];
239 sp->state[0] = *cp++; cp++; 234 sp->ppid = fast_strtoul_10(cp + 4, &cp);
240 sp->ppid = fast_strtoul_10(cp, &cp);
241 sp->pgid = fast_strtoul_10(cp, &cp); 235 sp->pgid = fast_strtoul_10(cp, &cp);
242 sp->sid = fast_strtoul_10(cp, &cp); 236 sp->sid = fast_strtoul_10(cp, &cp);
243 sp->tty_str[0] = '?';
244 /* sp->tty_str[1] = '\0'; - done by memset */
245 tty = fast_strtoul_10(cp, &cp); 237 tty = fast_strtoul_10(cp, &cp);
246 if (tty && (flags & PSSCAN_TTY)) { 238 sp->tty_major = (tty >> 8) & 0xfff;
247 /* tty field of "0" means "no tty" */ 239 sp->tty_minor = (tty & 0xff) | ((tty >> 12) & 0xfff00);
248 snprintf(sp->tty_str, sizeof(sp->tty_str), "%u,%u",
249 (tty >> 8) & 0xfff, /* major */
250 (tty & 0xff) | ((tty >> 12) & 0xfff00));
251 }
252 cp = skip_fields(cp, 6); /* tpgid, flags, min_flt, cmin_flt, maj_flt, cmaj_flt */ 240 cp = skip_fields(cp, 6); /* tpgid, flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
253 sp->utime = fast_strtoul_10(cp, &cp); 241 sp->utime = fast_strtoul_10(cp, &cp);
254 sp->stime = fast_strtoul_10(cp, &cp); 242 sp->stime = fast_strtoul_10(cp, &cp);
diff --git a/procps/ps.c b/procps/ps.c
index c3023cf5e..fd53eca5b 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -68,7 +68,10 @@ static void func_rss(char *buf, int size, const procps_status_t *ps)
68 68
69static void func_tty(char *buf, int size, const procps_status_t *ps) 69static void func_tty(char *buf, int size, const procps_status_t *ps)
70{ 70{
71 safe_strncpy(buf, ps->tty_str, size+1); 71 buf[0] = '?';
72 buf[1] = '\0';
73 if (ps->tty_major) /* tty field of "0" means "no tty" */
74 snprintf(buf, size+1, "%u,%u", ps->tty_major, ps->tty_minor);
72} 75}
73 76
74#if ENABLE_SELINUX 77#if ENABLE_SELINUX