Home | History | Annotate | Line # | Download | only in Ruby
      1 #!/usr/sbin/dtrace -Zs
      2 /*
      3  * rb_calls.d - count Ruby calls using DTrace.
      4  *              Written for the Ruby DTrace provider.
      5  *
      6  * $Id: rb_calls.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_calls.d 		# hit Ctrl-C to end
     12  *
     13  * FIELDS:
     14  *		FILE		Filename of the Ruby program
     15  *		TYPE		Type of call (method/obj-new/...)
     16  *		NAME		Descriptive name of call
     17  *		COUNT		Number of calls during sample
     18  *
     19  * Filename and method names are printed if available.
     20  *
     21  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
     22  *
     23  * CDDL HEADER START
     24  *
     25  *  The contents of this file are subject to the terms of the
     26  *  Common Development and Distribution License, Version 1.0 only
     27  *  (the "License").  You may not use this file except in compliance
     28  *  with the License.
     29  *
     30  *  You can obtain a copy of the license at Docs/cddl1.txt
     31  *  or http://www.opensolaris.org/os/licensing.
     32  *  See the License for the specific language governing permissions
     33  *  and limitations under the License.
     34  *
     35  * CDDL HEADER END
     36  *
     37  * 09-Sep-2007	Brendan Gregg	Created this.
     38  */
     39 
     40 #pragma D option quiet
     41 
     42 dtrace:::BEGIN
     43 {
     44         printf("Tracing... Hit Ctrl-C to end.\n");
     45 }
     46 
     47 ruby*:::function-entry
     48 {
     49 	this->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1));
     50         @calls[basename(copyinstr(arg2)), "method", this->name] = count();
     51 }
     52 
     53 ruby*:::object-create-start
     54 {
     55 	this->name = copyinstr(arg0);
     56 	this->filename = basename(copyinstr(arg1));
     57 	this->filename = this->filename != NULL ? this->filename : ".";
     58         @calls[this->filename, "obj-new", this->name] = count();
     59 }
     60 
     61 ruby*:::object-free
     62 {
     63 	this->name = copyinstr(arg0);
     64         @calls[".", "obj-free", this->name] = count();
     65 }
     66 
     67 ruby*:::gc-begin
     68 {
     69         @calls[".", "gc", "begin"] = count();
     70 }
     71 
     72 ruby*:::raise
     73 {
     74 	this->name = copyinstr(arg0);
     75         @calls[basename(copyinstr(arg1)), "raise", this->name] = count();
     76 }
     77 
     78 ruby*:::rescue
     79 {
     80         @calls[basename(copyinstr(arg0)), "rescue", "-"] = count();
     81 }
     82 
     83 dtrace:::END
     84 {
     85         printf(" %-24s %-10s %-30s %8s\n", "FILE", "TYPE", "NAME", "CALLS");
     86         printa(" %-24s %-10s %-30s %@8d\n", @calls);
     87 }
     88