Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mytools/debug/systemtap/fiohist.stp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
80 lines (73 sloc)
1.95 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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])) | |
} | |
} |