Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Jun 2014 15:52:07 GMT
From:      zkorchev@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r269256 - soc2014/zkorchev/freebsd_head/usr.bin/netstat
Message-ID:  <201406081552.s58Fq7tM053795@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: zkorchev
Date: Sun Jun  8 15:52:07 2014
New Revision: 269256
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=269256

Log:
  partial netstat integration with SOL

Modified:
  soc2014/zkorchev/freebsd_head/usr.bin/netstat/Makefile
  soc2014/zkorchev/freebsd_head/usr.bin/netstat/bpf.c
  soc2014/zkorchev/freebsd_head/usr.bin/netstat/flowtable.c
  soc2014/zkorchev/freebsd_head/usr.bin/netstat/if.c
  soc2014/zkorchev/freebsd_head/usr.bin/netstat/main.c
  soc2014/zkorchev/freebsd_head/usr.bin/netstat/mbuf.c
  soc2014/zkorchev/freebsd_head/usr.bin/netstat/netisr.c
  soc2014/zkorchev/freebsd_head/usr.bin/netstat/netstat.h
  soc2014/zkorchev/freebsd_head/usr.bin/netstat/route.c

Modified: soc2014/zkorchev/freebsd_head/usr.bin/netstat/Makefile
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/netstat/Makefile	Sun Jun  8 15:51:28 2014	(r269255)
+++ soc2014/zkorchev/freebsd_head/usr.bin/netstat/Makefile	Sun Jun  8 15:52:07 2014	(r269256)
@@ -31,10 +31,12 @@
 CFLAGS+=-DPF
 .endif
 
+CFLAGS+=-DSOL_ON -I/usr/local/include
+
 BINGRP=	kmem
 BINMODE=2555
 DPADD=	${LIBKVM} ${LIBMEMSTAT} ${LIBUTIL}
-LDADD=	-lkvm -lmemstat -lutil
+LDADD=	-lkvm -lmemstat -lutil -lsol
 
 .if ${MK_NETGRAPH_SUPPORT} != "no"
 SRCS+=	netgraph.c

Modified: soc2014/zkorchev/freebsd_head/usr.bin/netstat/bpf.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/netstat/bpf.c	Sun Jun  8 15:51:28 2014	(r269255)
+++ soc2014/zkorchev/freebsd_head/usr.bin/netstat/bpf.c	Sun Jun  8 15:52:07 2014	(r269256)
@@ -48,6 +48,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sol.h>
 
 #include "netstat.h"
 
@@ -120,9 +121,15 @@
 		free(bd);
 		return;
 	}
