Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Sep 2015 17:02:01 +0000 (UTC)
From:      Allan Jude <allanjude@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r287486 - head/usr.bin/procstat
Message-ID:  <201509051702.t85H21JL055809@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: allanjude
Date: Sat Sep  5 17:02:01 2015
New Revision: 287486
URL: https://svnweb.freebsd.org/changeset/base/287486

Log:
  Introduce libxo to procstat(1)
  
  Reviewed by:	rodrigc, bapt
  Approved by:	marcel (mentor)
  Relnotes:	yes
  Sponsored by:	ScaleEngine Inc.
  Differential Revision:	https://reviews.freebsd.org/D2446

Modified:
  head/usr.bin/procstat/Makefile
  head/usr.bin/procstat/procstat.1
  head/usr.bin/procstat/procstat.c
  head/usr.bin/procstat/procstat.h
  head/usr.bin/procstat/procstat_args.c
  head/usr.bin/procstat/procstat_auxv.c
  head/usr.bin/procstat/procstat_basic.c
  head/usr.bin/procstat/procstat_bin.c
  head/usr.bin/procstat/procstat_cred.c
  head/usr.bin/procstat/procstat_cs.c
  head/usr.bin/procstat/procstat_files.c
  head/usr.bin/procstat/procstat_kstack.c
  head/usr.bin/procstat/procstat_rlimit.c
  head/usr.bin/procstat/procstat_rusage.c
  head/usr.bin/procstat/procstat_sigs.c
  head/usr.bin/procstat/procstat_threads.c
  head/usr.bin/procstat/procstat_vm.c

Modified: head/usr.bin/procstat/Makefile
==============================================================================
--- head/usr.bin/procstat/Makefile	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/Makefile	Sat Sep  5 17:02:01 2015	(r287486)
@@ -17,6 +17,6 @@ SRCS=	procstat.c		\
 	procstat_threads.c	\
 	procstat_vm.c
 
-LIBADD+=	util procstat
+LIBADD+=	procstat xo util sbuf
 
 .include <bsd.prog.mk>

Modified: head/usr.bin/procstat/procstat.1
==============================================================================
--- head/usr.bin/procstat/procstat.1	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/procstat.1	Sat Sep  5 17:02:01 2015	(r287486)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 18, 2015
+.Dd September 5, 2015
 .Dt PROCSTAT 1
 .Os
 .Sh NAME
@@ -33,6 +33,7 @@
 .Nd get detailed process information
 .Sh SYNOPSIS
 .Nm
+.Op Fl -libxo
 .Op Fl CHhn
 .Op Fl w Ar interval
 .Op Fl b | c | e | f | i | j | k | l | r | s | S | t | v | x
@@ -52,6 +53,13 @@ By default, basic process statistics are
 options may be specified in order to select more detailed process information
 for printing:
 .Bl -tag -width indent
+.It Fl -libxo
+Generate output via
+.Xr libxo 3
+in a selection of different human and machine readable formats.
+See
+.Xr xo_parse_args 3
+for details on command line arguments.
 .It Fl b
 Display binary information for the process.
 .It Fl c
@@ -531,16 +539,19 @@ auxiliary vector value
 .Xr cap_enter 2 ,
 .Xr cap_rights_limit 2 ,
 .Xr libprocstat 3 ,
+.Xr libxo 3 ,
+.Xr xo_parse_args 3 ,
 .Xr ddb 4 ,
 .Xr stack 9
 .Sh AUTHORS
-.An Robert N M Watson
+.An Robert N M Watson Aq Mt rwatson@FreeBSD.org .
+.br
+.Xr libxo 3
+support was added by
+.An -nosplit
+Allan Jude
+.Aq Mt allanjude@FreeBSD.org .
 .Sh BUGS
-Some field values may include spaces, which limits the extent to which the
-output of
-.Nm
-may be mechanically parsed.
-.Pp
 The display of open file or memory mapping pathnames is implemented using the
 kernel's name cache.
 If a file system does not use the name cache, or the path to a file is not in

