1#!/usr/sbin/dtrace -Zs 2/* 3 * rb_flowtime.d - snoop Ruby function (method) flow using DTrace. 4 * Written for the Ruby DTrace provider. 5 * 6 * $Id: rb_flowtime.d 41 2007-09-17 02:20:10Z brendan $ 7 * 8 * This traces activity from all Ruby programs on the system that are 9 * running with Ruby provider support. 10 * 11 * USAGE: rb_flowtime.d # hit Ctrl-C to end 12 * 13 * FIELDS: 14 * C CPU-id 15 * TIME(us) Time since boot, us 16 * FILE Filename that this method belongs to 17 * DELTA(us) Elapsed time from previous line to this line 18 * CLASS::METHOD Ruby class and method name 19 * 20 * LEGEND: 21 * -> method entry 22 * <- method return 23 * 24 * Filename and method names are printed if available. 25 * 26 * WARNING: Watch the first column carefully, it prints the CPU-id. If it 27 * changes, then it is very likely that the output has been shuffled. 28 * 29 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 30 * 31 * CDDL HEADER START 32 * 33 * The contents of this file are subject to the terms of the 34 * Common Development and Distribution License, Version 1.0 only 35 * (the "License"). You may not use this file except in compliance 36 * with the License. 37 * 38 * You can obtain a copy of the license at Docs/cddl1.txt 39 * or http://www.opensolaris.org/os/licensing. 40 * See the License for the specific language governing permissions 41 * and limitations under the License. 42 * 43 * CDDL HEADER END 44 * 45 * 09-Sep-2007 Brendan Gregg Created this. 46 */ 47 48#pragma D option quiet 49#pragma D option switchrate=10 50 51self int depth; 52 53dtrace:::BEGIN 54{ 55 printf("%3s %-16s %-16s %9s -- %s\n", "C", "TIME(us)", "FILE", 56 "DELTA(us)", "CLASS::METHOD"); 57} 58 59ruby*:::function-entry, 60ruby*:::function-return 61/self->last == 0/ 62{ 63 self->last = timestamp; 64} 65 66ruby*:::function-entry 67{ 68 this->delta = (timestamp - self->last) / 1000; 69 printf("%3d %-16d %-16s %9d %*s-> %s::%s\n", cpu, timestamp / 1000, 70 basename(copyinstr(arg2)), this->delta, self->depth * 2, "", 71 copyinstr(arg0), copyinstr(arg1)); 72 self->depth++; 73 self->last = timestamp; 74} 75 76ruby*:::function-return 77{ 78 this->delta = (timestamp - self->last) / 1000; 79 self->depth -= self->depth > 0 ? 1 : 0; 80 printf("%3d %-16d %-16s %9d %*s<- %s::%s\n", cpu, timestamp / 1000, 81 basename(copyinstr(arg2)), this->delta, self->depth * 2, "", 82 copyinstr(arg0), copyinstr(arg1)); 83 self->last = timestamp; 84} 85