php_flow.d revision 235368
1234353Sdim#!/usr/sbin/dtrace -Zs
2218885Sdim/*
3218885Sdim * php_flow.d - snoop PHP execution showing function flow.
4218885Sdim *              Written for the PHP DTrace provider.
5218885Sdim *
6218885Sdim * $Id: php_flow.d 53 2007-09-24 04:58:38Z brendan $
7218885Sdim *
8218885Sdim * This traces PHP activity from all PHP programs on the system
9218885Sdim * running with PHP provider support.
10218885Sdim *
11218885Sdim * USAGE: php_flow.d			# hit Ctrl-C to end
12218885Sdim *
13218885Sdim * This watches PHP function entries and returns, and indents child
14218885Sdim * function calls.
15249423Sdim *
16234353Sdim * FIELDS:
17218885Sdim *		C		CPU-id
18218885Sdim *		TIME(us)	Time since boot, us
19239462Sdim *		FILE		Filename that this function belongs to
20218885Sdim *		FUNC		Function name
21218885Sdim *
22218885Sdim * LEGEND:
23218885Sdim *		->		function entry
24218885Sdim *		<-		function return
25249423Sdim *
26249423Sdim * WARNING: Watch the first column carefully, it prints the CPU-id. If it
27249423Sdim * changes, then it is very likely that the output has been shuffled.
28218885Sdim *
29218885Sdim * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
30218885Sdim *
31218885Sdim * CDDL HEADER START
32218885Sdim *
33218885Sdim *  The contents of this file are subject to the terms of the
34218885Sdim *  Common Development and Distribution License, Version 1.0 only
35218885Sdim *  (the "License").  You may not use this file except in compliance
36218885Sdim *  with the License.
37218885Sdim *
38218885Sdim *  You can obtain a copy of the license at Docs/cddl1.txt
39218885Sdim *  or http://www.opensolaris.org/os/licensing.
40218885Sdim *  See the License for the specific language governing permissions
41218885Sdim *  and limitations under the License.
42218885Sdim *
43218885Sdim * CDDL HEADER END
44218885Sdim *
45218885Sdim * 09-Sep-2007	Brendan Gregg	Created this.
46218885Sdim */
47218885Sdim
48218885Sdim#pragma D option quiet
49218885Sdim#pragma D option switchrate=10
50218885Sdim
51218885Sdimself int depth;
52218885Sdim
53218885Sdimdtrace:::BEGIN
54218885Sdim{
55218885Sdim	printf("%3s %-16s %-16s -- %s\n", "C", "TIME(us)", "FILE", "FUNC");
56218885Sdim}
57218885Sdim
58218885Sdimphp*:::function-entry
59218885Sdim/arg0/
60218885Sdim{
61218885Sdim	printf("%3d %-16d %-16s %*s-> %s\n", cpu, timestamp / 1000,
62218885Sdim	    basename(copyinstr(arg1)), self->depth * 2, "", copyinstr(arg0));
63218885Sdim	self->depth++;
64218885Sdim}
65218885Sdim
66218885Sdimphp*:::function-return
67218885Sdim/arg0/
68218885Sdim{
69218885Sdim	self->depth -= self->depth > 0 ? 1 : 0;
70218885Sdim	printf("%3d %-16d %-16s %*s<- %s\n", cpu, timestamp / 1000,
71218885Sdim	    basename(copyinstr(arg1)), self->depth * 2, "", copyinstr(arg0));
72218885Sdim}
73218885Sdim