]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Python/py_flow.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Python / py_flow.d
1 #!/usr/sbin/dtrace -Zs
2 /*
3  * py_flow.d - snoop Python execution showing function flow.
4  *             Written for the Python DTrace provider.
5  *
6  * $Id: py_flow.d 51 2007-09-24 00:55:23Z brendan $
7  *
8  * This traces Python activity from all Python programs on the system
9  * running with Python provider support.
10  *
11  * USAGE: py_flow.d                     # hit Ctrl-C to end
12  *
13  * This watches Python function entries and returns, and indents child
14  * function calls.
15  *
16  * FIELDS:
17  *              C               CPU-id
18  *              TIME(us)        Time since boot, us
19  *              FILE            Filename that this function belongs to
20  *              FUNC            Function name
21  *
22  * LEGEND:
23  *              ->              function entry
24  *              <-              function return
25  *
26  * WARNING: Watch the first column carefully, it prints the CPU-id. If it
27  * changes, then it is very likely that the output has been shuffled.
28  *
29  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
30  *
31  * CDDL HEADER START
32  *
33  *  The contents of this file are subject to the terms of the
34  *  Common Development and Distribution License, Version 1.0 only
35  *  (the "License").  You may not use this file except in compliance
36  *  with the License.
37  *
38  *  You can obtain a copy of the license at Docs/cddl1.txt
39  *  or http://www.opensolaris.org/os/licensing.
40  *  See the License for the specific language governing permissions
41  *  and limitations under the License.
42  *
43  * CDDL HEADER END
44  *
45  * 09-Sep-2007  Brendan Gregg   Created this.
46  */
47
48 #pragma D option quiet
49 #pragma D option switchrate=10
50
51 self int depth;
52
53 dtrace:::BEGIN
54 {
55         printf("%3s %-16s %-16s -- %s\n", "C", "TIME(us)", "FILE", "FUNC");
56 }
57
58 python*:::function-entry
59 {
60         printf("%3d %-16d %-16s %*s-> %s\n", cpu, timestamp / 1000, 
61             basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));
62         self->depth++;
63 }
64
65 python*:::function-return
66 {
67         self->depth -= self->depth > 0 ? 1 : 0;
68         printf("%3d %-16d %-16s %*s<- %s\n", cpu, timestamp / 1000,
69             basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));
70 }