pl_calltime.d revision 1.1 1 1.1 christos #!/usr/sbin/dtrace -Zs
2 1.1 christos /*
3 1.1 christos * pl_calltime.d - measure Perl elapsed times for subroutines.
4 1.1 christos * Written for the Perl DTrace provider.
5 1.1 christos *
6 1.1 christos * $Id: pl_calltime.d,v 1.1 2015/09/30 22:01:09 christos Exp $
7 1.1 christos *
8 1.1 christos * This traces Perl activity from all programs running on the system with
9 1.1 christos * Perl provider support.
10 1.1 christos *
11 1.1 christos * USAGE: pl_calltime.d # hit Ctrl-C to end
12 1.1 christos *
13 1.1 christos * FIELDS:
14 1.1 christos * FILE Filename of the Perl program
15 1.1 christos * TYPE Type of call (sub/total)
16 1.1 christos * NAME Name of call
17 1.1 christos * TOTAL Total elapsed time for calls (us)
18 1.1 christos *
19 1.1 christos * Filename and subroutine names are printed if available.
20 1.1 christos *
21 1.1 christos * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
22 1.1 christos *
23 1.1 christos * CDDL HEADER START
24 1.1 christos *
25 1.1 christos * The contents of this file are subject to the terms of the
26 1.1 christos * Common Development and Distribution License, Version 1.0 only
27 1.1 christos * (the "License"). You may not use this file except in compliance
28 1.1 christos * with the License.
29 1.1 christos *
30 1.1 christos * You can obtain a copy of the license at Docs/cddl1.txt
31 1.1 christos * or http://www.opensolaris.org/os/licensing.
32 1.1 christos * See the License for the specific language governing permissions
33 1.1 christos * and limitations under the License.
34 1.1 christos *
35 1.1 christos * CDDL HEADER END
36 1.1 christos *
37 1.1 christos * 09-Sep-2007 Brendan Gregg Created this.
38 1.1 christos */
39 1.1 christos
40 1.1 christos #pragma D option quiet
41 1.1 christos
42 1.1 christos dtrace:::BEGIN
43 1.1 christos {
44 1.1 christos printf("Tracing... Hit Ctrl-C to end.\n");
45 1.1 christos }
46 1.1 christos
47 1.1 christos perl*:::sub-entry
48 1.1 christos {
49 1.1 christos self->depth++;
50 1.1 christos self->exclude[self->depth] = 0;
51 1.1 christos self->sub[self->depth] = timestamp;
52 1.1 christos }
53 1.1 christos
54 1.1 christos perl*:::sub-return
55 1.1 christos /self->sub[self->depth]/
56 1.1 christos {
57 1.1 christos this->elapsed_incl = timestamp - self->sub[self->depth];
58 1.1 christos this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth];
59 1.1 christos self->sub[self->depth] = 0;
60 1.1 christos self->exclude[self->depth] = 0;
61 1.1 christos this->file = basename(copyinstr(arg1));
62 1.1 christos this->name = copyinstr(arg0);
63 1.1 christos
64 1.1 christos @num[this->file, "sub", this->name] = count();
65 1.1 christos @num["-", "total", "-"] = count();
66 1.1 christos @types_incl[this->file, "sub", this->name] = sum(this->elapsed_incl);
67 1.1 christos @types_excl[this->file, "sub", this->name] = sum(this->elapsed_excl);
68 1.1 christos @types_excl["-", "total", "-"] = sum(this->elapsed_excl);
69 1.1 christos
70 1.1 christos self->depth--;
71 1.1 christos self->exclude[self->depth] += this->elapsed_incl;
72 1.1 christos }
73 1.1 christos
74 1.1 christos dtrace:::END
75 1.1 christos {
76 1.1 christos printf("\nCount,\n");
77 1.1 christos printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
78 1.1 christos printa(" %-20s %-10s %-32s %@8d\n", @num);
79 1.1 christos
80 1.1 christos normalize(@types_excl, 1000);
81 1.1 christos printf("\nExclusive subroutine elapsed times (us),\n");
82 1.1 christos printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
83 1.1 christos printa(" %-20s %-10s %-32s %@8d\n", @types_excl);
84 1.1 christos
85 1.1 christos normalize(@types_incl, 1000);
86 1.1 christos printf("\nInclusive subroutine elapsed times (us),\n");
87 1.1 christos printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
88 1.1 christos printa(" %-20s %-10s %-32s %@8d\n", @types_incl);
89 1.1 christos }
90