1235368Sgnn#!/usr/sbin/dtrace -Zs 2235368Sgnn/* 3235368Sgnn * tcl_stat.d - Tcl operation stats using DTrace. 4235368Sgnn * Written for the Tcl DTrace provider. 5235368Sgnn * 6235368Sgnn * $Id: tcl_stat.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_stat.d [interval [count]] 12235368Sgnn * 13235368Sgnn * FIELDS: 14235368Sgnn * EXEC/s Tcl programs executed per second, including 15235368Sgnn * those without Tcl provider support 16235368Sgnn * PROC/s Procedures called, per second 17235368Sgnn * CMD/s Commands created, per second 18235368Sgnn * OBJNEW/s Objects created, per second 19235368Sgnn * OBJFRE/s Objects freed, per second 20235368Sgnn * OP/s Bytecode operations, per second 21235368Sgnn * 22235368Sgnn * The numbers are counts for the interval specified. The default interval 23235368Sgnn * is 1 second. 24235368Sgnn * 25235368Sgnn * If you see a count in "EXECS" but not in the other columns, then you 26235368Sgnn * may have older Tcl software that does not have the integrated DTrace 27235368Sgnn * provider (or newer software where the provider has changed). 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 defaultargs 50235368Sgnn 51235368Sgnninline int SCREEN = 21; 52235368Sgnn 53235368Sgnndtrace:::BEGIN 54235368Sgnn{ 55235368Sgnn execs = procs = cmds = objnew = objfree = ops = 0; 56235368Sgnn lines = SCREEN + 1; 57235368Sgnn interval = $1 ? $1 : 1; 58235368Sgnn counts = $2 ? $2 : -1; 59235368Sgnn secs = interval; 60235368Sgnn first = 1; 61235368Sgnn} 62235368Sgnn 63235368Sgnnprofile:::tick-1sec 64235368Sgnn{ 65235368Sgnn secs--; 66235368Sgnn} 67235368Sgnn 68235368Sgnn/* 69235368Sgnn * Print Header 70235368Sgnn */ 71235368Sgnndtrace:::BEGIN, 72235368Sgnnprofile:::tick-1sec 73235368Sgnn/first || (secs == 0 && lines > SCREEN)/ 74235368Sgnn{ 75235368Sgnn printf("%-20s %6s %8s %8s %8s %8s %8s\n", "TIME", "EXEC/s", 76235368Sgnn "PROC/s", "CMD/s", "OBJNEW/s", "OBJFRE/s", "OP/s"); 77235368Sgnn lines = 0; 78235368Sgnn first = 0; 79235368Sgnn} 80235368Sgnn 81235368Sgnn/* 82235368Sgnn * Tally Data 83235368Sgnn */ 84235368Sgnnproc:::exec-success 85235368Sgnn/execname == "tcl" || execname == "tclsh"/ 86235368Sgnn{ 87235368Sgnn execs++; 88235368Sgnn} 89235368Sgnn 90235368Sgnntcl*:::proc-entry 91235368Sgnn{ 92235368Sgnn procs++; 93235368Sgnn} 94235368Sgnn 95235368Sgnntcl*:::cmd-entry 96235368Sgnn{ 97235368Sgnn cmds++; 98235368Sgnn} 99235368Sgnn 100235368Sgnntcl*:::obj-create 101235368Sgnn{ 102235368Sgnn objnew++; 103235368Sgnn} 104235368Sgnn 105235368Sgnntcl*:::obj-free 106235368Sgnn{ 107235368Sgnn objfree++; 108235368Sgnn} 109235368Sgnn 110235368Sgnntcl*:::inst-start 111235368Sgnn{ 112235368Sgnn ops++; 113235368Sgnn} 114235368Sgnn 115235368Sgnn/* 116235368Sgnn * Print Output 117235368Sgnn */ 118235368Sgnnprofile:::tick-1sec 119235368Sgnn/secs == 0/ 120235368Sgnn{ 121235368Sgnn printf("%-20Y %6d %8d %8d %8d %8d %8d\n", walltimestamp, 122235368Sgnn execs / interval, procs / interval, cmds / interval, 123235368Sgnn objnew / interval, objfree / interval, ops / interval); 124235368Sgnn execs = procs = cmds = objnew = objfree = ops = 0; 125235368Sgnn secs = interval; 126235368Sgnn lines++; 127235368Sgnn counts--; 128235368Sgnn} 129235368Sgnn 130235368Sgnn/* 131235368Sgnn * End 132235368Sgnn */ 133235368Sgnnprofile:::tick-1sec 134235368Sgnn/counts == 0/ 135235368Sgnn{ 136235368Sgnn exit(0); 137235368Sgnn} 138