shithub: fork

Download patch

ref: 6b18bfa39eb89fa6315ed478ce80c196303c0334
parent: e4db1403541ca7f092046154a7a88eaaf5828e64
author: qwx <qwx@sciops.net>
date: Mon Nov 6 03:07:14 EST 2023

stats: sync latest

--- a/sys/src/cmd/stats.c
+++ b/sys/src/cmd/stats.c
@@ -64,8 +64,7 @@
 	int		remote;
 	int		statsfd;
 	int		swapfd;
-	int		etherfd;
-	int		ifstatsfd;
+	int		etherfd[10];
 	int		batteryfd;
 	int		bitsybatfd;
 	int		tempfd;
@@ -79,7 +78,6 @@
 	uvlong		netetherstats[8];
 	uvlong		prevetherstats[8];
 	uvlong		batterystats[2];
-	uvlong		netetherifstats[2];
 	uvlong		temp[10];
 
 	/* big enough to hold /dev/sysstat even with many processors */
@@ -128,7 +126,6 @@
 	Msyscall,
 	Mtlbmiss,
 	Mtlbpurge,
-	Msignal,
 	Mtemp,
 	Nmenu2,
 };
@@ -153,7 +150,6 @@
 	"add  syscall ",
 	"add  tlbmiss ",
 	"add  tlbpurge",
-	"add  802.11b ",
 	"add  temp    ",
 	nil,
 };
@@ -178,7 +174,6 @@
 	tlbmissval(Machine*, uvlong*, uvlong*, int),
 	tlbpurgeval(Machine*, uvlong*, uvlong*, int),
 	batteryval(Machine*, uvlong*, uvlong*, int),
-	signalval(Machine*, uvlong*, uvlong*, int),
 	tempval(Machine*, uvlong*, uvlong*, int);
 
 Menu	menu2 = {menu2str, nil};
@@ -203,7 +198,6 @@
 	syscallval,
 	tlbmissval,
 	tlbpurgeval,
-	signalval,
 	tempval,
 };
 
@@ -562,9 +556,10 @@
 int
 initmach(Machine *m, char *name)
 {
-	int n;
+	int n, i, j, fd;
 	uvlong a[MAXNUM];
 	char *p, mpt[256], buf[256];
+	Dir *d;
 
 	p = strchr(name, '!');
 	if(p)
@@ -615,18 +610,27 @@
 		m->nproc = 1;
 	m->lgproc = ilog10(m->nproc);
 
-	snprint(buf, sizeof buf, "%s/net/ether0/stats", mpt);
-	m->etherfd = open(buf, OREAD);
-	if(loadbuf(m, &m->etherfd) && readnums(m, nelem(m->netetherstats), a, 1))
-		memmove(m->netetherstats, a, sizeof m->netetherstats);
-
-	snprint(buf, sizeof buf, "%s/net/ether0/ifstats", mpt);
-	m->ifstatsfd = open(buf, OREAD);
-	if(loadbuf(m, &m->ifstatsfd)){
-		/* need to check that this is a wavelan interface */
-		if(strncmp(m->buf, "Signal: ", 8) == 0 && readnums(m, nelem(m->netetherifstats), a, 1))
-			memmove(m->netetherifstats, a, sizeof m->netetherifstats);
+	/* find all the ethernets */
+	n = 0;
+	snprint(buf, sizeof buf, "%s/net/", mpt);
+	if((fd = open(buf, OREAD)) >= 0){
+		for(d = nil; (i = dirread(fd, &d)) > 0; free(d)){
+			for(j=0; j<i; j++){
+				if(strncmp(d[j].name, "ether", 5))
+					continue;
+				snprint(buf, sizeof buf, "%s/net/%s/stats", mpt, d[j].name);
+				if((m->etherfd[n] = open(buf, OREAD)) < 0)
+					continue;
+				if(++n >= nelem(m->etherfd))
+					break;
+			}
+			if(n >= nelem(m->etherfd))
+				break;
+		}
+		close(fd);
 	}
+	while(n < nelem(m->etherfd))
+		m->etherfd[n++] = -1;
 
 	snprint(buf, sizeof buf, "%s/mnt/apm/battery", mpt);
 	m->batteryfd = open(buf, OREAD);
@@ -703,12 +707,6 @@
 }
 
 int
-needsignal(int init)
-{
-	return init | present[Msignal];
-}
-
-int
 needtemp(int init)
 {
 	static uint step = 0;
@@ -722,9 +720,18 @@
 }
 
 void
+vadd(uvlong *a, uvlong *b, int n)
+{
+	int i;
+
+	for(i=0; i<n; i++)
+		a[i] += b[i];
+}
+
+void
 readmach(Machine *m, int init)
 {
-	int n, i;
+	int n;
 	uvlong a[nelem(m->devsysstat)];
 	char buf[32];
 
@@ -754,16 +761,16 @@
 		memmove(m->prevsysstat, m->devsysstat, sizeof m->devsysstat);
 		memset(m->devsysstat, 0, sizeof m->devsysstat);
 		for(n=0; n<m->nproc && readnums(m, nelem(m->devsysstat), a, 0); n++)
-			for(i=0; i<nelem(m->devsysstat); i++)
-				m->devsysstat[i] += a[i];
+			vadd(m->devsysstat, a, nelem(m->devsysstat));
 	}
-	if(needether(init) && loadbuf(m, &m->etherfd) && readnums(m, nelem(m->netetherstats), a, 1)){
+	if(needether(init)){
 		memmove(m->prevetherstats, m->netetherstats, sizeof m->netetherstats);
-		memmove(m->netetherstats, a, sizeof m->netetherstats);
+		memset(m->netetherstats, 0, sizeof(m->netetherstats));
+		for(n=0; n<nelem(m->etherfd) && m->etherfd[n] >= 0; n++){
+			if(loadbuf(m, &m->etherfd[n]) && readnums(m, nelem(m->netetherstats), a, 1))
+				vadd(m->netetherstats, a, nelem(m->netetherstats));
+		}
 	}
-	if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)){
-		memmove(m->netetherifstats, a, sizeof m->netetherifstats);
-	}
 	if(needbattery(init)){
 		if(loadbuf(m, &m->batteryfd) && readnums(m, nelem(m->batterystats), a, 0))
 			memmove(m->batterystats, a, sizeof(m->batterystats));
@@ -947,23 +954,6 @@
 }
 
 void
-signalval(Machine *m, uvlong *v, uvlong *vmax, int)
-{
-	ulong l;
-
-	*vmax = sleeptime;
-	l = m->netetherifstats[0];
-	/*
-	 * Range is seen to be from about -45 (strong) to -95 (weak); rescale
-	 */
-	if(l == 0){	/* probably not present */
-		*v = 0;
-		return;
-	}
-	*v = 20*(l+95);
-}
-
-void
 tempval(Machine *m, uvlong *v, uvlong *vmax, int)
 {
 	ulong l;
@@ -1390,9 +1380,6 @@
 	case 't':
 		addgraph(Mtlbmiss);
 		addgraph(Mtlbpurge);
-		break;
-	case '8':
-		addgraph(Msignal);
 		break;
 	case 'w':
 		addgraph(Mswap);