3 * sh_calltime.d - measure Bourne shell elapsed times for types of operation.
4 * Written for the sh DTrace provider.
6 * $Id: sh_calltime.d 46 2007-09-17 10:25:36Z brendan $
8 * This traces shell activity from all Bourne shells on the system that are
9 * running with sh provider support.
11 * USAGE: sh_calltime.d # hit Ctrl-C to end
14 * FILE Filename of the shell or shellscript
15 * TYPE Type of call (func/builtin/cmd/total)
17 * TOTAL Total elapsed time for calls (us)
19 * Filename and call names are printed if available.
21 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
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
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.
37 * 09-Sep-2007 Brendan Gregg Created this.
40 #pragma D option quiet
44 printf("Tracing... Hit Ctrl-C to end.\n");
50 self->exclude[self->depth] = 0;
51 self->function[self->depth] = timestamp;
55 /self->function[self->depth]/
57 this->elapsed_incl = timestamp - self->function[self->depth];
58 this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];
59 self->function[self->depth] = 0;
60 self->exclude[self->depth] = 0;
61 this->file = basename(copyinstr(arg0));
62 this->name = copyinstr(arg1);
64 @num[this->file, "func", this->name] = count();
65 @num["-", "total", "-"] = count();
66 @types_incl[this->file, "func", this->name] = sum(this->elapsed_incl);
67 @types_excl[this->file, "func", this->name] = sum(this->elapsed_excl);
68 @types_excl["-", "total", "-"] = sum(this->elapsed_excl);
71 self->exclude[self->depth] += this->elapsed_incl;
76 self->builtin = timestamp;
82 this->elapsed = timestamp - self->builtin;
84 this->file = basename(copyinstr(arg0));
85 this->name = copyinstr(arg1);
87 @num[this->file, "builtin", this->name] = count();
88 @num["-", "total", "-"] = count();
89 @types[this->file, "builtin", this->name] = sum(this->elapsed);
90 @types["-", "total", "-"] = sum(this->elapsed);
92 self->exclude[self->depth] += this->elapsed;
97 self->command = timestamp;
103 this->elapsed = timestamp - self->command;
105 this->file = basename(copyinstr(arg0));
106 this->name = copyinstr(arg1);
108 @num[this->file, "cmd", this->name] = count();
109 @num["-", "total", "-"] = count();
110 @types[this->file, "cmd", this->name] = sum(this->elapsed);
111 @types["-", "total", "-"] = sum(this->elapsed);
113 self->exclude[self->depth] += this->elapsed;
118 printf("\nCounts,\n");
119 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
120 printa(" %-20s %-10s %-32s %@8d\n", @num);
122 normalize(@types, 1000);
123 printf("\nElapsed times (us),\n");
124 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
125 printa(" %-20s %-10s %-32s %@8d\n", @types);
127 normalize(@types_excl, 1000);
128 printf("\nExclusive function elapsed times (us),\n");
129 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
130 printa(" %-20s %-10s %-32s %@8d\n", @types_excl);
132 normalize(@types_incl, 1000);
133 printf("\nInclusive function elapsed times (us),\n");
134 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
135 printa(" %-20s %-10s %-32s %@8d\n", @types_incl);