diff options
author | gnn <gnn@FreeBSD.org> | 2012-05-12 20:38:18 +0000 |
---|---|---|
committer | gnn <gnn@FreeBSD.org> | 2012-05-12 20:38:18 +0000 |
commit | 4297c1b2d07fec7f50b70e26e3adb4d062b19e15 (patch) | |
tree | aec2772e8855e6dbaea6d8136ed0c47bcb825dee /Perl | |
parent | 111c75a23278cd9317f0a13867c22ee0f6c95b26 (diff) | |
download | FreeBSD-src-4297c1b2d07fec7f50b70e26e3adb4d062b19e15.zip FreeBSD-src-4297c1b2d07fec7f50b70e26e3adb4d062b19e15.tar.gz |
Add the remaining scripts from the DTraceToolkit, version 0.99, to the
vendor tree.
http://www.brendangregg.com/dtrace.html#DTraceToolkit
Diffstat (limited to 'Perl')
-rw-r--r-- | Perl/Readme | 38 | ||||
-rwxr-xr-x | Perl/pl_calldist.d | 82 | ||||
-rwxr-xr-x | Perl/pl_calltime.d | 89 | ||||
-rwxr-xr-x | Perl/pl_cpudist.d | 82 | ||||
-rwxr-xr-x | Perl/pl_cputime.d | 89 | ||||
-rwxr-xr-x | Perl/pl_flow.d | 70 | ||||
-rwxr-xr-x | Perl/pl_flowinfo.d | 86 | ||||
-rwxr-xr-x | Perl/pl_flowtime.d | 88 | ||||
-rwxr-xr-x | Perl/pl_malloc.d | 81 | ||||
-rwxr-xr-x | Perl/pl_subcalls.d | 55 | ||||
-rwxr-xr-x | Perl/pl_syscalls.d | 65 | ||||
-rwxr-xr-x | Perl/pl_syscolors.d | 119 | ||||
-rwxr-xr-x | Perl/pl_who.d | 56 |
13 files changed, 1000 insertions, 0 deletions
diff --git a/Perl/Readme b/Perl/Readme new file mode 100644 index 0000000..36fcab5 --- /dev/null +++ b/Perl/Readme @@ -0,0 +1,38 @@ +Perl - DTracing Perl + + These scripts trace the Perl programming language, and require a version + of Perl to be built with the DTrace probes patch applied. + + The Perl DTrace provider was originally written by Alan Burlison, and + later rewritten by Richard Dawe. These scripts were written and tested + with Richard's patch to perl, which can be found in the comments on + Alan's original blog entry, + + http://blogs.sun.com/alanbur/entry/dtrace_and_perl + + To get this and these scripts working, the rough steps are, + + 1. Download and extract perl 5.8.8 (www.cpan.org) + 2. Download Richard's patch + 3. Apply Richard's patch (gpatch -p1 -i patchfile) + 4. sh Configure + 5. make perldtrace.h + 6. /usr/sbin/dtrace -h -s perldtrace.d -o perldtrace.h + 7. make + + If things go awry, you might find help by asking on the + dtrace-discuss@opensolaris.org mailing list. + + Since the DTrace Perl 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 perl { + probe sub-entry(subroutine, file, lineno) + probe sub-return(subroutine, file, lineno) + }; + diff --git a/Perl/pl_calldist.d b/Perl/pl_calldist.d new file mode 100755 index 0000000..a4bd2da --- /dev/null +++ b/Perl/pl_calldist.d @@ -0,0 +1,82 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_calldist.d - measure Perl elapsed times for subroutines. + * Written for the Perl DTrace provider. + * + * $Id: pl_calldist.d 28 2007-09-13 10:49:37Z brendan $ + * + * This traces Perl activity from all programs running on the system with + * Perl provider support. + * + * USAGE: pl_calldist.d # hit Ctrl-C to end + * + * This script prints distribution plots of elapsed time for Perl subroutines. + * Use pl_calltime.d for summary reports. + * + * FIELDS: + * 1 Filename of the Perl program + * 2 Type of call (sub) + * 3 Name of call + * + * Filename and subroutine 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"); +} + +perl*:::sub-entry +{ + self->depth++; + self->exclude[self->depth] = 0; + self->sub[self->depth] = timestamp; +} + +perl*:::sub-return +/self->sub[self->depth]/ +{ + this->elapsed_incl = timestamp - self->sub[self->depth]; + this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth]; + self->sub[self->depth] = 0; + self->exclude[self->depth] = 0; + this->file = basename(copyinstr(arg1)); + this->name = copyinstr(arg0); + + @types_incl[this->file, "sub", this->name] = + quantize(this->elapsed_incl / 1000); + @types_excl[this->file, "sub", this->name] = + quantize(this->elapsed_excl / 1000); + + self->depth--; + self->exclude[self->depth] += this->elapsed_incl; +} + +dtrace:::END +{ + printf("\nExclusive subroutine elapsed times (us),\n"); + printa(" %s, %s, %s %@d\n", @types_excl); + + printf("\nInclusive subroutine elapsed times (us),\n"); + printa(" %s, %s, %s %@d\n", @types_incl); +} diff --git a/Perl/pl_calltime.d b/Perl/pl_calltime.d new file mode 100755 index 0000000..0bf1804 --- /dev/null +++ b/Perl/pl_calltime.d @@ -0,0 +1,89 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_calltime.d - measure Perl elapsed times for subroutines. + * Written for the Perl DTrace provider. + * + * $Id: pl_calltime.d 41 2007-09-17 02:20:10Z brendan $ + * + * This traces Perl activity from all programs running on the system with + * Perl provider support. + * + * USAGE: pl_calltime.d # hit Ctrl-C to end + * + * FIELDS: + * FILE Filename of the Perl program + * TYPE Type of call (sub/total) + * NAME Name of call + * TOTAL Total elapsed time for calls (us) + * + * Filename and subroutine 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"); +} + +perl*:::sub-entry +{ + self->depth++; + self->exclude[self->depth] = 0; + self->sub[self->depth] = timestamp; +} + +perl*:::sub-return +/self->sub[self->depth]/ +{ + this->elapsed_incl = timestamp - self->sub[self->depth]; + this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth]; + self->sub[self->depth] = 0; + self->exclude[self->depth] = 0; + this->file = basename(copyinstr(arg1)); + this->name = copyinstr(arg0); + + @num[this->file, "sub", this->name] = count(); + @num["-", "total", "-"] = count(); + @types_incl[this->file, "sub", this->name] = sum(this->elapsed_incl); + @types_excl[this->file, "sub", 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 subroutine 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 subroutine 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/Perl/pl_cpudist.d b/Perl/pl_cpudist.d new file mode 100755 index 0000000..94c421f --- /dev/null +++ b/Perl/pl_cpudist.d @@ -0,0 +1,82 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_cpudist.d - measure Perl on-CPU times for subroutines. + * Written for the Perl DTrace provider. + * + * $Id: pl_cpudist.d 28 2007-09-13 10:49:37Z brendan $ + * + * This traces Perl activity from all programs running on the system with + * Perl provider support. + * + * USAGE: pl_cpudist.d # hit Ctrl-C to end + * + * This script prints distribution plots of elapsed time for Perl subrotines. + * Use pl_cputime.d for summary reports. + * + * FIELDS: + * 1 Filename of the Perl program + * 2 Type of call (sub) + * 3 Name of call + * + * Filename and subroutine 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"); +} + +perl*:::sub-entry +{ + self->depth++; + self->exclude[self->depth] = 0; + self->sub[self->depth] = vtimestamp; +} + +perl*:::sub-return +/self->sub[self->depth]/ +{ + this->oncpu_incl = vtimestamp - self->sub[self->depth]; + this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth]; + self->sub[self->depth] = 0; + self->exclude[self->depth] = 0; + this->file = basename(copyinstr(arg1)); + this->name = copyinstr(arg0); + + @types_incl[this->file, "sub", this->name] = + quantize(this->oncpu_incl / 1000); + @types_excl[this->file, "sub", this->name] = + quantize(this->oncpu_excl / 1000); + + self->depth--; + self->exclude[self->depth] += this->oncpu_incl; +} + +dtrace:::END +{ + printf("\nExclusive subroutine on-CPU times (us),\n"); + printa(" %s, %s, %s %@d\n", @types_excl); + + printf("\nInclusive subroutine on-CPU times (us),\n"); + printa(" %s, %s, %s %@d\n", @types_incl); +} diff --git a/Perl/pl_cputime.d b/Perl/pl_cputime.d new file mode 100755 index 0000000..150f204 --- /dev/null +++ b/Perl/pl_cputime.d @@ -0,0 +1,89 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_cputime.d - measure Perl on-CPU times for subroutines. + * Written for the Perl DTrace provider. + * + * $Id: pl_cputime.d 41 2007-09-17 02:20:10Z brendan $ + * + * This traces Perl activity from all programs running on the system with + * Perl provider support. + * + * USAGE: pl_cputime.d # hit Ctrl-C to end + * + * FIELDS: + * FILE Filename of the Perl program + * TYPE Type of call (sub/total) + * NAME Name of call (subroutine name) + * TOTAL Total on-CPU time for calls (us) + * + * Filename and subroutine 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"); +} + +perl*:::sub-entry +{ + self->depth++; + self->exclude[self->depth] = 0; + self->sub[self->depth] = vtimestamp; +} + +perl*:::sub-return +/self->sub[self->depth]/ +{ + this->oncpu_incl = vtimestamp - self->sub[self->depth]; + this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth]; + self->sub[self->depth] = 0; + self->exclude[self->depth] = 0; + this->file = basename(copyinstr(arg1)); + this->name = copyinstr(arg0); + + @num[this->file, "sub", this->name] = count(); + @num["-", "total", "-"] = count(); + @types_incl[this->file, "sub", this->name] = sum(this->oncpu_incl); + @types_excl[this->file, "sub", 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 subroutine 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 subroutine 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/Perl/pl_flow.d b/Perl/pl_flow.d new file mode 100755 index 0000000..7948db2 --- /dev/null +++ b/Perl/pl_flow.d @@ -0,0 +1,70 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_flow.d - snoop Perl execution showing subroutine flow. + * Written for the Solaris Perl DTrace provider. + * + * $Id: pl_flow.d 41 2007-09-17 02:20:10Z brendan $ + * + * This traces Perl activity from all Perl programs on the system + * running with Perl provider support. + * + * USAGE: pl_flow.d # hit Ctrl-C to end + * + * This watches Perl subroutine entries and returns, and indents child + * subroutine calls. + * + * FIELDS: + * C CPU-id + * TIME(us) Time since boot, us + * FILE Filename that this subroutine belongs to + * SUB Subroutine name + * + * LEGEND: + * -> subroutine entry + * <- subroutine 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", "SUB"); +} + +perl*:::sub-entry +{ + printf("%3d %-16d %-16s %*s-> %s\n", cpu, timestamp / 1000, + basename(copyinstr(arg1)), self->depth * 2, "", copyinstr(arg0)); + self->depth++; +} + +perl*:::sub-return +{ + self->depth -= self->depth > 0 ? 1 : 0; + printf("%3d %-16d %-16s %*s<- %s\n", cpu, timestamp / 1000, + basename(copyinstr(arg1)), self->depth * 2, "", copyinstr(arg0)); +} diff --git a/Perl/pl_flowinfo.d b/Perl/pl_flowinfo.d new file mode 100755 index 0000000..06769fd --- /dev/null +++ b/Perl/pl_flowinfo.d @@ -0,0 +1,86 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_flowinfo.d - snoop Perl subroutine flow with info using DTrace. + * Written for the Perl DTrace provider. + * + * $Id: pl_flowinfo.d 41 2007-09-17 02:20:10Z brendan $ + * + * This traces activity from all Perl programs on the system that are + * running with Perl provider support. + * + * USAGE: pl_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 Perl program + * LINE Line number of filename + * TYPE Type of call (sub) + * SUB Perl subroutine + * + * LEGEND: + * -> subroutine entry + * <- subroutine return + * + * Filename and subroutine 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", "SUB"); +} + +perl*:::sub-entry, +perl*:::sub-return +/self->last == 0/ +{ + self->last = timestamp; +} + +perl*:::sub-entry +{ + this->delta = (timestamp - self->last) / 1000; + printf("%d %6d %10d %16s:%-4d %-8s %*s-> %s\n", cpu, pid, this->delta, + basename(copyinstr(arg1)), arg2, "sub", self->depth * 2, "", + copyinstr(arg0)); + self->depth++; + self->last = timestamp; +} + +perl*:::sub-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(arg1)), arg2, "sub", self->depth * 2, "", + copyinstr(arg0)); + self->last = timestamp; +} diff --git a/Perl/pl_flowtime.d b/Perl/pl_flowtime.d new file mode 100755 index 0000000..1fa727c --- /dev/null +++ b/Perl/pl_flowtime.d @@ -0,0 +1,88 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_flowtime.d - snoop Perl subroutines with flow and delta times. + * Written for the Perl DTrace provider. + * + * $Id: pl_flowtime.d 41 2007-09-17 02:20:10Z brendan $ + * + * This traces shell activity from Perl programs on the system that are + * running with Perl provider support. + * + * USAGE: pl_flowtime.d # hit Ctrl-C to end + * + * This watches Perl subroutine entries and returns, and indents child + * subroutine calls. + * + * FIELDS: + * C CPU-id + * TIME(us) Time since boot, us + * FILE Filename that this subroutine belongs to + * DELTA(us) Elapsed time from previous line to this line + * SUB Perl subroutine name + * + * LEGEND: + * -> method entry + * <- method return + * + * Filename and subroutine 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)", "SUB"); +} + +perl*:::sub-entry, +perl*:::sub-return +/self->last == 0/ +{ + self->last = timestamp; +} + +perl*:::sub-entry +{ + this->delta = (timestamp - self->last) / 1000; + printf("%3d %-16d %-16s %9d %*s-> %s\n", cpu, timestamp / 1000, + basename(copyinstr(arg1)), this->delta, self->depth * 2, "", + copyinstr(arg0)); + self->depth++; + self->last = timestamp; +} + +perl*:::sub-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(arg1)), this->delta, self->depth * 2, "", + copyinstr(arg0)); + self->last = timestamp; +} diff --git a/Perl/pl_malloc.d b/Perl/pl_malloc.d new file mode 100755 index 0000000..b71e765 --- /dev/null +++ b/Perl/pl_malloc.d @@ -0,0 +1,81 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_malloc.d - Perl libc malloc analysis. + * Written for the Perl DTrace provider. + * + * $Id: pl_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 Perl subroutine, then that subroutine is + * identified as responsible; else the caller of malloc() is identified as + * responsible - which will be a function from the Perl engine. + * + * USAGE: pl_malloc.d { -p PID | -c cmd } # hit Ctrl-C to end + * + * Filename and subroutine 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"); +} + +perl$target:::sub-entry +{ + self->file = basename(copyinstr(arg1)); + self->name = copyinstr(arg0); +} + +perl$target:::sub-return +{ + self->file = 0; + self->name = 0; +} + +pid$target:libc:malloc:entry +/self->file != NULL/ +{ + @malloc_sub_size[self->file, self->name] = sum(arg0); + @malloc_sub_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("\nPerl malloc byte distributions by engine caller,\n\n"); + printa(" %A, total bytes = %@d %@d\n", @malloc_lib_size, + @malloc_lib_dist); + + printf("\nPerl malloc byte distributions by Perl file and "); + printf("subroutine,\n\n"); + printa(" %s, %s, bytes total = %@d %@d\n", @malloc_sub_size, + @malloc_sub_dist); +} diff --git a/Perl/pl_subcalls.d b/Perl/pl_subcalls.d new file mode 100755 index 0000000..30d922f --- /dev/null +++ b/Perl/pl_subcalls.d @@ -0,0 +1,55 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_subcalls.d - measure Perl subroutine calls using DTrace. + * Written for the Perl DTrace provider. + * + * $Id: pl_subcalls.d 25 2007-09-12 09:51:58Z brendan $ + * + * This traces Perl activity from all running programs on the system + * which support the Perl DTrace provider. + * + * USAGE: pl_subcalls.d # hit Ctrl-C to end + * + * FIELDS: + * FILE Filename that contained the subroutine + * SUB Perl subroutine name + * CALLS Subroutine calls during this sample + * + * Filename and subroutine 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"); +} + +perl*:::sub-entry +{ + @subs[basename(copyinstr(arg1)), copyinstr(arg0)] = count(); +} + +dtrace:::END +{ + printf(" %-32s %-32s %8s\n", "FILE", "SUB", "CALLS"); + printa(" %-32s %-32s %@8d\n", @subs); +} diff --git a/Perl/pl_syscalls.d b/Perl/pl_syscalls.d new file mode 100755 index 0000000..9c5a765 --- /dev/null +++ b/Perl/pl_syscalls.d @@ -0,0 +1,65 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_syscalls.d - count Perl subroutine calls and syscalls using DTrace. + * Written for the Perl DTrace provider. + * + * $Id: pl_syscalls.d 25 2007-09-12 09:51:58Z brendan $ + * + * USAGE: pl_syscalls.d { -p PID | -c cmd } # hit Ctrl-C to end + * + * FIELDS: + * FILE Filename of the Perl program + * TYPE Type of call (sub/syscall) + * NAME Name of call + * COUNT Number of calls during sample + * + * Filename and subroutine names are printed if available. + * The filename for syscalls may be printed as "perl", if the program + * was invoked using the form "perl 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 + +self string filename; + +dtrace:::BEGIN +{ + printf("Tracing... Hit Ctrl-C to end.\n"); +} + +perl$target:::sub-entry +{ + @calls[basename(copyinstr(arg1)), "sub", copyinstr(arg0)] = 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/Perl/pl_syscolors.d b/Perl/pl_syscolors.d new file mode 100755 index 0000000..ec689f2 --- /dev/null +++ b/Perl/pl_syscolors.d @@ -0,0 +1,119 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_syscolors.d - trace Perl subroutine flow plus syscalls, in color. + * Written for the Perl DTrace provider. + * + * $Id: pl_syscolors.d 27 2007-09-13 09:26:01Z brendan $ + * + * USAGE: pl_syscolors.d { -p PID | -c cmd } # hit Ctrl-C to end + * + * This watches Perl subroutine entries and returns, and indents child + * subroutine calls. + * + * FIELDS: + * C CPU-id + * PID Process ID + * DELTA(us) Elapsed time from previous line to this line + * FILE Filename of the Perl program + * LINE Line number of filename + * TYPE Type of call (sub/syscall) + * NAME Perl subroutine or syscall name + * + * Filename and subroutine 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 +{ + /* + * The following are terminal color escape sequences. + * Change them to whatever you prefer, eg HTML font tags. + */ + color_perl = "\033[2;35m"; /* violet, 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"); +} + +perl$target:::sub-entry, +perl$target:::sub-return, +syscall:::entry, +syscall:::return +/self->last == 0 && pid == $target/ +{ + self->last = timestamp; +} + +perl$target:::sub-entry +{ + this->delta = (timestamp - self->last) / 1000; + printf("%s%d %6d %10d %16s:%-4d %-8s %*s-> %s%s\n", color_perl, + cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "sub", + self->depth * 2, "", copyinstr(arg1), color_off); + self->depth++; + self->last = timestamp; +} + +perl$target:::sub-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_perl, + cpu, pid, this->delta, basename(copyinstr(arg0)), arg2, "sub", + 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/Perl/pl_who.d b/Perl/pl_who.d new file mode 100755 index 0000000..a461311 --- /dev/null +++ b/Perl/pl_who.d @@ -0,0 +1,56 @@ +#!/usr/sbin/dtrace -Zs +/* + * pl_who.d - trace Perl subroutine execution by process using DTrace. + * Written for the Perl DTrace provider. + * + * $Id: pl_who.d 25 2007-09-12 09:51:58Z brendan $ + * + * This traces Perl activity from all Perl programs on the system that are + * running with Perl provider support. + * + * USAGE: pl_who.d # hit Ctrl-C to end + * + * FIELDS: + * PID Process ID of Perl + * UID User ID of the owner + * SUBS Number of subroutine calls + * FILE Pathname of the Perl 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"); +} + +perl*:::sub-entry +{ + @lines[pid, uid, copyinstr(arg1)] = count(); +} + +dtrace:::END +{ + printf(" %6s %6s %6s %s\n", "PID", "UID", "SUBS", "FILE"); + printa(" %6d %6d %@6d %s\n", @lines); +} |