rb_flowtime.d revision 235368
1235368Sgnn#!/usr/sbin/dtrace -Zs 2235368Sgnn/* 3235368Sgnn * rb_flowtime.d - snoop Ruby function (method) flow using DTrace. 4235368Sgnn * Written for the Ruby DTrace provider. 5235368Sgnn * 6235368Sgnn * $Id: rb_flowtime.d 41 2007-09-17 02:20:10Z 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_flowtime.d # hit Ctrl-C to end 12235368Sgnn * 13235368Sgnn * FIELDS: 14235368Sgnn * C CPU-id 15235368Sgnn * TIME(us) Time since boot, us 16235368Sgnn * FILE Filename that this method belongs to 17235368Sgnn * DELTA(us) Elapsed time from previous line to this line 18235368Sgnn * CLASS::METHOD Ruby class and method name 19235368Sgnn * 20235368Sgnn * LEGEND: 21235368Sgnn * -> method entry 22235368Sgnn * <- method return 23235368Sgnn * 24235368Sgnn * Filename and method names are printed if available. 25235368Sgnn * 26235368Sgnn * WARNING: Watch the first column carefully, it prints the CPU-id. If it 27235368Sgnn * changes, then it is very likely that the output has been shuffled. 28235368Sgnn * 29235368Sgnn * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 30235368Sgnn * 31235368Sgnn * CDDL HEADER START 32235368Sgnn * 33235368Sgnn * The contents of this file are subject to the terms of the 34235368Sgnn * Common Development and Distribution License, Version 1.0 only 35235368Sgnn * (the "License"). You may not use this file except in compliance 36235368Sgnn * with the License. 37235368Sgnn * 38235368Sgnn * You can obtain a copy of the license at Docs/cddl1.txt 39235368Sgnn * or http://www.opensolaris.org/os/licensing. 40235368Sgnn * See the License for the specific language governing permissions 41235368Sgnn * and limitations under the License. 42235368Sgnn * 43235368Sgnn * CDDL HEADER END 44235368Sgnn * 45235368Sgnn * 09-Sep-2007 Brendan Gregg Created this. 46235368Sgnn */ 47235368Sgnn 48235368Sgnn#pragma D option quiet 49235368Sgnn#pragma D option switchrate=10 50235368Sgnn 51235368Sgnnself int depth; 52235368Sgnn 53235368Sgnndtrace:::BEGIN 54235368Sgnn{ 55235368Sgnn printf("%3s %-16s %-16s %9s -- %s\n", "C", "TIME(us)", "FILE", 56235368Sgnn "DELTA(us)", "CLASS::METHOD"); 57235368Sgnn} 58235368Sgnn 59235368Sgnnruby*:::function-entry, 60235368Sgnnruby*:::function-return 61235368Sgnn/self->last == 0/ 62235368Sgnn{ 63235368Sgnn self->last = timestamp; 64235368Sgnn} 65235368Sgnn 66235368Sgnnruby*:::function-entry 67235368Sgnn{ 68235368Sgnn this->delta = (timestamp - self->last) / 1000; 69235368Sgnn printf("%3d %-16d %-16s %9d %*s-> %s::%s\n", cpu, timestamp / 1000, 70235368Sgnn basename(copyinstr(arg2)), this->delta, self->depth * 2, "", 71235368Sgnn copyinstr(arg0), copyinstr(arg1)); 72235368Sgnn self->depth++; 73235368Sgnn self->last = timestamp; 74235368Sgnn} 75235368Sgnn 76235368Sgnnruby*:::function-return 77235368Sgnn{ 78235368Sgnn this->delta = (timestamp - self->last) / 1000; 79235368Sgnn self->depth -= self->depth > 0 ? 1 : 0; 80235368Sgnn printf("%3d %-16d %-16s %9d %*s<- %s::%s\n", cpu, timestamp / 1000, 81235368Sgnn basename(copyinstr(arg2)), this->delta, self->depth * 2, "", 82235368Sgnn copyinstr(arg0), copyinstr(arg1)); 83235368Sgnn self->last = timestamp; 84235368Sgnn} 85