ports/151838: Update sysutils/pcpustat to version 1.4

Sterling Camden sterling at camdensoftware.com
Sat Oct 30 21:00:19 UTC 2010


>Number:         151838
>Category:       ports
>Synopsis:       Update sysutils/pcpustat to version 1.4
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          maintainer-update
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 30 21:00:18 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Sterling Camden
>Release:        FreeBSD 8.1-STABLE amd64
>Organization:
Camden Software Consulting
>Environment:
System: FreeBSD libertas.local.camdensoftware.com 8.1-STABLE FreeBSD 8.1-STABLE #85: Fri Oct 29 10:27:19 PDT 2010 sterling at libertas.local.camdensoftware.com:/usr/obj/usr/src/sys/LIBERTAS amd64


>Description:
	Update pcpustat utility to versionm 1.4, which includes a -d (--delimiter) option.
>How-To-Repeat:
	N/A - new feature
>Fix:
	Patches follow:
diff -u port/Makefile 1.4/Makefile
--- port/Makefile	2010-10-29 05:10:35.000000000 -0700
+++ 1.4/Makefile	2010-10-30 13:41:18.000000000 -0700
@@ -1,12 +1,12 @@
 # New ports collection makefile for:   pcpustat
-# Date created:        13 July 2010
+# Date created:        30 October 2010
 # Whom:                sterling
 #
 # $FreeBSD: ports/sysutils/pcpustat/Makefile,v 1.4 2010/10/29 12:10:35 pav Exp $
 #
 
 PORTNAME=	pcpustat
-PORTVERSION=	1.3
+PORTVERSION=	1.4
 CATEGORIES=	sysutils
 MASTER_SITES=	http://chipstips.com/download/
 
diff -u port/distinfo 1.4/distinfo
--- port/distinfo	2010-09-15 05:15:08.000000000 -0700
+++ 1.4/distinfo	2010-10-30 13:45:38.000000000 -0700
@@ -1,3 +1,2 @@
-MD5 (pcpustat-1.3.tar.bz2) = 040f1d0436e95b181ab08f69683e80b7
-SHA256 (pcpustat-1.3.tar.bz2) = 878a9e38f41ba434288f99e0d6a2c0321ed2fa34401113b42fe961b3ad3fa490
-SIZE (pcpustat-1.3.tar.bz2) = 4038
+SHA256 (pcpustat-1.4.tar.bz2) = 001fcafd28b50b9a0867aab5e7d89b65ccd05197f5a644538e901a7a0d8b2db1
+SIZE (pcpustat-1.4.tar.bz2) = 4947

diff -ur port/work/pcpustat-1.3/man/man1/pcpustat.1 1.4/work/pcpustat-1.4/man/man1/pcpustat.1
--- port/work/pcpustat-1.3/man/man1/pcpustat.1	2010-09-02 13:43:01.000000000 -0700
+++ 1.4/work/pcpustat-1.4/man/man1/pcpustat.1	2010-10-30 13:40:13.000000000 -0700
@@ -1,5 +1,5 @@
 .\" man page for the pcpustat utility.
-.Dd July 12, 2010
+.Dd September 26, 2010
 .Dt PCPUSTAT 1
 .Os
 .Sh NAME
@@ -9,6 +9,7 @@
 .Nm
 .Op Fl ahinqstux
 .Op Fl c Ar count
+.Op Fl d Ar delimiter
 .Op Fl p Ar cpu
 .Op Fl w Ar wait
 .Sh DESCRIPTION
@@ -19,6 +20,8 @@
 Include all usage statistics (same as -instu).  This is the default if no specific statistics are selected.
 .It Fl c, count Ar count
 Sample statistics the specified number of times.  If not specified, it defaults to 1 if -w is not specified, otherwise forever.
+.It Fl d, delim Ar delimiter
+Delimit columns with delimiter instead of justifying them with spaces.
 .It Fl h, help
 Print the list of options and exit.
 .It Fl i, idle
@@ -39,9 +42,47 @@
 Pause the specified number of seconds between updates.  The default is 1.
 .It Fl x, not
 Report the percentage of time not in each state.  If specified, each percentage is subtracted from 100.  The header (unless the -q option is selected) displays a "!" before each heading.
