*
* This is written specifically for the linux /proc/<PID>/stat(m)
* files format.
-
+ *
* This reads the PIDs of all processes and their status and shows
* the status of processes (first ones that fit to screen) at given
* intervals.
* - CPU where Process was last seen running
* (to see effect of sched_setaffinity() etc)
* - CPU Time Split (idle/IO/wait etc) PER CPU
- */
-
-/* Original code Copyrights */
-/*
+ *
* Copyright (c) 1992 Branko Lankester
* Copyright (c) 1992 Roger Binns
* Copyright (C) 1994-1996 Charles L. Blake.
* Copyright (C) 1992-1998 Michael K. Johnson
- * May be distributed under the conditions of the
- * GNU Library General Public License
+ *
+ * Licensed under GPLv2, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
} top_status_t;
typedef struct jiffy_counts_t {
- unsigned long long usr,nic,sys,idle,iowait,irq,softirq,steal;
+ /* Linux 2.4.x has only first four */
+ unsigned long long usr, nic, sys, idle;
+ unsigned long long iowait, irq, softirq, steal;
unsigned long long total;
unsigned long long busy;
} jiffy_counts_t;
return 0;
}
-/* NOINLINE so that complier doesn't unfold the call
- * causing multiple copies of the arithmatic instrns
- */
static NOINLINE int read_cpu_jiffy(FILE *fp, jiffy_counts_t *p_jif)
{
#if !ENABLE_FEATURE_TOP_SMP_CPU
- static const char fmt[] = "cpu %lld %lld %lld %lld %lld %lld %lld %lld";
+ static const char fmt[] = "cpu %llu %llu %llu %llu %llu %llu %llu %llu";
#else
- static const char fmt[] = "cp%*s %lld %lld %lld %lld %lld %lld %lld %lld";
+ static const char fmt[] = "cp%*s %llu %llu %llu %llu %llu %llu %llu %llu";
#endif
int ret;
&p_jif->usr, &p_jif->nic, &p_jif->sys, &p_jif->idle,
&p_jif->iowait, &p_jif->irq, &p_jif->softirq,
&p_jif->steal);
- if (ret > 4) {
+ if (ret >= 4) {
p_jif->total = p_jif->usr + p_jif->nic + p_jif->sys + p_jif->idle
+ p_jif->iowait + p_jif->irq + p_jif->softirq + p_jif->steal;
/* procps 2.x does not count iowait as busy time */
| PSSCAN_UTIME
| PSSCAN_STATE
| PSSCAN_COMM
-#if ENABLE_FEATURE_TOP_SMP_PROCESS
| PSSCAN_CPU
-#endif
| PSSCAN_UIDGID,
TOPMEM_MASK = 0
| PSSCAN_PID
int lines_rem;
unsigned interval;
char *str_interval, *str_iterations;
- SKIP_FEATURE_TOPMEM(const) unsigned scan_mask = TOP_MASK;
+ IF_NOT_FEATURE_TOPMEM(const) unsigned scan_mask = TOP_MASK;
#if ENABLE_FEATURE_USE_TERMIOS
struct termios new_settings;
struct pollfd pfd[1];
if (c == 'q')
break;
if (c == 'n') {
- USE_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
+ IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
sort_function[0] = pid_sort;
}
if (c == 'm') {
- USE_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
+ IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
sort_function[0] = mem_sort;
#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
sort_function[1] = pcpu_sort;
}
#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
if (c == 'p') {
- USE_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
+ IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
sort_function[0] = pcpu_sort;
sort_function[1] = mem_sort;
sort_function[2] = time_sort;
}
if (c == 't') {
- USE_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
+ IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
sort_function[0] = time_sort;
sort_function[1] = mem_sort;
sort_function[2] = pcpu_sort;