1235368Sgnn#!/usr/sbin/dtrace -Zs 2235368Sgnn/* 3235368Sgnn * tcl_flowtime.d - snoop Tcl execution showing procedure flow and delta times. 4235368Sgnn * Written for the Tcl DTrace provider. 5235368Sgnn * 6235368Sgnn * $Id: tcl_flowtime.d 63 2007-10-04 04:34:38Z brendan $ 7235368Sgnn * 8235368Sgnn * This traces activity from all Tcl processes on the system with DTrace 9235368Sgnn * provider support (tcl8.4.16). 10235368Sgnn * 11235368Sgnn * USAGE: tcl_flowtime.d # hit Ctrl-C to end 12235368Sgnn * 13235368Sgnn * This watches Tcl method entries and returns, and indents child 14235368Sgnn * method calls. 15235368Sgnn * 16235368Sgnn * FIELDS: 17235368Sgnn * C CPU-id 18235368Sgnn * PID Process ID 19235368Sgnn * TIME(us) Time since boot, us 20235368Sgnn * DELTA(us) Elapsed time from previous line to this line 21235368Sgnn * CALL Tcl command or procedure name 22235368Sgnn * 23235368Sgnn * LEGEND: 24235368Sgnn * -> procedure entry 25235368Sgnn * <- procedure return 26235368Sgnn * > command entry 27235368Sgnn * < command return 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; 55235368Sgnn 56235368Sgnndtrace:::BEGIN 57235368Sgnn{ 58235368Sgnn printf("%3s %6s %-16s %9s -- %s\n", "C", "PID", "TIME(us)", 59235368Sgnn "DELTA(us)", "CALL"); 60235368Sgnn} 61235368Sgnn 62235368Sgnntcl*:::proc-entry, 63235368Sgnntcl*:::proc-return, 64235368Sgnntcl*:::cmd-entry, 65235368Sgnntcl*:::cmd-return 66235368Sgnn/self->last == 0/ 67235368Sgnn{ 68235368Sgnn self->last = timestamp; 69235368Sgnn} 70235368Sgnn 71235368Sgnntcl*:::proc-entry 72235368Sgnn{ 73235368Sgnn this->delta = (timestamp - self->last) / 1000; 74235368Sgnn printf("%3d %6d %-16d %9d %*s-> %s\n", cpu, pid, timestamp / 1000, 75235368Sgnn this->delta, self->depth * 2, "", copyinstr(arg0)); 76235368Sgnn self->depth++; 77235368Sgnn self->last = timestamp; 78235368Sgnn} 79235368Sgnn 80235368Sgnntcl*:::proc-return 81235368Sgnn{ 82235368Sgnn this->delta = (timestamp - self->last) / 1000; 83235368Sgnn self->depth -= self->depth > 0 ? 1 : 0; 84235368Sgnn printf("%3d %6d %-16d %9d %*s<- %s\n", cpu, pid, timestamp / 1000, 85235368Sgnn this->delta, self->depth * 2, "", copyinstr(arg0)); 86235368Sgnn self->last = timestamp; 87235368Sgnn} 88235368Sgnn 89235368Sgnntcl*:::cmd-entry 90235368Sgnn{ 91235368Sgnn this->delta = (timestamp - self->last) / 1000; 92235368Sgnn printf("%3d %6d %-16d %9d %*s > %s\n", cpu, pid, timestamp / 1000, 93235368Sgnn this->delta, self->depth * 2, "", copyinstr(arg0)); 94235368Sgnn self->depth++; 95235368Sgnn self->last = timestamp; 96235368Sgnn} 97235368Sgnn 98235368Sgnntcl*:::cmd-return 99235368Sgnn{ 100235368Sgnn this->delta = (timestamp - self->last) / 1000; 101235368Sgnn self->depth -= self->depth > 0 ? 1 : 0; 102235368Sgnn printf("%3d %6d %-16d %9d %*s < %s\n", cpu, pid, timestamp / 1000, 103235368Sgnn this->delta, self->depth * 2, "", copyinstr(arg0)); 104235368Sgnn self->last = timestamp; 105235368Sgnn} 106