aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/top/machine.h1
-rw-r--r--contrib/top/top.X5
-rw-r--r--contrib/top/top.c8
-rw-r--r--usr.bin/top/machine.c19
4 files changed, 13 insertions, 20 deletions
diff --git a/contrib/top/machine.h b/contrib/top/machine.h
index 4584650c8ee4..a09424c19ca2 100644
--- a/contrib/top/machine.h
+++ b/contrib/top/machine.h
@@ -44,7 +44,6 @@ struct system_info
int *memory;
int *swap;
struct timeval boottime;
- unsigned long cpumask; /* bitfield of cpu states represented */
int ncpus;
};
diff --git a/contrib/top/top.X b/contrib/top/top.X
index e78df07a5e64..31d317af9a5e 100644
--- a/contrib/top/top.X
+++ b/contrib/top/top.X
@@ -10,7 +10,7 @@ top \- display and update information about the top cpu processes
.SH SYNOPSIS
.B top
[
-.B \-bCHIijnqStuv
+.B \-bCHIijnPqStuv
] [
.BI \-d count
] [
@@ -113,6 +113,9 @@ Display either 'cpu' or 'io' statistics. Default is 'cpu'.
Use \*(lqnon-interactive\*(rq mode. This is identical to \*(lqbatch\*(rq
mode.
.TP
+.B \-P
+Display per-cpu CPU usage statistics.
+.TP
.B \-q
Renice
.I top
diff --git a/contrib/top/top.c b/contrib/top/top.c
index 52d8517f2b49..3bf58e16763f 100644
--- a/contrib/top/top.c
+++ b/contrib/top/top.c
@@ -283,7 +283,7 @@ char *argv[];
optind = 1;
}
- while ((i = getopt(ac, av, "CSIHPbijnpquvs:d:U:m:o:t")) != EOF)
+ while ((i = getopt(ac, av, "CSIHPbijnquvs:d:U:m:o:t")) != EOF)
{
switch(i)
{
@@ -408,14 +408,10 @@ char *argv[];
pcpu_stats = Yes;
break;
- case 'p':
- pcpu_stats = No;
- break;
-
default:
fprintf(stderr,
"Top version %s\n"
-"Usage: %s [-bCHIijnqStuv] [-d count] [-m io | cpu] [-o field] [-s time]\n"
+"Usage: %s [-bCHIijnPqStuv] [-d count] [-m io | cpu] [-o field] [-s time]\n"
" [-U username] [number]\n",
version_string(), myname);
exit(1);
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index d5db8b771be3..9dc6fcf2ae8a 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -305,6 +305,7 @@ machine_init(struct statics *statics)
err(1, "malloc %zd bytes", size);
if (sysctlbyname("kern.cp_times", times, &size, NULL, 0) == -1)
err(1, "sysctlbyname kern.cp_times");
+ pcpu_cp_time = calloc(1, size);
maxid = (size / CPUSTATES / sizeof(long)) - 1;
for (i = 0; i <= maxid; i++) {
empty = 1;
@@ -328,14 +329,9 @@ machine_init(struct statics *statics)
Header_lines += ncpus - 1; /* 7 */
}
size = sizeof(long) * ncpus * CPUSTATES;
- pcpu_cp_time = malloc(size);
- pcpu_cp_old = malloc(size);
- pcpu_cp_diff = malloc(size);
- pcpu_cpu_states = malloc(size);
- bzero(pcpu_cp_time, size);
- bzero(pcpu_cp_old, size);
- bzero(pcpu_cp_diff, size);
- bzero(pcpu_cpu_states, size);
+ pcpu_cp_old = calloc(1, size);
+ pcpu_cp_diff = calloc(1, size);
+ pcpu_cpu_states = calloc(1, size);
statics->ncpus = ncpus;
} else {
statics->ncpus = 1;
@@ -410,14 +406,15 @@ get_system_info(struct system_info *si)
si->load_avg[i] = (double)sysload.ldavg[i] / sysload.fscale;
if (pcpu_stats) {
- for (i = j = 0; i <= maxid; i++, j++) {
- if (cpumask && (1ul << i) == 0)
+ for (i = j = 0; i <= maxid; i++) {
+ if ((cpumask & (1ul << i)) == 0)
continue;
/* convert cp_time counts to percentages */
percentages(CPUSTATES, &pcpu_cpu_states[j * CPUSTATES],
&pcpu_cp_time[j * CPUSTATES],
&pcpu_cp_old[j * CPUSTATES],
&pcpu_cp_diff[j * CPUSTATES]);
+ j++;
}
} else {
/* convert cp_time counts to percentages */
@@ -478,11 +475,9 @@ get_system_info(struct system_info *si)
/* set arrays and strings */
if (pcpu_stats) {
si->cpustates = pcpu_cpu_states;
- si->cpumask = cpumask;
si->ncpus = ncpus;
} else {
si->cpustates = cpu_states;
- si->cpumask = 1;
si->ncpus = 1;
}
si->memory = memory_stats;