+.Sh OUTPUT FORMAT
+If the 
+.Op Fl q
+option is not specified, the first two lines of output will contain a header.
+.Pp
+The first line lists the CPUs, by number.  If the options
+specify only one column of information per CPU, then this line will only contain the CPU numbers (starting with 0), otherwise it will contain
+the string "cpu " followed by the number.  This heading will be right-justified over the columns that apply to that CPU, unless the
+.Op Fl d
+option is specified (in which case the headers are also delimited).
+.Pp
+The second header line labels the columns within the output for each CPU.  These labels can be any of the following:
+.Pp
+.Bl -tag -width indent -compact
+.It \&us
+% of cpu time in user mode
+.It \&ni
+% of cpu time in user mode running niced processes
+.It \&sy
+% of cpu time in system mode
+.It \&in
+% of cpu time in interrupt mode
+.It \&id
+% of cpu time in idle mode
+.El
+.Pp
+If the
+.Op Fl x
+option was specified, then each of the above is prefixed by '!'.
+.Pp
+The remaining lines of output will be the percentage of time each CPU spent in each of the designated states since the previous line (or since pcpustat started, in the case of the first line).
+.Pp
+If the
+.Op Fl d
+option is specified, then the string specified as its argument will occur between each column.  Otherwise, enough spaces will be used to
+right-align each column under its heading.
 .Sh SEE ALSO
 top(1), iostat(8), sysctl(3), sysctl(8)
 .Sh AUTHOR
-Sterling (Chip) Camden <sterling at camdensoftware.com>, http://chipstips.com/?tag=c_pcpustat
+Sterling (Chip) Camden <sterling at camdensoftware.com>
+.Sh SITE
+http://chipstips.com/?tag=c_pcpustat
 .Sh BUGS
 The pcpustat utility can only report on CPUs 0-n, where n is one less than the number of bits in a long.
diff -ur port/work/pcpustat-1.3/pcpustat.c 1.4/work/pcpustat-1.4/pcpustat.c
--- port/work/pcpustat-1.3/pcpustat.c	2010-09-02 13:43:01.000000000 -0700
+++ 1.4/work/pcpustat-1.4/pcpustat.c	2010-10-30 13:39:50.000000000 -0700
@@ -12,7 +12,7 @@
 #define CPUSTATES	5	/* OSX doesn't define this */
 #endif
 
-static const char* what_string="@(#)pcpustat 1.3";
+static const char* what_string="@(#)pcpustat 1.4";
 
 /* Bit flags for what stats to include: */
 
