rb_flow.d revision 1
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne#!/usr/sbin/dtrace -Zs
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne/*
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * rb_flow.d - snoop Ruby execution showing method flow using DTrace.
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * Written for the Ruby DTrace provider.
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * $Id: rb_flow.d 41 2007-09-17 02:20:10Z brendan $
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * This traces activity from all Ruby programs on the system that are
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * running with Ruby provider support.
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * USAGE: rb_flow.d # hit Ctrl-C to end
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * FIELDS:
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * C CPU-id
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * TIME(us) Time since boot, us
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * FILE Filename that this method belongs to
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * CLASS::METHOD Ruby classname and method
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * LEGEND:
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * -> method entry
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * <- method return
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * Filename and method names are printed if available.
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * WARNING: Watch the first column carefully, it prints the CPU-id. If it
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * changes, then it is very likely that the output has been shuffled.
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * CDDL HEADER START
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feasel * The contents of this file are subject to the terms of the
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * Common Development and Distribution License, Version 1.0 only
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * (the "License"). You may not use this file except in compliance
352c411653c48af103d64372adc7832043da4257Elizabeth Browne * with the License.
352c411653c48af103d64372adc7832043da4257Elizabeth Browne *
352c411653c48af103d64372adc7832043da4257Elizabeth Browne * You can obtain a copy of the license at Docs/cddl1.txt
352c411653c48af103d64372adc7832043da4257Elizabeth Browne * or http://www.opensolaris.org/os/licensing.
352c411653c48af103d64372adc7832043da4257Elizabeth Browne * See the License for the specific language governing permissions
352c411653c48af103d64372adc7832043da4257Elizabeth Browne * and limitations under the License.
352c411653c48af103d64372adc7832043da4257Elizabeth Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * CDDL HEADER END
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne *
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne * 09-Sep-2007 Brendan Gregg Created this.
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne */
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne#pragma D option quiet
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne#pragma D option switchrate=10
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feasel
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feaselself int depth;
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feasel
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feaseldtrace:::BEGIN
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feasel{
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feasel printf("%3s %-16s %-22s -- %s\n", "C", "TIME(us)", "FILE",
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne "CLASS::METHOD");
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne}
1e80314f6b8449684f9baac9e8bcae33f0b4e507Jason Browne
1e80314f6b8449684f9baac9e8bcae33f0b4e507Jason Browneruby*:::function-entry
1e80314f6b8449684f9baac9e8bcae33f0b4e507Jason Browne{
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne printf("%3d %-16d %-22s %*s-> %s::%s\n", cpu, timestamp / 1000,
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne basename(copyinstr(arg2)), self->depth * 2, "", copyinstr(arg0),
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne copyinstr(arg1));
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne self->depth++;
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne}
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browneruby*:::function-return
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne{
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feasel self->depth -= self->depth > 0 ? 1 : 0;
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feasel printf("%3d %-16d %-22s %*s<- %s::%s\n", cpu, timestamp / 1000,
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne basename(copyinstr(arg2)), self->depth * 2, "", copyinstr(arg0),
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feasel copyinstr(arg1));
d1a2899a06be1eab885056aeda85adcd67c010b0Jason Browne}
0e2f85c75c270eec9d148bab17911441d8843a2aJake Feasel