Skip to content

Instantly share code, notes, and snippets.

@brendangregg
Created June 27, 2014 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendangregg/dc75f69a2cb6fa87005a to your computer and use it in GitHub Desktop.
Save brendangregg/dc75f69a2cb6fa87005a to your computer and use it in GitHub Desktop.
I CAN HAZ SYSTEMTAP
#!/usr/bin/stap
/*
* rwtime.stp read/write syscalls by latency.
*
* USAGE: ./rwtime.stp [execname]
*
* An option argument of the program name, eg, "httpd", can be provided. Without
* this, all processes are traced.
*
* 24-Jun-2014 Brendan Gregg Created this.
*/
global read, write, tproc = "";
probe begin
{
%( $# > 0 %?
tproc = @1
printf("Tracing read/write syscalls for processes named \"%s\"",
tproc);
%:
printf("Tracing read/write syscalls");
%);
printf("... Hit Ctrl-C to end.\n");
}
probe nd_syscall.read.return
{
if (!$# || execname() == tproc) {
read <<< gettimeofday_ns() - @entry(gettimeofday_ns());
}
}
probe nd_syscall.write.return
{
if (!$# || execname() == tproc) {
write <<< gettimeofday_ns() - @entry(gettimeofday_ns());
}
}
probe end
{
printf("\nsyscall read latency (ns):\n");
if (@count(read)) { print(@hist_log(read)); }
printf("\nsyscall write latency (ns):\n");
if (@count(write)) { print(@hist_log(write)); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment