svn commit: r183852 - in stable/6: contrib/top usr.bin/top

John Baldwin jhb at FreeBSD.org
Mon Oct 13 21:35:11 UTC 2008


Author: jhb
Date: Mon Oct 13 21:35:10 2008
New Revision: 183852
URL: http://svn.freebsd.org/changeset/base/183852

Log:
  MFC: Several top '-P' fixes originally from ru at .  This fixes top -P
  on i386.
  
  Approved by:	re (kib)

Modified:
  stable/6/contrib/top/machine.h
  stable/6/contrib/top/top.X
  stable/6/contrib/top/top.c
  stable/6/usr.bin/top/machine.c

Modified: stable/6/contrib/top/machine.h
==============================================================================
--- stable/6/contrib/top/machine.h	Mon Oct 13 21:20:50 2008	(r183851)
+++ stable/6/contrib/top/machine.h	Mon Oct 13 21:35:10 2008	(r183852)
@@ -44,7 +44,6 @@ struct system_info
     int    *memory;
     int    *swap;
     struct timeval boottime;
-    unsigned long cpumask;	/* bitfield of cpu states represented */
     int    ncpus;
 };
 

Modified: stable/6/contrib/top/top.X
==============================================================================
--- stable/6/contrib/top/top.X	Mon Oct 13 21:20:50 2008	(r183851)
+++ stable/6/contrib/top/top.X	Mon Oct 13 21:35:10 2008	(r183852)
@@ -10,7 +10,7 @@ top \- display and update information ab
 .SH SYNOPSIS
 .B top
 [
-.B \-bCHIijnqStuv
+.B \-bCHIijnPqStuv
 ] [
 .BI \-d count
 ] [
@@ -113,6 +113,9 @@ Display either 'cpu' or 'io' statistics.
 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

Modified: stable/6/contrib/top/top.c
==============================================================================
--- stable/6/contrib/top/top.c	Mon Oct 13 21:20:50 2008	(r183851)
+++ stable/6/contrib/top/top.c	Mon Oct 13 21:35:10 2008	(r183852)
@@ -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);

Modified: stable/6/usr.bin/top/machine.c
==============================================================================
--- stable/6/usr.bin/top/machine.c	Mon Oct 13 21:20:50 2008	(r183851)
+++ stable/6/usr.bin/top/machine.c	Mon Oct 13 21:35:10 2008	(r183852)
@@ -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;


More information about the svn-src-all mailing list