sh_calls.d revision 235368
11638Srgrimes#!/usr/sbin/dtrace -Zs 248210Sjmg/* 31638Srgrimes * sh_calls.d - count Bourne calls (func/builtin/cmd/subsh) using DTrace. 417706Sjulian * Written for the sh DTrace provider. 517706Sjulian * 613987Smpp * $Id: sh_calls.d 52 2007-09-24 04:28:01Z brendan $ 748210Sjmg * 848210Sjmg * This traces shell activity from all Bourne shells on the system that are 913987Smpp * running with sh provider support. 107139Sbde * 117139Sbde * USAGE: sh_calls.d # hit Ctrl-C to end 127139Sbde * 137139Sbde * FIELDS: 1433107Sjlemon * FILE Filename of the shell or shellscript 1515058Smpp * TYPE Type of call (func/builtin/cmd/subsh) 1615058Smpp * NAME Name of call 1715058Smpp * COUNT Number of calls during sample 1815058Smpp * 1915058Smpp * Filename and function names are printed if available. 2015058Smpp * 2115058Smpp * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 2213987Smpp * 2313987Smpp * CDDL HEADER START 2413987Smpp * 2513987Smpp * The contents of this file are subject to the terms of the 2613987Smpp * Common Development and Distribution License, Version 1.0 only 2713987Smpp * (the "License"). You may not use this file except in compliance 2813987Smpp * with the License. 2915969Swosch * 3015969Swosch * You can obtain a copy of the license at Docs/cddl1.txt 3113987Smpp * or http://www.opensolaris.org/os/licensing. 3213987Smpp * See the License for the specific language governing permissions 3313987Smpp * and limitations under the License. 341638Srgrimes * 351638Srgrimes * CDDL HEADER END 361638Srgrimes * 371638Srgrimes * 09-Sep-2007 Brendan Gregg Created this. 38 */ 39 40#pragma D option quiet 41 42dtrace:::BEGIN 43{ 44 printf("Tracing... Hit Ctrl-C to end.\n"); 45} 46 47sh*:::function-entry 48{ 49 @calls[basename(copyinstr(arg0)), "func", copyinstr(arg1)] = count(); 50} 51 52sh*:::builtin-entry 53{ 54 @calls[basename(copyinstr(arg0)), "builtin", copyinstr(arg1)] = count(); 55} 56 57sh*:::command-entry 58{ 59 @calls[basename(copyinstr(arg0)), "cmd", copyinstr(arg1)] = count(); 60} 61 62sh*:::subshell-entry 63/arg1 != 0/ 64{ 65 @calls[basename(copyinstr(arg0)), "subsh", "-"] = count(); 66} 67 68dtrace:::END 69{ 70 printf(" %-22s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT"); 71 printa(" %-22s %-10s %-32s %@8d\n", @calls); 72} 73