-	(void) printf("%5s %6s %7s %9s %9s %9s %5s %5s %s\n",
-	    "Pid", "Netif", "Flags", "Recv", "Drop", "Match", "Sblen",
-	    "Hblen", "Command");
+
+#if defined(SOL_ON)
+	if (Oflag)
+		sol_map_start(&sol_stream);
+	else
+#endif
+		(void) printf("%5s %6s %7s %9s %9s %9s %5s %5s %s\n",
+			"Pid", "Netif", "Flags", "Recv", "Drop", "Match", "Sblen",
+			"Hblen", "Command");
 	for (d = &bd[0]; d < &bd[size / sizeof(*d)]; d++) {
 		if (d->bd_structsize != sizeof(*d)) {
 			warnx("bpf_stats_extended: version mismatch");
@@ -132,6 +139,37 @@
 			continue;
 		bpf_flags(d, flagbuf);
 		pname = bpf_pidname(d->bd_pid);
+#if defined(SOL_ON)
+	if (Oflag) {
+		sol_map_key(&sol_stream, "pid", 3);
+		sol_integer(&sol_stream, d->bd_pid);
+
+		sol_map_key(&sol_stream, "if", 2);
+		sol_string(&sol_stream, d->bd_ifname, strlen(d->bd_ifname));
+
+		sol_map_key(&sol_stream, "flags", 5);
+		sol_string(&sol_stream, flagbuf, strlen(flagbuf));
+
+		sol_map_key(&sol_stream, "recv", 4);
+		sol_integer(&sol_stream, d->bd_rcount);
+
+		sol_map_key(&sol_stream, "drop", 4);
+		sol_integer(&sol_stream, d->bd_dcount);
+
+		sol_map_key(&sol_stream, "match", 5);
+		sol_integer(&sol_stream, d->bd_fcount);
+
+		sol_map_key(&sol_stream, "sblen", 5);
+		sol_integer(&sol_stream, d->bd_slen);
+
+		sol_map_key(&sol_stream, "hblen", 5);
+		sol_integer(&sol_stream, d->bd_hlen);
+
+		sol_map_key(&sol_stream, "cmd", 3);
+		sol_string(&sol_stream, pname, strlen(pname));
+	}
+	else
+#endif
 		(void) printf("%5d %6s %7s %9ju %9ju %9ju %5d %5d %s\n",
 		    d->bd_pid, d->bd_ifname, flagbuf,
 		    d->bd_rcount, d->bd_dcount, d->bd_fcount,
@@ -139,4 +177,9 @@
 		free(pname);
 	}
 	free(bd);
+
+#if defined(SOL_ON)
+	if (Oflag)
+		sol_map_end(&sol_stream);
+#endif
 }

Modified: soc2014/zkorchev/freebsd_head/usr.bin/netstat/flowtable.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/netstat/flowtable.c	Sun Jun  8 15:51:28 2014	(r269255)
+++ soc2014/zkorchev/freebsd_head/usr.bin/netstat/flowtable.c	Sun Jun  8 15:52:07 2014	(r269256)
@@ -34,6 +34,7 @@
 #include <err.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <sol.h>
 #include "netstat.h"
 
 /*
@@ -44,23 +45,50 @@
 print_stats(struct flowtable_stat *stat)
 {
 
+#if defined(SOL_ON)
+	if (Oflag)
+	{
+		sol_map_start(&sol_stream);
+
+#define	p(f, m) if (stat->f || sflag <= 1) do { \
+	SOL_MAP_KEYL(&sol_stream, m); \
+	sol_integer(&sol_stream, stat->f); \
+} while (0)
+
+		p(ft_lookups, "lookups");
+		p(ft_hits, "hits");
+		p(ft_misses, "misses");
+		p(ft_inserts, "inserts");
+		p(ft_collisions, "collisions");
+		p(ft_free_checks, "free checks");
+		p(ft_frees, "frees");
+		p(ft_fail_lle_invalid, "lookups with not resolved Layer 2 address");
+
+#undef p
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+	{
 #define	p(f, m) if (stat->f || sflag <= 1) \
 	printf(m, (uintmax_t)stat->f, plural(stat->f))
 #define	p2(f, m) if (stat->f || sflag <= 1) \
 	printf(m, (uintmax_t)stat->f, plurales(stat->f))
 
-	p(ft_lookups, "\t%ju lookup%s\n");
-	p(ft_hits, "\t%ju hit%s\n");
-	p2(ft_misses, "\t%ju miss%s\n");
-	p(ft_inserts, "\t%ju insert%s\n");
-	p(ft_collisions, "\t%ju collision%s\n");
-	p(ft_free_checks, "\t%ju free check%s\n");
-	p(ft_frees, "\t%ju free%s\n");
-	p(ft_fail_lle_invalid,
-	    "\t%ju lookup%s with not resolved Layer 2 address\n");
+		p(ft_lookups, "\t%ju lookup%s\n");
+		p(ft_hits, "\t%ju hit%s\n");
+		p2(ft_misses, "\t%ju miss%s\n");
+		p(ft_inserts, "\t%ju insert%s\n");
+		p(ft_collisions, "\t%ju collision%s\n");
+		p(ft_free_checks, "\t%ju free check%s\n");
+		p(ft_frees, "\t%ju free%s\n");
+		p(ft_fail_lle_invalid,
+			"\t%ju lookup%s with not resolved Layer 2 address\n");
 
 #undef	p2
 #undef	p
+	}
 }
 
 void
@@ -73,12 +101,22 @@
 		return;
 
 	if (sysctlbyname("net.flowtable.ip4.stat", &stat, &len, NULL, 0) == 0) {
-		printf("flowtable for IPv4:\n");
+#if defined(SOL_ON)
+		if (Oflag)
+			SOL_MAP_KEYL(&sol_stream, "IPv4");
+		else
+#endif
+			printf("flowtable for IPv4:\n");
 		print_stats(&stat);
 	}
 
 	if (sysctlbyname("net.flowtable.ip6.stat", &stat, &len, NULL, 0) == 0) {
-		printf("flowtable for IPv6:\n");
+#if defined(SOL_ON)
+		if (Oflag)
+			SOL_MAP_KEYL(&sol_stream, "IPv6");
+		else
+#endif
+			printf("flowtable for IPv6:\n");
 		print_stats(&stat);
 	}
 }

Modified: soc2014/zkorchev/freebsd_head/usr.bin/netstat/if.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/netstat/if.c	Sun Jun  8 15:51:28 2014	(r269255)
+++ soc2014/zkorchev/freebsd_head/usr.bin/netstat/if.c	Sun Jun  8 15:52:07 2014	(r269256)
@@ -72,6 +72,7 @@
 #include <string.h>
 #include <sysexits.h>
 #include <unistd.h>
+#include <sol.h>
 
 #include "netstat.h"
 
@@ -235,7 +236,9 @@
 	if (aflag && getifmaddrs(&ifmap) != 0)
 		err(EX_OSERR, "getifmaddrs");
 
-	if (!pfunc) {
+	// TODO finish sol output
+
+	if (!Oflag && !pfunc) {
 		if (Wflag)
 			printf("%-7.7s", "Name");
 		else

Modified: soc2014/zkorchev/freebsd_head/usr.bin/netstat/main.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/netstat/main.c	Sun Jun  8 15:51:28 2014	(r269255)
+++ soc2014/zkorchev/freebsd_head/usr.bin/netstat/main.c	Sun Jun  8 15:52:07 2014	(r269256)
@@ -67,6 +67,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sol.h>
 #include "netstat.h"
 
 static struct nlist nl[] = {
@@ -292,6 +293,7 @@
 int	noutputs = 0;	/* how much outputs before we exit */
 int	numeric_addr;	/* show addresses numerically */
 int	numeric_port;	/* show ports numerically */
+int Oflag;			/* use JSON as output format */
 static int pflag;	/* show given protocol */
 int	Qflag;		/* show netisr information */
 int	rflag;		/* show routing tables (or routing stats) */
@@ -302,6 +304,10 @@
 int	xflag;		/* extra information, includes all socket buffer info */
 int	zflag;		/* zero stats */
 
+#if defined(SOL_ON)
+struct sol_stream sol_stream;
+#endif
+
 int	interval;	/* repeat interval for i/f stats */
 
 char	*interface;	/* desired i/f for stats, or NULL for all i/fs */
@@ -320,7 +326,7 @@
 
 	af = AF_UNSPEC;
 
-	while ((ch = getopt(argc, argv, "46AaBbdF:f:ghI:iLlM:mN:np:Qq:RrSTsuWw:xz"))
+	while ((ch = getopt(argc, argv, "46AaBbdF:f:ghI:iLlM:mN:nOp:Qq:RrSTsuWw:xz"))
 	    != -1)
 		switch(ch) {
 		case '4':
@@ -415,6 +421,13 @@
 		case 'n':
 			numeric_addr = numeric_port = 1;
 			break;
+		case 'O':
+#if defined(SOL_ON)
+			Oflag = 1;
+#else
+			errx(1, "-O support is not compiled in");
+#endif
+			break;
 		case 'p':
 			if ((tp = name2protox(optarg)) == NULL) {
 				errx(1,
@@ -488,6 +501,10 @@
 	}
 #endif
 
+#if defined(SOL_ON)
+	if (Oflag) sol_init(&sol_stream, SOL_JSON);
+#endif
+
 	/*
 	 * Discard setgid privileges if not the running kernel so that bad
 	 * guys can't print interesting stuff from kernel memory.
@@ -503,6 +520,9 @@
 		if (!live)
 			usage();
 		bpf_stats(interface);
+#if defined(SOL_ON)
+		if (Oflag) sol_term(&sol_stream);
+#endif
 		exit(0);
 	}
 	if (mflag) {
@@ -511,6 +531,9 @@
 				mbpr(kvmd, nl[N_SFSTAT].n_value);
 		} else
 			mbpr(NULL, 0);
+#if defined(SOL_ON)
+		if (Oflag) sol_term(&sol_stream);
+#endif
 		exit(0);
 	}
 	if (Qflag) {
@@ -519,6 +542,9 @@
 				netisr_stats(kvmd);
 		} else
 			netisr_stats(NULL);
+#if defined(SOL_ON)
+		if (Oflag) sol_term(&sol_stream);
+#endif
 		exit(0);
 	}
 #if 0
@@ -537,14 +563,26 @@
 #endif
 	if (iflag && !sflag) {
 		intpr(interval, NULL, af);
+#if defined(SOL_ON)
+		if (Oflag) sol_term(&sol_stream);
+#endif
 		exit(0);
 	}
 	if (rflag) {
+#if defined(SOL_ON)
+		if (Oflag) sol_map_start(&sol_stream);
+#endif
 		if (sflag) {
 			rt_stats();
 			flowtable_stats();
 		} else
 			routepr(fib, af);
+#if defined(SOL_ON)
+		if (Oflag) {
+			sol_map_end(&sol_stream);
+			sol_term(&sol_stream);
+		}
+#endif
 		exit(0);
 	}
 
@@ -564,6 +602,9 @@
 				mroute6pr();
 #endif
 		}
+#if defined(SOL_ON)
+		if (Oflag) sol_term(&sol_stream);
+#endif
 		exit(0);
 	}
 
@@ -572,6 +613,9 @@
 
 	if (tp) {
 		printproto(tp, tp->pr_name);
+#if defined(SOL_ON)
+		if (Oflag) sol_term(&sol_stream);
+#endif
 		exit(0);
 	}
 	if (af == AF_INET || af == AF_UNSPEC)
@@ -596,6 +640,9 @@
 		unixpr(nl[N_UNP_COUNT].n_value, nl[N_UNP_GENCNT].n_value,
 		    nl[N_UNP_DHEAD].n_value, nl[N_UNP_SHEAD].n_value,
 		    nl[N_UNP_SPHEAD].n_value);
+#if defined(SOL_ON)
+	if (Oflag) sol_term(&sol_stream);
+#endif
 	exit(0);
 }
 
@@ -825,20 +872,20 @@
 {
 	(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
 "usage: netstat [-46AaLnRSTWx] [-f protocol_family | -p protocol]\n"
-"               [-M core] [-N system]",
+"               [-M core] [-N system] [-O]",
 "       netstat -i | -I interface [-46abdhnW] [-f address_family]\n"
-"               [-M core] [-N system]",
-"       netstat -w wait [-I interface] [-46d] [-M core] [-N system] [-q howmany]",
+"               [-M core] [-N system] [-O]",
+"       netstat -w wait [-I interface] [-46d] [-M core] [-N system] [-q howmany] [-O]",
 "       netstat -s [-s] [-46z] [-f protocol_family | -p protocol]\n"
-"               [-M core] [-N system]",
+"               [-M core] [-N system] [-O]",
 "       netstat -i | -I interface [-46s] [-f protocol_family | -p protocol]\n"
-"               [-M core] [-N system]",
-"       netstat -m [-M core] [-N system]",
-"       netstat -B [-I interface]",
-"       netstat -r [-46AanW] [-f address_family] [-M core] [-N system]",
-"       netstat -rs [-s] [-M core] [-N system]",
-"       netstat -g [-46W] [-f address_family] [-M core] [-N system]",
-"       netstat -gs [-46s] [-f address_family] [-M core] [-N system]",
-"       netstat -Q");
+"               [-M core] [-N system] [-O]",
+"       netstat -m [-M core] [-N system] [-O]",
+"       netstat -B [-I interface] [-O]",
+"       netstat -r [-46AanW] [-f address_family] [-M core] [-N system] [-O]",
+"       netstat -rs [-s] [-M core] [-N system] [-O]",
+"       netstat -g [-46W] [-f address_family] [-M core] [-N system] [-O]",
+"       netstat -gs [-46s] [-f address_family] [-M core] [-N system] [-O]",
+"       netstat -Q [-O]");
 	exit(1);
 }

Modified: soc2014/zkorchev/freebsd_head/usr.bin/netstat/mbuf.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/netstat/mbuf.c	Sun Jun  8 15:51:28 2014	(r269255)
+++ soc2014/zkorchev/freebsd_head/usr.bin/netstat/mbuf.c	Sun Jun  8 15:52:07 2014	(r269256)
@@ -57,9 +57,17 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sol.h>
 #include "netstat.h"
 
 /*
+ * Upward approximation of the maximum number of characters needed to
+ * represent a value of integral type t as a string, excluding the
+ * NUL terminator.
+ */
+#define	STRBUF_SIZEOF(t)	(CHAR_BIT * sizeof(t) / 3 + 1)
+
+/*
  * Print mbuf statistics.
  */
 void
@@ -92,6 +100,10 @@
 		return;
 	}
 
+#if defined(SOL_ON)
+	if (Oflag) sol_map_start(&sol_stream);
+#endif
+
 	/*
 	 * Use memstat_*_all() because some mbuf-related memory is in uma(9),
 	 * and some malloc(9).
@@ -199,33 +211,137 @@
 	jumbo16_sleeps = memstat_get_sleeps(mtp);
 	jumbo16_size = memstat_get_size(mtp);
 
-	printf("%ju/%ju/%ju mbufs in use (current/cache/total)\n",
-	    mbuf_count + packet_count, mbuf_free + packet_free,
-	    mbuf_count + packet_count + mbuf_free + packet_free);
-
-	printf("%ju/%ju/%ju/%ju mbuf clusters in use "
-	    "(current/cache/total/max)\n",
-	    cluster_count - packet_free, cluster_free + packet_free,
-	    cluster_count + cluster_free, cluster_limit);
-
-	printf("%ju/%ju mbuf+clusters out of packet secondary zone in use "
-	    "(current/cache)\n",
-	    packet_count, packet_free);
-
-	printf("%ju/%ju/%ju/%ju %juk (page size) jumbo clusters in use "
-	    "(current/cache/total/max)\n",
-	    jumbop_count, jumbop_free, jumbop_count + jumbop_free,
-	    jumbop_limit, jumbop_size / 1024);
-
-	printf("%ju/%ju/%ju/%ju 9k jumbo clusters in use "
-	    "(current/cache/total/max)\n",
-	    jumbo9_count, jumbo9_free, jumbo9_count + jumbo9_free,
-	    jumbo9_limit);
-
-	printf("%ju/%ju/%ju/%ju 16k jumbo clusters in use "
-	    "(current/cache/total/max)\n",
-	    jumbo16_count, jumbo16_free, jumbo16_count + jumbo16_free,
-	    jumbo16_limit);
+#if defined(SOL_ON)
+	if (Oflag) {
+		sol_map_key(&sol_stream, "mbufs", 5);
+		sol_map_start(&sol_stream);
+
+		sol_map_key(&sol_stream, "current", 7);
+		sol_integer(&sol_stream, mbuf_count + packet_count);
+		sol_map_key(&sol_stream, "cache", 5);
+		sol_integer(&sol_stream, mbuf_free + packet_free);
+		sol_map_key(&sol_stream, "total", 5);
+		sol_integer(&sol_stream, mbuf_count + packet_count + mbuf_free + packet_free);
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+		printf("%ju/%ju/%ju mbufs in use (current/cache/total)\n",
+			mbuf_count + packet_count, mbuf_free + packet_free,
+			mbuf_count + packet_count + mbuf_free + packet_free);
+
+#if defined(SOL_ON)
+	if (Oflag) {
+		sol_map_key(&sol_stream, "mbuf clusters", sizeof("mbuf clusters") - 1);
+		sol_map_start(&sol_stream);
+
+		sol_map_key(&sol_stream, "current", 7);
+		sol_integer(&sol_stream, cluster_count - packet_free);
+		sol_map_key(&sol_stream, "cache", 5);
+		sol_integer(&sol_stream, cluster_free + packet_free);
+		sol_map_key(&sol_stream, "total", 5);
+		sol_integer(&sol_stream, cluster_count + cluster_free);
+		sol_map_key(&sol_stream, "max", 3);
+		sol_integer(&sol_stream, cluster_limit);
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+		printf("%ju/%ju/%ju/%ju mbuf clusters in use "
+			"(current/cache/total/max)\n",
+			cluster_count - packet_free, cluster_free + packet_free,
+			cluster_count + cluster_free, cluster_limit);
+
+#if defined(SOL_ON)
+	if (Oflag) {
+		SOL_MAP_KEYL(&sol_stream, "mbuf+clusters");
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "current");
+		sol_integer(&sol_stream, packet_count);
+		SOL_MAP_KEYL(&sol_stream, "cache");
+		sol_integer(&sol_stream, packet_free);
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+		printf("%ju/%ju mbuf+clusters out of packet secondary zone in use "
+			"(current/cache)\n",
+			packet_count, packet_free);
+
+#if defined(SOL_ON)
+	if (Oflag) {
+		SOL_MAP_KEYL(&sol_stream, "jumbo clusters");
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "current");
+		sol_integer(&sol_stream, jumbop_count);
+		SOL_MAP_KEYL(&sol_stream, "cache");
+		sol_integer(&sol_stream, jumbop_free);
+		SOL_MAP_KEYL(&sol_stream, "total");
+		sol_integer(&sol_stream, jumbop_count + jumbop_free);
+		SOL_MAP_KEYL(&sol_stream, "max");
+		sol_integer(&sol_stream, jumbop_limit);
+		SOL_MAP_KEYL(&sol_stream, "page size (k)");
+		sol_integer(&sol_stream, jumbop_size / 1024);
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+		printf("%ju/%ju/%ju/%ju %juk (page size) jumbo clusters in use "
+			"(current/cache/total/max)\n",
+			jumbop_count, jumbop_free, jumbop_count + jumbop_free,
+			jumbop_limit, jumbop_size / 1024);
+
+#if defined(SOL_ON)
+	if (Oflag) {
+		SOL_MAP_KEYL(&sol_stream, "jumbo clusters 9k");
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "current");
+		sol_integer(&sol_stream, jumbo9_count);
+		SOL_MAP_KEYL(&sol_stream, "cache");
+		sol_integer(&sol_stream, jumbo9_free);
+		SOL_MAP_KEYL(&sol_stream, "total");
+		sol_integer(&sol_stream, jumbo9_count + jumbo9_free);
+		SOL_MAP_KEYL(&sol_stream, "max");
+		sol_integer(&sol_stream, jumbo9_limit);
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+		printf("%ju/%ju/%ju/%ju 9k jumbo clusters in use "
+			"(current/cache/total/max)\n",
+			jumbo9_count, jumbo9_free, jumbo9_count + jumbo9_free,
+			jumbo9_limit);
+
+#if defined(SOL_ON)
+	if (Oflag) {
+		SOL_MAP_KEYL(&sol_stream, "jumbo clusters 16k");
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "current");
+		sol_integer(&sol_stream, jumbo16_count);
+		SOL_MAP_KEYL(&sol_stream, "cache");
+		sol_integer(&sol_stream, jumbo16_free);
+		SOL_MAP_KEYL(&sol_stream, "total");
+		sol_integer(&sol_stream, jumbo16_count + jumbo16_free);
+		SOL_MAP_KEYL(&sol_stream, "max");
+		sol_integer(&sol_stream, jumbo16_limit);
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+		printf("%ju/%ju/%ju/%ju 16k jumbo clusters in use "
+			"(current/cache/total/max)\n",
+			jumbo16_count, jumbo16_free, jumbo16_count + jumbo16_free,
+			jumbo16_limit);
 
 #if 0
 	printf("%ju mbuf tags in use\n", tag_count);
@@ -276,23 +392,106 @@
 	 */
 	bytes_total = bytes_inuse + bytes_incache;
 
-	printf("%juK/%juK/%juK bytes allocated to network "
-	    "(current/cache/total)\n", bytes_inuse / 1024,
-	    bytes_incache / 1024, bytes_total / 1024);
-
-	printf("%ju/%ju/%ju requests for mbufs denied (mbufs/clusters/"
-	    "mbuf+clusters)\n", mbuf_failures, cluster_failures,
-	    packet_failures);
-	printf("%ju/%ju/%ju requests for mbufs delayed (mbufs/clusters/"
-	    "mbuf+clusters)\n", mbuf_sleeps, cluster_sleeps,
-	    packet_sleeps);
-
-	printf("%ju/%ju/%ju requests for jumbo clusters delayed "
-	    "(%juk/9k/16k)\n", jumbop_sleeps, jumbo9_sleeps,
-	    jumbo16_sleeps, jumbop_size / 1024);
-	printf("%ju/%ju/%ju requests for jumbo clusters denied "
-	    "(%juk/9k/16k)\n", jumbop_failures, jumbo9_failures,
-	    jumbo16_failures, jumbop_size / 1024);
+#if defined(SOL_ON)
+	if (Oflag) {
+		SOL_MAP_KEYL(&sol_stream, "network");
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "current (K)");
+		sol_integer(&sol_stream, bytes_inuse / 1024);
+		SOL_MAP_KEYL(&sol_stream, "cache (K)");
+		sol_integer(&sol_stream, bytes_incache / 1024);
+		SOL_MAP_KEYL(&sol_stream, "total (K)");
+		sol_integer(&sol_stream, bytes_total / 1024);
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+		printf("%juK/%juK/%juK bytes allocated to network "
+			"(current/cache/total)\n", bytes_inuse / 1024,
+			bytes_incache / 1024, bytes_total / 1024);
+
+#if defined(SOL_ON)
+	if (Oflag)
+	{
+		SOL_MAP_KEYL(&sol_stream, "mbuf requests");
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "denied");
+		sol_map_start(&sol_stream);
+		SOL_MAP_KEYL(&sol_stream, "mbufs");
+		sol_integer(&sol_stream, bytes_inuse / 1024);
+		SOL_MAP_KEYL(&sol_stream, "clusters");
+		sol_integer(&sol_stream, bytes_incache / 1024);
+		SOL_MAP_KEYL(&sol_stream, "packets");
+		sol_integer(&sol_stream, bytes_total / 1024);
+		sol_map_end(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "delayed");
+		sol_map_start(&sol_stream);
+		SOL_MAP_KEYL(&sol_stream, "mbufs");
+		sol_integer(&sol_stream, mbuf_sleeps);
+		SOL_MAP_KEYL(&sol_stream, "clusters");
+		sol_integer(&sol_stream, cluster_sleeps);
+		SOL_MAP_KEYL(&sol_stream, "packets");
+		sol_integer(&sol_stream, packet_sleeps);
+		sol_map_end(&sol_stream);
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+	{
+		printf("%ju/%ju/%ju requests for mbufs denied (mbufs/clusters/"
+			"mbuf+clusters)\n", mbuf_failures, cluster_failures,
+			packet_failures);
+		printf("%ju/%ju/%ju requests for mbufs delayed (mbufs/clusters/"
+			"mbuf+clusters)\n", mbuf_sleeps, cluster_sleeps,
+			packet_sleeps);
+	}
+
+#if defined(SOL_ON)
+	if (Oflag)
+	{
+		char pagesize[STRBUF_SIZEOF(uintmax_t) + sizeof("k")];
+		size_t len = snprintf(pagesize, sizeof(pagesize), "%juk", jumbop_size / 1024);
+
+		SOL_MAP_KEYL(&sol_stream, "jumbo cluster requests");
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "denied");
+		sol_map_start(&sol_stream);
+		sol_map_key(&sol_stream, pagesize, len);
+		sol_integer(&sol_stream, jumbop_sleeps);
+		SOL_MAP_KEYL(&sol_stream, "9k");
+		sol_integer(&sol_stream, jumbo9_sleeps);
+		SOL_MAP_KEYL(&sol_stream, "16k");
+		sol_integer(&sol_stream, jumbo16_sleeps);
+		sol_map_end(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "delayed");
+		sol_map_start(&sol_stream);
+		sol_map_key(&sol_stream, pagesize, len);
+		sol_integer(&sol_stream, mbuf_sleeps);
+		SOL_MAP_KEYL(&sol_stream, "9k");
+		sol_integer(&sol_stream, cluster_sleeps);
+		SOL_MAP_KEYL(&sol_stream, "16k");
+		sol_integer(&sol_stream, packet_sleeps);
+		sol_map_end(&sol_stream);
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+	{
+		printf("%ju/%ju/%ju requests for jumbo clusters delayed "
+			"(%juk/9k/16k)\n", jumbop_sleeps, jumbo9_sleeps,
+			jumbo16_sleeps, jumbop_size / 1024);
+		printf("%ju/%ju/%ju requests for jumbo clusters denied "
+			"(%juk/9k/16k)\n", jumbop_failures, jumbo9_failures,
+			jumbo16_failures, jumbop_size / 1024);
+	}
 
 	if (live) {
 		mlen = sizeof(nsfbufs);
@@ -301,9 +500,26 @@
 		    !sysctlbyname("kern.ipc.nsfbufsused", &nsfbufsused,
 		    &mlen, NULL, 0) &&
 		    !sysctlbyname("kern.ipc.nsfbufspeak", &nsfbufspeak,
-		    &mlen, NULL, 0))
-			printf("%d/%d/%d sfbufs in use (current/peak/max)\n",
-			    nsfbufsused, nsfbufspeak, nsfbufs);
+		    &mlen, NULL, 0)) {
+#if defined(SOL_ON)
+			if (Oflag) {
+				SOL_MAP_KEYL(&sol_stream, "sfbufs");
+				sol_map_start(&sol_stream);
+
+				SOL_MAP_KEYL(&sol_stream, "current");
+				sol_integer(&sol_stream, nsfbufsused);
+				SOL_MAP_KEYL(&sol_stream, "peak");
+				sol_integer(&sol_stream, nsfbufspeak);
+				SOL_MAP_KEYL(&sol_stream, "max");
+				sol_integer(&sol_stream, nsfbufs);
+
+				sol_map_end(&sol_stream);
+			}
+			else
+#endif
+				printf("%d/%d/%d sfbufs in use (current/peak/max)\n",
+					nsfbufsused, nsfbufspeak, nsfbufs);
+		}
 		mlen = sizeof(sfstat);
 		if (sysctlbyname("kern.ipc.sfstat", &sfstat, &mlen, NULL, 0)) {
 			warn("kern.ipc.sfstat");
@@ -313,12 +529,35 @@
 		if (kread_counters(mbaddr, (char *)&sfstat, sizeof sfstat) != 0)
 			goto out;
 	}
-	printf("%ju requests for sfbufs denied\n",
-	    (uintmax_t)sfstat.sf_allocfail);
-	printf("%ju requests for sfbufs delayed\n",
-	    (uintmax_t)sfstat.sf_allocwait);
-	printf("%ju requests for I/O initiated by sendfile\n",
-	    (uintmax_t)sfstat.sf_iocnt);
+#if defined(SOL_ON)
+	if (Oflag)
+	{
+		SOL_MAP_KEYL(&sol_stream, "sfbuf requests");
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "denied");
+		sol_integer(&sol_stream, sfstat.sf_allocfail);
+		SOL_MAP_KEYL(&sol_stream, "delayed");
+		sol_integer(&sol_stream, sfstat.sf_allocwait);
+
+		sol_map_end(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "I/O sendfile requests");
+		sol_integer(&sol_stream, sfstat.sf_iocnt);
+	}
+	else
+#endif
+	{
+		printf("%ju requests for sfbufs denied\n",
+			(uintmax_t)sfstat.sf_allocfail);
+		printf("%ju requests for sfbufs delayed\n",
+			(uintmax_t)sfstat.sf_allocwait);
+		printf("%ju requests for I/O initiated by sendfile\n",
+			(uintmax_t)sfstat.sf_iocnt);
+	}
 out:
