From 1549bc5bc624389db34297a2b5746de46799a4d5 Mon Sep 17 00:00:00 2001 From: Miro Torrielli Date: Sat, 30 Mar 2024 11:15:29 +0100 Subject: [PATCH 1/4] Fixed ether outputs. From the regexec(3) man page: "regexec() returns zero for a successful match or REG_NOMATCH for failure." --- src/cmd/auxstats/Linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/auxstats/Linux.c b/src/cmd/auxstats/Linux.c index 74491ac294..33ae3330dc 100644 --- a/src/cmd/auxstats/Linux.c +++ b/src/cmd/auxstats/Linux.c @@ -143,7 +143,7 @@ xnet(int first) tokens(i); if(ntok < 8+8) continue; - if(regexec(netdev, tok[0], nil, 0) != 1) + if(regexec(netdev, tok[0], nil, 0) != 0) continue; inb = atoll(tok[1]); oub = atoll(tok[9]); From 868e43801d1c54cd7d983c2789b424be43400de4 Mon Sep 17 00:00:00 2001 From: Miro Torrielli Date: Sat, 30 Mar 2024 11:19:04 +0100 Subject: [PATCH 2/4] Fixed user, sys, and cpu outputs by scaling to total number of logical cpu cores --- src/cmd/auxstats/Linux.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/cmd/auxstats/Linux.c b/src/cmd/auxstats/Linux.c index 33ae3330dc..653949530f 100644 --- a/src/cmd/auxstats/Linux.c +++ b/src/cmd/auxstats/Linux.c @@ -174,9 +174,23 @@ void xstat(int first) { static int fd = -1; + static long long numcores = 0; int i; if(first){ + fd = open("/proc/cpuinfo", OREAD); + readfile(fd); + for(i=0; i= 2){ + numcores = atoll(tok[2]); + break; + } + } + close(fd); + fd = open("/proc/stat", OREAD); return; } @@ -187,9 +201,12 @@ xstat(int first) if(ntok < 2) continue; if(strcmp(tok[0], "cpu") == 0 && ntok >= 5){ - Bprint(&bout, "user %lld 100\n", atoll(tok[1])); - Bprint(&bout, "sys %lld 100\n", atoll(tok[3])); - Bprint(&bout, "cpu %lld 100\n", atoll(tok[1])+atoll(tok[3])); + long long user = atoll(tok[1]) / numcores; + long long sys = atoll(tok[3]) / numcores; + long long cpu = user + sys; + Bprint(&bout, "user %lld 100\n", user); + Bprint(&bout, "sys %lld 100\n", sys); + Bprint(&bout, "cpu %lld 100\n", cpu); Bprint(&bout, "idle %lld 100\n", atoll(tok[4])); } /* From afd6acb3837791320edafdfed6a7de45e946f2dc Mon Sep 17 00:00:00 2001 From: Miro Torrielli Date: Sat, 30 Mar 2024 11:27:03 +0100 Subject: [PATCH 3/4] Made user, sys, and cpu const --- src/cmd/auxstats/Linux.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/auxstats/Linux.c b/src/cmd/auxstats/Linux.c index 653949530f..a4f9aa7bd8 100644 --- a/src/cmd/auxstats/Linux.c +++ b/src/cmd/auxstats/Linux.c @@ -201,9 +201,9 @@ xstat(int first) if(ntok < 2) continue; if(strcmp(tok[0], "cpu") == 0 && ntok >= 5){ - long long user = atoll(tok[1]) / numcores; - long long sys = atoll(tok[3]) / numcores; - long long cpu = user + sys; + const long long user = atoll(tok[1]) / numcores; + const long long sys = atoll(tok[3]) / numcores; + const long long cpu = user + sys; Bprint(&bout, "user %lld 100\n", user); Bprint(&bout, "sys %lld 100\n", sys); Bprint(&bout, "cpu %lld 100\n", cpu); From fd31012b2c35e3a3ebd14b5246b3a35f3d60d0f8 Mon Sep 17 00:00:00 2001 From: Miro Torrielli Date: Sat, 30 Mar 2024 11:34:03 +0100 Subject: [PATCH 4/4] ntok must be greater than or equal to 3, not 2 --- src/cmd/auxstats/Linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/auxstats/Linux.c b/src/cmd/auxstats/Linux.c index a4f9aa7bd8..52f1a840e1 100644 --- a/src/cmd/auxstats/Linux.c +++ b/src/cmd/auxstats/Linux.c @@ -182,9 +182,9 @@ xstat(int first) readfile(fd); for(i=0; i= 2){ + if(strcmp(tok[0], "siblings") == 0 && ntok >= 3){ numcores = atoll(tok[2]); break; }