shithub: riscv

Download patch

ref: 921aa0a6c387eaeca5c485f7d9c49bdef7a435a9
parent: 45b79036bed41e170dd4fca0bbec4425aee5033e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Jun 16 04:08:42 EDT 2015

stats: add kernel malloc and kernel draw allocation size graphs

--- a/sys/man/8/stats
+++ b/sys/man/8/stats
@@ -68,6 +68,12 @@
 The graph displays the fraction
 of the machine's total memory in use.
 .TP
+.B "k kern
+kernel memory allocation size in bytes.
+.TP
+.B "d draw
+draw memory allocation size in bytes.
+.TP
 .B 
 .B "n etherin,out,err
 number of packets sent and received per second, and total number of errors, displayed as separate graphs.
--- a/sys/src/cmd/stats.c
+++ b/sys/src/cmd/stats.c
@@ -34,6 +34,11 @@
 	Swap,
 	Maxswap,
 
+	Kern,
+	Maxkern,
+	Draw,
+	Maxdraw,
+
 	/* /dev/sysstats */
 	Procno	= 0,
 	Context,
@@ -66,7 +71,7 @@
 	int		tempfd;
 	int		disable;
 
-	uvlong		devswap[4];
+	uvlong		devswap[8];
 	uvlong		devsysstat[10];
 	uvlong		prevsysstat[10];
 	int		nproc;
@@ -117,6 +122,8 @@
 	Mload,
 	Mmem,
 	Mswap,
+	Mkern,
+	Mdraw,
 	Msyscall,
 	Mtlbmiss,
 	Mtlbpurge,
@@ -139,6 +146,8 @@
 	"add  load    ",
 	"add  mem     ",
 	"add  swap    ",
+	"add  kern    ",
+	"add  draw    ",
 	"add  syscall ",
 	"add  tlbmiss ",
 	"add  tlbpurge",
@@ -160,6 +169,8 @@
 	idleval(Machine*, uvlong*, uvlong*, int),
 	memval(Machine*, uvlong*, uvlong*, int),
 	swapval(Machine*, uvlong*, uvlong*, int),
+	kernval(Machine*, uvlong*, uvlong*, int),
+	drawval(Machine*, uvlong*, uvlong*, int),
 	syscallval(Machine*, uvlong*, uvlong*, int),
 	tlbmissval(Machine*, uvlong*, uvlong*, int),
 	tlbpurgeval(Machine*, uvlong*, uvlong*, int),
@@ -183,6 +194,8 @@
 	loadval,
 	memval,
 	swapval,
+	kernval,
+	drawval,
 	syscallval,
 	tlbmissval,
 	tlbpurgeval,
@@ -194,7 +207,7 @@
 Graph	*graph;
 Machine	*mach;
 char	*mysysname;
-char	argchars[] = "8bceEfiImlnpstwz";
+char	argchars[] = "8bcdeEfiIkmlnpstwz";
 int	pids[NPROC];
 int 	parity;	/* toggled to avoid patterns in textured background */
 int	nmach;
@@ -599,9 +612,35 @@
 		a[1] = a[4];
 		a[2] = a[5];
 		a[3] = a[6];
+
+		a[4] = 0;
+		a[5] = 0;
+		if(m->bufp = strstr(m->buf, "kernel malloc")){
+			while(m->bufp > m->buf && m->bufp[-1] != '\n')
+				m->bufp--;
+			a[4] = strtoull(m->bufp, &m->bufp, 10);
+			while(*m->bufp++ == '/')
+				a[5] = strtoull(m->bufp, &m->bufp, 10);
+		}
+
+		a[6] = 0;
+		a[7] = 0;
+		if(m->bufp = strstr(m->buf, "kernel draw")){
+			while(m->bufp > m->buf && m->bufp[-1] != '\n')
+				m->bufp--;
+			a[6] = strtoull(m->bufp, &m->bufp, 10);
+			while(*m->bufp++ == '/')
+				a[7] = strtoull(m->bufp, &m->bufp, 10);
+		}
+
 		return 1;
 	}
-	return readnums(m, nelem(m->devswap), a, 0);
+
+	a[4] = 0;
+	a[5] = 0;
+	a[6] = 0;
+	a[7] = 0;
+	return readnums(m, 4, a, 0);
 }
 
 char*
@@ -665,10 +704,6 @@
 	m->swapfd = open(buf, OREAD);
 	if(loadbuf(m, &m->swapfd) && readswap(m, a))
 		memmove(m->devswap, a, sizeof m->devswap);
-	else{
-		m->devswap[Maxswap] = 100;
-		m->devswap[Maxmem] = 100;
-	}
 
 	snprint(buf, sizeof buf, "%s/dev/sysstat", mpt);
 	m->statsfd = open(buf, OREAD);
@@ -726,7 +761,7 @@
 int
 needswap(int init)
 {
-	return init | present[Mmem] | present[Mswap];
+	return init | present[Mmem] | present[Mswap] | present[Mkern] | present[Mdraw];
 }
 
 
@@ -823,6 +858,8 @@
 {
 	*v = m->devswap[Mem];
 	*vmax = m->devswap[Maxmem];
+	if(*vmax == 0)
+		*vmax = 1;
 }
 
 void
@@ -830,9 +867,29 @@
 {
 	*v = m->devswap[Swap];
 	*vmax = m->devswap[Maxswap];
+	if(*vmax == 0)
+		*vmax = 1;
 }
 
 void
+kernval(Machine *m, uvlong *v, uvlong *vmax, int)
+{
+	*v = m->devswap[Kern];
+	*vmax = m->devswap[Maxkern];
+	if(*vmax == 0)
+		*vmax = 1;
+}
+
+void
+drawval(Machine *m, uvlong *v, uvlong *vmax, int)
+{
+	*v = m->devswap[Draw];
+	*vmax = m->devswap[Maxdraw];
+	if(*vmax == 0)
+		*vmax = 1;
+}
+
+void
 contextval(Machine *m, uvlong *v, uvlong *vmax, int init)
 {
 	*v = (m->devsysstat[Context]-m->prevsysstat[Context])&0xffffffff;
@@ -1090,6 +1147,8 @@
 	uvlong v, vmax;
 
 	g->newvalue(g->mach, &v, &vmax, 1);
+	if(vmax == 0)
+		vmax = 1;
 	if(logscale){
 		for(j=1; j<=2; j++)
 			sprint(strs[j-1], "%g", scale*pow(10., j)*(double)vmax/100.);
@@ -1403,6 +1462,12 @@
 		break;
 	case 'w':
 		addgraph(Mswap);
+		break;
+	case 'k':
+		addgraph(Mkern);
+		break;
+	case 'd':
+		addgraph(Mdraw);
 		break;
 	case 'z':
 		addgraph(Mtemp);