1 #!/usr/sbin/dtrace -CZs
3 * py_profile.d - sample stack traces with Python translations using DTrace.
4 * Written for the Python DTrace provider.
6 * $Id: py_profile.d 19 2007-09-12 07:47:59Z brendan $
8 * USAGE: py_profile.d { -p PID | -c cmd } # hit Ctrl-C to end
10 * This samples stack traces for the process specified. This stack trace
11 * will cross the Python engine and system libraries, and insert
12 * translations for Python stack frames where appropriate. This is best
13 * explained with an example stack frame output,
15 * libpython2.4.so.1.0`PyEval_EvalFrame+0x2fbf
16 * [ ./func_loop.py:5 (func_c) ]
17 * libpython2.4.so.1.0`fast_function+0xa8
18 * libpython2.4.so.1.0`call_function+0xda
19 * libpython2.4.so.1.0`PyEval_EvalFrame+0xbdf
20 * [ ./func_loop.py:11 (func_b) ]
21 * libpython2.4.so.1.0`fast_function+0xa8
22 * libpython2.4.so.1.0`call_function+0xda
23 * libpython2.4.so.1.0`PyEval_EvalFrame+0xbdf
24 * [ ./func_loop.py:14 (func_a) ]
25 * libpython2.4.so.1.0`fast_function+0xa8
26 * libpython2.4.so.1.0`call_function+0xda
27 * libpython2.4.so.1.0`PyEval_EvalFrame+0xbdf
28 * [ ./func_loop.py:16 (?) ]
30 * The lines in square brackets are the native Python frames, the rest
31 * are the Python engine.
33 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
37 * The contents of this file are subject to the terms of the
38 * Common Development and Distribution License, Version 1.0 only
39 * (the "License"). You may not use this file except in compliance
42 * You can obtain a copy of the license at Docs/cddl1.txt
43 * or http://www.opensolaris.org/os/licensing.
44 * See the License for the specific language governing permissions
45 * and limitations under the License.
49 * 09-Sep-2007 Brendan Gregg Created this.
52 #pragma D option quiet
53 #pragma D option jstackstrsize=1024
58 #define DEPTH 10 /* stack depth, frames */
59 #define RATE 1001 /* sampling rate, Hertz */
60 #define TOP 25 /* number of stacks to output */
64 printf("Sampling %d-level stacks at %d Hertz... Hit Ctrl-C to end.\n",
71 @stacks[jstack(DEPTH)] = count();
77 printf("Top %d most frequently sampled stacks,\n", TOP);