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