Debian Codegraph @

testsuite/systemtap.examples/lwtools/biolatency-nd.stp

raw
1 #!/usr/bin/stap
2 /*
3 * biolatency-nd.stp Measure storage (bio) latency distribution.
4 * For Linux, uses SystemTap (non-debuginfo).
5 *
6 * USAGE: ./biolatency-nd.stp [interval [count]]
7 *
8 * This script uses the kernel tracepoints block_rq_issue and block_rq_complete,
9 * to trace the time from storage request to completion. To include extra time
10 * spent queued in the kernel, change block_rq_issue to block_rq_insert.
11 *
12 * From systemtap-lwtools: https://github.com/brendangregg/systemtap-lwtools
13 *
14 * See the corresponding man page (in systemtap-lwtools) for more info.
15 *
16 * Copyright (C) 2015 Brendan Gregg.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * 01-Feb-2015 Brendan Gregg Created this.
29 */
30
31 global ts[65536]; # 65536 is max concurrent I/O
32 global lat, interval = 0, secs = 0, count = 0, output = 0;
33
34 probe begin
35 {
36 printf("Tracing block I/O... ");
37 if (argv_1 != "") {
38 interval = strtol(argv_1, 10);
39 if (argv_2 != "") {
40 count = strtol(argv_2, 10);
41 }
42 printf("Output every %d secs.\n", interval);
43 } else {
44 printf("Hit Ctrl-C to end.\n");
45 }
46 }
47
48 probe kernel.trace("block_rq_issue") {
49 ts[$rq] = gettimeofday_ns();
50 }
51
52 probe kernel.trace("block_rq_complete") {
53 if (ts[$rq]) {
54 lat <<< gettimeofday_ns() - ts[$rq];
55 delete ts[$rq];
56 }
57 }
58
59 function print_report()
60 {
61 printf("\nbio latency (ns):\n");
62 if (@count(lat)) { print(@hist_log(lat)); }
63 delete lat;
64 }
65
66 probe timer.s(1)
67 {
68 if (interval) {
69 if (++secs == interval) {
70 print_report();
71 secs = 0;
72 count && (++output == count) && exit();
73 }
74 }
75 }
76
77 probe end
78 {
79 !interval && print_report();
80 delete secs;
81 delete output;
82 }