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