3 * sh_calldist.d - measure Bourne shell elapsed times for types of operation.
4 * Written for the sh DTrace provider.
6 * $Id: sh_calldist.d 28 2007-09-13 10:49:37Z brendan $
8 * This traces shell activity from all Bourne shells on the system that are
9 * running with sh provider support.
11 * USAGE: sh_calldist.d # hit Ctrl-C to end
13 * This script prints distribution plots of elapsed time for shell
14 * operations. Use sh_calltime.d for summary reports.
17 * 1 Filename of the shell or shellscript
18 * 2 Type of call (func/builtin/cmd)
21 * Filename and call names are printed if available.
23 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
27 * The contents of this file are subject to the terms of the
28 * Common Development and Distribution License, Version 1.0 only
29 * (the "License"). You may not use this file except in compliance
32 * You can obtain a copy of the license at Docs/cddl1.txt
33 * or http://www.opensolaris.org/os/licensing.
34 * See the License for the specific language governing permissions
35 * and limitations under the License.
39 * 09-Sep-2007 Brendan Gregg Created this.
42 #pragma D option quiet
46 printf("Tracing... Hit Ctrl-C to end.\n");
52 self->exclude[self->depth] = 0;
53 self->function[self->depth] = timestamp;
57 /self->function[self->depth]/
59 this->elapsed_incl = timestamp - self->function[self->depth];
60 this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];
61 self->function[self->depth] = 0;
62 self->exclude[self->depth] = 0;
63 this->file = basename(copyinstr(arg0));
64 this->name = copyinstr(arg1);
66 @types_incl[this->file, "func", this->name] =
67 quantize(this->elapsed_incl / 1000);
68 @types_excl[this->file, "func", this->name] =
69 quantize(this->elapsed_excl / 1000);
72 self->exclude[self->depth] += this->elapsed_incl;
77 self->builtin = timestamp;
83 this->elapsed = timestamp - self->builtin;
86 @types[basename(copyinstr(arg0)), "builtin", copyinstr(arg1)] =
87 quantize(this->elapsed / 1000);
89 self->exclude[self->depth] += this->elapsed;
94 self->command = timestamp;
100 this->elapsed = timestamp - self->command;
103 @types[basename(copyinstr(arg0)), "cmd", copyinstr(arg1)] =
104 quantize(this->elapsed / 1000);
106 self->exclude[self->depth] += this->elapsed;
111 printf("Elapsed times (us),\n\n");
112 printa(" %s, %s, %s %@d\n", @types);
114 printf("Exclusive function elapsed times (us),\n\n");
115 printa(" %s, %s, %s %@d\n", @types_excl);
117 printf("Inclusive function elapsed times (us),\n\n");
118 printa(" %s, %s, %s %@d\n", @types_incl);