Debian Codegraph @

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

raw
1 #!/usr/bin/stap
2 /*
3 * accept2close-nd.stp Show socket duration: accept()->close().
4 *
5 * USAGE: ./accept2close.stp [min_ms]
6 *
7 * NOTE: This will miss sockets that are opened by one process, and then closed
8 * by another (eg, sshd).
9 *
10 * A minimum latency threshold, in milliseconds, can be provided as an optional
11 * argument. Without this, all events are shown.
12 *
13 * Copyright (C) 2015 Brendan Gregg.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * 20-Jun-2014 Brendan Gregg Created this.
26 */
27
28 global duration, ts, min_ns;
29
30 probe begin
31 {
32 # process arguments
33 if (argv_1 != "") {
34 min_ns = strtol(argv_1, 10) * 1000000;
35 printf("Only tracing events slower than %s ms.\n", argv_1);
36 } else {
37 min_ns = 0;
38 }
39
40 printf("%-24s %-6s %-14s %-4s %s\n", "TIME", "PID", "COMM", "FD",
41 "DURATION");
42 }
43
44 probe nd_syscall.accept.return,
45 nd_syscall.accept4.return
46 {
47 ts[tid(), retval] = gettimeofday_ns();
48 }
49
50 probe nd_syscall.close
51 {
52 last = ts[tid(), int_arg(1)];
53 if (last) {
54 delta = gettimeofday_ns() - last;
55 if (delta >= min_ns) {
56 printf("%-24s %-6d %-14s %-4d %d ms\n",
57 ctime(gettimeofday_s()),
58 pid(), execname(), int_arg(1), delta / 1000000);
59 duration <<< delta;
60 }
61 delete ts[tid(), int_arg(1)];
62 }
63 }
64
65 probe end
66 {
67 printf("\nDuration (ns):\n");
68 if (@count(duration)) { print(@hist_log(duration)); }
69 }