1235368Sgnn#!/usr/sbin/dtrace -Zs 2235368Sgnn/* 3235368Sgnn * rb_stat.d - Ruby operation stats using DTrace. 4235368Sgnn * Written for the Ruby DTrace provider. 5235368Sgnn * 6235368Sgnn * $Id: rb_stat.d 20 2007-09-12 09:28:22Z 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_stat.d [interval [count]] 12235368Sgnn * 13235368Sgnn * FIELDS: 14235368Sgnn * EXEC/s Ruby programs executed per second, including 15235368Sgnn * those without Ruby provider support 16235368Sgnn * METHOD/s Methods called, per second 17235368Sgnn * OBJNEW/s Objects created, per second 18235368Sgnn * OBJFRE/s Objects freed, per second 19235368Sgnn * RAIS/s Raises, per second 20235368Sgnn * RESC/s Rescues, per second 21235368Sgnn * GC/s Garbage collects, per second 22235368Sgnn * 23235368Sgnn * The numbers are counts for the interval specified. The default interval 24235368Sgnn * is 1 second. 25235368Sgnn * 26235368Sgnn * If you see a count in "EXECS" but not in the other columns, then your 27235368Sgnn * Ruby software is probably not running with the DTrace Ruby provider. 28235368Sgnn * See Ruby/Readme. 29235368Sgnn * 30235368Sgnn * Filename and method names are printed if available. 31235368Sgnn * 32235368Sgnn * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 33235368Sgnn * 34235368Sgnn * CDDL HEADER START 35235368Sgnn * 36235368Sgnn * The contents of this file are subject to the terms of the 37235368Sgnn * Common Development and Distribution License, Version 1.0 only 38235368Sgnn * (the "License"). You may not use this file except in compliance 39235368Sgnn * with the License. 40235368Sgnn * 41235368Sgnn * You can obtain a copy of the license at Docs/cddl1.txt 42235368Sgnn * or http://www.opensolaris.org/os/licensing. 43235368Sgnn * See the License for the specific language governing permissions 44235368Sgnn * and limitations under the License. 45235368Sgnn * 46235368Sgnn * CDDL HEADER END 47235368Sgnn * 48235368Sgnn * 09-Sep-2007 Brendan Gregg Created this. 49235368Sgnn */ 50235368Sgnn 51235368Sgnn#pragma D option quiet 52235368Sgnn#pragma D option defaultargs 53235368Sgnn 54235368Sgnninline int SCREEN = 21; 55235368Sgnn 56235368Sgnndtrace:::BEGIN 57235368Sgnn{ 58235368Sgnn execs = methods = objnew = objfree = gc = raised = rescue = 0; 59235368Sgnn lines = SCREEN + 1; 60235368Sgnn interval = $1 ? $1 : 1; 61235368Sgnn counts = $2 ? $2 : -1; 62235368Sgnn secs = interval; 63235368Sgnn first = 1; 64235368Sgnn} 65235368Sgnn 66235368Sgnnprofile:::tick-1sec 67235368Sgnn{ 68235368Sgnn secs--; 69235368Sgnn} 70235368Sgnn 71235368Sgnn/* 72235368Sgnn * Print Header 73235368Sgnn */ 74235368Sgnndtrace:::BEGIN, 75235368Sgnnprofile:::tick-1sec 76235368Sgnn/first || (secs == 0 && lines > SCREEN)/ 77235368Sgnn{ 78235368Sgnn printf("%-20s %8s %8s %8s %8s %6s %6s %6s\n", "TIME", "EXEC/s", 79235368Sgnn "METHOD/s", "OBJNEW/s", "OBJFRE/s", "RAIS/s", "RESC/s", "GC/s"); 80235368Sgnn lines = 0; 81235368Sgnn first = 0; 82235368Sgnn} 83235368Sgnn 84235368Sgnn/* 85235368Sgnn * Tally Data 86235368Sgnn */ 87235368Sgnnproc:::exec-success 88235368Sgnn/execname == "ruby"/ 89235368Sgnn{ 90235368Sgnn execs++; 91235368Sgnn} 92235368Sgnn 93235368Sgnnruby*:::function-entry 94235368Sgnn{ 95235368Sgnn methods++; 96235368Sgnn} 97235368Sgnn 98235368Sgnnruby*:::object-create-start 99235368Sgnn{ 100235368Sgnn objnew++; 101235368Sgnn} 102235368Sgnn 103235368Sgnnruby*:::object-free 104235368Sgnn{ 105235368Sgnn objfree++; 106235368Sgnn} 107235368Sgnn 108235368Sgnnruby*:::raise 109235368Sgnn{ 110235368Sgnn raised++; 111235368Sgnn} 112235368Sgnn 113235368Sgnnruby*:::rescue 114235368Sgnn{ 115235368Sgnn rescue++; 116235368Sgnn} 117235368Sgnn 118235368Sgnnruby*:::gc-begin 119235368Sgnn{ 120235368Sgnn gc++; 121235368Sgnn} 122235368Sgnn 123235368Sgnn/* 124235368Sgnn * Print Output 125235368Sgnn */ 126235368Sgnnprofile:::tick-1sec 127235368Sgnn/secs == 0/ 128235368Sgnn{ 129235368Sgnn printf("%-20Y %8d %8d %8d %8d %6d %6d %6d\n", walltimestamp, 130235368Sgnn execs / interval, methods / interval, objnew / interval, 131235368Sgnn objfree / interval, raised / interval, rescue / interval, 132235368Sgnn gc / interval); 133235368Sgnn execs = methods = objnew = objfree = gc = raised = rescue = 0; 134235368Sgnn secs = interval; 135235368Sgnn lines++; 136235368Sgnn counts--; 137235368Sgnn} 138235368Sgnn 139235368Sgnn/* 140235368Sgnn * End 141235368Sgnn */ 142235368Sgnnprofile:::tick-1sec 143235368Sgnn/counts == 0/ 144235368Sgnn{ 145235368Sgnn exit(0); 146235368Sgnn} 147