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