xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Ruby/rb_calldist.d (revision 87d689fb734c654d2486f87f7be32f1b53ecdbec)
1 #!/usr/sbin/dtrace -Zs
2 /*
3  * rb_calldist.d - measure Ruby elapsed times for types of operation.
4  *                 Written for the Ruby DTrace provider.
5  *
6  * $Id: rb_calldist.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $
7  *
8  * This traces Ruby activity from all programs running on the system with
9  * Ruby provider support.
10  *
11  * USAGE: rb_calldist.d 	# hit Ctrl-C to end
12  *
13  * This script prints distribution plots of elapsed time for Ruby
14  * operations. Use rb_calltime.d for summary reports.
15  *
16  * FIELDS:
17  *		1		Filename of the Ruby program
18  *		2		Type of call (method/obj-new/gc)
19  *		3		Name of call
20  *
21  * Filename and method names are printed if available.
22  *
23  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
24  *
25  * CDDL HEADER START
26  *
27  *  The contents of this file are subject to the terms of the
28  *  Common Development and Distribution License, Version 1.0 only
29  *  (the "License").  You may not use this file except in compliance
30  *  with the License.
31  *
32  *  You can obtain a copy of the license at Docs/cddl1.txt
33  *  or http://www.opensolaris.org/os/licensing.
34  *  See the License for the specific language governing permissions
35  *  and limitations under the License.
36  *
37  * CDDL HEADER END
38  *
39  * 09-Sep-2007	Brendan Gregg	Created this.
40  */
41 
42 #pragma D option quiet
43 
44 dtrace:::BEGIN
45 {
46 	printf("Tracing... Hit Ctrl-C to end.\n");
47 }
48 
49 ruby*:::function-entry
50 {
51 	self->depth++;
52 	self->exclude[self->depth] = 0;
53 	self->function[self->depth] = timestamp;
54 }
55 
56 ruby*:::function-return
57 /self->function[self->depth]/
58 {
59 	this->elapsed_incl = timestamp - self->function[self->depth];
60 	this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];
61 	self->function[self->depth] = 0;
62 	self->exclude[self->depth] = 0;
63 	this->file = basename(copyinstr(arg2));
64 	this->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1));
65 
66 	@types_incl[this->file, "func", this->name] =
67 	    quantize(this->elapsed_incl / 1000);
68 	@types_excl[this->file, "func", this->name] =
69 	    quantize(this->elapsed_excl / 1000);
70 
71 	self->depth--;
72 	self->exclude[self->depth] += this->elapsed_incl;
73 }
74 
75 ruby*:::object-create-start
76 {
77 	self->object = timestamp;
78 }
79 
80 ruby*:::object-create-done
81 /self->object/
82 {
83 	this->elapsed = timestamp - self->object;
84 	self->object = 0;
85 	this->file = basename(copyinstr(arg1));
86 	this->file = this->file != NULL ? this->file : ".";
87 
88 	@types[this->file, "obj-new", copyinstr(arg0)] =
89 	    quantize(this->elapsed / 1000);
90 
91 	self->exclude[self->depth] += this->elapsed;
92 }
93 
94 ruby*:::gc-begin
95 {
96 	self->gc = timestamp;
97 }
98 
99 ruby*:::gc-end
100 /self->gc/
101 {
102 	this->elapsed = timestamp - self->gc;
103 	self->gc = 0;
104 
105 	@types[".", "gc", "-"] = quantize(this->elapsed / 1000);
106 
107 	self->exclude[self->depth] += this->elapsed;
108 }
109 
110 dtrace:::END
111 {
112 	printf("\nElapsed times (us),\n");
113 	printa("   %s, %s, %s %@d\n", @types);
114 
115 	printf("\nExclusive function elapsed times (us),\n");
116 	printa("   %s, %s, %s %@d\n", @types_excl);
117 
118 	printf("\nInclusive function elapsed times (us),\n");
119 	printa("   %s, %s, %s %@d\n", @types_incl);
120 }
121