Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auxstat: Fixed ether, user, sys, and cpu outputs on Linux. #647

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/cmd/auxstats/Linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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<nline; i++){
tokens(i);
if(ntok < 3)
continue;
if(strcmp(tok[0], "siblings") == 0 && ntok >= 3){
numcores = atoll(tok[2]);
break;
}
}
close(fd);

fd = open("/proc/stat", OREAD);
return;
}
Expand All @@ -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]));
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);
Bprint(&bout, "idle %lld 100\n", atoll(tok[4]));
}
/*
Expand Down