Modified: head/usr.bin/procstat/procstat.c
==============================================================================
--- head/usr.bin/procstat/procstat.c	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/procstat.c	Sat Sep  5 17:02:01 2015	(r287486)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2007, 2011 Robert N. M. Watson
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -47,17 +48,24 @@ static void
 usage(void)
 {
 
-	fprintf(stderr, "usage: procstat [-CHhn] [-M core] [-N system] "
-	    "[-w interval] \n");
-	fprintf(stderr, "                [-b | -c | -e | -f | -i | -j | -k | "
-	    "-l | -r | -s | -S | -t | -v | -x]\n");
-	fprintf(stderr, "                [-a | pid | core ...]\n");
+	xo_error("usage: procstat [-CHhn] [-M core] [-N system] "
+	    "[-w interval]\n"
+	    "                [-b | -c | -e | -f | -i | -j | -k | "
+	    "-l | -r | -s | -S | -t | -v | -x]\n"
+	    "                [-a | pid | core ...]\n");
+	xo_finish();
 	exit(EX_USAGE);
 }
 
 static void
 procstat(struct procstat *prstat, struct kinfo_proc *kipp)
 {
+	char *pidstr = NULL;
+
+	asprintf(&pidstr, "%d", kipp->ki_pid);
+	if (pidstr == NULL)
+		xo_errc(1, ENOMEM, "Failed to allocate memory in procstat()");
+	xo_open_container(pidstr);
 
 	if (bflag)
 		procstat_bin(prstat, kipp);
@@ -89,6 +97,9 @@ procstat(struct procstat *prstat, struct
 		procstat_cs(prstat, kipp);
 	else
 		procstat_basic(kipp);
+
+	xo_close_container(pidstr);
+	free(pidstr);
 }
 
 /*
@@ -126,10 +137,14 @@ main(int argc, char *argv[])
 	pid_t pid;
 	char *dummy;
 	char *nlistf, *memf;
+	const char *xocontainer;
 	int cnt;
 
 	interval = 0;
 	memf = nlistf = NULL;
+	argc = xo_parse_args(argc, argv);
+	xocontainer = "basic";
+
 	while ((ch = getopt(argc, argv, "CHN:M:abcefijklhrsStvw:x")) != -1) {
 		switch (ch) {
 		case 'C':
@@ -148,6 +163,7 @@ main(int argc, char *argv[])
 			break;
 		case 'S':
 			Sflag++;
+			xocontainer = "cs";
 			break;
 		case 'a':
 			aflag++;
@@ -155,34 +171,42 @@ main(int argc, char *argv[])
 
 		case 'b':
 			bflag++;
+			xocontainer = "binary";
 			break;
 
 		case 'c':
 			cflag++;
+			xocontainer = "arguments";
 			break;
 
 		case 'e':
 			eflag++;
+			xocontainer = "environment";
 			break;
 
 		case 'f':
 			fflag++;
+			xocontainer = "files";
 			break;
 
 		case 'i':
 			iflag++;
+			xocontainer = "signals";
 			break;
 
 		case 'j':
 			jflag++;
+			xocontainer = "thread_signals";
 			break;
 
 		case 'k':
 			kflag++;
+			xocontainer = "kstack";
 			break;
 
 		case 'l':
 			lflag++;
+			xocontainer = "rlimit";
 			break;
 
 		case 'n':
@@ -195,18 +219,22 @@ main(int argc, char *argv[])
 
 		case 'r':
 			rflag++;
+			xocontainer = "rusage";
 			break;
 
 		case 's':
 			sflag++;
+			xocontainer = "credentials";
 			break;
 
 		case 't':
 			tflag++;
+			xocontainer = "threads";
 			break;
 
 		case 'v':
 			vflag++;
+			xocontainer = "vm";
 			break;
 
 		case 'w':
@@ -220,6 +248,7 @@ main(int argc, char *argv[])
 
 		case 'x':
 			xflag++;
+			xocontainer = "auxv";
 			break;
 
 		case '?':
@@ -254,18 +283,23 @@ main(int argc, char *argv[])
 	else
 		prstat = procstat_open_sysctl();
 	if (prstat == NULL)
-		errx(1, "procstat_open()");
+		xo_errx(1, "procstat_open()");
 	do {
+		xo_set_version(PROCSTAT_XO_VERSION);
+		xo_open_container("procstat");
+		xo_open_container(xocontainer);
+
 		if (aflag) {
 			p = procstat_getprocs(prstat, KERN_PROC_PROC, 0, &cnt);
 			if (p == NULL)
-				errx(1, "procstat_getprocs()");
+				xo_errx(1, "procstat_getprocs()");
 			kinfo_proc_sort(p, cnt);
 			for (i = 0; i < cnt; i++) {
 				procstat(prstat, &p[i]);
 
 				/* Suppress header after first process. */
 				hflag = 1;
+				xo_flush();
 			}
 			procstat_freeprocs(prstat, p);
 		}
@@ -276,9 +310,10 @@ main(int argc, char *argv[])
 					usage();
 				pid = l;
 
-				p = procstat_getprocs(prstat, KERN_PROC_PID, pid, &cnt);
+				p = procstat_getprocs(prstat, KERN_PROC_PID,
+				    pid, &cnt);
 				if (p == NULL)
-					errx(1, "procstat_getprocs()");
+					xo_errx(1, "procstat_getprocs()");
 				if (cnt != 0)
 					procstat(prstat, p);
 				procstat_freeprocs(prstat, p);
@@ -291,7 +326,7 @@ main(int argc, char *argv[])
 				p = procstat_getprocs(cprstat, KERN_PROC_PID,
 				    -1, &cnt);
 				if (p == NULL)
-					errx(1, "procstat_getprocs()");
+					xo_errx(1, "procstat_getprocs()");
 				if (cnt != 0)
 					procstat(cprstat, p);
 				procstat_freeprocs(cprstat, p);
@@ -300,9 +335,15 @@ main(int argc, char *argv[])
 			/* Suppress header after first process. */
 			hflag = 1;
 		}
+
+		xo_close_container(xocontainer);
+		xo_close_container("procstat");
+		xo_finish();
 		if (interval)
 			sleep(interval);
 	} while (interval);
