]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Perl/pl_cpudist.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Perl / pl_cpudist.d
1 #!/usr/sbin/dtrace -Zs
2 /*
3  * pl_cpudist.d - measure Perl on-CPU times for subroutines.
4  *                Written for the Perl DTrace provider.
5  *
6  * $Id: pl_cpudist.d 28 2007-09-13 10:49:37Z brendan $
7  *
8  * This traces Perl activity from all programs running on the system with
9  * Perl provider support.
10  *
11  * USAGE: pl_cpudist.d          # hit Ctrl-C to end
12  *
13  * This script prints distribution plots of elapsed time for Perl subrotines.
14  * Use pl_cputime.d for summary reports.
15  *
16  * FIELDS:
17  *              1               Filename of the Perl program
18  *              2               Type of call (sub)
19  *              3               Name of call
20  *
21  * Filename and subroutine names are printed if available.
22  *
23  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
24  *
25  * CDDL HEADER START
26  *
27  *  The contents of this file are subject to the terms of the
28  *  Common Development and Distribution License, Version 1.0 only
29  *  (the "License").  You may not use this file except in compliance
30  *  with the License.
31  *
32  *  You can obtain a copy of the license at Docs/cddl1.txt
33  *  or http://www.opensolaris.org/os/licensing.
34  *  See the License for the specific language governing permissions
35  *  and limitations under the License.
36  *
37  * CDDL HEADER END
38  *
39  * 09-Sep-2007  Brendan Gregg   Created this.
40  */
41
42 #pragma D option quiet
43
44 dtrace:::BEGIN
45 {
46         printf("Tracing... Hit Ctrl-C to end.\n");
47 }
48
49 perl*:::sub-entry
50 {
51         self->depth++;
52         self->exclude[self->depth] = 0;
53         self->sub[self->depth] = vtimestamp;
54 }
55
56 perl*:::sub-return
57 /self->sub[self->depth]/
58 {
59         this->oncpu_incl = vtimestamp - self->sub[self->depth];
60         this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth];
61         self->sub[self->depth] = 0;
62         self->exclude[self->depth] = 0;
63         this->file = basename(copyinstr(arg1));
64         this->name = copyinstr(arg0);
65
66         @types_incl[this->file, "sub", this->name] =
67             quantize(this->oncpu_incl / 1000);
68         @types_excl[this->file, "sub", this->name] =
69             quantize(this->oncpu_excl / 1000);
70
71         self->depth--;
72         self->exclude[self->depth] += this->oncpu_incl;
73 }
74
75 dtrace:::END
76 {
77         printf("\nExclusive subroutine on-CPU times (us),\n");
78         printa("   %s, %s, %s %@d\n", @types_excl);
79
80         printf("\nInclusive subroutine on-CPU times (us),\n");
81         printa("   %s, %s, %s %@d\n", @types_incl);
82 }