+#if defined(SOL_ON)
+	if (Oflag) sol_map_end(&sol_stream);
+#endif
 	memstat_mtl_free(mtlp);
 }

Modified: soc2014/zkorchev/freebsd_head/usr.bin/netstat/netisr.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/netstat/netisr.c	Sun Jun  8 15:51:28 2014	(r269255)
+++ soc2014/zkorchev/freebsd_head/usr.bin/netstat/netisr.c	Sun Jun  8 15:52:07 2014	(r269256)
@@ -47,6 +47,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sol.h>
 
 #include "netstat.h"
 
@@ -457,22 +458,55 @@
 static void
 netisr_print_proto(struct sysctl_netisr_proto *snpp)
 {
-	char tmp[20];
-
-	printf("%-6s", snpp->snp_name);
-	printf(" %5u", snpp->snp_proto);
-	printf(" %6u", snpp->snp_qlimit);
-	printf(" %6s",
-	    (snpp->snp_policy == NETISR_POLICY_SOURCE) ?  "source" :
-	    (snpp->snp_policy == NETISR_POLICY_FLOW) ? "flow" :
-	    (snpp->snp_policy == NETISR_POLICY_CPU) ? "cpu" : "-");
-	netisr_dispatch_policy_to_string(snpp->snp_dispatch, tmp,
-	    sizeof(tmp));
-	printf(" %8s", tmp);
-	printf("   %s%s%s\n",
-	    (snpp->snp_flags & NETISR_SNP_FLAGS_M2CPUID) ?  "C" : "-",
-	    (snpp->snp_flags & NETISR_SNP_FLAGS_DRAINEDCPU) ?  "D" : "-",
-	    (snpp->snp_flags & NETISR_SNP_FLAGS_M2FLOW) ? "F" : "-");
+	char dispatch[20];
+	const char *policy;
+	char flags[4];
+
+	netisr_dispatch_policy_to_string(snpp->snp_dispatch, dispatch, sizeof(dispatch));
+
+	policy = (snpp->snp_policy == NETISR_POLICY_SOURCE) ?  "source" :
+		(snpp->snp_policy == NETISR_POLICY_FLOW) ? "flow" :
+		(snpp->snp_policy == NETISR_POLICY_CPU) ? "cpu" : "-";
+
+	flags[0] = ((snpp->snp_flags & NETISR_SNP_FLAGS_M2CPUID) ? 'C' : '-');
+	flags[1] = ((snpp->snp_flags & NETISR_SNP_FLAGS_DRAINEDCPU) ?  'D' : '-');
+	flags[2] = ((snpp->snp_flags & NETISR_SNP_FLAGS_M2FLOW) ? 'F' : '-');
+	flags[3] = 0;
+
+#if defined(SOL_ON)
+	if (Oflag)
+	{
+		sol_map_key(&sol_stream, snpp->snp_name, strlen(snpp->snp_name));
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "proto");
+		sol_integer(&sol_stream, snpp->snp_proto);
+
+		SOL_MAP_KEYL(&sol_stream, "qlimit");
+		sol_integer(&sol_stream, snpp->snp_qlimit);
+
+		SOL_MAP_KEYL(&sol_stream, "policy");
+		sol_string(&sol_stream, policy, strlen(policy));
+
+		SOL_MAP_KEYL(&sol_stream, "dispatch");
+		sol_string(&sol_stream, dispatch, strlen(dispatch));
+
+		SOL_MAP_KEYL(&sol_stream, "flags");
+		sol_string(&sol_stream, flags, sizeof(flags) - 1);
+
+		sol_map_end(&sol_stream);
+	}
+	else
+#endif
+	{
+		printf("%-6s %5u %6u %6s %8s   %s\n",
+			snpp->snp_name,
+			snpp->snp_proto,
+			snpp->snp_qlimit,
+			policy,
+			dispatch,
+			flags);
+	}
 }
 
 static void