+
 	procstat_close(prstat);
+
 	exit(0);
 }

Modified: head/usr.bin/procstat/procstat.h
==============================================================================
--- head/usr.bin/procstat/procstat.h	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/procstat.h	Sat Sep  5 17:02:01 2015	(r287486)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2007 Robert N. M. Watson
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -26,9 +27,13 @@
  * $FreeBSD$
  */
 
+#include <libxo/xo.h>
+
 #ifndef PROCSTAT_H
 #define	PROCSTAT_H
 
+#define PROCSTAT_XO_VERSION "1"
+
 extern int	hflag, nflag, Cflag, Hflag;
 
 struct kinfo_proc;

Modified: head/usr.bin/procstat/procstat_args.c
==============================================================================
--- head/usr.bin/procstat/procstat_args.c	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/procstat_args.c	Sat Sep  5 17:02:01 2015	(r287486)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2007 Robert N. M. Watson
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -40,40 +41,56 @@
 
 #include "procstat.h"
 
-static void
-do_args(struct procstat *procstat, struct kinfo_proc *kipp, int env)
+void
+procstat_args(struct procstat *procstat, struct kinfo_proc *kipp)
 {
 	int i;
 	char **args;
 
 	if (!hflag) {
-		printf("%5s %-16s %-53s\n", "PID", "COMM",
-		    env ? "ENVIRONMENT" : "ARGS");
+		xo_emit("{T:/%5s %-16s %-53s}\n", "PID", "COMM", "ARGS");
 	}
 
-	args = env ? procstat_getenvv(procstat, kipp, 0) :
-	    procstat_getargv(procstat, kipp, 0);
+	args = procstat_getargv(procstat, kipp, 0);
 
-	printf("%5d %-16s", kipp->ki_pid, kipp->ki_comm);
+	xo_emit("{k:process_id/%5d/%d} {:command/%-16s/%s}", kipp->ki_pid,
+	    kipp->ki_comm);
 
 	if (args == NULL) {
-		printf(" -\n");
+		xo_emit(" {d:args/-}\n");
 		return;
 	}
 
+	xo_open_list("arguments");
 	for (i = 0; args[i] != NULL; i++)
-		printf(" %s", args[i]);
-	printf("\n");
-}
-
-void
-procstat_args(struct procstat *procstat, struct kinfo_proc *kipp)
-{
-	do_args(procstat, kipp, 0);
+		xo_emit(" {l:args/%s}", args[i]);
+	xo_close_list("arguments");
+	xo_emit("\n");
 }
 
 void
 procstat_env(struct procstat *procstat, struct kinfo_proc *kipp)
 {
-	do_args(procstat, kipp, 1);
+	int i;
+	char **envs;
+
+	if (!hflag) {
+		xo_emit("{T:/%5s %-16s %-53s}\n", "PID", "COMM", "ENVIRONMENT");
+	}
+
+	envs = procstat_getenvv(procstat, kipp, 0);
+
+	xo_emit("{k:process_id/%5d/%d} {:command/%-16s/%s}", kipp->ki_pid,
+	    kipp->ki_comm);
+
+	if (envs == NULL) {
+		xo_emit(" {d:env/-}\n");
+		return;
+	}
+
+	xo_open_list("environment");
+	for (i = 0; envs[i] != NULL; i++)
+		xo_emit(" {l:env/%s}", envs[i]);
+	xo_close_list("environment");
+	xo_emit("\n");
 }

Modified: head/usr.bin/procstat/procstat_auxv.c
==============================================================================
--- head/usr.bin/procstat/procstat_auxv.c	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/procstat_auxv.c	Sat Sep  5 17:02:01 2015	(r287486)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2011 Mikolaj Golub
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -43,11 +44,6 @@
 
 #include "procstat.h"
 
