Date: Mon, 27 Oct 2008 18:00:39 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-releng@freebsd.org Subject: svn commit: r184363 - in releng/6.4: contrib/top usr.bin/top Message-ID: <200810271800.m9RI0d1h047805@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Mon Oct 27 18:00:39 2008 New Revision: 184363 URL: http://svn.freebsd.org/changeset/base/184363 Log: MFC: Several top '-P' fixes originally from ru@. This fixes top -P on i386. Approved by: re (kensmith) Modified: releng/6.4/contrib/top/machine.h releng/6.4/contrib/top/top.X releng/6.4/contrib/top/top.c releng/6.4/usr.bin/top/machine.c Modified: releng/6.4/contrib/top/machine.h ============================================================================== --- releng/6.4/contrib/top/machine.h Mon Oct 27 17:57:03 2008 (r184362) +++ releng/6.4/contrib/top/machine.h Mon Oct 27 18:00:39 2008 (r184363) @@ -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: releng/6.4/contrib/top/top.X ============================================================================== --- releng/6.4/contrib/top/top.X Mon Oct 27 17:57:03 2008 (r184362) +++ releng/6.4/contrib/top/top.X Mon Oct 27 18:00:39 2008 (r184363) @@ -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: releng/6.4/contrib/top/top.c ============================================================================== --- releng/6.4/contrib/top/top.c Mon Oct 27 17:57:03 2008 (r184362) +++ releng/6.4/contrib/top/top.c Mon Oct 27 18:00:39 2008 (r184363) @@ -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: releng/6.4/usr.bin/top/machine.c ============================================================================== --- releng/6.4/usr.bin/top/machine.c Mon Oct 27 17:57:03 2008 (r184362) +++ releng/6.4/usr.bin/top/machine.c Mon Oct 27 18:00:39 2008 (r184363) @@ -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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200810271800.m9RI0d1h047805>