@@ -485,18 +519,62 @@
 		snwp = &work_array[i];
 		if (snwp->snw_wsid != snwsp->snws_wsid)
 			continue;
-		printf("%4u ", snwsp->snws_wsid);
-		printf("%3u ", snwsp->snws_cpu);
-		printf("%2s", "");
-		printf("%-6s", netisr_proto2name(snwp->snw_proto));
-		printf(" %5u", snwp->snw_len);
-		printf(" %5u", snwp->snw_watermark);
-		printf(" %8ju", snwp->snw_dispatched);
-		printf(" %8ju", snwp->snw_hybrid_dispatched);
-		printf(" %8ju", snwp->snw_qdrops);
-		printf(" %8ju", snwp->snw_queued);
-		printf(" %8ju", snwp->snw_handled);
-		printf("\n");
+
+#if defined(SOL_ON)
+		if (Oflag)
+		{
+			const char *name = netisr_proto2name(snwp->snw_proto);
+
+			sol_map_start(&sol_stream);
+
+			SOL_MAP_KEYL(&sol_stream, "WSID");
+			sol_integer(&sol_stream, snwsp->snws_wsid);
+
+			SOL_MAP_KEYL(&sol_stream, "CPU");
+			sol_integer(&sol_stream, snwsp->snws_cpu);
+
+			SOL_MAP_KEYL(&sol_stream, "name");
+			sol_string(&sol_stream, name, strlen(name));
+
+			SOL_MAP_KEYL(&sol_stream, "len");
+			sol_integer(&sol_stream, snwp->snw_len);
+
+			SOL_MAP_KEYL(&sol_stream, "wmark");
+			sol_integer(&sol_stream, snwp->snw_watermark);
+
+			SOL_MAP_KEYL(&sol_stream, "displayed");
+			sol_integer(&sol_stream, snwp->snw_dispatched);
+
+			SOL_MAP_KEYL(&sol_stream, "Hdisplayed");
+			sol_integer(&sol_stream, snwp->snw_hybrid_dispatched);
+
+			SOL_MAP_KEYL(&sol_stream, "qdrops");
+			sol_integer(&sol_stream, snwp->snw_qdrops);
+
+			SOL_MAP_KEYL(&sol_stream, "queued");
+			sol_integer(&sol_stream, snwp->snw_queued);
+
+			SOL_MAP_KEYL(&sol_stream, "handled");
+			sol_integer(&sol_stream, snwp->snw_handled);
+
+			sol_map_end(&sol_stream);
+		}
+		else
+#endif
+		{
+			printf("%4u ", snwsp->snws_wsid);
+			printf("%3u ", snwsp->snws_cpu);
+			printf("%2s", "");
+			printf("%-6s", netisr_proto2name(snwp->snw_proto));
+			printf(" %5u", snwp->snw_len);
+			printf(" %5u", snwp->snw_watermark);
+			printf(" %8ju", snwp->snw_dispatched);
+			printf(" %8ju", snwp->snw_hybrid_dispatched);
+			printf(" %8ju", snwp->snw_qdrops);
+			printf(" %8ju", snwp->snw_queued);
+			printf(" %8ju", snwp->snw_handled);
+			printf("\n");
+		}
 	}
 }
 