-#define	PRINT(name, spec, val)		\
-	printf("%s %-16s " #spec "\n", prefix, #name, (val))
-#define	PRINT_UNKNOWN(type, val)	\
-	printf("%s %16ld %#lx\n", prefix, (long)type, (u_long)(val))
-
 void
 procstat_auxv(struct procstat *procstat, struct kinfo_proc *kipp)
 {
@@ -56,12 +52,18 @@ procstat_auxv(struct procstat *procstat,
 	static char prefix[256];
 
 	if (!hflag)
-		printf("%5s %-16s %-16s %-16s\n", "PID", "COMM", "AUXV", "VALUE");
+		xo_emit("{T:/%5s %-16s %-16s %-16s}\n", "PID", "COMM", "AUXV",
+		    "VALUE");
+
 	auxv = procstat_getauxv(procstat, kipp, &count);
 	if (auxv == NULL)
 		return;
-	snprintf(prefix, sizeof(prefix), "%5d %-16s", kipp->ki_pid,
+        snprintf(prefix, sizeof(prefix), "%5d %-16s", kipp->ki_pid,
+            kipp->ki_comm);
+
+	xo_emit("{e:process_id/%5d/%d}{e:command/%-16s/%s}", kipp->ki_pid,
 	    kipp->ki_comm);
+
 	for (i = 0; i < count; i++) {
 		switch(auxv[i].a_type) {
 		case AT_NULL:
@@ -69,92 +71,119 @@ procstat_auxv(struct procstat *procstat,
 		case AT_IGNORE:
 			break;
 		case AT_EXECFD:
-			PRINT(AT_EXECFD, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_EXECFD/%ld}\n",
+			    prefix, "AT_EXECFD", (long)auxv[i].a_un.a_val);
 			break;
 		case AT_PHDR:
-			PRINT(AT_PHDR, %p, auxv[i].a_un.a_ptr);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PHDR/%p}\n",
+			    prefix, "AT_PHDR", auxv[i].a_un.a_ptr);
 			break;
 		case AT_PHENT:
-			PRINT(AT_PHENT, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PHENT/%ld}\n",
+			    prefix, "AT_PHENT", (long)auxv[i].a_un.a_val);
 			break;
 		case AT_PHNUM:
-			PRINT(AT_PHNUM, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PHNUM/%ld}\n",
+			    prefix, "AT_PHNUM", (long)auxv[i].a_un.a_val);
 			break;
 		case AT_PAGESZ:
-			PRINT(AT_PAGESZ, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PAGESZ/%ld}\n",
+			    prefix, "AT_PAGESZ", (long)auxv[i].a_un.a_val);
 			break;
 		case AT_BASE:
-			PRINT(AT_BASE, %p, auxv[i].a_un.a_ptr);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_BASE/%p}\n",
+			    prefix, "AT_BASE", auxv[i].a_un.a_ptr);
 			break;
 		case AT_FLAGS:
-			PRINT(AT_FLAGS, %#lx, (u_long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_FLAGS/%#lx}\n",
+			    prefix, "AT_FLAGS", (u_long)auxv[i].a_un.a_val);
 			break;
 		case AT_ENTRY:
-			PRINT(AT_ENTRY, %p, auxv[i].a_un.a_ptr);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_ENTRY/%p}\n",
+			    prefix, "AT_ENTRY", auxv[i].a_un.a_ptr);
 			break;
 #ifdef AT_NOTELF
 		case AT_NOTELF:
-			PRINT(AT_NOTELF, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_NOTELF/%ld}\n",
+			    prefix, "AT_NOTELF", (long)auxv[i].a_un.a_val);
 			break;
 #endif
 #ifdef AT_UID
 		case AT_UID:
-			PRINT(AT_UID, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_UID/%ld}\n",
+			    prefix, "AT_UID", (long)auxv[i].a_un.a_val);
 			break;
 #endif
 #ifdef AT_EUID
 		case AT_EUID:
-			PRINT(AT_EUID, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_EUID/%ld}\n",
+			    prefix, "AT_EUID", (long)auxv[i].a_un.a_val);
 			break;
 #endif
 #ifdef AT_GID
 		case AT_GID:
-			PRINT(AT_GID, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_GID/%ld}\n",
+			    prefix, "AT_GID", (long)auxv[i].a_un.a_val);
 			break;
 #endif
 #ifdef AT_EGID
 		case AT_EGID:
-			PRINT(AT_EGID, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_EGID/%ld}\n",
+			    prefix, "AT_EGID", (long)auxv[i].a_un.a_val);
 			break;
 #endif
 		case AT_EXECPATH:
-			PRINT(AT_EXECPATH, %p, auxv[i].a_un.a_ptr);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_EXECPATH/%p}\n",
+			    prefix, "AT_EXECPATH", auxv[i].a_un.a_ptr);
 			break;
 		case AT_CANARY:
-			PRINT(AT_CANARY, %p, auxv[i].a_un.a_ptr);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_CANARY/%p}\n",
+			    prefix, "AT_CANARY", auxv[i].a_un.a_ptr);
 			break;
 		case AT_CANARYLEN:
-			PRINT(AT_CANARYLEN, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_CANARYLEN/%ld}\n",
+			    prefix, "AT_CANARYLEN", (long)auxv[i].a_un.a_val);
 			break;
 		case AT_OSRELDATE:
-			PRINT(AT_OSRELDATE, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_OSRELDATE/%ld}\n",
+			    prefix, "AT_OSRELDATE", (long)auxv[i].a_un.a_val);
 			break;
 		case AT_NCPUS:
-			PRINT(AT_NCPUS, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_NCPUS/%ld}\n",
+			    prefix, "AT_NCPUS", (long)auxv[i].a_un.a_val);
 			break;
 		case AT_PAGESIZES:
-			PRINT(AT_PAGESIZES, %p, auxv[i].a_un.a_ptr);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_PAGESIZES/%p}\n",
+			    prefix, "AT_PAGESIZES", auxv[i].a_un.a_ptr);
 			break;
 		case AT_PAGESIZESLEN:
-			PRINT(AT_PAGESIZESLEN, %ld, (long)auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}"
+			    "{:AT_PAGESIZESLEN/%ld}\n", prefix,
+			    "AT_PAGESIZESLEN", (long)auxv[i].a_un.a_val);
 			break;
 		case AT_STACKPROT:
 			if ((auxv[i].a_un.a_val & VM_PROT_EXECUTE) != 0)
