1235368Sgnn#!/usr/sbin/dtrace -Zs 2235368Sgnn/* 3235368Sgnn * pl_flowtime.d - snoop Perl subroutines with flow and delta times. 4235368Sgnn * Written for the Perl DTrace provider. 5235368Sgnn * 6235368Sgnn * $Id: pl_flowtime.d 41 2007-09-17 02:20:10Z brendan $ 7235368Sgnn * 8235368Sgnn * This traces shell activity from Perl programs on the system that are 9235368Sgnn * running with Perl provider support. 10235368Sgnn * 11235368Sgnn * USAGE: pl_flowtime.d # hit Ctrl-C to end 12235368Sgnn * 13235368Sgnn * This watches Perl subroutine entries and returns, and indents child 14235368Sgnn * subroutine calls. 15235368Sgnn * 16235368Sgnn * FIELDS: 17235368Sgnn * C CPU-id 18235368Sgnn * TIME(us) Time since boot, us 19235368Sgnn * FILE Filename that this subroutine belongs to 20235368Sgnn * DELTA(us) Elapsed time from previous line to this line 21235368Sgnn * SUB Perl subroutine name 22235368Sgnn * 23235368Sgnn * LEGEND: 24235368Sgnn * -> method entry 25235368Sgnn * <- method return 26235368Sgnn * 27235368Sgnn * Filename and subroutine names are printed if available. 28235368Sgnn * 29235368Sgnn * WARNING: Watch the first column carefully, it prints the CPU-id. If it 30235368Sgnn * changes, then it is very likely that the output has been shuffled. 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 switchrate=10 53235368Sgnn 54235368Sgnnself int depth; 55235368Sgnnself int last; 56235368Sgnn 57235368Sgnndtrace:::BEGIN 58235368Sgnn{ 59235368Sgnn printf("%3s %-16s %-16s %9s -- %s\n", "C", "TIME(us)", "FILE", 60235368Sgnn "DELTA(us)", "SUB"); 61235368Sgnn} 62235368Sgnn 63235368Sgnnperl*:::sub-entry, 64235368Sgnnperl*:::sub-return 65235368Sgnn/self->last == 0/ 66235368Sgnn{ 67235368Sgnn self->last = timestamp; 68235368Sgnn} 69235368Sgnn 70235368Sgnnperl*:::sub-entry 71235368Sgnn{ 72235368Sgnn this->delta = (timestamp - self->last) / 1000; 73235368Sgnn printf("%3d %-16d %-16s %9d %*s-> %s\n", cpu, timestamp / 1000, 74235368Sgnn basename(copyinstr(arg1)), this->delta, self->depth * 2, "", 75235368Sgnn copyinstr(arg0)); 76235368Sgnn self->depth++; 77235368Sgnn self->last = timestamp; 78235368Sgnn} 79235368Sgnn 80235368Sgnnperl*:::sub-return 81235368Sgnn{ 82235368Sgnn this->delta = (timestamp - self->last) / 1000; 83235368Sgnn self->depth -= self->depth > 0 ? 1 : 0; 84235368Sgnn printf("%3d %-16d %-16s %9d %*s<- %s\n", cpu, timestamp / 1000, 85235368Sgnn basename(copyinstr(arg1)), this->delta, self->depth * 2, "", 86235368Sgnn copyinstr(arg0)); 87235368Sgnn self->last = timestamp; 88235368Sgnn} 89