1235368Sgnn#!/usr/sbin/dtrace -Zs
2235368Sgnn/*
3235368Sgnn * rb_calls.d - count Ruby calls using DTrace.
4235368Sgnn *              Written for the Ruby DTrace provider.
5235368Sgnn *
6235368Sgnn * $Id: rb_calls.d 28 2007-09-13 10:49:37Z brendan $
7235368Sgnn *
8235368Sgnn * This traces activity from all Ruby programs on the system that are
9235368Sgnn * running with Ruby provider support.
10235368Sgnn *
11235368Sgnn * USAGE: rb_calls.d 		# hit Ctrl-C to end
12235368Sgnn *
13235368Sgnn * FIELDS:
14235368Sgnn *		FILE		Filename of the Ruby program
15235368Sgnn *		TYPE		Type of call (method/obj-new/...)
16235368Sgnn *		NAME		Descriptive name of call
17235368Sgnn *		COUNT		Number of calls during sample
18235368Sgnn *
19235368Sgnn * Filename and method names are printed if available.
20235368Sgnn *
21235368Sgnn * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
22235368Sgnn *
23235368Sgnn * CDDL HEADER START
24235368Sgnn *
25235368Sgnn *  The contents of this file are subject to the terms of the
26235368Sgnn *  Common Development and Distribution License, Version 1.0 only
27235368Sgnn *  (the "License").  You may not use this file except in compliance
28235368Sgnn *  with the License.
29235368Sgnn *
30235368Sgnn *  You can obtain a copy of the license at Docs/cddl1.txt
31235368Sgnn *  or http://www.opensolaris.org/os/licensing.
32235368Sgnn *  See the License for the specific language governing permissions
33235368Sgnn *  and limitations under the License.
34235368Sgnn *
35235368Sgnn * CDDL HEADER END
36235368Sgnn *
37235368Sgnn * 09-Sep-2007	Brendan Gregg	Created this.
38235368Sgnn */
39235368Sgnn
40235368Sgnn#pragma D option quiet
41235368Sgnn
42235368Sgnndtrace:::BEGIN
43235368Sgnn{
44235368Sgnn        printf("Tracing... Hit Ctrl-C to end.\n");
45235368Sgnn}
46235368Sgnn
47235368Sgnnruby*:::function-entry
48235368Sgnn{
49235368Sgnn	this->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1));
50235368Sgnn        @calls[basename(copyinstr(arg2)), "method", this->name] = count();
51235368Sgnn}
52235368Sgnn
53235368Sgnnruby*:::object-create-start
54235368Sgnn{
55235368Sgnn	this->name = copyinstr(arg0);
56235368Sgnn	this->filename = basename(copyinstr(arg1));
57235368Sgnn	this->filename = this->filename != NULL ? this->filename : ".";
58235368Sgnn        @calls[this->filename, "obj-new", this->name] = count();
59235368Sgnn}
60235368Sgnn
61235368Sgnnruby*:::object-free
62235368Sgnn{
63235368Sgnn	this->name = copyinstr(arg0);
64235368Sgnn        @calls[".", "obj-free", this->name] = count();
65235368Sgnn}
66235368Sgnn
67235368Sgnnruby*:::gc-begin
68235368Sgnn{
69235368Sgnn        @calls[".", "gc", "begin"] = count();
70235368Sgnn}
71235368Sgnn
72235368Sgnnruby*:::raise
73235368Sgnn{
74235368Sgnn	this->name = copyinstr(arg0);
75235368Sgnn        @calls[basename(copyinstr(arg1)), "raise", this->name] = count();
76235368Sgnn}
77235368Sgnn
78235368Sgnnruby*:::rescue
79235368Sgnn{
80235368Sgnn        @calls[basename(copyinstr(arg0)), "rescue", "-"] = count();
81235368Sgnn}
82235368Sgnn
83235368Sgnndtrace:::END
84235368Sgnn{
85235368Sgnn        printf(" %-24s %-10s %-30s %8s\n", "FILE", "TYPE", "NAME", "CALLS");
86235368Sgnn        printa(" %-24s %-10s %-30s %@8d\n", @calls);
87235368Sgnn}
88