-				PRINT(AT_STACKPROT, %s, "NONEXECUTABLE");
+				xo_emit("{dw:/%s}{Lw:/%-16s/%s}"
+				    "{:AT_STACKPROT/%s}\n", prefix,
+				    "AT_STACKPROT", "NONEXECUTABLE");
 			else
-				PRINT(AT_STACKPROT, %s, "EXECUTABLE");
+				xo_emit("{dw:/%s}{Lw:/%-16s/%s}"
+				    "{:AT_STACKPROT/%s}\n", prefix,
+				    "AT_STACKPROT", "EXECUTABLE");
 			break;
 #ifdef AT_TIMEKEEP
 		case AT_TIMEKEEP:
-			PRINT(AT_TIMEKEEP, %p, auxv[i].a_un.a_ptr);
+			xo_emit("{dw:/%s}{Lw:/%-16s/%s}{:AT_TIMEKEEP/%p}\n",
+			    prefix, "AT_TIMEKEEP", auxv[i].a_un.a_ptr);
 			break;
 #endif
 		default:
-			PRINT_UNKNOWN(auxv[i].a_type, auxv[i].a_un.a_val);
+			xo_emit("{dw:/%s}{Lw:/%16ld/%ld}{:UNKNOWN/%#lx}\n",
+			    prefix, auxv[i].a_type, auxv[i].a_un.a_val);
 			break;
 		}
 	}
-	printf("\n");
+	xo_emit("\n");
 	procstat_freeauxv(procstat, auxv);
 }
 

