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