Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Jun 2014 14:01:51 GMT
From:      zkorchev@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r268956 - soc2014/zkorchev/freebsd_head/usr.bin/vmstat
Message-ID:  <201406021401.s52E1pc5036658@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: zkorchev
Date: Mon Jun  2 14:01:50 2014
New Revision: 268956
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=268956

Log:
  SOL API simplified

Modified:
  soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.c
  soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.h
  soc2014/zkorchev/freebsd_head/usr.bin/vmstat/vmstat.c

Modified: soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.c	Mon Jun  2 13:48:57 2014	(r268955)
+++ soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.c	Mon Jun  2 14:01:50 2014	(r268956)
@@ -27,10 +27,10 @@
 
 #include "sol.h"
 
-//static struct sol_stream sol;
-
 // TODO error checks
 
+// TODO track whether a key or a value is expected and generate error when appropriate?
+
 int sol_init(struct sol_stream *restrict stream, enum sol_format format)
 {
 	stream->f = format;
@@ -86,21 +86,6 @@
 	return 0;
 }
 
-int sol_string(struct sol_stream *restrict stream, const char *data, size_t length)
-{
-	// TODO ?handle special characters
-	yajl_gen_string(stream->ctx.g, (const unsigned char *)data, length);
-
-	return 0;
-}
-
-int sol_integer(struct sol_stream *restrict stream, long long value)
-{
-	yajl_gen_integer(stream->ctx.g, value);
-
-	return 0;
-}
-
 int sol_map_start(struct sol_stream *restrict stream)
 {
 	yajl_gen_map_open(stream->ctx.g);
@@ -117,38 +102,28 @@
 
 int sol_map_key(struct sol_stream *restrict stream, const char *key, size_t length)
 {
-	// TODO error if value is expected
-
-	// TODO ?handle special characters
 	yajl_gen_string(stream->ctx.g, (const unsigned char *)key, length);
 
 	return 0;
 }
 
-int sol_map_string(struct sol_stream *restrict stream, const char *value, size_t length)
+int sol_string(struct sol_stream *restrict stream, const char *data, size_t length)
 {
-	// TODO error if key is expected?
-
-	// TODO ?handle special characters
-	yajl_gen_string(stream->ctx.g, (const unsigned char *)value, length);
+	yajl_gen_string(stream->ctx.g, (const unsigned char *)data, length);
 
 	return 0;
 }
 
-int sol_map_integer(struct sol_stream *restrict stream, long long value)
+int sol_integer(struct sol_stream *restrict stream, long long value)
 {
-	// TODO error if key is expected?
-
 	yajl_gen_integer(stream->ctx.g, value);
 
 	return 0;
 }
 
-int sol_map_float(struct sol_stream *restrict stream, double value)
+int sol_float(struct sol_stream *restrict stream, double value)
 {
-	// TODO error if key is expected?
-
-	// TODO round mantissa?
+	// todo round mantissa?
 	yajl_gen_double(stream->ctx.g, value);
 
 	return 0;

Modified: soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.h
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.h	Mon Jun  2 13:48:57 2014	(r268955)
+++ soc2014/zkorchev/freebsd_head/usr.bin/vmstat/sol.h	Mon Jun  2 14:01:50 2014	(r268956)
@@ -45,13 +45,10 @@
 int sol_array_start(struct sol_stream *restrict stream);
 int sol_array_end(struct sol_stream *restrict stream);
 
-int sol_integer(struct sol_stream *restrict stream, long long value);
-int sol_string(struct sol_stream *restrict stream, const char *data, size_t length);
-
 int sol_map_start(struct sol_stream *restrict stream);
 int sol_map_end(struct sol_stream *restrict stream);
-
 int sol_map_key(struct sol_stream *restrict stream, const char *key, size_t length);
-int sol_map_string(struct sol_stream *restrict stream, const char *value, size_t length);
-int sol_map_integer(struct sol_stream *restrict stream, long long value);
-int sol_map_float(struct sol_stream *restrict stream, double value);
+
+int sol_integer(struct sol_stream *restrict stream, long long value);
+int sol_string(struct sol_stream *restrict stream, const char *data, size_t length);
+int sol_float(struct sol_stream *restrict stream, double value);

Modified: soc2014/zkorchev/freebsd_head/usr.bin/vmstat/vmstat.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/vmstat/vmstat.c	Mon Jun  2 13:48:57 2014	(r268955)
+++ soc2014/zkorchev/freebsd_head/usr.bin/vmstat/vmstat.c	Mon Jun  2 14:01:50 2014	(r268956)
@@ -804,13 +804,13 @@
 		{
 			sol_map_start(&sol_stream);
 
-			sol_map_key(&sol_stream, "pages_r", 7);
+			sol_map_key(&sol_stream, "procs_r", 7);
 			sol_integer(&sol_stream, total.t_rq - 1);
 
-			sol_map_key(&sol_stream, "pages_b", 7);
+			sol_map_key(&sol_stream, "procs_b", 7);
 			sol_integer(&sol_stream, total.t_dw + total.t_pw);
 
-			sol_map_key(&sol_stream, "pages_w", 7);
+			sol_map_key(&sol_stream, "procs_w", 7);
 			sol_integer(&sol_stream, total.t_sw);
 
 			if (hflag) {
@@ -826,33 +826,33 @@
 			}
 
 			sol_map_key(&sol_stream, "page_flt", 8);
-			sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_vm_faults - osum.v_vm_faults));
+			sol_integer(&sol_stream, (unsigned long)rate(sum.v_vm_faults - osum.v_vm_faults));
 
 			sol_map_key(&sol_stream, "page_re", 7);
-			sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_reactivated - osum.v_reactivated));
+			sol_integer(&sol_stream, (unsigned long)rate(sum.v_reactivated - osum.v_reactivated));
 
 			sol_map_key(&sol_stream, "page_pi", 7);
