-
Notifications
You must be signed in to change notification settings - Fork 0
/
allctx
executable file
·48 lines (38 loc) · 1.19 KB
/
allctx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/awk -f
BEGIN {
interval = 5
sort = "sort -nk2"
print "Sampling for", interval, "seconds"
while ("ps -u " ENVIRON["USER"] " --noheaders" | getline)
procs[$1] = $4
for (pid in procs) {
while (getline < ("/proc/"pid"/status")) {
if ($1 == "voluntary_ctxt_switches:")
ctxv1[pid] = $2
else if ($1 == "nonvoluntary_ctxt_switches:")
ctxn1[pid] = $2
}
close("/proc/"pid"/status")
}
system("sleep " interval)
for (pid in procs)
while (getline < ("/proc/"pid"/status"))
if ($1 == "voluntary_ctxt_switches:")
ctxv2[pid] = $2
else if ($1 == "nonvoluntary_ctxt_switches:")
ctxn2[pid] = $2
for (pid in procs) {
vol = ctxv2[pid] - ctxv1[pid]
nvol = ctxn2[pid] - ctxn1[pid]
both = vol + nvol
printf "%-20s %5d %8.1f %12d %8.1f %15d %8.1f\n", procs[pid], both, both/interval, vol, vol/interval, nvol, nvol/interval |& sort
totalv += vol
totaln += nvol
total += both
}
close(sort, "to")
while (sort |& getline)
print $0
printf "--------------------- Total --- T/s --- Voluntary --- V/s --- Nonvoluntary --- N/s ---\n"
printf "%-20s %5d %8.1f %12d %8.1f %15d %8.1f\n", "Total", total, total/interval, total, totalv/interval, totaln, totaln/interval
}