summaryrefslogtreecommitdiffstats
path: root/cddl/contrib/dtracetoolkit/Python
diff options
context:
space:
mode:
Diffstat (limited to 'cddl/contrib/dtracetoolkit/Python')
-rw-r--r--cddl/contrib/dtracetoolkit/Python/Readme28
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_calldist.d82
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_calltime.d89
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_cpudist.d82
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_cputime.d89
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_flow.d70
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_flowinfo.d86
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_flowtime.d89
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_funccalls.d55
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_malloc.d81
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_mallocstk.d49
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_profile.d79
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_syscalls.d63
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_syscolors.d116
-rwxr-xr-xcddl/contrib/dtracetoolkit/Python/py_who.d56
15 files changed, 1114 insertions, 0 deletions
diff --git a/cddl/contrib/dtracetoolkit/Python/Readme b/cddl/contrib/dtracetoolkit/Python/Readme
new file mode 100644
index 0000000..f183c74
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/Readme
@@ -0,0 +1,28 @@
+Python - DTracing Python
+
+ These scripts trace the Python programming language, and require a version
+ of Python which has been built with DTrace probes.
+
+ The Python DTrace provider was originally written by John Levon, and
+ was integrated into Solaris Nevada in build 65. If you are on a different
+ OS with DTrace and would like to use these scripts, you could download
+ Python and the Python DTrace provider patch listed in the comments here,
+
+ http://blogs.sun.com/levon/entry/python_and_dtrace_in_build
+
+ You will need patch and build Python for these probes to work.
+ Or, check if a pre-built package is available someone on opensolaris.org.
+
+ Since the DTrace Python provider may be developed further, there is a chance
+ that it has 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 provider when these scripts
+ were written - check for changes and update the scripts accordingly,
+
+ provider python {
+ probe function-entry(file, subroutine, lineno)
+ probe function-return(file, subroutine, lineno)
+ };
+
diff --git a/cddl/contrib/dtracetoolkit/Python/py_calldist.d b/cddl/contrib/dtracetoolkit/Python/py_calldist.d
new file mode 100755
index 0000000..1c64c10
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_calldist.d
@@ -0,0 +1,82 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_calldist.d - measure Python elapsed times for functions.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_calldist.d 28 2007-09-13 10:49:37Z brendan $
+ *
+ * This traces Python activity from all programs running on the system with
+ * Python provider support.
+ *
+ * USAGE: py_calldist.d # hit Ctrl-C to end
+ *
+ * This script prints distribution plots of elapsed time for Python
+ * operations. Use py_calltime.d for summary reports.
+ *
+ * FIELDS:
+ * 1 Filename of the Python program
+ * 2 Type of call (func)
+ * 3 Name of call
+ *
+ * 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");
+}
+
+python*:::function-entry
+{
+ self->depth++;
+ self->exclude[self->depth] = 0;
+ self->function[self->depth] = timestamp;
+}
+
+python*:::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;
+}
+
+dtrace:::END
+{
+ printf("\nExclusive function elapsed times (us),\n");
+ printa(" %s, %s, %s %@d\n", @types_excl);
+
+ printf("\nInclusive function elapsed times (us),\n");
+ printa(" %s, %s, %s %@d\n", @types_incl);
+}
diff --git a/cddl/contrib/dtracetoolkit/Python/py_calltime.d b/cddl/contrib/dtracetoolkit/Python/py_calltime.d
new file mode 100755
index 0000000..d152b35
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_calltime.d
@@ -0,0 +1,89 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_calltime.d - measure Python elapsed times for functions.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_calltime.d 41 2007-09-17 02:20:10Z brendan $
+ *
+ * This traces Python activity from all programs running on the system with
+ * Python provider support.
+ *
+ * USAGE: py_calltime.d # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * FILE Filename of the Python program
+ * TYPE Type of call (func/total)
+ * NAME Name of call
+ * TOTAL Total elapsed time for calls (us)
+ *
+ * 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");
+}
+
+python*:::function-entry
+{
+ self->depth++;
+ self->exclude[self->depth] = 0;
+ self->function[self->depth] = timestamp;
+}
+
+python*:::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;
+}
+
+dtrace:::END
+{
+ printf("\nCount,\n");
+ printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
+ printa(" %-20s %-10s %-32s %@8d\n", @num);
+
+ 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/Python/py_cpudist.d b/cddl/contrib/dtracetoolkit/Python/py_cpudist.d
new file mode 100755
index 0000000..cf0e7b2
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_cpudist.d
@@ -0,0 +1,82 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_cpudist.d - measure Python on-CPU times for functions.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_cpudist.d 28 2007-09-13 10:49:37Z brendan $
+ *
+ * This traces Python activity from all programs running on the system with
+ * Python provider support.
+ *
+ * USAGE: py_cpudist.d # hit Ctrl-C to end
+ *
+ * This script prints distribution plots of elapsed time for Python
+ * operations. Use py_cputime.d for summary reports.
+ *
+ * FIELDS:
+ * 1 Filename of the Python program
+ * 2 Type of call (func)
+ * 3 Name of call
+ *
+ * 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");
+}
+
+python*:::function-entry
+{
+ self->depth++;
+ self->exclude[self->depth] = 0;
+ self->function[self->depth] = vtimestamp;
+}
+
+python*:::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;
+}
+
+dtrace:::END
+{
+ printf("\nExclusive function on-CPU times (us),\n");
+ printa(" %s, %s, %s %@d\n", @types_excl);
+
+ printf("\nInclusive function on-CPU times (us),\n");
+ printa(" %s, %s, %s %@d\n", @types_incl);
+}
diff --git a/cddl/contrib/dtracetoolkit/Python/py_cputime.d b/cddl/contrib/dtracetoolkit/Python/py_cputime.d
new file mode 100755
index 0000000..ca40a93
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_cputime.d
@@ -0,0 +1,89 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_cputime.d - measure Python on-CPU times for functions.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_cputime.d 41 2007-09-17 02:20:10Z brendan $
+ *
+ * This traces Python activity from all programs running on the system with
+ * Python provider support.
+ *
+ * USAGE: py_cputime.d # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * FILE Filename of the Python program
+ * TYPE Type of call (func/total)
+ * NAME Name of call (function name)
+ * TOTAL Total on-CPU time for calls (us)
+ *
+ * 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");
+}
+
+python*:::function-entry
+{
+ self->depth++;
+ self->exclude[self->depth] = 0;
+ self->function[self->depth] = vtimestamp;
+}
+
+python*:::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;
+}
+
+dtrace:::END
+{
+ printf("\nCount,\n");
+ printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
+ printa(" %-20s %-10s %-32s %@8d\n", @num);
+
+ 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/Python/py_flow.d b/cddl/contrib/dtracetoolkit/Python/py_flow.d
new file mode 100755
index 0000000..893ea78
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_flow.d
@@ -0,0 +1,70 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_flow.d - snoop Python execution showing function flow.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_flow.d 51 2007-09-24 00:55:23Z brendan $
+ *
+ * This traces Python activity from all Python programs on the system
+ * running with Python provider support.
+ *
+ * USAGE: py_flow.d # hit Ctrl-C to end
+ *
+ * This watches Python function entries and returns, and indents child
+ * function calls.
+ *
+ * FIELDS:
+ * C CPU-id
+ * TIME(us) Time since boot, us
+ * FILE Filename that this function belongs to
+ * FUNC Function name
+ *
+ * LEGEND:
+ * -> function entry
+ * <- function return
+ *
+ * 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
+{
+ printf("%3s %-16s %-16s -- %s\n", "C", "TIME(us)", "FILE", "FUNC");
+}
+
+python*:::function-entry
+{
+ printf("%3d %-16d %-16s %*s-> %s\n", cpu, timestamp / 1000,
+ basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg1));
+ self->depth++;
+}
+
+python*:::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));
+}
diff --git a/cddl/contrib/dtracetoolkit/Python/py_flowinfo.d b/cddl/contrib/dtracetoolkit/Python/py_flowinfo.d
new file mode 100755
index 0000000..ccba1df
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_flowinfo.d
@@ -0,0 +1,86 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_flowinfo.d - snoop Python function flow with info using DTrace.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_flowinfo.d 41 2007-09-17 02:20:10Z brendan $
+ *
+ * This traces activity from all Python programs on the system that are
+ * running with Python provider support.
+ *
+ * USAGE: py_flowinfo.d # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * C CPU-id
+ * PID Process ID
+ * DELTA(us) Elapsed time from previous line to this line
+ * FILE Filename of the Python program
+ * LINE Line number of filename
+ * TYPE Type of call (func)
+ * FUNC Python function
+ *
+ * LEGEND:
+ * -> function entry
+ * <- function return
+ *
+ * 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;
+
+dtrace:::BEGIN
+{
+ printf("%s %6s %10s %16s:%-4s %-8s -- %s\n", "C", "PID", "DELTA(us)",
+ "FILE", "LINE", "TYPE", "FUNC");
+}
+
+python*:::function-entry,
+python*:::function-return
+/self->last == 0/
+{
+ self->last = timestamp;
+}
+
+python*:::function-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%d %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;
+}
+
+python*:::function-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%d %6d %10d %16s:%-4d %-8s %*s<- %s\n", cpu, pid, this->delta,
+ basename(copyinstr(arg0)), arg2, "func", self->depth * 2, "",
+ copyinstr(arg1));
+ self->last = timestamp;
+}
diff --git a/cddl/contrib/dtracetoolkit/Python/py_flowtime.d b/cddl/contrib/dtracetoolkit/Python/py_flowtime.d
new file mode 100755
index 0000000..a339eac
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_flowtime.d
@@ -0,0 +1,89 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_flowtime.d - snoop Python functions with flow and delta times.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_flowtime.d 41 2007-09-17 02:20:10Z brendan $
+ *
+ * This traces shell activity from Python programs on the system that are
+ * running with Python provider support.
+ *
+ * USAGE: py_flowtime.d # hit Ctrl-C to end
+ *
+ * This watches Python function entries and returns, and indents child
+ * function calls.
+ *
+ * FIELDS:
+ * C CPU-id
+ * TIME(us) Time since boot, us
+ * FILE Filename that this function belongs to
+ * DELTA(us) Elapsed time from previous line to this line
+ * FUNC Python function name
+ *
+ * LEGEND:
+ * -> function entry
+ * <- function return
+ *
+ * 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 int last;
+
+dtrace:::BEGIN
+{
+ printf("%3s %-16s %-16s %9s -- %s\n", "C", "TIME(us)", "FILE",
+ "DELTA(us)", "FUNC");
+}
+
+python*:::function-entry,
+python*:::function-return
+/self->last == 0/
+{
+ self->last = timestamp;
+}
+
+python*:::function-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%3d %-16d %-16s %9d %*s-> %s\n", cpu, timestamp / 1000,
+ basename(copyinstr(arg0)), this->delta, self->depth * 2, "",
+ copyinstr(arg1));
+ self->depth++;
+ self->last = timestamp;
+}
+
+python*:::function-return
+{
+ this->delta = (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->delta, self->depth * 2, "",
+ copyinstr(arg1));
+ self->last = timestamp;
+}
diff --git a/cddl/contrib/dtracetoolkit/Python/py_funccalls.d b/cddl/contrib/dtracetoolkit/Python/py_funccalls.d
new file mode 100755
index 0000000..b430f29
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_funccalls.d
@@ -0,0 +1,55 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_funccalls.d - measure Python function calls using DTrace.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_funccalls.d 25 2007-09-12 09:51:58Z brendan $
+ *
+ * This traces Python activity from all running programs on the system
+ * which support the Python DTrace provider.
+ *
+ * USAGE: py_funccalls.d # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * FILE Filename that contained the function
+ * FUNC Python function name
+ * CALLS Function calls during this 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");
+}
+
+python*:::function-entry
+{
+ @funcs[basename(copyinstr(arg0)), copyinstr(arg1)] = count();
+}
+
+dtrace:::END
+{
+ printf(" %-32s %-32s %8s\n", "FILE", "FUNC", "CALLS");
+ printa(" %-32s %-32s %@8d\n", @funcs);
+}
diff --git a/cddl/contrib/dtracetoolkit/Python/py_malloc.d b/cddl/contrib/dtracetoolkit/Python/py_malloc.d
new file mode 100755
index 0000000..7f0860e
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_malloc.d
@@ -0,0 +1,81 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_malloc.d - Python libc malloc analysis.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_malloc.d 19 2007-09-12 07:47:59Z brendan $
+ *
+ * This is an expiremental script to identify who is calling malloc() for
+ * memory allocation, and to print distribution plots of the requested bytes.
+ * If a malloc() occured while in a Python function, then that function is
+ * identified as responsible; else the caller of malloc() is identified as
+ * responsible - which will be a function from the Python engine.
+ *
+ * USAGE: py_malloc.d { -p PID | -c cmd } # hit Ctrl-C to end
+ *
+ * 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");
+}
+
+python$target:::function-entry
+{
+ self->file = basename(copyinstr(arg0));
+ self->name = copyinstr(arg1);
+}
+
+python$target:::function-return
+{
+ self->file = 0;
+ self->name = 0;
+}
+
+pid$target:libc:malloc:entry
+/self->file != NULL/
+{
+ @malloc_func_size[self->file, self->name] = sum(arg0);
+ @malloc_func_dist[self->file, self->name] = quantize(arg0);
+}
+
+pid$target:libc:malloc:entry
+/self->name == NULL/
+{
+ @malloc_lib_size[usym(ucaller)] = sum(arg0);
+ @malloc_lib_dist[usym(ucaller)] = quantize(arg0);
+}
+
+
+dtrace:::END
+{
+ printf("\nPython malloc byte distributions by engine caller,\n\n");
+ printa(" %A, total bytes = %@d %@d\n", @malloc_lib_size,
+ @malloc_lib_dist);
+
+ printf("\nPython malloc byte distributions by Python file and ");
+ printf("function,\n\n");
+ printa(" %s, %s, bytes total = %@d %@d\n", @malloc_func_size,
+ @malloc_func_dist);
+}
diff --git a/cddl/contrib/dtracetoolkit/Python/py_mallocstk.d b/cddl/contrib/dtracetoolkit/Python/py_mallocstk.d
new file mode 100755
index 0000000..ca42801
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_mallocstk.d
@@ -0,0 +1,49 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_mallocstk.d - Python libc malloc analysis with full stack traces.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_mallocstk.d 19 2007-09-12 07:47:59Z brendan $
+ *
+ * USAGE: py_mallocstk.d { -p PID | -c cmd } # hit Ctrl-C to end
+ *
+ * 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
+
+/* tune as desired, */
+#pragma D option jstackframes=64
+#pragma D option jstackstrsize=1024
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+pid$target:libc:malloc:entry
+{
+ @mallocs[jstack()] = quantize(arg0);
+}
+
+dtrace:::END
+{
+ printf("\nPython malloc byte distributions by stack trace,\n\n");
+ printa(@mallocs);
+}
diff --git a/cddl/contrib/dtracetoolkit/Python/py_profile.d b/cddl/contrib/dtracetoolkit/Python/py_profile.d
new file mode 100755
index 0000000..ff02df6
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_profile.d
@@ -0,0 +1,79 @@
+#!/usr/sbin/dtrace -CZs
+/*
+ * py_profile.d - sample stack traces with Python translations using DTrace.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_profile.d 19 2007-09-12 07:47:59Z brendan $
+ *
+ * USAGE: py_profile.d { -p PID | -c cmd } # hit Ctrl-C to end
+ *
+ * This samples stack traces for the process specified. This stack trace
+ * will cross the Python engine and system libraries, and insert
+ * translations for Python stack frames where appropriate. This is best
+ * explained with an example stack frame output,
+ *
+ * libpython2.4.so.1.0`PyEval_EvalFrame+0x2fbf
+ * [ ./func_loop.py:5 (func_c) ]
+ * libpython2.4.so.1.0`fast_function+0xa8
+ * libpython2.4.so.1.0`call_function+0xda
+ * libpython2.4.so.1.0`PyEval_EvalFrame+0xbdf
+ * [ ./func_loop.py:11 (func_b) ]
+ * libpython2.4.so.1.0`fast_function+0xa8
+ * libpython2.4.so.1.0`call_function+0xda
+ * libpython2.4.so.1.0`PyEval_EvalFrame+0xbdf
+ * [ ./func_loop.py:14 (func_a) ]
+ * libpython2.4.so.1.0`fast_function+0xa8
+ * libpython2.4.so.1.0`call_function+0xda
+ * libpython2.4.so.1.0`PyEval_EvalFrame+0xbdf
+ * [ ./func_loop.py:16 (?) ]
+ *
+ * The lines in square brackets are the native Python frames, the rest
+ * are the Python engine.
+ *
+ * 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 jstackstrsize=1024
+
+/*
+ * Tunables
+ */
+#define DEPTH 10 /* stack depth, frames */
+#define RATE 1001 /* sampling rate, Hertz */
+#define TOP 25 /* number of stacks to output */
+
+dtrace:::BEGIN
+{
+ printf("Sampling %d-level stacks at %d Hertz... Hit Ctrl-C to end.\n",
+ DEPTH, RATE);
+}
+
+profile-RATE
+/pid == $target/
+{
+ @stacks[jstack(DEPTH)] = count();
+}
+
+dtrace:::END
+{
+ trunc(@stacks, TOP);
+ printf("Top %d most frequently sampled stacks,\n", TOP);
+ printa(@stacks);
+}
diff --git a/cddl/contrib/dtracetoolkit/Python/py_syscalls.d b/cddl/contrib/dtracetoolkit/Python/py_syscalls.d
new file mode 100755
index 0000000..2b3e44d
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_syscalls.d
@@ -0,0 +1,63 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_syscalls.d - count Python function calls and syscalls using DTrace.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_syscalls.d 25 2007-09-12 09:51:58Z brendan $
+ *
+ * USAGE: py_syscalls.d { -p PID | -c cmd } # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * FILE Filename of the Python program
+ * TYPE Type of call (func/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 "python", if the program
+ * was invoked using the form "python filename" rather than running the
+ * program 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
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C to end.\n");
+}
+
+python$target:::function-entry
+{
+ @calls[basename(copyinstr(arg0)), "func", 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/Python/py_syscolors.d b/cddl/contrib/dtracetoolkit/Python/py_syscolors.d
new file mode 100755
index 0000000..9f958ef
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_syscolors.d
@@ -0,0 +1,116 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_syscolors.d - trace Python function flow plus syscalls, in color.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_syscolors.d 27 2007-09-13 09:26:01Z brendan $
+ *
+ * USAGE: py_syscolors.d { -p PID | -c cmd } # hit Ctrl-C to end
+ *
+ * This watches Python function entries and returns, and indents child
+ * function calls.
+ *
+ * FIELDS:
+ * C CPU-id
+ * PID Process ID
+ * DELTA(us) Elapsed time from previous line to this line
+ * FILE Filename of the Python program
+ * LINE Line number of filename
+ * TYPE Type of call (func/syscall)
+ * NAME Python function or syscall name
+ *
+ * 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;
+
+dtrace:::BEGIN
+{
+ color_python = "\033[2;35m"; /* violet, faint */
+ color_syscall = "\033[2;32m"; /* green, faint */
+ color_off = "\033[0m"; /* default */
+
+ self->depth = 0;
+ printf("%s %6s %10s %16s:%-4s %-8s -- %s\n", "C", "PID", "DELTA(us)",
+ "FILE", "LINE", "TYPE", "NAME");
+}
+
+python$target:::function-entry,
+python$target:::function-return,
+syscall:::entry,
+syscall:::return
+/self->last == 0 && pid == $target/
+{
+ self->last = timestamp;
+}
+
+python$target:::function-entry
+{
+ this->delta = (timestamp - self->last) / 1000;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s-> %s%s\n", color_python,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "func",
+ self->depth * 2, "", copyinstr(arg1), color_off);
+ self->depth++;
+ self->last = timestamp;
+}
+
+python$target:::function-return
+{
+ this->delta = (timestamp - self->last) / 1000;
+ this->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1));
+ self->depth -= self->depth > 0 ? 1 : 0;
+ printf("%s%d %6d %10d %16s:%-4d %-8s %*s<- %s%s\n", color_python,
+ cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "func",
+ self->depth * 2, "", copyinstr(arg1), 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, "\"", "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, "\"", "syscall", self->depth * 2, "",
+ probefunc, color_off);
+ self->last = timestamp;
+}
+
+proc:::exit
+/pid == $target/
+{
+ exit(0);
+}
diff --git a/cddl/contrib/dtracetoolkit/Python/py_who.d b/cddl/contrib/dtracetoolkit/Python/py_who.d
new file mode 100755
index 0000000..3a772e3
--- /dev/null
+++ b/cddl/contrib/dtracetoolkit/Python/py_who.d
@@ -0,0 +1,56 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * py_who.d - trace Python function execution by process using DTrace.
+ * Written for the Python DTrace provider.
+ *
+ * $Id: py_who.d 25 2007-09-12 09:51:58Z brendan $
+ *
+ * This traces Python activity from all Python programs on the system that are
+ * running with Python provider support.
+ *
+ * USAGE: py_who.d # hit Ctrl-C to end
+ *
+ * FIELDS:
+ * PID Process ID of Python
+ * UID User ID of the owner
+ * FUNCS Number of function calls
+ * FILE Pathname of the Python program
+ *
+ * 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");
+}
+
+python*:::function-entry
+{
+ @lines[pid, uid, copyinstr(arg0)] = count();
+}
+
+dtrace:::END
+{
+ printf(" %6s %6s %6s %s\n", "PID", "UID", "FUNCS", "FILE");
+ printa(" %6d %6d %@6d %s\n", @lines);
+}
OpenPOWER on IntegriCloud