| 1 |
#!/usr/bin/stap |
| 2 |
/* |
| 3 |
* rwtime-nd.stp read/write syscalls by latency. |
| 4 |
* For Linux, uses SystemTap (non-debuginfo). |
| 5 |
* |
| 6 |
* USAGE: ./rwtime.stp [execname] |
| 7 |
* |
| 8 |
* An option argument of the program name, eg, "httpd", can be provided. Without |
| 9 |
* this, all processes are traced. |
| 10 |
* |
| 11 |
* Copyright (C) 2015 Brendan Gregg. |
| 12 |
* |
| 13 |
* This program is free software; you can redistribute it and/or modify |
| 14 |
* it under the terms of the GNU General Public License as published by |
| 15 |
* the Free Software Foundation; either version 2 of the License, or |
| 16 |
* (at your option) any later version. |
| 17 |
* |
| 18 |
* This program is distributed in the hope that it will be useful, |
| 19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
* GNU General Public License for more details. |
| 22 |
* |
| 23 |
* 24-Jun-2014 Brendan Gregg Created this. |
| 24 |
*/ |
| 25 |
|
| 26 |
global read, write, tproc = ""; |
| 27 |
|
| 28 |
probe begin |
| 29 |
{ |
| 30 |
tproc = argv_1; |
| 31 |
if (tproc != "") { |
| 32 |
printf("Tracing read/write syscalls for processes named \"%s\"", |
| 33 |
tproc); |
| 34 |
} else { |
| 35 |
printf("Tracing read/write syscalls"); |
| 36 |
} |
| 37 |
printf("... Hit Ctrl-C to end.\n"); |
| 38 |
} |
| 39 |
|
| 40 |
probe nd_syscall.read.return |
| 41 |
{ |
| 42 |
if (tproc == "" || execname() == tproc) { |
| 43 |
read <<< gettimeofday_ns() - @entry(gettimeofday_ns()); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
probe nd_syscall.write.return |
| 48 |
{ |
| 49 |
if (tproc == "" || execname() == tproc) { |
| 50 |
write <<< gettimeofday_ns() - @entry(gettimeofday_ns()); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
probe end |
| 55 |
{ |
| 56 |
printf("\nsyscall read latency (ns):\n"); |
| 57 |
if (@count(read)) { print(@hist_log(read)); } |
| 58 |
printf("syscall write latency (ns):\n"); |
| 59 |
if (@count(write)) { print(@hist_log(write)); } |
| 60 |
} |