sh_syscalls.d revision 235368
1#!/usr/sbin/dtrace -Zs 2/* 3 * sh_syscalls.d - count Bourne calls and syscalls using DTrace. 4 * Written for the sh DTrace provider. 5 * 6 * $Id: sh_syscalls.d 25 2007-09-12 09:51:58Z brendan $ 7 * 8 * USAGE: sh_syscalls.d { -p PID | -c cmd } # hit Ctrl-C to end 9 * 10 * FIELDS: 11 * FILE Filename of the shell or shellscript 12 * TYPE Type of call (func/builtin/cmd/syscall) 13 * NAME Name of call 14 * COUNT Number of calls during sample 15 * 16 * Filename and function names are printed if available. 17 * The filename for syscalls may be printed as the shell name, if the 18 * script was invoked using the form "shell filename" rather than running 19 * the script with an interpreter line. 20 * 21 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 22 * 23 * CDDL HEADER START 24 * 25 * The contents of this file are subject to the terms of the 26 * Common Development and Distribution License, Version 1.0 only 27 * (the "License"). You may not use this file except in compliance 28 * with the License. 29 * 30 * You can obtain a copy of the license at Docs/cddl1.txt 31 * or http://www.opensolaris.org/os/licensing. 32 * See the License for the specific language governing permissions 33 * and limitations under the License. 34 * 35 * CDDL HEADER END 36 * 37 * 09-Sep-2007 Brendan Gregg Created this. 38 */ 39 40#pragma D option quiet 41 42self string filename; 43 44dtrace:::BEGIN 45{ 46 printf("Tracing... Hit Ctrl-C to end.\n"); 47} 48 49sh$target:::function-entry, 50sh$target:::builtin-entry, 51sh$target:::command-entry 52/self->filename == NULL/ 53{ 54 self->filename = basename(copyinstr(arg0)); 55} 56 57sh$target:::function-entry 58{ 59 @calls[self->filename, "func", copyinstr(arg1)] = count(); 60} 61 62sh$target:::builtin-entry 63{ 64 @calls[self->filename, "builtin", copyinstr(arg1)] = count(); 65} 66 67sh$target:::command-entry 68{ 69 @calls[self->filename, "cmd", copyinstr(arg1)] = count(); 70} 71 72syscall:::entry 73/pid == $target/ 74{ 75 @calls[basename(execname), "syscall", probefunc] = count(); 76} 77 78dtrace:::END 79{ 80 printf("\nCalls for PID %d,\n\n", $target); 81 printf(" %-32s %-10s %-22s %8s\n", "FILE", "TYPE", "NAME", "COUNT"); 82 printa(" %-32s %-10s %-22s %@8d\n", @calls); 83} 84