-			sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_swapin + sum.v_vnodein - (osum.v_swapin + osum.v_vnodein)));
+			sol_integer(&sol_stream, (unsigned long)rate(sum.v_swapin + sum.v_vnodein - (osum.v_swapin + osum.v_vnodein)));
 
 			sol_map_key(&sol_stream, "page_po", 7);
-			sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_swapout + sum.v_vnodeout - (osum.v_swapout + osum.v_vnodeout)));
+			sol_integer(&sol_stream, (unsigned long)rate(sum.v_swapout + sum.v_vnodeout - (osum.v_swapout + osum.v_vnodeout)));
 
 			sol_map_key(&sol_stream, "page_fr", 7);
-			sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_tfree - osum.v_tfree));
+			sol_integer(&sol_stream, (unsigned long)rate(sum.v_tfree - osum.v_tfree));
 
 			sol_map_key(&sol_stream, "page_sr", 7);
-			sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_pdpages - osum.v_pdpages));
+			sol_integer(&sol_stream, (unsigned long)rate(sum.v_pdpages - osum.v_pdpages));
 
 			devstats();
 
 			sol_map_key(&sol_stream, "fault_in", 8);
-			sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_intr - osum.v_intr));
+			sol_integer(&sol_stream, (unsigned long)rate(sum.v_intr - osum.v_intr));
 
 			sol_map_key(&sol_stream, "fault_sy", 8);
-			sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_syscall - osum.v_syscall));
+			sol_integer(&sol_stream, (unsigned long)rate(sum.v_syscall - osum.v_syscall));
 
 			sol_map_key(&sol_stream, "fault_cs", 8);
-			sol_map_integer(&sol_stream, (unsigned long)rate(sum.v_swtch - osum.v_swtch));
+			sol_integer(&sol_stream, (unsigned long)rate(sum.v_swtch - osum.v_swtch));
 
 			// 3
 
@@ -1188,11 +1188,11 @@
 		sol_map_key(&sol_stream, "fork", 4);
 		sol_map_start(&sol_stream);
 		sol_map_key(&sol_stream, "count", 5);
-		sol_map_integer(&sol_stream, sum.v_forks);
+		sol_integer(&sol_stream, sum.v_forks);
 		sol_map_key(&sol_stream, "pages", 5);
-		sol_map_integer(&sol_stream, sum.v_forkpages);
+		sol_integer(&sol_stream, sum.v_forkpages);
 		sol_map_key(&sol_stream, "average", 7);