@@ -521,33 +599,99 @@
 		netisr_load_kvm_workstream(kd);		/* Also does work. */
 	}
 
-	printf("Configuration:\n");
-	printf("%-25s %12s %12s\n", "Setting", "Current", "Limit");
-	printf("%-25s %12u %12u\n", "Thread count", numthreads, maxthreads);
-	printf("%-25s %12u %12u\n", "Default queue limit", defaultqlimit,
-	    maxqlimit);
-	printf("%-25s %12s %12s\n", "Dispatch policy", dispatch_policy,
-	    "n/a");
-	printf("%-25s %12s %12s\n", "Threads bound to CPUs",
-	    bindthreads ? "enabled" : "disabled", "n/a");
-	printf("\n");
-
-	printf("Protocols:\n");
-	printf("%-6s %5s %6s %-6s %-8s %-5s\n", "Name", "Proto", "QLimit",
-	    "Policy", "Dispatch", "Flags");
-	for (i = 0; i < proto_array_len; i++) {
-		snpp = &proto_array[i];
-		netisr_print_proto(snpp);
+#if defined(SOL_ON)
+	if (Oflag)
+	{
+		char *threads_bound = (bindthreads ? "enabled" : "disabled");
+
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "configuration");
+		sol_map_start(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "thread count");
+		sol_map_start(&sol_stream);
+		SOL_MAP_KEYL(&sol_stream, "current");
+		sol_integer(&sol_stream, numthreads);
+		SOL_MAP_KEYL(&sol_stream, "limit");
+		sol_integer(&sol_stream, maxthreads);
+		sol_map_end(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "queue limit");
+		sol_map_start(&sol_stream);
+		SOL_MAP_KEYL(&sol_stream, "current");
+		sol_integer(&sol_stream, defaultqlimit);
+		SOL_MAP_KEYL(&sol_stream, "limit");
+		sol_integer(&sol_stream, maxqlimit);
+		sol_map_end(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "dispatch policy");
+		sol_map_start(&sol_stream);
+		SOL_MAP_KEYL(&sol_stream, "current");
+		sol_string(&sol_stream, dispatch_policy, strlen(dispatch_policy));
+		SOL_MAP_KEYL(&sol_stream, "limit");
+		sol_string(&sol_stream, "n/a", 3);
+		sol_map_end(&sol_stream);
+
+		SOL_MAP_KEYL(&sol_stream, "threads bound to CPUs");
+		sol_map_start(&sol_stream);
+		SOL_MAP_KEYL(&sol_stream, "current");
+		sol_string(&sol_stream, threads_bound, strlen(threads_bound));

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



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