Debian Codegraph @

testsuite/systemtap.examples/io/io_submit.stp

raw
1 #! /usr/bin/env stap
2 #
3 # Copyright (C) 2007 Oracle Corp. Chris Mason <[email protected]>
4 #
5 # This was implemented to find the most common causes of schedule during
6 # the AIO io_submit call. It does this by recording which pids are inside
7 # AIO, and recording the current stack trace if one of those pids is
8 # inside schedule.
9 # When the probe exits, it prints out the 30 most common call stacks for
10 # schedule().
11 #
12 # This file is free software. You can redistribute it and/or modify it under
13 # the terms of the GNU General Public License (GPL); either version 2, or (at
14 # your option) any later version.
15
16 global in_iosubmit
17 global traces
18
19 /*
20 * add a probe to sys_io_submit, on entry, record in the in_iosubmit
21 * hash table that this proc is in io_submit
22 */
23 probe syscall.io_submit {
24 in_iosubmit[tid()] = 1
25 }
26
27 /*
28 * when we return from sys_io_submit, record that we're no longer there
29 */
30 probe syscall.io_submit.return {
31 delete in_iosubmit[tid()]
32 }
33
34 /*
35 * every time we call schedule, check to see if we started off in
36 * io_submit. If so, record our backtrace into the traces histogram
37 */
38 probe kernel.function("schedule") {
39 if (tid() in in_iosubmit) {
40 traces[backtrace()] <<< 1
41
42 /*
43 * change this to if (1) if you want a backtrace every time
44 * you go into schedule from io_submit. Unfortunately, the traces
45 * saved into the traces histogram above are truncated to just a
46 * few lines. so the only way to see the full trace is via the
47 * more verbose print_backtrace() right here.
48 */
49 if (0) {
50 printf("schedule in io_submit!\n")
51 print_backtrace()
52 }
53 }
54 }
55
56 probe begin {
57 printf("Ready!\n")
58 }
59
60 /*
61 * when stap is done (via ctrl-c) go through the record of all the
62 * trace paths and print the 30 most common.
63 */
64 probe end {
65 foreach (stack in traces- limit 30) {
66 printf("%d:", @count(traces[stack]))
67 print_syms(stack);
68 }
69 }
70