Modified: head/usr.bin/procstat/procstat_basic.c
==============================================================================
--- head/usr.bin/procstat/procstat_basic.c	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/procstat_basic.c	Sat Sep  5 17:02:01 2015	(r287486)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2007 Robert N. M. Watson
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -42,24 +43,26 @@ procstat_basic(struct kinfo_proc *kipp)
 {
 
 	if (!hflag)
-		printf("%5s %5s %5s %5s %5s %3s %-8s %-9s %-13s %-12s\n",
+		xo_emit("{T:/%5s %5s %5s %5s %5s %3s %-8s %-9s %-13s %-12s}\n",
 		    "PID", "PPID", "PGID", "SID", "TSID", "THR", "LOGIN",
 		    "WCHAN", "EMUL", "COMM");
 
-	printf("%5d ", kipp->ki_pid);
-	printf("%5d ", kipp->ki_ppid);
-	printf("%5d ", kipp->ki_pgid);
-	printf("%5d ", kipp->ki_sid);
-	printf("%5d ", kipp->ki_tsid);
-	printf("%3d ", kipp->ki_numthreads);
-	printf("%-8s ", strlen(kipp->ki_login) ? kipp->ki_login : "-");
+	xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid);
+	xo_emit("{:parent_process_id/%5d/%d} ", kipp->ki_ppid);
+	xo_emit("{:process_group_id/%5d/%d} ", kipp->ki_pgid);
+	xo_emit("{:session_id/%5d/%d} ", kipp->ki_sid);
+	xo_emit("{:terminal_session_id/%5d/%d} ", kipp->ki_tsid);
+	xo_emit("{:threads/%3d/%d} ", kipp->ki_numthreads);
+	xo_emit("{:login/%-8s/%s} ", strlen(kipp->ki_login) ?
+	    kipp->ki_login : "-");
 	if (kipp->ki_kiflag & KI_LOCKBLOCK) {
-		printf("*%-8s ", strlen(kipp->ki_lockname) ?
+		xo_emit("{:lockname/*%-8s/%s} ", strlen(kipp->ki_lockname) ?
 		    kipp->ki_lockname : "-");
 	} else {
-		printf("%-9s ", strlen(kipp->ki_wmesg) ?
+		xo_emit("{:wait_channel/%-9s/%s} ", strlen(kipp->ki_wmesg) ?
 		    kipp->ki_wmesg : "-");
 	}
-	printf("%-13s ", strcmp(kipp->ki_emul, "null") ? kipp->ki_emul : "-");
-	printf("%-12s\n", kipp->ki_comm);
+	xo_emit("{:emulation/%-13s/%s} ", strcmp(kipp->ki_emul, "null") ?
+	    kipp->ki_emul : "-");
+	xo_emit("{:command/%-12s/%s}\n", kipp->ki_comm);
 }

Modified: head/usr.bin/procstat/procstat_bin.c
==============================================================================
--- head/usr.bin/procstat/procstat_bin.c	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/procstat_bin.c	Sat Sep  5 17:02:01 2015	(r287486)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2007 Robert N. M. Watson
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -46,7 +47,8 @@ procstat_bin(struct procstat *prstat, st
 	static char pathname[PATH_MAX];
 
 	if (!hflag)
-		printf("%5s %-16s %8s %s\n", "PID", "COMM", "OSREL", "PATH");
+		xo_emit("{T:/%5s %-16s %8s %s}\n", "PID", "COMM", "OSREL",
+		    "PATH");
 
 	if (procstat_getpathname(prstat, kipp, pathname, sizeof(pathname)) != 0)
 		return;
@@ -55,8 +57,8 @@ procstat_bin(struct procstat *prstat, st
 	if (procstat_getosrel(prstat, kipp, &osrel) != 0)
 		return;
 
-	printf("%5d ", kipp->ki_pid);
-	printf("%-16s ", kipp->ki_comm);
-	printf("%8d ", osrel);
-	printf("%s\n", pathname);
+	xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid);
+	xo_emit("{:command/%-16s/%s} ", kipp->ki_comm);
+	xo_emit("{:osrel/%8d/%d} ", osrel);
+	xo_emit("{:pathname/%s}\n", pathname);
 }

Modified: head/usr.bin/procstat/procstat_cred.c
==============================================================================
--- head/usr.bin/procstat/procstat_cred.c	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/procstat_cred.c	Sat Sep  5 17:02:01 2015	(r287486)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2007-2008 Robert N. M. Watson
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -48,21 +49,22 @@ procstat_cred(struct procstat *procstat,
 	gid_t *groups;
 
 	if (!hflag)
-		printf("%5s %-16s %5s %5s %5s %5s %5s %5s %5s %5s %-15s\n",
+		xo_emit("{T:/%5s %-16s %5s %5s %5s %5s %5s %5s %5s %5s %-15s}\n",
 		    "PID", "COMM", "EUID", "RUID", "SVUID", "EGID", "RGID",
 		    "SVGID", "UMASK", "FLAGS", "GROUPS");
 
-	printf("%5d ", kipp->ki_pid);
-	printf("%-16s ", kipp->ki_comm);
-	printf("%5d ", kipp->ki_uid);
-	printf("%5d ", kipp->ki_ruid);
-	printf("%5d ", kipp->ki_svuid);
-	printf("%5d ", kipp->ki_groups[0]);
-	printf("%5d ", kipp->ki_rgid);
-	printf("%5d ", kipp->ki_svgid);
-	printf("%5s ", get_umask(procstat, kipp));
-	printf("%s", kipp->ki_cr_flags & CRED_FLAG_CAPMODE ? "C" : "-");
-	printf("     ");
+	xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid);
+	xo_emit("{:command/%-16s/%s} ", kipp->ki_comm);
+	xo_emit("{:uid/%5d} ", kipp->ki_uid);
+	xo_emit("{:ruid/%5d} ", kipp->ki_ruid);
+	xo_emit("{:svuid/%5d} ", kipp->ki_svuid);
+	xo_emit("{:group/%5d} ", kipp->ki_groups[0]);
+	xo_emit("{:rgid/%5d} ", kipp->ki_rgid);
+	xo_emit("{:svgid/%5d} ", kipp->ki_svgid);
+	xo_emit("{:umask/%5s} ", get_umask(procstat, kipp));
+	xo_emit("{:cr_flags/%s}", kipp->ki_cr_flags & CRED_FLAG_CAPMODE ?
+	    "C" : "-");
+	xo_emit("{P:     }");
 
 	groups = NULL;
 	/*
@@ -76,12 +78,14 @@ procstat_cred(struct procstat *procstat,
 		ngroups = kipp->ki_ngroups;
 		groups = kipp->ki_groups;
 	}
+	xo_open_list("groups");
 	for (i = 0; i < ngroups; i++)
-		printf("%s%d", (i > 0) ? "," : "", groups[i]);
+		xo_emit("{D:/%s}{l:groups/%d}", (i > 0) ? "," : "", groups[i]);
 	if (groups != kipp->ki_groups)
 		procstat_freegroups(procstat, groups);
 
-	printf("\n");
+	xo_close_list("groups");
+	xo_emit("\n");
 }
 
 static const char *

Modified: head/usr.bin/procstat/procstat_cs.c
==============================================================================
--- head/usr.bin/procstat/procstat_cs.c	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/procstat_cs.c	Sat Sep  5 17:02:01 2015	(r287486)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2007 Robert N. M. Watson
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,6 +29,7 @@
 
 #include <sys/param.h>
 #include <sys/cpuset.h>
+#include <sys/sbuf.h>
 #include <sys/sysctl.h>
 #include <sys/user.h>
 
@@ -46,11 +48,12 @@ procstat_cs(struct procstat *procstat, s
 	cpusetid_t cs;
 	cpuset_t mask;
 	struct kinfo_proc *kip;
+	struct sbuf *cpusetbuf;
 	unsigned int count, i;
 	int once, twice, lastcpu, cpu;
 
 	if (!hflag)
-		printf("%5s %6s %-16s %-16s %2s %4s %-7s\n", "PID",
+		xo_emit("{T:/%5s %6s %-16s %-16s %2s %4s %-7s}\n", "PID",
 		    "TID", "COMM", "TDNAME", "CPU", "CSID", "CPU MASK");
 
 	kip = procstat_getprocs(procstat, KERN_PROC_PID | KERN_PROC_INC_THREAD,
@@ -60,49 +63,57 @@ procstat_cs(struct procstat *procstat, s
 	kinfo_proc_sort(kip, count);
 	for (i = 0; i < count; i++) {
 		kipp = &kip[i];
-		printf("%5d ", kipp->ki_pid);
-		printf("%6d ", kipp->ki_tid);
-		printf("%-16s ", strlen(kipp->ki_comm) ?
+		xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid);
+		xo_emit("{:thread_id/%6d/%d} ", kipp->ki_tid);
+		xo_emit("{:command/%-16s/%s} ", strlen(kipp->ki_comm) ?
 		    kipp->ki_comm : "-");
-		printf("%-16s ", (strlen(kipp->ki_tdname) &&
+		xo_emit("{:thread_name/%-16s/%s} ", (strlen(kipp->ki_tdname) &&
 		    (strcmp(kipp->ki_comm, kipp->ki_tdname) != 0)) ?
 		    kipp->ki_tdname : "-");
 		if (kipp->ki_oncpu != 255)
-			printf("%3d ", kipp->ki_oncpu);
+			xo_emit("{:cpu/%3d/%d} ", kipp->ki_oncpu);
 		else if (kipp->ki_lastcpu != 255)
-			printf("%3d ", kipp->ki_lastcpu);
+			xo_emit("{:cpu/%3d/%d} ", kipp->ki_lastcpu);
 		else
-			printf("%3s ", "-");
+			xo_emit("{:cpu/%3s/%s} ", "-");
 		if (cpuset_getid(CPU_LEVEL_CPUSET, CPU_WHICH_TID,
 		    kipp->ki_tid, &cs) != 0) {
 			cs = CPUSET_INVALID;
 		}
-		printf("%4d ", cs);
+		xo_emit("{:cpu_set_id/%4d/%d} ", cs);
 		if ((cs != CPUSET_INVALID) && 
 		    (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID,
 		    kipp->ki_tid, sizeof(mask), &mask) == 0)) {
 			lastcpu = -1;
 			once = 0;
 			twice = 0;
+			cpusetbuf = sbuf_new_auto();
 			for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
 				if (CPU_ISSET(cpu, &mask)) {
 					if (once == 0) {
-						printf("%d", cpu);
+						sbuf_printf(cpusetbuf, "%d",
+						    cpu);
 						once = 1;
 					} else if (cpu == lastcpu + 1) {
 						twice = 1;
 					} else if (twice == 1) {
-						printf("-%d,%d", lastcpu, cpu);
+						sbuf_printf(cpusetbuf, "-%d,%d",
+						    lastcpu, cpu);
 						twice = 0;
 					} else
-						printf(",%d", cpu);
+						sbuf_printf(cpusetbuf, ",%d",
+						    cpu);
 					lastcpu = cpu;
 				}
 			}
 			if (once && twice)
-				printf("-%d", lastcpu);
+				sbuf_printf(cpusetbuf, "-%d", lastcpu);
+			if (sbuf_finish(cpusetbuf) != 0)
+				xo_err(1, "Could not generate output");
+			xo_emit("{:cpu_set/%s}", sbuf_data(cpusetbuf));
+			sbuf_delete(cpusetbuf);
 		}
-		printf("\n");
+		xo_emit("\n");
 	}
 	procstat_freeprocs(procstat, kip);
 }

Modified: head/usr.bin/procstat/procstat_files.c
==============================================================================
--- head/usr.bin/procstat/procstat_files.c	Sat Sep  5 16:59:30 2015	(r287485)
+++ head/usr.bin/procstat/procstat_files.c	Sat Sep  5 17:02:01 2015	(r287486)
@@ -1,5 +1,6 @@
 /*-
  * Copyright (c) 2007-2011 Robert N. M. Watson
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -123,15 +124,6 @@ addr_to_string(struct sockaddr_storage *
 	}
 }
 
-static void
-print_address(struct sockaddr_storage *ss)
-{
-	char addr[PATH_MAX];
-
-	addr_to_string(ss, addr, sizeof(addr));
-	printf("%s", addr);
-}
-
 static struct cap_desc {
 	uint64_t	 cd_right;
 	const char	*cd_desc;
@@ -273,19 +265,22 @@ print_capability(cap_rights_t *rightsp, 
 	width = 0;
 	for (i = width_capability(rightsp); i < capwidth; i++) {
 		if (i != 0)
-			printf(" ");
+			xo_emit(" ");
 		else
-			printf("-");
+			xo_emit("-");
 	}
+	xo_open_list("capabilities");
 	for (i = 0; i < cap_desc_count; i++) {
 		if (cap_rights_is_set(rightsp, cap_desc[i].cd_right)) {
-			printf("%s%s", count ? "," : "", cap_desc[i].cd_desc);
+			xo_emit("{D:/%s}{l:capabilities/%s}", count ? "," : "",
+			    cap_desc[i].cd_desc);
 			width += strlen(cap_desc[i].cd_desc);
 			if (count)
 				width++;
 			count++;
 		}
 	}
+	xo_close_list("capabilities");
 }
 
 void
@@ -298,6 +293,8 @@ procstat_files(struct procstat *procstat
 	struct vnstat vn;
 	u_int capwidth, width;
 	int error;
+	char src_addr[PATH_MAX];
+	char dst_addr[PATH_MAX];
 
 	/*
 	 * To print the header in capability mode, we need to know the width
@@ -319,84 +316,103 @@ procstat_files(struct procstat *procstat
 
 	if (!hflag) {
 		if (Cflag)
-			printf("%5s %-16s %5s %1s %-8s %-*s "
-			    "%-3s %-12s\n", "PID", "COMM", "FD", "T",
+			xo_emit("{T:/%5s %-16s %5s %1s %-8s %-*s "
+			    "%-3s %-12s}\n", "PID", "COMM", "FD", "T",
 			    "FLAGS", capwidth, "CAPABILITIES", "PRO",
 			    "NAME");
 		else
-			printf("%5s %-16s %5s %1s %1s %-8s "
-			    "%3s %7s %-3s %-12s\n", "PID", "COMM", "FD", "T",
+			xo_emit("{T:/%5s %-16s %5s %1s %1s %-8s "
+			    "%3s %7s %-3s %-12s}\n", "PID", "COMM", "FD", "T",
 			    "V", "FLAGS", "REF", "OFFSET", "PRO", "NAME");
 	}
 
 	if (head == NULL)
 		return;
+	xo_emit("{ek:process_id/%5d/%d}", kipp->ki_pid);
+	xo_emit("{e:command/%-16s/%s}", kipp->ki_comm);
+	xo_open_list("files");
 	STAILQ_FOREACH(fst, head, next) {
-		printf("%5d ", kipp->ki_pid);
-		printf("%-16s ", kipp->ki_comm);
+		xo_open_instance("files");
+		xo_emit("{dk:process_id/%5d/%d} ", kipp->ki_pid);
+		xo_emit("{d:command/%-16s/%s} ", kipp->ki_comm);
 		if (fst->fs_uflags & PS_FST_UFLAG_CTTY)
-			printf(" ctty ");
+			xo_emit("{P: }{:fd/%s} ", "ctty");
 		else if (fst->fs_uflags & PS_FST_UFLAG_CDIR)
-			printf("  cwd ");
+			xo_emit("{P:  }{:fd/%s} ", "cwd");
 		else if (fst->fs_uflags & PS_FST_UFLAG_JAIL)
-			printf(" jail ");
+			xo_emit("{P: }{:fd/%s} ", "jail");
 		else if (fst->fs_uflags & PS_FST_UFLAG_RDIR)
-			printf(" root ");
+			xo_emit("{P: }{:fd/%s} ", "root");
 		else if (fst->fs_uflags & PS_FST_UFLAG_TEXT)
-			printf(" text ");
+			xo_emit("{P: }{:fd/%s} ", "text");
 		else if (fst->fs_uflags & PS_FST_UFLAG_TRACE)
-			printf("trace ");
+			xo_emit("{:fd/%s} ", "trace");
 		else
-			printf("%5d ", fst->fs_fd);
+			xo_emit("{:fd/%5d} ", fst->fs_fd);
 
 		switch (fst->fs_type) {
 		case PS_FST_TYPE_VNODE:
 			str = "v";
+			xo_emit("{eq:fd_type/vnode}");
 			break;
 
 		case PS_FST_TYPE_SOCKET:
 			str = "s";
+			xo_emit("{eq:fd_type/socket}");
 			break;
 
 		case PS_FST_TYPE_PIPE:
 			str = "p";
+			xo_emit("{eq:fd_type/pipe}");
 			break;
 
 		case PS_FST_TYPE_FIFO:
 			str = "f";
+			xo_emit("{eq:fd_type/fifo}");
 			break;
 
 		case PS_FST_TYPE_KQUEUE:
 			str = "k";
+			xo_emit("{eq:fd_type/kqueue}");
 			break;
 
 		case PS_FST_TYPE_CRYPTO:
 			str = "c";
+			xo_emit("{eq:fd_type/crypto}");
 			break;
 
 		case PS_FST_TYPE_MQUEUE:
 			str = "m";
+			xo_emit("{eq:fd_type/mqueue}");
 			break;
 
 		case PS_FST_TYPE_SHM:
 			str = "h";
+			xo_emit("{eq:fd_type/shm}");
 			break;
 
 		case PS_FST_TYPE_PTS:
 			str = "t";
+			xo_emit("{eq:fd_type/pts}");
 			break;
 
 		case PS_FST_TYPE_SEM:
 			str = "e";
+			xo_emit("{eq:fd_type/sem}");
 			break;
 
 		case PS_FST_TYPE_NONE:
+			str = "?";
+			xo_emit("{eq:fd_type/none}");
+			break;
+
 		case PS_FST_TYPE_UNKNOWN:
 		default:
 			str = "?";
+			xo_emit("{eq:fd_type/unknown}");
 			break;
 		}
-		printf("%1s ", str);
+		xo_emit("{d:fd_type/%1s/%s} ", str);
 		if (!Cflag) {
 			str = "-";
 			if (fst->fs_type == PS_FST_TYPE_VNODE) {
@@ -405,74 +421,118 @@ procstat_files(struct procstat *procstat
 				switch (vn.vn_type) {
 				case PS_FST_VTYPE_VREG:
 					str = "r";
+					xo_emit("{eq:vode_type/regular}");
 					break;
 

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201509051702.t85H21JL055809>