rb_cputime.d revision 256281
1#!/usr/sbin/dtrace -Zs 2/* 3 * rb_cputime.d - measure Ruby on-CPU times for types of operation. 4 * Written for the Ruby DTrace provider. 5 * 6 * $Id: rb_cputime.d 49 2007-09-17 12:03:20Z brendan $ 7 * 8 * This traces Ruby activity from all programs running on the system with 9 * Ruby provider support. 10 * 11 * USAGE: rb_cputime.d # hit Ctrl-C to end 12 * 13 * FIELDS: 14 * FILE Filename of the Ruby program 15 * TYPE Type of call (method/obj-new/gc/total) 16 * NAME Name of call 17 * TOTAL Total on-CPU time for calls (us) 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 42dtrace:::BEGIN 43{ 44 printf("Tracing... Hit Ctrl-C to end.\n"); 45} 46 47ruby*:::function-entry 48{ 49 self->depth++; 50 self->exclude[self->depth] = 0; 51 self->function[self->depth] = vtimestamp; 52} 53 54ruby*:::function-return 55/self->function[self->depth]/ 56{ 57 this->oncpu_incl = vtimestamp - self->function[self->depth]; 58 this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth]; 59 self->function[self->depth] = 0; 60 self->exclude[self->depth] = 0; 61 this->file = basename(copyinstr(arg2)); 62 this->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1)); 63 64 @num[this->file, "func", this->name] = count(); 65 @num["-", "total", "-"] = count(); 66 @types_incl[this->file, "func", this->name] = sum(this->oncpu_incl); 67 @types_excl[this->file, "func", this->name] = sum(this->oncpu_excl); 68 @types_excl["-", "total", "-"] = sum(this->oncpu_excl); 69 70 self->depth--; 71 self->exclude[self->depth] += this->oncpu_incl; 72} 73 74ruby*:::object-create-start 75{ 76 self->object = vtimestamp; 77} 78 79ruby*:::object-create-done 80/self->object/ 81{ 82 this->oncpu = vtimestamp - self->object; 83 self->object = 0; 84 this->file = basename(copyinstr(arg1)); 85 this->file = this->file != NULL ? this->file : "."; 86 this->name = copyinstr(arg0); 87 88 @num[this->file, "obj-new", this->name] = count(); 89 @types[this->file, "obj-new", this->name] = sum(this->oncpu); 90 91 self->exclude[self->depth] += this->oncpu; 92} 93 94ruby*:::gc-begin 95{ 96 self->gc = vtimestamp; 97} 98 99ruby*:::gc-end 100/self->gc/ 101{ 102 this->oncpu = vtimestamp - self->gc; 103 self->gc = 0; 104 @num[".", "gc", "-"] = count(); 105 @types[".", "gc", "-"] = sum(this->oncpu); 106 self->exclude[self->depth] += this->oncpu; 107} 108 109dtrace:::END 110{ 111 printf("\nCount,\n"); 112 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT"); 113 printa(" %-20s %-10s %-32s %@8d\n", @num); 114 115 normalize(@types, 1000); 116 printf("\nElapsed times (us),\n"); 117 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL"); 118 printa(" %-20s %-10s %-32s %@8d\n", @types); 119 120 normalize(@types_excl, 1000); 121 printf("\nExclusive function on-CPU times (us),\n"); 122 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL"); 123 printa(" %-20s %-10s %-32s %@8d\n", @types_excl); 124 125 normalize(@types_incl, 1000); 126 printf("\nInclusive function on-CPU times (us),\n"); 127 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL"); 128 printa(" %-20s %-10s %-32s %@8d\n", @types_incl); 129} 130