sh_calls.d revision 235380
1234353Sdim#!/usr/sbin/dtrace -Zs 2224133Sdim/* 3224133Sdim * sh_calls.d - count Bourne calls (func/builtin/cmd/subsh) using DTrace. 4224133Sdim * Written for the sh DTrace provider. 5224133Sdim * 6224133Sdim * $Id: sh_calls.d 52 2007-09-24 04:28:01Z brendan $ 7224133Sdim * 8224133Sdim * This traces shell activity from all Bourne shells on the system that are 9224133Sdim * running with sh provider support. 10224133Sdim * 11224133Sdim * USAGE: sh_calls.d # hit Ctrl-C to end 12224133Sdim * 13224133Sdim * FIELDS: 14224133Sdim * FILE Filename of the shell or shellscript 15224133Sdim * TYPE Type of call (func/builtin/cmd/subsh) 16224133Sdim * NAME Name of call 17234353Sdim * COUNT Number of calls during sample 18234353Sdim * 19224133Sdim * Filename and function names are printed if available. 20224133Sdim * 21224133Sdim * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 22224133Sdim * 23224133Sdim * CDDL HEADER START 24224133Sdim * 25224133Sdim * The contents of this file are subject to the terms of the 26224133Sdim * Common Development and Distribution License, Version 1.0 only 27224133Sdim * (the "License"). You may not use this file except in compliance 28224133Sdim * with the License. 29234353Sdim * 30224133Sdim * You can obtain a copy of the license at Docs/cddl1.txt 31224133Sdim * or http://www.opensolaris.org/os/licensing. 32234353Sdim * See the License for the specific language governing permissions 33234353Sdim * and limitations under the License. 34234353Sdim * 35234353Sdim * CDDL HEADER END 36234353Sdim * 37224133Sdim * 09-Sep-2007 Brendan Gregg Created this. 38234353Sdim */ 39234353Sdim 40234353Sdim#pragma D option quiet 41224133Sdim 42234353Sdimdtrace:::BEGIN 43224133Sdim{ 44224133Sdim printf("Tracing... Hit Ctrl-C to end.\n"); 45224133Sdim} 46224133Sdim 47224133Sdimsh*:::function-entry 48224133Sdim{ 49224133Sdim @calls[basename(copyinstr(arg0)), "func", copyinstr(arg1)] = count(); 50234353Sdim} 51234353Sdim 52224133Sdimsh*:::builtin-entry 53224133Sdim{ 54224133Sdim @calls[basename(copyinstr(arg0)), "builtin", copyinstr(arg1)] = count(); 55224133Sdim} 56224133Sdim 57224133Sdimsh*:::command-entry 58224133Sdim{ 59224133Sdim @calls[basename(copyinstr(arg0)), "cmd", copyinstr(arg1)] = count(); 60224133Sdim} 61224133Sdim 62224133Sdimsh*:::subshell-entry 63224133Sdim/arg1 != 0/ 64224133Sdim{ 65224133Sdim @calls[basename(copyinstr(arg0)), "subsh", "-"] = count(); 66224133Sdim} 67224133Sdim 68224133Sdimdtrace:::END 69224133Sdim{ 70224133Sdim printf(" %-22s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT"); 71224133Sdim printa(" %-22s %-10s %-32s %@8d\n", @calls); 72224133Sdim} 73224133Sdim