3 * php_cputime.d - measure PHP on-CPU times for functions.
4 * Written for the PHP DTrace provider.
6 * $Id: php_cputime.d 53 2007-09-24 04:58:38Z brendan $
8 * This traces PHP activity from all programs running on the system with
9 * PHP provider support.
11 * USAGE: php_cputime.d # hit Ctrl-C to end
14 * FILE Filename of the PHP program
15 * TYPE Type of call (func/total)
16 * NAME Name of call (function name)
17 * TOTAL Total on-CPU time for calls (us)
19 * Filename and function names are printed if available.
21 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
25 * The contents of this file are subject to the terms of the
26 * Common Development and Distribution License, Version 1.0 only
27 * (the "License"). You may not use this file except in compliance
30 * You can obtain a copy of the license at Docs/cddl1.txt
31 * or http://www.opensolaris.org/os/licensing.
32 * See the License for the specific language governing permissions
33 * and limitations under the License.
37 * 09-Sep-2007 Brendan Gregg Created this.
40 #pragma D option quiet
44 printf("Tracing... Hit Ctrl-C to end.\n");
51 self->exclude[self->depth] = 0;
52 self->function[self->depth] = vtimestamp;
55 php*:::function-return
56 /arg0 && self->function[self->depth]/
58 this->oncpu_incl = vtimestamp - self->function[self->depth];
59 this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth];
60 self->function[self->depth] = 0;
61 self->exclude[self->depth] = 0;
62 this->file = basename(copyinstr(arg1));
63 this->name = copyinstr(arg0);
65 @num[this->file, "func", this->name] = count();
66 @num["-", "total", "-"] = count();
67 @types_incl[this->file, "func", this->name] = sum(this->oncpu_incl);
68 @types_excl[this->file, "func", this->name] = sum(this->oncpu_excl);
69 @types_excl["-", "total", "-"] = sum(this->oncpu_excl);
72 self->exclude[self->depth] += this->oncpu_incl;
78 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
79 printa(" %-20s %-10s %-32s %@8d\n", @num);
81 normalize(@types_excl, 1000);
82 printf("\nExclusive function on-CPU times (us),\n");
83 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
84 printa(" %-20s %-10s %-32s %@8d\n", @types_excl);
86 normalize(@types_incl, 1000);
87 printf("\nInclusive function on-CPU times (us),\n");
88 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
89 printa(" %-20s %-10s %-32s %@8d\n", @types_incl);