summaryrefslogtreecommitdiffstats
path: root/cddl/contrib/dtracetoolkit/Shell
diff options
context:
space:
mode:
Diffstat (limited to 'cddl/contrib/dtracetoolkit/Shell')
-rw-r--r--cddl/contrib/dtracetoolkit/Shell/Readme35
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_calldist.d119
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_calls.d72
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_calltime.d136
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_cpudist.d142
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_cputime.d158
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_flow.d85
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_flowinfo.d152
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_flowtime.d118
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_lines.d55
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_pidcolors.d203
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_stat.d133
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_syscalls.d83
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_syscolors.d169
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_wasted.d101
-rwxr-xr-xcddl/contrib/dtracetoolkit/Shell/sh_who.d56
16 files changed, 1817 insertions, 0 deletions
diff --git a/cddl/contrib/dtracetoolkit/Shell/Readme b/cddl/contrib/dtracetoolkit/Shell/Readme
new file mode 100644
index 0000000..9bf96ff
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/Readme
@@ -0,0 +1,35 @@
+Shell - DTracing Shell Scripting
+
+ These scripts trace activity of various shell programming languages,
+ and make use of specific shell DTrace providers, which are either
+ integrated or available for download from the shells page listed below.
+ Each script has a prefix to make the shell language clear.
+
+ http://www.opensolaris.org/os/community/dtrace/shells/
+
+ sh - the Bourne Shell. This provider was written by Alan Hargreaves and
+ is currently available both as a diff and in binary form from the shells
+ page.
+
+ Since the DTrace Shell providers are under development, there is a chance
+ that they have changed slightly by the time you are reading this, causing
+ these scripts to either break or behave oddly. Firstly, check for newer
+ versions of the DTraceToolkit; if it hasn't been updated and you need
+ to use these scripts immediately, then updating them shouldn't take
+ too long. The following was the state of the providers when these scripts
+ were written - check for changes and update the scripts accordingly,
+
+ provider sh {
+ probe function-entry(file, function, lineno);
+ probe function-return(file, function, rval);
+ probe builtin-entry(file, function, lineno);
+ probe builtin-return(file, function, rval);
+ probe command-entry(file, function, lineno);
+ probe command-return(file, function, rval);
+ probe script-start(file);
+ probe script-done(file, rval);
+ probe subshell-entry(file, childpid);
+ probe subshell-return(file, rval);
+ probe line(file, lineno);
+ };
+
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_calldist.d b/cddl/contrib/dtracetoolkit/Shell/sh_calldist.d
new file mode 100755
index 0000000..e758bab
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_calldist.d
@@ -0,0 +1,119 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_calldist.d - measure Bourne shell elapsed times for types of operation.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_calldist.d 28 2007-09-13 10:49:37Z brendan $
+ *
+ * This traces shell activity from all Bourne shells on the system that are
+ * running with sh provider support.
+ *
+ * USAGE: sh_calldist.d # hit Ctrl-C to end
+ *
+ * This script prints distribution plots of elapsed time for shell
+ * operations. Use sh_calltime.d for summary reports.
+ *
+ * FIELDS:
+ * 1 Filename of the shell or shellscript
+ * 2 Type of call (func/builtin/cmd)
+ * 3 Name of call
+ *
+ * Filename and call names are printed if available.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+sh*:::function-entry
+{
+ self->depth++;
+ self->exclude[self->depth] = 0;
+ self->function[self->depth] = timestamp;
+}
+
+sh*:::function-return
+/self->function[self->depth]/
+{
+ this->elapsed_incl = timestamp - self->function[self->depth];
+ this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];
+ self->function[self->depth] = 0;
+ self->exclude[self->depth] = 0;
+ this->file = basename(copyinstr(arg0));
+ this->name = copyinstr(arg1);
+
+ @types_incl[this->file, "func", this->name] =
+ quantize(this->elapsed_incl / 1000);
+ @types_excl[this->file, "func", this->name] =
+ quantize(this->elapsed_excl / 1000);
+
+ self->depth--;
+ self->exclude[self->depth] += this->elapsed_incl;
+}
+
+sh*:::builtin-entry
+{
+ self->builtin = timestamp;
+}
+
+sh*:::builtin-return
+/self->builtin/
+{
+ this->elapsed = timestamp - self->builtin;
+ self->builtin = 0;
+
+ @types[basename(copyinstr(arg0)), "builtin", copyinstr(arg1)] =
+ quantize(this->elapsed / 1000);
+
+ self->exclude[self->depth] += this->elapsed;
+}
+
+sh*:::command-entry
+{
+ self->command = timestamp;
+}
+
+sh*:::command-return
+/self->command/
+{
+ this->elapsed = timestamp - self->command;
+ self->command = 0;
+
+ @types[basename(copyinstr(arg0)), "cmd", copyinstr(arg1)] =
+ quantize(this->elapsed / 1000);
+
+ self->exclude[self->depth] += this->elapsed;
+}
+
+dtrace:::END
+{
+ printf("Elapsed times (us),\n\n");
+ printa(" %s, %s, %s %@d\n", @types);
+
+ printf("Exclusive function elapsed times (us),\n\n");
+ printa(" %s, %s, %s %@d\n", @types_excl);
+
+ printf("Inclusive function elapsed times (us),\n\n");
+ printa(" %s, %s, %s %@d\n", @types_incl);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_calls.d b/cddl/contrib/dtracetoolkit/Shell/sh_calls.d
new file mode 100755
index 0000000..2ad72f1
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_calls.d
@@ -0,0 +1,72 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_calls.d - count Bourne calls (func/builtin/cmd/subsh) using DTrace.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_calls.d 52 2007-09-24 04:28:01Z brendan $
+ *
+ * This traces shell activity from all Bourne shells on the system that are
+ * running with sh provider support.
+ *
+ * USAGE: sh_calls.d # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * FILE Filename of the shell or shellscript
+ * TYPE Type of call (func/builtin/cmd/subsh)
+ * NAME Name of call
+ * COUNT Number of calls during sample
+ *
+ * Filename and function names are printed if available.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+sh*:::function-entry
+{
+ @calls[basename(copyinstr(arg0)), "func", copyinstr(arg1)] = count();
+}
+
+sh*:::builtin-entry
+{
+ @calls[basename(copyinstr(arg0)), "builtin", copyinstr(arg1)] = count();
+}
+
+sh*:::command-entry
+{
+ @calls[basename(copyinstr(arg0)), "cmd", copyinstr(arg1)] = count();
+}
+
+sh*:::subshell-entry
+/arg1 != 0/
+{
+ @calls[basename(copyinstr(arg0)), "subsh", "-"] = count();
+}
+
+dtrace:::END
+{
+ printf(" %-22s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
+ printa(" %-22s %-10s %-32s %@8d\n", @calls);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_calltime.d b/cddl/contrib/dtracetoolkit/Shell/sh_calltime.d
new file mode 100755
index 0000000..e3c72b4
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_calltime.d
@@ -0,0 +1,136 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_calltime.d - measure Bourne shell elapsed times for types of operation.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_calltime.d 46 2007-09-17 10:25:36Z brendan $
+ *
+ * This traces shell activity from all Bourne shells on the system that are
+ * running with sh provider support.
+ *
+ * USAGE: sh_calltime.d # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * FILE Filename of the shell or shellscript
+ * TYPE Type of call (func/builtin/cmd/total)
+ * NAME Name of call
+ * TOTAL Total elapsed time for calls (us)
+ *
+ * Filename and call names are printed if available.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+sh*:::function-entry
+{
+ self->depth++;
+ self->exclude[self->depth] = 0;
+ self->function[self->depth] = timestamp;
+}
+
+sh*:::function-return
+/self->function[self->depth]/
+{
+ this->elapsed_incl = timestamp - self->function[self->depth];
+ this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];
+ self->function[self->depth] = 0;
+ self->exclude[self->depth] = 0;
+ this->file = basename(copyinstr(arg0));
+ this->name = copyinstr(arg1);
+
+ @num[this->file, "func", this->name] = count();
+ @num["-", "total", "-"] = count();
+ @types_incl[this->file, "func", this->name] = sum(this->elapsed_incl);
+ @types_excl[this->file, "func", this->name] = sum(this->elapsed_excl);
+ @types_excl["-", "total", "-"] = sum(this->elapsed_excl);
+
+ self->depth--;
+ self->exclude[self->depth] += this->elapsed_incl;
+}
+
+sh*:::builtin-entry
+{
+ self->builtin = timestamp;
+}
+
+sh*:::builtin-return
+/self->builtin/
+{
+ this->elapsed = timestamp - self->builtin;
+ self->builtin = 0;
+ this->file = basename(copyinstr(arg0));
+ this->name = copyinstr(arg1);
+
+ @num[this->file, "builtin", this->name] = count();
+ @num["-", "total", "-"] = count();
+ @types[this->file, "builtin", this->name] = sum(this->elapsed);
+ @types["-", "total", "-"] = sum(this->elapsed);
+
+ self->exclude[self->depth] += this->elapsed;
+}
+
+sh*:::command-entry
+{
+ self->command = timestamp;
+}
+
+sh*:::command-return
+/self->command/
+{
+ this->elapsed = timestamp - self->command;
+ self->command = 0;
+ this->file = basename(copyinstr(arg0));
+ this->name = copyinstr(arg1);
+
+ @num[this->file, "cmd", this->name] = count();
+ @num["-", "total", "-"] = count();
+ @types[this->file, "cmd", this->name] = sum(this->elapsed);
+ @types["-", "total", "-"] = sum(this->elapsed);
+
+ self->exclude[self->depth] += this->elapsed;
+}
+
+dtrace:::END
+{
+ printf("\nCounts,\n");
+ printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
+ printa(" %-20s %-10s %-32s %@8d\n", @num);
+
+ normalize(@types, 1000);
+ printf("\nElapsed times (us),\n");
+ printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
+ printa(" %-20s %-10s %-32s %@8d\n", @types);
+
+ normalize(@types_excl, 1000);
+ printf("\nExclusive function elapsed times (us),\n");
+ printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
+ printa(" %-20s %-10s %-32s %@8d\n", @types_excl);
+
+ normalize(@types_incl, 1000);
+ printf("\nInclusive function elapsed times (us),\n");
+ printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
+ printa(" %-20s %-10s %-32s %@8d\n", @types_incl);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_cpudist.d b/cddl/contrib/dtracetoolkit/Shell/sh_cpudist.d
new file mode 100755
index 0000000..0809fd5
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_cpudist.d
@@ -0,0 +1,142 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_cpudist.d - measure Bourne shell on-CPU times for types of operation.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_cpudist.d 28 2007-09-13 10:49:37Z brendan $
+ *
+ * This traces shell activity from all Bourne shells on the system that are
+ * running with sh provider support.
+ *
+ * USAGE: sh_cpudist.d # hit Ctrl-C to end
+ *
+ * This script prints distribution plots of on-CPU time for shell
+ * operations. Use sh_cputime.d for summary reports.
+ *
+ * FIELDS:
+ * 1 Filename of the shell or shellscript
+ * 2 Type of call (func/builtin/cmd)
+ * 3 Name of call
+ *
+ * Filename and call names are printed if available.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+sh*:::function-entry
+{
+ self->depth++;
+ self->function[self->depth] = vtimestamp;
+ self->exclude[self->depth] = 0;
+}
+
+sh*:::function-return
+/self->function[self->depth]/
+{
+ this->oncpu_incl = vtimestamp - self->function[self->depth];
+ this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth];
+ self->function[self->depth] = 0;
+ self->exclude[self->depth] = 0;
+ this->file = basename(copyinstr(arg0));
+ this->name = copyinstr(arg1);
+
+ @types_incl[this->file, "func", this->name] =
+ quantize(this->oncpu_incl / 1000);
+ @types_excl[this->file, "func", this->name] =
+ quantize(this->oncpu_excl / 1000);
+
+ self->depth--;
+ self->exclude[self->depth] += this->oncpu_incl;
+}
+
+sh*:::builtin-entry
+{
+ self->builtin = vtimestamp;
+}
+
+sh*:::builtin-return
+/self->builtin/
+{
+ this->oncpu = vtimestamp - self->builtin;
+ self->builtin = 0;
+
+ @types[basename(copyinstr(arg0)), "builtin", copyinstr(arg1)] =
+ quantize(this->oncpu / 1000);
+
+ self->exclude[self->depth] += this->oncpu;
+}
+
+sh*:::command-entry
+{
+ incmd[pid] = basename(copyinstr(arg0));
+ depth[pid] = self->depth;
+}
+
+sh*:::command-return
+{
+ incmd[pid] = 0;
+}
+
+proc:::exec-success
+{
+ /*
+ * Due to thread timing after fork(), this probe can fire before
+ * sh*:::command-entry has, which means we can't predicate this
+ * exec() away just yet. Store the vtimestamp in case it is needed.
+ */
+ self->command = vtimestamp;
+}
+
+proc:::exit
+/incmd[ppid] == NULL/
+{
+ self->command = 0;
+}
+
+proc:::exit
+/incmd[ppid] != NULL/
+{
+ this->oncpu = vtimestamp - self->command;
+ self->command = 0;
+
+ @types[incmd[ppid], "cmd", execname] = quantize(this->oncpu / 1000);
+
+ self->exclude[depth[ppid]] += this->oncpu;
+ incmd[ppid] = 0;
+ depth[ppid] = 0;
+}
+
+dtrace:::END
+{
+ printf("On-CPU times (us),\n\n");
+ printa(" %s, %s, %s %@d\n", @types);
+
+ printf("Exclusive function on-CPU times (us),\n\n");
+ printa(" %s, %s, %s %@d\n", @types_excl);
+
+ printf("Inclusive function on-CPU times (us),\n\n");
+ printa(" %s, %s, %s %@d\n", @types_incl);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_cputime.d b/cddl/contrib/dtracetoolkit/Shell/sh_cputime.d
new file mode 100755
index 0000000..433ce8e
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_cputime.d
@@ -0,0 +1,158 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_cputime.d - measure Bourne shell on-CPU times for types of operation.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_cputime.d 46 2007-09-17 10:25:36Z brendan $
+ *
+ * This traces shell activity from all Bourne shells on the system that are
+ * running with sh provider support.
+ *
+ * USAGE: sh_cputime.d # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * FILE Filename of the shell or shellscript
+ * TYPE Type of call (func/builtin/cmd/total)
+ * NAME Name of call
+ * TOTAL Total on-CPU time for calls (us)
+ *
+ * Filename and call names are printed if available.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+sh*:::function-entry
+{
+ self->depth++;
+ self->function[self->depth] = vtimestamp;
+ self->exclude[self->depth] = 0;
+}
+
+sh*:::function-return
+/self->function[self->depth]/
+{
+ this->oncpu_incl = vtimestamp - self->function[self->depth];
+ this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth];
+ self->function[self->depth] = 0;
+ self->exclude[self->depth] = 0;
+ this->file = basename(copyinstr(arg0));
+ this->name = copyinstr(arg1);
+
+ @num[this->file, "func", this->name] = count();
+ @num["-", "total", "-"] = count();
+ @types_incl[this->file, "func", this->name] = sum(this->oncpu_incl);
+ @types_excl[this->file, "func", this->name] = sum(this->oncpu_excl);
+ @types_excl["-", "total", "-"] = sum(this->oncpu_excl);
+
+ self->depth--;
+ self->exclude[self->depth] += this->oncpu_incl;
+}
+
+sh*:::builtin-entry
+{
+ self->builtin = vtimestamp;
+}
+
+sh*:::builtin-return
+/self->builtin/
+{
+ this->oncpu = vtimestamp - self->builtin;
+ self->builtin = 0;
+ this->file = basename(copyinstr(arg0));
+ this->name = copyinstr(arg1);
+
+ @num[this->file, "builtin", this->name] = count();
+ @num["-", "total", "-"] = count();
+ @types[this->file, "builtin", this->name] = sum(this->oncpu);
+ @types["-", "total", "-"] = sum(this->oncpu);
+
+ self->exclude[self->depth] += this->oncpu;
+}
+
+sh*:::command-entry
+{
+ incmd[pid] = basename(copyinstr(arg0));
+ depth[pid] = self->depth;
+}
+
+sh*:::command-return
+{
+ incmd[pid] = 0;
+}
+
+proc:::exec-success
+{
+ /*
+ * Due to thread timing after fork(), this probe can fire before
+ * sh*:::command-entry has, which means we can't predicate this
+ * exec() away just yet. Store the vtimestamp in case it is needed.
+ */
+ self->command = vtimestamp;
+}
+
+proc:::exit
+/incmd[ppid] == NULL/
+{
+ self->command = 0;
+}
+
+proc:::exit
+/incmd[ppid] != NULL/
+{
+ this->oncpu = vtimestamp - self->command;
+ self->command = 0;
+
+ @num[incmd[ppid], "cmd", execname] = count();
+ @num["-", "total", "-"] = count();
+ @types[incmd[ppid], "cmd", execname] = sum(this->oncpu);
+ @types["-", "total", "-"] = sum(this->oncpu);
+
+ self->exclude[depth[ppid]] += this->oncpu;
+ incmd[ppid] = 0;
+ depth[ppid] = 0;
+}
+
+dtrace:::END
+{
+ printf("\nCounts,\n");
+ printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
+ printa(" %-20s %-10s %-32s %@8d\n", @num);
+
+ normalize(@types, 1000);
+ printf("\nOn-CPU times (us),\n");
+ printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
+ printa(" %-20s %-10s %-32s %@8d\n", @types);
+
+ normalize(@types_excl, 1000);
+ printf("\nExclusive function on-CPU times (us),\n");
+ printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
+ printa(" %-20s %-10s %-32s %@8d\n", @types_excl);
+
+ normalize(@types_incl, 1000);
+ printf("\nInclusive function on-CPU times (us),\n");
+ printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
+ printa(" %-20s %-10s %-32s %@8d\n", @types_incl);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_flow.d b/cddl/contrib/dtracetoolkit/Shell/sh_flow.d
new file mode 100755
index 0000000..ff24f59
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_flow.d
@@ -0,0 +1,85 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_flow.d - snoop Bourne shell execution showing function flow using DTrace.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_flow.d 41 2007-09-17 02:20:10Z brendan $
+ *
+ * This traces shell activity from all Bourne shells on the system that are
+ * running with sh provider support.
+ *
+ * USAGE: sh_flow.d # hit Ctrl-C to end
+ *
+ * This watches shell function entries and returns, and indents child
+ * function calls. Shell builtins are also printed.
+ *
+ * FIELDS:
+ * C CPU-id
+ * TIME(us) Time since boot, us
+ * FILE Filename that this function belongs to
+ * NAME Shell function, builtin or command name
+ *
+ * LEGEND:
+ * -> function entry
+ * <- function return
+ * > builtin
+ * | external command
+ *
+ * WARNING: Watch the first column carefully, it prints the CPU-id. If it
+ * changes, then it is very likely that the output has been shuffled.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+#pragma D option switchrate=10
+
+self int depth;
+
+dtrace:::BEGIN
+{
+ self->depth = 0;
+ printf("%3s %-16s %-16s -- %s\n", "C", "TIME(us)", "FILE", "NAME");
+}
+
+sh*:::function-entry
+{
+ printf("%3d %-16d %-16s %*s-> %s\n", cpu, timestamp / 1000,
+ basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));
+ self->depth++;
+}
+
+sh*:::function-return
+{
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%3d %-16d %-16s %*s<- %s\n", cpu, timestamp / 1000,
+ basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));
+}
+
+sh*:::builtin-entry
+{
+ printf("%3d %-16d %-16s %*s> %s\n", cpu, timestamp / 1000,
+ basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));
+}
+
+sh*:::command-entry
+{
+ printf("%3d %-16d %-16s %*s| %s\n", cpu, timestamp / 1000,
+ basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_flowinfo.d b/cddl/contrib/dtracetoolkit/Shell/sh_flowinfo.d
new file mode 100755
index 0000000..6da0836
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_flowinfo.d
@@ -0,0 +1,152 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_flowinfo.d - snoop Bourne shell flow with additional info.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_flowinfo.d 52 2007-09-24 04:28:01Z brendan $
+ *
+ * This traces shell activity from all Bourne shells on the system that are
+ * running with sh provider support.
+ *
+ * USAGE: sh_flowinfo.d # hit Ctrl-C to end
+ *
+ * This watches shell function entries and returns, and indents child
+ * function calls. Shell builtins and external commands are also printed.
+ *
+ * FIELDS:
+ * C CPU-id
+ * PID Process ID
+ * DELTA(us) Elapsed time from previous line to this line
+ * FILE Filename of the shell script
+ * LINE Line number of filename
+ * TYPE Type of call (func/builtin/cmd/subsh)
+ * NAME Shell function, builtin or command name
+ *
+ * WARNING: Watch the first column carefully, it prints the CPU-id. If it
+ * changes, then it is very likely that the output has been shuffled.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+#pragma D option switchrate=10
+
+self int depth;
+
+dtrace:::BEGIN
+{
+ self->depth = 0;
+ printf("%3s %6s %10s %16s:%-4s %-8s -- %s\n", "C", "PID", "DELTA(us)",
+ "FILE", "LINE", "TYPE", "NAME");
+}
+
+sh*:::function-entry,
+sh*:::function-return,
+sh*:::builtin-entry,
+sh*:::builtin-return,
+sh*:::command-entry,
+sh*:::command-return,
+sh*:::subshell-entry,
+sh*:::subshell-return
+/self->last == 0/
+{
+ self->last = timestamp;
+}
+
+sh*:::function-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%3d %6d %10d %16s:%-4d %-8s %*s-> %s\n", cpu, pid,
+ this->delta, basename(copyinstr(arg0)), arg2, "func",
+ self->depth * 2, "", copyinstr(arg1));
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh*:::function-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%3d %6d %10d %16s:- %-8s %*s<- %s\n", cpu, pid,
+ this->delta, basename(copyinstr(arg0)), "func", self->depth * 2,
+ "", copyinstr(arg1));
+ self->last = timestamp;
+}
+
+sh*:::builtin-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%3d %6d %10d %16s:%-4d %-8s %*s-> %s\n", cpu, pid,
+ this->delta, basename(copyinstr(arg0)), arg2, "builtin",
+ self->depth * 2, "", copyinstr(arg1));
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh*:::builtin-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%3d %6d %10d %16s:- %-8s %*s<- %s\n", cpu, pid,
+ this->delta, basename(copyinstr(arg0)), "builtin",
+ self->depth * 2, "", copyinstr(arg1));
+ self->last = timestamp;
+}
+
+sh*:::command-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%3d %6d %10d %16s:%-4d %-8s %*s-> %s\n", cpu, pid,
+ this->delta, basename(copyinstr(arg0)), arg2, "cmd",
+ self->depth * 2, "", copyinstr(arg1));
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh*:::command-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%3d %6d %10d %16s:- %-8s %*s<- %s\n", cpu, pid,
+ this->delta, basename(copyinstr(arg0)), "cmd",
+ self->depth * 2, "", copyinstr(arg1));
+ self->last = timestamp;
+}
+
+sh*:::subshell-entry
+/arg1 != 0/
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%3d %6d %10d %16s:- %-8s %*s-> pid %d\n", cpu, pid,
+ this->delta, basename(copyinstr(arg0)), "subsh",
+ self->depth * 2, "", arg1);
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh*:::subshell-return
+/self->last/
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%3d %6d %10d %16s:- %-8s %*s<- = %d\n", cpu, pid,
+ this->delta, basename(copyinstr(arg0)), "subsh",
+ self->depth * 2, "", arg1);
+ self->last = timestamp;
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_flowtime.d b/cddl/contrib/dtracetoolkit/Shell/sh_flowtime.d
new file mode 100755
index 0000000..5df118b
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_flowtime.d
@@ -0,0 +1,118 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_flowtime.d - snoop Bourne shell execution with flow and delta times.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_flowtime.d 45 2007-09-17 08:54:56Z brendan $
+ *
+ * This traces shell activity from all Bourne shells on the system that are
+ * running with sh provider support.
+ *
+ * USAGE: sh_flowtime.d # hit Ctrl-C to end
+ *
+ * This watches shell function entries and returns, and indents child
+ * function calls. Shell builtins are also printed.
+ *
+ * FIELDS:
+ * C CPU-id
+ * TIME(us) Time since boot, us
+ * FILE Filename that this function belongs to
+ * NAME Shell function or builtin name
+ *
+ * LEGEND:
+ * -> function entry
+ * <- function return
+ * > builtin
+ * | external command
+ *
+ * DELTAs:
+ * -> previous line to the start of this function
+ * <- previous line to the end of this function
+ * > previous line to the end of this builtin
+ * | previous line to the end of this command
+ *
+ * See sh_flowinfo.d for more verbose and more straightforward delta times.
+ *
+ * Filename and function names are printed if available.
+ *
+ * WARNING: Watch the first column carefully, it prints the CPU-id. If it
+ * changes, then it is very likely that the output has been shuffled.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+#pragma D option switchrate=10
+
+self int depth;
+
+self uint64_t last;
+
+dtrace:::BEGIN
+{
+ printf("%3s %-16s %-16s %9s -- %s\n", "C", "TIME(us)", "FILE",
+ "DELTA(us)", "NAME");
+}
+
+sh*:::function-entry,
+sh*:::function-return,
+sh*:::builtin-return,
+sh*:::command-return
+/self->last == 0/
+{
+ self->last = timestamp;
+}
+
+sh*:::function-entry
+{
+ this->elapsed = (timestamp - self->last) / 1000;
+ printf("%3d %-16d %-16s %9d %*s-> %s\n", cpu, timestamp / 1000,
+ basename(copyinstr(arg0)), this->elapsed, self->depth * 2, "",
+ copyinstr(arg1));
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh*:::function-return
+{
+ this->elapsed = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%3d %-16d %-16s %9d %*s<- %s\n", cpu, timestamp / 1000,
+ basename(copyinstr(arg0)), this->elapsed, self->depth * 2, "",
+ copyinstr(arg1));
+ self->last = timestamp;
+}
+
+sh*:::builtin-return
+{
+ this->elapsed = (timestamp - self->last) / 1000;
+ printf("%3d %-16d %-16s %9d %*s> %s\n", cpu, timestamp / 1000,
+ basename(copyinstr(arg0)), this->elapsed, self->depth * 2, "",
+ copyinstr(arg1));
+ self->last = timestamp;
+}
+
+sh*:::command-return
+{
+ this->elapsed = (timestamp - self->last) / 1000;
+ printf("%3d %-16d %-16s %9d %*s| %s\n", cpu, timestamp / 1000,
+ basename(copyinstr(arg0)), this->elapsed, self->depth * 2, "",
+ copyinstr(arg1));
+ self->last = timestamp;
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_lines.d b/cddl/contrib/dtracetoolkit/Shell/sh_lines.d
new file mode 100755
index 0000000..5cfeb49
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_lines.d
@@ -0,0 +1,55 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_lines.d - trace Bourne shell line execution using DTrace.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_lines.d 25 2007-09-12 09:51:58Z brendan $
+ *
+ * This traces shell activity from all Bourne shells on the system that are
+ * running with sh provider support.
+ *
+ * USAGE: sh_lines.d # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * FILE Filename of the shell or shellscript
+ * LINE Line number
+ * COUNT Number of times a line was executed
+ *
+ * Filenames are printed if available.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+sh*:::line
+{
+ @calls[basename(copyinstr(arg0)), arg1] = count();
+}
+
+dtrace:::END
+{
+ printf(" %32s:%-6s %10s\n", "FILE", "LINE", "COUNT");
+ printa(" %32s:%-6d %@10d\n", @calls);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_pidcolors.d b/cddl/contrib/dtracetoolkit/Shell/sh_pidcolors.d
new file mode 100755
index 0000000..0196218
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_pidcolors.d
@@ -0,0 +1,203 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_pidcolors.d - Demonstration of deeper DTrace Bourne shell analysis.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_pidcolors.d 27 2007-09-13 09:26:01Z brendan $
+ *
+ * USAGE: sh_pidcolors.d { -p PID | -c cmd } # hit Ctrl-C to end
+ *
+ * This extends sh_syscolors.d by including some "pid" provider tracing
+ * as a starting point for deeper analysis. Currently it adds the probes,
+ *
+ * pid$target:a.out:e*:entry,
+ * pid$target:a.out:e*:return
+ *
+ * which means, all functions from the /usr/bin/sh binary that begin with
+ * the letter "e". This adds about 34 probes. Customise it to whichever
+ * parts of /usr/bin/sh or the system libraries you are interested in.
+ *
+ * FIELDS:
+ * C CPU-id
+ * PID Process ID
+ * DELTA(us) Elapsed time from previous line to this line
+ * FILE Filename of the shell script
+ * LINE Line number of filename
+ * TYPE Type of call (func/builtin/cmd/line/shell)
+ * NAME Shell function, builtin or command name
+ *
+ * The filename for syscalls may be printed as the shell name, if the
+ * script was invoked using the form "shell filename" rather than running
+ * the script with an interpreter line.
+ *
+ * WARNING: Watch the first column carefully, it prints the CPU-id. If it
+ * changes, then it is very likely that the output has been shuffled.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+#pragma D option switchrate=10
+
+self int depth;
+
+dtrace:::BEGIN
+{
+ color_shell = "\033[2;35m"; /* violet, faint */
+ color_line = "\033[1;35m"; /* violet, bold */
+ color_lib = "\033[2;34m"; /* blue, faint */
+ color_syscall = "\033[2;32m"; /* green, faint */
+ color_off = "\033[0m"; /* default */
+
+ printf("%s %6s %10s %16s:%-4s %-8s -- %s\n", "C", "PID", "DELTA(us)",
+ "FILE", "LINE", "TYPE", "NAME");
+}
+
+sh$target:::function-entry,
+sh$target:::function-return,
+sh$target:::builtin-entry,
+sh$target:::command-entry,
+syscall:::entry,
+syscall:::return,
+/* Customize Here, */
+pid$target:a.out:e*:entry,
+pid$target:a.out:e*:return
+/self->last == 0 && pid == $target/
+{
+ self->last = timestamp;
+}
+
+sh$target:::function-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s-> %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "func",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh$target:::function-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%s%d %6d %10d %16s:- %-8s %*s<- %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), "func",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->last = timestamp;
+}
+
+sh$target:::builtin-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s-> %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "builtin",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh$target:::builtin-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s<- %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "builtin",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->last = timestamp;
+}
+
+sh$target:::command-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s-> %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "cmd",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh$target:::command-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s<- %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "cmd",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->last = timestamp;
+}
+
+sh$target:::line
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s-- %s\n", color_line,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg1, "line",
+ self->depth * 2, "", color_off);
+ self->last = timestamp;
+}
+
+/* Customise Here, */
+pid$target:a.out:e*:entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:- %-8s %*s-> %s%s\n", color_lib,
+ cpu, pid, this->delta, basename(execname), "sh",
+ self->depth * 2, "", probefunc, color_off);
+ self->depth++;
+ self->last = timestamp;
+}
+
+/* Customise Here, */
+pid$target:a.out:e*:return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%s%d %6d %10d %16s:- %-8s %*s<- %s%s\n", color_lib,
+ cpu, pid, this->delta, basename(execname), "sh",
+ self->depth * 2, "", probefunc, color_off);
+ self->last = timestamp;
+}
+
+syscall:::entry
+/pid == $target/
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:- %-8s %*s-> %s%s\n", color_syscall,
+ cpu, pid, this->delta, basename(execname), "syscall",
+ self->depth * 2, "", probefunc, color_off);
+ self->depth++;
+ self->last = timestamp;
+}
+
+syscall:::return
+/pid == $target/
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%s%d %6d %10d %16s:- %-8s %*s<- %s%s\n", color_syscall,
+ cpu, pid, this->delta, basename(execname), "syscall",
+ self->depth * 2, "", probefunc, color_off);
+ self->last = timestamp;
+}
+
+proc:::exit
+/pid == $target/
+{
+ exit(0);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_stat.d b/cddl/contrib/dtracetoolkit/Shell/sh_stat.d
new file mode 100755
index 0000000..70e29b4
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_stat.d
@@ -0,0 +1,133 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_stat.d - Bourne shell operation stats using DTrace.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_stat.d 52 2007-09-24 04:28:01Z brendan $
+ *
+ * This traces activity from all sh processes on the system that are running
+ * with sh provider support.
+ *
+ * USAGE: sh_stat.d [interval [count]]
+ *
+ * FIELDS:
+ * EXEC/s Bourne shells executed per second, including
+ * those without sh provider support
+ * FUNC/s Functions called, per second
+ * BLTIN/s Builtins called, per second
+ * SUB-SH/s Sub-shells called, per second
+ * CMD/s External commands called, per second
+ *
+ * The numbers are counts for the interval specified. The default interval
+ * is 1 second.
+ *
+ * If you see a count in "EXECS" but not in the other columns, then sh
+ * scripts may be running without the DTrace sh provider. See Shell/Readme.
+ *
+ * Filename and function names are printed if available.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+#pragma D option defaultargs
+
+inline int SCREEN = 21;
+
+dtrace:::BEGIN
+{
+ execs = funcs = builtins = subs = cmds = 0;
+ lines = SCREEN + 1;
+ interval = $1 ? $1 : 1;
+ counts = $2 ? $2 : -1;
+ secs = interval;
+ first = 1;
+}
+
+profile:::tick-1sec
+{
+ secs--;
+}
+
+/*
+ * Print Header
+ */
+dtrace:::BEGIN,
+profile:::tick-1sec
+/first || (secs == 0 && lines > SCREEN)/
+{
+ printf("%-20s %8s %8s %8s %8s %8s\n", "TIME", "EXEC/s", "FUNCS/s",
+ "BLTINS/s", "SUB-SH/s", "CMD/s");
+ lines = 0;
+ first = 0;
+}
+
+/*
+ * Tally Data
+ */
+proc:::exec-success
+/execname == "sh"/
+{
+ execs++;
+}
+
+sh*:::function-entry
+{
+ funcs++;
+}
+
+sh*:::builtin-entry
+{
+ builtins++;
+}
+
+sh*:::subshell-entry
+/arg0 != 0/
+{
+ subs++;
+}
+
+sh*:::command-entry
+{
+ cmds++;
+}
+
+/*
+ * Print Output
+ */
+profile:::tick-1sec
+/secs == 0/
+{
+ printf("%-20Y %8d %8d %8d %8d %8d\n", walltimestamp, execs / interval,
+ funcs / interval, builtins / interval, subs / interval,
+ cmds / interval);
+ execs = funcs = builtins = subs = cmds = 0;
+ secs = interval;
+ lines++;
+ counts--;
+}
+
+/*
+ * End
+ */
+profile:::tick-1sec
+/counts == 0/
+{
+ exit(0);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_syscalls.d b/cddl/contrib/dtracetoolkit/Shell/sh_syscalls.d
new file mode 100755
index 0000000..127bede
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_syscalls.d
@@ -0,0 +1,83 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_syscalls.d - count Bourne calls and syscalls using DTrace.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_syscalls.d 25 2007-09-12 09:51:58Z brendan $
+ *
+ * USAGE: sh_syscalls.d { -p PID | -c cmd } # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * FILE Filename of the shell or shellscript
+ * TYPE Type of call (func/builtin/cmd/syscall)
+ * NAME Name of call
+ * COUNT Number of calls during sample
+ *
+ * Filename and function names are printed if available.
+ * The filename for syscalls may be printed as the shell name, if the
+ * script was invoked using the form "shell filename" rather than running
+ * the script with an interpreter line.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+
+self string filename;
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+sh$target:::function-entry,
+sh$target:::builtin-entry,
+sh$target:::command-entry
+/self->filename == NULL/
+{
+ self->filename = basename(copyinstr(arg0));
+}
+
+sh$target:::function-entry
+{
+ @calls[self->filename, "func", copyinstr(arg1)] = count();
+}
+
+sh$target:::builtin-entry
+{
+ @calls[self->filename, "builtin", copyinstr(arg1)] = count();
+}
+
+sh$target:::command-entry
+{
+ @calls[self->filename, "cmd", copyinstr(arg1)] = count();
+}
+
+syscall:::entry
+/pid == $target/
+{
+ @calls[basename(execname), "syscall", probefunc] = count();
+}
+
+dtrace:::END
+{
+ printf("\nCalls for PID %d,\n\n", $target);
+ printf(" %-32s %-10s %-22s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
+ printa(" %-32s %-10s %-22s %@8d\n", @calls);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_syscolors.d b/cddl/contrib/dtracetoolkit/Shell/sh_syscolors.d
new file mode 100755
index 0000000..3622cb3
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_syscolors.d
@@ -0,0 +1,169 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_syscolors.d - trace Bourne shell flow plus syscalls, in color.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_syscolors.d 27 2007-09-13 09:26:01Z brendan $
+ *
+ * USAGE: sh_syscolors.d { -p PID | -c cmd } # hit Ctrl-C to end
+ *
+ * This watches shell function entries and returns, and indents child
+ * function calls. Shell builtins, commands and lines are also printed.
+ *
+ * FIELDS:
+ * C CPU-id
+ * PID Process ID
+ * DELTA(us) Elapsed time from previous line to this line
+ * FILE Filename of the shell script
+ * LINE Line number of filename
+ * TYPE Type of call (func/builtin/cmd/line/shell)
+ * NAME Shell function, builtin or command name
+ *
+ * The filename for syscalls may be printed as the shell name, if the
+ * script was invoked using the form "shell filename" rather than running
+ * the script with an interpreter line.
+ *
+ * WARNING: Watch the first column carefully, it prints the CPU-id. If it
+ * changes, then it is very likely that the output has been shuffled.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+#pragma D option switchrate=10
+
+self int depth;
+
+dtrace:::BEGIN
+{
+ color_shell = "\033[2;35m"; /* violet, faint */
+ color_line = "\033[1;35m"; /* violet, bold */
+ color_syscall = "\033[2;32m"; /* green, faint */
+ color_off = "\033[0m"; /* default */
+
+ printf("%s %6s %10s %16s:%-4s %-8s -- %s\n", "C", "PID", "DELTA(us)",
+ "FILE", "LINE", "TYPE", "NAME");
+}
+
+sh$target:::function-entry,
+sh$target:::function-return,
+sh$target:::builtin-entry,
+sh$target:::command-entry,
+sh$target:::line,
+syscall:::entry,
+syscall:::return
+/self->last == 0 && pid == $target/
+{
+ self->last = timestamp;
+}
+
+sh$target:::function-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s-> %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "func",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh$target:::function-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%s%d %6d %10d %16s:- %-8s %*s<- %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), "func",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->last = timestamp;
+}
+
+sh$target:::builtin-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s-> %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "builtin",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh$target:::builtin-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s<- %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "builtin",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->last = timestamp;
+}
+
+sh$target:::command-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s-> %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "cmd",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->depth++;
+ self->last = timestamp;
+}
+
+sh$target:::command-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s<- %s%s\n", color_shell,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "cmd",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->last = timestamp;
+}
+
+sh$target:::line
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s-- %s\n", color_line,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg1, "line",
+ self->depth * 2, "", color_off);
+ self->last = timestamp;
+}
+
+syscall:::entry
+/pid == $target/
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:- %-8s %*s-> %s%s\n", color_syscall,
+ cpu, pid, this->delta, basename(execname), "syscall",
+ self->depth * 2, "", probefunc, color_off);
+ self->last = timestamp;
+}
+
+syscall:::return
+/pid == $target/
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:- %-8s %*s<- %s%s\n", color_syscall,
+ cpu, pid, this->delta, basename(execname), "syscall",
+ self->depth * 2, "", probefunc, color_off);
+ self->last = timestamp;
+}
+
+proc:::exit
+/pid == $target/
+{
+ exit(0);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_wasted.d b/cddl/contrib/dtracetoolkit/Shell/sh_wasted.d
new file mode 100755
index 0000000..e20db8e
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_wasted.d
@@ -0,0 +1,101 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_wasted.d - measure Bourne shell elapsed times for "wasted" commands.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_wasted.d 25 2007-09-12 09:51:58Z brendan $
+ *
+ * USAGE: sh_wasted.d { -p PID | -c cmd } # hit Ctrl-C to end
+ *
+ * This script measures "wasted" commands - those which are called externally
+ * but are in fact builtins to the shell. Ever seen a script which calls
+ * /usr/bin/echo needlessly? This script measures that cost.
+ *
+ * FIELDS:
+ * FILE Filename of the shell or shellscript
+ * NAME Name of call
+ * TIME Total elapsed time for calls (us)
+ *
+ * IDEA: Mike Shapiro
+ *
+ * Filename and call names are printed if available.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ isbuiltin["echo"] = 1;
+ isbuiltin["test"] = 1;
+ /* add builtins here */
+
+ printf("Tracing... Hit Ctrl-C to end.\n");
+ self->start = timestamp;
+}
+
+sh$target:::command-entry
+{
+ self->command = timestamp;
+}
+
+sh$target:::command-return
+{
+ this->elapsed = timestamp - self->command;
+ this->path = copyinstr(arg1);
+ this->cmd = basename(this->path);
+}
+
+sh$target:::command-return
+/self->command && !isbuiltin[this->cmd]/
+{
+ @types_cmd[basename(copyinstr(arg0)), this->path] = sum(this->elapsed);
+ self->command = 0;
+}
+
+sh$target:::command-return
+/self->command/
+{
+ @types_wasted[basename(copyinstr(arg0)), this->path] =
+ sum(this->elapsed);
+ self->command = 0;
+}
+
+proc:::exit
+/pid == $target/
+{
+ exit(0);
+}
+
+dtrace:::END
+{
+ this->elapsed = (timestamp - self->start) / 1000;
+ printf("Script duration: %d us\n", this->elapsed);
+
+ normalize(@types_cmd, 1000);
+ printf("\nExternal command elapsed times,\n");
+ printf(" %-30s %-22s %8s\n", "FILE", "NAME", "TIME(us)");
+ printa(" %-30s %-22s %@8d\n", @types_cmd);
+
+ normalize(@types_wasted, 1000);
+ printf("\nWasted command elapsed times,\n");
+ printf(" %-30s %-22s %8s\n", "FILE", "NAME", "TIME(us)");
+ printa(" %-30s %-22s %@8d\n", @types_wasted);
+}
diff --git a/cddl/contrib/dtracetoolkit/Shell/sh_who.d b/cddl/contrib/dtracetoolkit/Shell/sh_who.d
new file mode 100755
index 0000000..3e106ff
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Shell/sh_who.d
@@ -0,0 +1,56 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * sh_who.d - trace Bourne shell line execution by process using DTrace.
+ * Written for the sh DTrace provider.
+ *
+ * $Id: sh_who.d 25 2007-09-12 09:51:58Z brendan $
+ *
+ * This traces shell activity from all Bourne shells on the system that are
+ * running with sh provider support.
+ *
+ * USAGE: sh_who.d # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * PID Process ID of the shell
+ * UID User ID of the owner
+ * LINES Number of times a line was executed
+ * FILE Pathname of the shell or shellscript
+ *
+ * Filenames are printed if available.
+ *
+ * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at Docs/cddl1.txt
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * CDDL HEADER END
+ *
+ * 09-Sep-2007 Brendan Gregg Created this.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+sh*:::line
+{
+ @lines[pid, uid, copyinstr(arg0)] = count();
+}
+
+dtrace:::END
+{
+ printf(" %6s %6s %6s %s\n", "PID", "UID", "LINES", "FILE");
+ printa(" %6d %6d %@6d %s\n", @lines);
+}
OpenPOWER on IntegriCloud