3 * sh_flowtime.d - snoop Bourne shell execution with flow and delta times.
4 * Written for the sh DTrace provider.
6 * $Id: sh_flowtime.d 45 2007-09-17 08:54:56Z brendan $
8 * This traces shell activity from all Bourne shells on the system that are
9 * running with sh provider support.
11 * USAGE: sh_flowtime.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 or builtin name
29 * -> previous line to the start of this function
30 * <- previous line to the end of this function
31 * > previous line to the end of this builtin
32 * | previous line to the end of this command
34 * See sh_flowinfo.d for more verbose and more straightforward delta times.
36 * Filename and function names are printed if available.
38 * WARNING: Watch the first column carefully, it prints the CPU-id. If it
39 * changes, then it is very likely that the output has been shuffled.
41 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
45 * The contents of this file are subject to the terms of the
46 * Common Development and Distribution License, Version 1.0 only
47 * (the "License"). You may not use this file except in compliance
50 * You can obtain a copy of the license at Docs/cddl1.txt
51 * or http://www.opensolaris.org/os/licensing.
52 * See the License for the specific language governing permissions
53 * and limitations under the License.
57 * 09-Sep-2007 Brendan Gregg Created this.
60 #pragma D option quiet
61 #pragma D option switchrate=10
69 printf("%3s %-16s %-16s %9s -- %s\n", "C", "TIME(us)", "FILE",
74 sh*:::function-return,
79 self->last = timestamp;
84 this->elapsed = (timestamp - self->last) / 1000;
85 printf("%3d %-16d %-16s %9d %*s-> %s\n", cpu, timestamp / 1000,
86 basename(copyinstr(arg0)), this->elapsed, self->depth * 2, "",
89 self->last = timestamp;
94 this->elapsed = (timestamp - self->last) / 1000;
95 self->depth -= self->depth > 0 ? 1 : 0;
96 printf("%3d %-16d %-16s %9d %*s<- %s\n", cpu, timestamp / 1000,
97 basename(copyinstr(arg0)), this->elapsed, self->depth * 2, "",
99 self->last = timestamp;
104 this->elapsed = (timestamp - self->last) / 1000;
105 printf("%3d %-16d %-16s %9d %*s> %s\n", cpu, timestamp / 1000,
106 basename(copyinstr(arg0)), this->elapsed, self->depth * 2, "",
108 self->last = timestamp;
113 this->elapsed = (timestamp - self->last) / 1000;
114 printf("%3d %-16d %-16s %9d %*s| %s\n", cpu, timestamp / 1000,
115 basename(copyinstr(arg0)), this->elapsed, self->depth * 2, "",
117 self->last = timestamp;