int num_cpus;
#endif
char line_buf[80];
-};
-
+}; //FIX_ALIASING; - large code growth
enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
-
#define G (*(struct globals*)&bb_common_bufsiz1)
#define INIT_G() do { \
struct G_sizecheck { \
/* xxx_shift and xxx_scale variables allow us to replace
* expensive divides with multiply and shift */
unsigned pmem_shift, pmem_scale, pmem_half;
- unsigned tmp_unsigned;
#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
+ unsigned tmp_unsigned;
unsigned pcpu_shift, pcpu_scale, pcpu_half;
unsigned busy_jifs;
#endif
/* what info of the processes is shown */
printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width,
" PID PPID USER STAT VSZ %MEM"
-#if ENABLE_FEATURE_TOP_SMP_PROCESS
- " CPU"
-#endif
-#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
- " %CPU"
-#endif
+ IF_FEATURE_TOP_SMP_PROCESS(" CPU")
+ IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU")
" COMMAND");
lines_rem--;
/* PID PPID USER STAT VSZ %MEM [%CPU] COMMAND */
col = snprintf(line_buf, scr_width,
"\n" "%5u%6u %-8.8s %s%s" FMT
-#if ENABLE_FEATURE_TOP_SMP_PROCESS
- " %3d"
-#endif
-#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
- FMT
-#endif
+ IF_FEATURE_TOP_SMP_PROCESS(" %3d")
+ IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT)
" ",
s->pid, s->ppid, get_cached_username(s->uid),
s->state, vsz_str_buf,
SHOW_STAT(pmem)
-#if ENABLE_FEATURE_TOP_SMP_PROCESS
- , s->last_seen_on_cpu
-#endif
-#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
- , SHOW_STAT(pcpu)
-#endif
+ IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu)
+ IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(, SHOW_STAT(pcpu))
);
if ((int)(col + 1) < scr_width)
read_cmdline(line_buf + col, scr_width - col, s->pid, s->comm);
}
/* printf(" %d", hist_iterations); */
bb_putchar(OPT_BATCH_MODE ? '\n' : '\r');
- fflush(stdout);
+ fflush_all();
}
#undef UPSCALE
#undef SHOW_STAT
return inverted ? -n : n;
}
-/* Cut "NNNN " out of " NNNN kb" */
+/* Cut "NNNN" out of " NNNN kb" */
static char *grab_number(char *str, const char *match, unsigned sz)
{
if (strncmp(str, match, sz) == 0) {
str = skip_whitespace(str + sz);
- (skip_non_whitespace(str))[1] = '\0';
+ (skip_non_whitespace(str))[0] = '\0';
return xstrdup(str);
}
return NULL;
}
fclose(fp);
-#define S(s) (s ? s : "0 ")
+#define S(s) (s ? s : "0")
snprintf(linebuf, sizeof(linebuf),
- "Mem %stotal %sanon %smap %sfree",
+ "Mem total:%s anon:%s map:%s free:%s",
S(total), S(anon), S(map), S(mfree));
printf(OPT_BATCH_MODE ? "%.*s\n" : "\e[H\e[J%.*s\n", scr_width, linebuf);
snprintf(linebuf, sizeof(linebuf),
- " %sslab %sbuf %scache %sdirty %swrite",
+ " slab:%s buf:%s cache:%s dirty:%s write:%s",
S(slab), S(buf), S(cache), S(dirty), S(mwrite));
printf("%.*s\n", scr_width, linebuf);
snprintf(linebuf, sizeof(linebuf),
- "Swap %stotal %sfree", // TODO: % used?
+ "Swap total:%s free:%s", // TODO: % used?
S(swaptotal), S(swapfree));
printf("%.*s\n", scr_width, linebuf);
s++;
}
bb_putchar(OPT_BATCH_MODE ? '\n' : '\r');
- fflush(stdout);
+ fflush_all();
#undef HDR_STR
#undef MIN_WIDTH
}