py_flowtime.d revision 1.1 1 1.1 christos #!/usr/sbin/dtrace -Zs
2 1.1 christos /*
3 1.1 christos * py_flowtime.d - snoop Python functions with flow and delta times.
4 1.1 christos * Written for the Python DTrace provider.
5 1.1 christos *
6 1.1 christos * $Id: py_flowtime.d,v 1.1 2015/09/30 22:01:09 christos Exp $
7 1.1 christos *
8 1.1 christos * This traces shell activity from Python programs on the system that are
9 1.1 christos * running with Python provider support.
10 1.1 christos *
11 1.1 christos * USAGE: py_flowtime.d # hit Ctrl-C to end
12 1.1 christos *
13 1.1 christos * This watches Python function entries and returns, and indents child
14 1.1 christos * function calls.
15 1.1 christos *
16 1.1 christos * FIELDS:
17 1.1 christos * C CPU-id
18 1.1 christos * TIME(us) Time since boot, us
19 1.1 christos * FILE Filename that this function belongs to
20 1.1 christos * DELTA(us) Elapsed time from previous line to this line
21 1.1 christos * FUNC Python function name
22 1.1 christos *
23 1.1 christos * LEGEND:
24 1.1 christos * -> function entry
25 1.1 christos * <- function return
26 1.1 christos *
27 1.1 christos * Filename and function names are printed if available.
28 1.1 christos *
29 1.1 christos * WARNING: Watch the first column carefully, it prints the CPU-id. If it
30 1.1 christos * changes, then it is very likely that the output has been shuffled.
31 1.1 christos *
32 1.1 christos * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
33 1.1 christos *
34 1.1 christos * CDDL HEADER START
35 1.1 christos *
36 1.1 christos * The contents of this file are subject to the terms of the
37 1.1 christos * Common Development and Distribution License, Version 1.0 only
38 1.1 christos * (the "License"). You may not use this file except in compliance
39 1.1 christos * with the License.
40 1.1 christos *
41 1.1 christos * You can obtain a copy of the license at Docs/cddl1.txt
42 1.1 christos * or http://www.opensolaris.org/os/licensing.
43 1.1 christos * See the License for the specific language governing permissions
44 1.1 christos * and limitations under the License.
45 1.1 christos *
46 1.1 christos * CDDL HEADER END
47 1.1 christos *
48 1.1 christos * 09-Sep-2007 Brendan Gregg Created this.
49 1.1 christos */
50 1.1 christos
51 1.1 christos #pragma D option quiet
52 1.1 christos #pragma D option switchrate=10
53 1.1 christos
54 1.1 christos self int depth;
55 1.1 christos
56 1.1 christos self int last;
57 1.1 christos
58 1.1 christos dtrace:::BEGIN
59 1.1 christos {
60 1.1 christos printf("%3s %-16s %-16s %9s -- %s\n", "C", "TIME(us)", "FILE",
61 1.1 christos "DELTA(us)", "FUNC");
62 1.1 christos }
63 1.1 christos
64 1.1 christos python*:::function-entry,
65 1.1 christos python*:::function-return
66 1.1 christos /self->last == 0/
67 1.1 christos {
68 1.1 christos self->last = timestamp;
69 1.1 christos }
70 1.1 christos
71 1.1 christos python*:::function-entry
72 1.1 christos {
73 1.1 christos this->delta = (timestamp - self->last) / 1000;
74 1.1 christos printf("%3d %-16d %-16s %9d %*s-> %s\n", cpu, timestamp / 1000,
75 1.1 christos basename(copyinstr(arg0)), this->delta, self->depth * 2, "",
76 1.1 christos copyinstr(arg1));
77 1.1 christos self->depth++;
78 1.1 christos self->last = timestamp;
79 1.1 christos }
80 1.1 christos
81 1.1 christos python*:::function-return
82 1.1 christos {
83 1.1 christos this->delta = (timestamp - self->last) / 1000;
84 1.1 christos self->depth -= self->depth > 0 ? 1 : 0;
85 1.1 christos printf("%3d %-16d %-16s %9d %*s<- %s\n", cpu, timestamp / 1000,
86 1.1 christos basename(copyinstr(arg0)), this->delta, self->depth * 2, "",
87 1.1 christos copyinstr(arg1));
88 1.1 christos self->last = timestamp;
89 1.1 christos }
90