aboutsummaryrefslogtreecommitdiff
path: root/libbb
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 /libbb
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.
Diffstat (limited to 'libbb')
-rw-r--r--libbb/procps.c24
1 files changed, 6 insertions, 18 deletions
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);