@@ -37,12 +37,14 @@
 int main(int ac, char **av)
 {
     int c, option_index, stats=0, count=-1, wait=0, cpu, ncpu, quiet=0, not=0;
+    char *delim=NULL;
     size_t state_size;
     long cpus=0;
     long *cpu_prev, *cpu_curr;
     struct option options[] = {
       {"all", 0, 0, 'a'},
       {"count", 1, 0, 'c'},
+      {"delim", 1, 0, 'd'},
       {"help", 0, 0, 'h'},
       {"idle", 0, 0, 'i'},
       {"nice", 0, 0, 'n'},
@@ -57,6 +59,7 @@
     struct opthelp help[] = {
       {0,"include all usage statistics (-instu)"},
       {"count","repeat count times (default = forever if wait is specified)"},
+      {"delimiter","separate columns with delimiter instead of justifying with spaces"},
       {0,"print this list and exit"},
       {0,"include idle time"},
       {0,"include nice time"},
@@ -74,7 +77,7 @@
     if (ncpu > sizeof(long)*8)
       ncpu = sizeof(long)*8;	/* We're using a bit per CPU */
 
-    while ((c = getopt_long(ac, av, "ac:hinp:qsuw:x", options, &option_index)) >= 0)
+    while ((c = getopt_long(ac, av, "ac:d:hinp:qstuw:x", options, &option_index)) >= 0)
     {
         switch (c)
         {
@@ -86,10 +89,15 @@
 		count = strtol(optarg, NULL, 10);
 	        break;
 
+	    case 'd':
+	    	delim = malloc(strlen(optarg)+1);
+		strcpy(delim, optarg);
+		break;
+
             case 'h':
 	    {
 	        int n, nopts = (sizeof(options) / sizeof(struct option));
-		printf("usage: pcpustat [-");
+		printf("%s\nusage: pcpustat [-", what_string+4);
 		for (n = 0; n < nopts; n++)
 		  if (!(help[n].argname))
 		    printf("%c", options[n].val);
@@ -166,37 +174,79 @@
 
     if (!quiet)
     {
-	char head[21], fmt[5];
+	char *head, fmt[5];
 	int i;
 
-	sprintf(head, "%s%s%s%s%s",
-	    (stats & STAT_USER) ? "  us" : "",
-	    (stats & STAT_NICE) ? "  ni" : "",
-	    (stats & STAT_SYSTEM) ? "  sy" : "",
-	    (stats & STAT_INT) ? "  in" : "",
-	    (stats & STAT_IDLE) ? "  id" : "");
-	if (not)
-	  for (i=1; i<strlen(head); i+=4)
-	    head[i] = '!';
-        sprintf(fmt, "%%%ds", (int)strlen(head));
+	if (delim)
+	{
+	    head = malloc((strlen(delim)+3)*5+1);
+	    char *p = head;
+	    int cnt = 0;
+	    #define ADD_HEAD(s) { \
+				    if (not) *p++ = '!';\
+				    sprintf(p,"%s%s",s,delim);\
+				    p+=strlen(p);\
+				    cnt += 1;\
+				  }
+	    if (stats & STAT_USER)
+	      ADD_HEAD("us");
+	    if (stats & STAT_NICE)
+	      ADD_HEAD("ni");
+	    if (stats & STAT_SYSTEM)
+	      ADD_HEAD("sy");
+	    if (stats & STAT_INT)
+	      ADD_HEAD("in");
+	    if (stats & STAT_IDLE)
+	      ADD_HEAD("id");
+	    #undef ADD_HEAD
+	    *(p-=strlen(delim)) = 0;		/* Overwrite last delimiter */
+	    cnt--;
+	    for (cpu = 0; cpu < ncpu; cpu++)
+	    {
+	      int dc;
+	      if (cpu > 0)
+	        printf(delim);
+	      printf("cpu %d", cpu);
+	      for (dc=0; dc < cnt; dc++)
+	        printf(delim);
+	    }
+	    printf("\n");
+	}
+	else
+	{
+	    head = malloc(21);
+	    sprintf(head, "%s%s%s%s%s",
+		(stats & STAT_USER) ? "  us" : "",
+		(stats & STAT_NICE) ? "  ni" : "",
+		(stats & STAT_SYSTEM) ? "  sy" : "",
+		(stats & STAT_INT) ? "  in" : "",
+		(stats & STAT_IDLE) ? "  id" : "");
+	    if (not)
+	      for (i=1; i<strlen(head); i+=4)
+		head[i] = '!';
+	    sprintf(fmt, "%%%ds", (int)strlen(head));
 
+	    for (cpu = 0; cpu < ncpu; cpu++)
+	      if (cpus & (1 << cpu))
+	      {
+		char str[8];
+		if (strlen(head) > 5)
+		  sprintf(str, "cpu %d", cpu);
+		else
+		  sprintf(str, "%d", cpu);
+		printf(fmt, str);
+	      }
+	    printf("\n");
+	}
 	for (cpu = 0; cpu < ncpu; cpu++)
 	  if (cpus & (1 << cpu))
 	  {
-	    char str[8];
-	    if (strlen(head) > 5)
-	      sprintf(str, "cpu %d", cpu);
-	    else
-	      sprintf(str, "%d", cpu);
-	    printf(fmt, str);
-	  }
-	printf("\n");
-	for (cpu = 0; cpu < ncpu; cpu++)
-	  if (cpus & (1 << cpu))
-	  {
+	    if (delim && (cpu > 0))
+	      printf(delim);
 	    printf(head);
 	  }
 	printf("\n");
+	free(head);
     }
 
     state_size = getsysctllen("kern.cp_times");
@@ -207,6 +257,7 @@
     for (;count; count--)	/* Negative = forever */
     {
 	long *prev, *curr;
+	int first = 1;
 
 	if (wait > 0)
             sleep(wait);
@@ -231,7 +282,18 @@
 	        int pct = (int)((diff[n] * 100 + h) / total);
 		if (not)
 		  pct = 100 - pct;
-	        printf(" %3d", pct);
+		if (delim)
+		{
+		    if (first)
+		       first = 0;
+		    else
+		       printf(delim);
+		    printf("%d", pct);
+		}
+		else
+		{
+	            printf(" %3d", pct);
+		}
 	      }
 	  }
 	printf("\n");
@@ -242,6 +304,8 @@
 
     free(cpu_prev);
     free(cpu_curr);
+    if (delim)
+      free(delim);
     return(0);
 }
 
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list