-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfiohist.stp
executable file
·80 lines (73 loc) · 1.95 KB
/
fiohist.stp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/stap
global pid = 0, trace = 0
global opens, reads, writes, totals
probe begin {
printf("starting probe\n")
%( $# > 1 %? log("ERROR: argument can't be more than 1") exit() %)
%( $# == 1 %? pid = $1 %: trace = 1 %)
}
probe syscall.open {
if (trace || pid() == pid) {
e=execname();
opens[e] <<< 1 # statistics array
}
}
probe syscall.read.return {
if (trace || pid() == pid) {
count = $return
if ( count >= 0 ) {
e=execname();
reads[e] <<< count # statistics array
totals[e] += count
}
}
}
probe syscall.write.return {
if (trace || pid() == pid) {
count = $return
if (count >= 0 ) {
e=execname();
writes[e] <<< count # statistics array
totals[e] += count
}
}
}
probe end {
header = 1
foreach (name in totals- limit 10) { # sort by total io
if (header) {
printf("\nIO Summary:\n\n")
printf("\n%16s %8s %8s %8s %8s %8s %8s %8s\n",
"", "", "", "read", "read", "", "write", "write")
printf("%16s %8s %8s %8s %8s %8s %8s %8s\n",
"name", "open", "read", "KB tot", "B avg", "write", "KB tot", "B avg")
header = 0
}
printf("%16s %8d %8d %8d %8d %8d %8d %8d\n",
name, @count(opens[name]),
@count(reads[name]),
(@count(reads[name]) ? @sum(reads[name])>>10 : 0 ),
(@count(reads[name]) ? @avg(reads[name]) : 0 ),
@count(writes[name]),
(@count(writes[name]) ? @sum(writes[name])>>10 : 0 ),
(@count(writes[name]) ? @avg(writes[name]) : 0 ))
}
header = 1
foreach (name in reads- limit 10) { # sort by reads
if (header) {
printf("\nRead I/O size (bytes):\n\n")
header = 0
}
printf("process name: %s\n", name)
print(@hist_log(reads[name]))
}
header = 1
foreach (name in writes- limit 10) { # sort by writes
if (header) {
printf("\nWrite I/O size (bytes):\n\n")
header = 0
}
printf("process name: %s\n", name)
print(@hist_log(writes[name]))
}
}