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