3 * sh_flow.d - snoop Bourne shell execution showing function flow using DTrace.
4 * Written for the sh DTrace provider.
6 * $Id: sh_flow.d 41 2007-09-17 02:20:10Z brendan $
8 * This traces shell activity from all Bourne shells on the system that are
9 * running with sh provider support.
11 * USAGE: sh_flow.d # hit Ctrl-C to end
13 * This watches shell function entries and returns, and indents child
14 * function calls. Shell builtins are also printed.
18 * TIME(us) Time since boot, us
19 * FILE Filename that this function belongs to
20 * NAME Shell function, builtin or command name
28 * WARNING: Watch the first column carefully, it prints the CPU-id. If it
29 * changes, then it is very likely that the output has been shuffled.
31 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
35 * The contents of this file are subject to the terms of the
36 * Common Development and Distribution License, Version 1.0 only
37 * (the "License"). You may not use this file except in compliance
40 * You can obtain a copy of the license at Docs/cddl1.txt
41 * or http://www.opensolaris.org/os/licensing.
42 * See the License for the specific language governing permissions
43 * and limitations under the License.
47 * 09-Sep-2007 Brendan Gregg Created this.
50 #pragma D option quiet
51 #pragma D option switchrate=10
58 printf("%3s %-16s %-16s -- %s\n", "C", "TIME(us)", "FILE", "NAME");
63 printf("%3d %-16d %-16s %*s-> %s\n", cpu, timestamp / 1000,
64 basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));
70 self->depth -= self->depth > 0 ? 1 : 0;
71 printf("%3d %-16d %-16s %*s<- %s\n", cpu, timestamp / 1000,
72 basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));
77 printf("%3d %-16d %-16s %*s> %s\n", cpu, timestamp / 1000,
78 basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));
83 printf("%3d %-16d %-16s %*s| %s\n", cpu, timestamp / 1000,
84 basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));