-		sol_map_float(&sol_stream, ((sum.v_forks == 0) ?
+		sol_float(&sol_stream, ((sum.v_forks == 0) ?
 			0.0 :
 			(double)sum.v_forkpages / sum.v_forks));
 		sol_map_end(&sol_stream);
@@ -1200,11 +1200,11 @@
 		sol_map_key(&sol_stream, "vfork", 5);
 		sol_map_start(&sol_stream);
 		sol_map_key(&sol_stream, "count", 5);
-		sol_map_integer(&sol_stream, sum.v_vforks);
+		sol_integer(&sol_stream, sum.v_vforks);
 		sol_map_key(&sol_stream, "pages", 5);
-		sol_map_integer(&sol_stream, sum.v_vforkpages);
+		sol_integer(&sol_stream, sum.v_vforkpages);
 		sol_map_key(&sol_stream, "average", 7);
-		sol_map_float(&sol_stream, ((sum.v_vforks == 0) ?
+		sol_float(&sol_stream, ((sum.v_vforks == 0) ?
 			0.0 :
 			(double)sum.v_vforkpages / sum.v_vforks));
 		sol_map_end(&sol_stream);
@@ -1212,11 +1212,11 @@
 		sol_map_key(&sol_stream, "rfork", 5);
 		sol_map_start(&sol_stream);
 		sol_map_key(&sol_stream, "count", 5);
-		sol_map_integer(&sol_stream, sum.v_rforks);
+		sol_integer(&sol_stream, sum.v_rforks);
 		sol_map_key(&sol_stream, "pages", 5);
-		sol_map_integer(&sol_stream, sum.v_rforkpages);
+		sol_integer(&sol_stream, sum.v_rforkpages);
 		sol_map_key(&sol_stream, "average", 7);
-		sol_map_float(&sol_stream, ((sum.v_rforks == 0) ?
+		sol_float(&sol_stream, ((sum.v_rforks == 0) ?
 			0.0 :
 			(double)sum.v_rforkpages / sum.v_rforks));
 		sol_map_end(&sol_stream);
@@ -1280,7 +1280,7 @@
 				     dev_select[dn].unit_number);
 
 			sol_map_key(&sol_stream, buf, len);
-			sol_map_float(&sol_stream, transfers_per_second);
+			sol_float(&sol_stream, transfers_per_second);
 		}
 		else
 #endif
@@ -1323,11 +1323,11 @@
 	if (Oflag)
 	{
 		sol_map_key(&sol_stream, "cpu_user", 8);
-		sol_map_float(&sol_stream, (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct);
+		sol_float(&sol_stream, (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct);
 		sol_map_key(&sol_stream, "cpu_sys", 7);
-		sol_map_float(&sol_stream, (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct);
+		sol_float(&sol_stream, (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct);
 		sol_map_key(&sol_stream, "cpu_idle", 8);
-		sol_map_float(&sol_stream, cur.cp_time[CP_IDLE] * lpct);
+		sol_float(&sol_stream, cur.cp_time[CP_IDLE] * lpct);
 	}
 	else
 #endif
@@ -1386,15 +1386,15 @@
 			sol_map_start(&sol_stream);
 
 			sol_map_key(&sol_stream, "user", 4);
-			sol_map_float(&sol_stream, (cur_cp_times[i * CPUSTATES + CP_USER] +
+			sol_float(&sol_stream, (cur_cp_times[i * CPUSTATES + CP_USER] +
 				 cur_cp_times[i * CPUSTATES + CP_NICE]) * lpct);
 
 			sol_map_key(&sol_stream, "sys", 3);
-			sol_map_float(&sol_stream, (cur_cp_times[i * CPUSTATES + CP_SYS] +
+			sol_float(&sol_stream, (cur_cp_times[i * CPUSTATES + CP_SYS] +
 				 cur_cp_times[i * CPUSTATES + CP_INTR]) * lpct);
 
 			sol_map_key(&sol_stream, "idle", 4);
-			sol_map_float(&sol_stream, cur_cp_times[i * CPUSTATES + CP_IDLE] * lpct);
+			sol_float(&sol_stream, cur_cp_times[i * CPUSTATES + CP_IDLE] * lpct);
 		}
 		else
 #endif
@@ -1565,13 +1565,13 @@
 			sol_map_start(&sol_stream);
 
 			sol_map_key(&sol_stream, "inuse", 5);
-			sol_map_integer(&sol_stream, memstat_get_count(mtp));
+			sol_integer(&sol_stream, memstat_get_count(mtp));
 
 			sol_map_key(&sol_stream, "memuse", 6);
-			sol_map_integer(&sol_stream, (memstat_get_bytes(mtp) + 1023) / 1024);
+			sol_integer(&sol_stream, (memstat_get_bytes(mtp) + 1023) / 1024);
 
 			sol_map_key(&sol_stream, "requests", 8);
-			sol_map_integer(&sol_stream, memstat_get_numallocs(mtp));
+			sol_integer(&sol_stream, memstat_get_numallocs(mtp));
 
 			sol_map_key(&sol_stream, "size", 4);
 			sol_array_start(&sol_stream);
@@ -1652,28 +1652,28 @@
 
 			const char *name = memstat_get_name(mtp);
 			sol_map_key(&sol_stream, "item", 4);
-			sol_map_string(&sol_stream, name, strlen(name));
+			sol_string(&sol_stream, name, strlen(name));
 
 			sol_map_key(&sol_stream, "size", 4);
-			sol_map_integer(&sol_stream, memstat_get_size(mtp));
+			sol_integer(&sol_stream, memstat_get_size(mtp));
 
 			sol_map_key(&sol_stream, "limit", 4);
-			sol_map_integer(&sol_stream, memstat_get_countlimit(mtp));
+			sol_integer(&sol_stream, memstat_get_countlimit(mtp));
 
 			sol_map_key(&sol_stream, "used", 4);
-			sol_map_integer(&sol_stream, memstat_get_count(mtp));
+			sol_integer(&sol_stream, memstat_get_count(mtp));
 
 			sol_map_key(&sol_stream, "free", 4);
-			sol_map_integer(&sol_stream, memstat_get_free(mtp));
+			sol_integer(&sol_stream, memstat_get_free(mtp));
 
 			sol_map_key(&sol_stream, "req", 3);
-			sol_map_integer(&sol_stream, memstat_get_numallocs(mtp));
+			sol_integer(&sol_stream, memstat_get_numallocs(mtp));
 
 			sol_map_key(&sol_stream, "fail", 4);
-			sol_map_integer(&sol_stream, memstat_get_failures(mtp));
+			sol_integer(&sol_stream, memstat_get_failures(mtp));
 
 			sol_map_key(&sol_stream, "sleep", 5);
-			sol_map_integer(&sol_stream, memstat_get_sleeps(mtp));
+			sol_integer(&sol_stream, memstat_get_sleeps(mtp));
 
 			sol_map_end(&sol_stream);
 		}



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