From owner-svn-src-head@FreeBSD.ORG Fri Oct 24 04:01:15 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 31DB7302; Fri, 24 Oct 2014 04:01:15 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1277BEC3; Fri, 24 Oct 2014 04:01:15 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9O41Eie059946; Fri, 24 Oct 2014 04:01:14 GMT (envelope-from mckusick@FreeBSD.org) Received: (from mckusick@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9O41EBE059945; Fri, 24 Oct 2014 04:01:14 GMT (envelope-from mckusick@FreeBSD.org) Message-Id: <201410240401.s9O41EBE059945@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mckusick set sender to mckusick@FreeBSD.org using -f From: Kirk McKusick Date: Fri, 24 Oct 2014 04:01:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273575 - head/usr.bin/vmstat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Oct 2014 04:01:15 -0000 Author: mckusick Date: Fri Oct 24 04:01:14 2014 New Revision: 273575 URL: https://svnweb.freebsd.org/changeset/base/273575 Log: Fix formatting of vmstat (1) so that it looks cleaner on standard 80 column displays. In particular it wraps far less often. Submitted by: Andy Kosela PR: 191976 Modified: head/usr.bin/vmstat/vmstat.c Modified: head/usr.bin/vmstat/vmstat.c ============================================================================== --- head/usr.bin/vmstat/vmstat.c Fri Oct 24 03:53:49 2014 (r273574) +++ head/usr.bin/vmstat/vmstat.c Fri Oct 24 04:01:14 2014 (r273575) @@ -767,22 +767,26 @@ dovmstat(unsigned int interval, int reps fill_vmmeter(&sum); fill_vmtotal(&total); - (void)printf("%2d %1d %1d", + (void)printf("%1d %1d %1d", total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw); #define vmstat_pgtok(a) ((a) * (sum.v_page_size >> 10)) #define rate(x) (((x) * rate_adj + halfuptime) / uptime) /* round */ if (hflag) { + printf(""); + prthuman(total.t_avm * (u_int64_t)sum.v_page_size, 5); printf(" "); - prthuman(total.t_avm * (u_int64_t)sum.v_page_size, 7); - printf(" "); - prthuman(total.t_free * (u_int64_t)sum.v_page_size, 6); + prthuman(total.t_free * (u_int64_t)sum.v_page_size, 5); printf(" "); + (void)printf("%5lu ", + (unsigned long)rate(sum.v_vm_faults - + osum.v_vm_faults)); } else { - printf(" %7d ", vmstat_pgtok(total.t_avm)); - printf(" %6d ", vmstat_pgtok(total.t_free)); + printf(" %7d", vmstat_pgtok(total.t_avm)); + printf(" %7d ", vmstat_pgtok(total.t_free)); + (void)printf("%4lu ", + (unsigned long)rate(sum.v_vm_faults - + osum.v_vm_faults)); } - (void)printf("%5lu ", - (unsigned long)rate(sum.v_vm_faults - osum.v_vm_faults)); (void)printf("%3lu ", (unsigned long)rate(sum.v_reactivated - osum.v_reactivated)); (void)printf("%3lu ", @@ -793,10 +797,10 @@ dovmstat(unsigned int interval, int reps (osum.v_swapout + osum.v_vnodeout))); (void)printf("%5lu ", (unsigned long)rate(sum.v_tfree - osum.v_tfree)); - (void)printf("%3lu ", + (void)printf("%4lu ", (unsigned long)rate(sum.v_pdpages - osum.v_pdpages)); devstats(); - (void)printf("%4lu %4lu %4lu", + (void)printf("%4lu %5lu %5lu", (unsigned long)rate(sum.v_intr - osum.v_intr), (unsigned long)rate(sum.v_syscall - osum.v_syscall), (unsigned long)rate(sum.v_swtch - osum.v_swtch)); @@ -824,35 +828,43 @@ dovmstat(unsigned int interval, int reps } static void -printhdr(int maxid, u_long cpumask) +printhdr(int ncpus, u_long cpumask) { int i, num_shown; num_shown = (num_selected < maxshowdevs) ? num_selected : maxshowdevs; - (void)printf(" procs memory page%*s", 19, ""); + if (hflag) { + (void)printf("procs memory page%*s ", 19, ""); + } else { + (void)printf("procs memory page%*s ", 19, ""); + } if (num_shown > 1) - (void)printf(" disks %*s", num_shown * 4 - 7, ""); + (void)printf(" disks %*s", num_shown * 4 - 7, ""); else if (num_shown == 1) - (void)printf("disk"); - (void)printf(" faults "); + (void)printf(" disk"); + (void)printf(" faults "); if (Pflag) { - for (i = 0; i <= maxid; i++) { + for (i = 0; i < ncpus; i++) { if (cpumask & (1ul << i)) - printf("cpu%-2d ", i); + printf(" cpu%d ", i); } printf("\n"); } else - printf("cpu\n"); - (void)printf(" r b w avm fre flt re pi po fr sr "); + printf(" cpu\n"); + if (hflag) { + (void)printf("r b w avm fre flt re pi po fr sr "); + } else { + (void)printf("r b w avm fre flt re pi po fr sr "); + } for (i = 0; i < num_devices; i++) if ((dev_select[i].selected) && (dev_select[i].selected <= maxshowdevs)) (void)printf("%c%c%d ", dev_select[i].device_name[0], dev_select[i].device_name[1], dev_select[i].unit_number); - (void)printf(" in sy cs"); + (void)printf(" in sy cs"); if (Pflag) { - for (i = 0; i <= maxid; i++) { + for (i = 0; i < ncpus; i++) { if (cpumask & (1ul << i)) printf(" us sy id"); } @@ -982,7 +994,8 @@ dosum(void) (void)printf("%9u intransit blocking page faults\n", sum.v_intrans); (void)printf("%9u total VM faults taken\n", sum.v_vm_faults); (void)printf("%9u page faults requiring I/O\n", sum.v_io_faults); - (void)printf("%9u pages affected by kernel thread creation\n", sum.v_kthreadpages); + (void)printf("%9u pages affected by kernel thread creation\n", + sum.v_kthreadpages); (void)printf("%9u pages affected by fork()\n", sum.v_forkpages); (void)printf("%9u pages affected by vfork()\n", sum.v_vforkpages); (void)printf("%9u pages affected by rfork()\n", sum.v_rforkpages); @@ -1124,7 +1137,8 @@ pcpustats(int ncpus, u_long cpumask, int continue; for (state = 0; state < CPUSTATES; ++state) { tmp = cur_cp_times[i * CPUSTATES + state]; - cur_cp_times[i * CPUSTATES + state] -= last_cp_times[i * CPUSTATES + state]; + cur_cp_times[i * CPUSTATES + state] -= last_cp_times[i * + CPUSTATES + state]; last_cp_times[i * CPUSTATES + state] = tmp; } }