1235368Sgnn#!/usr/sbin/dtrace -Zs
2/*
3 * php_syscalls.d - count PHP function calls and syscalls using DTrace.
4 *                  Written for the PHP DTrace provider.
5 *
6 * This traces syscalls that occured during a PHP function call.
7 *
8 * $Id: php_syscalls.d 53 2007-09-24 04:58:38Z brendan $
9 *
10 * USAGE: php_syscalls.d 	# hit Ctrl-C to end
11 *
12 * FIELDS:
13 *		PID		Process ID
14 *		FILE		Filename of the PHP program
15 *		TYPE		Type of call (func/syscall)
16 *		NAME		Name of call
17 *		COUNT		Number of calls during sample
18 *
19 * Filename and function names are printed if available.
20 * The filename for syscalls may be printed as "php", if the program
21 * was invoked using the form "php filename" rather than running the
22 * program with an interpreter line.
23 *
24 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
25 *
26 * CDDL HEADER START
27 *
28 *  The contents of this file are subject to the terms of the
29 *  Common Development and Distribution License, Version 1.0 only
30 *  (the "License").  You may not use this file except in compliance
31 *  with the License.
32 *
33 *  You can obtain a copy of the license at Docs/cddl1.txt
34 *  or http://www.opensolaris.org/os/licensing.
35 *  See the License for the specific language governing permissions
36 *  and limitations under the License.
37 *
38 * CDDL HEADER END
39 *
40 * 09-Sep-2007	Brendan Gregg	Created this.
41 */
42
43#pragma D option quiet
44
45dtrace:::BEGIN
46{
47	printf("Tracing... Hit Ctrl-C to end.\n");
48}
49
50php*:::function-entry
51/arg0/
52{
53	@calls[pid, basename(copyinstr(arg1)), "func", copyinstr(arg0)] =
54	    count();
55	self->php++;
56}
57
58php*:::function-return
59/arg0/
60{
61	self->php -= self->php == 0 ? 0 : 1;
62}
63
64syscall:::entry
65/self->php > 0/
66{
67	@calls[pid, basename(execname), "syscall", probefunc] = count();
68}
69
70dtrace:::END
71{
72	printf(" %-6s  %-26s %-10s %-22s %8s\n", "PID", "FILE", "TYPE", "NAME",
73	    "COUNT");
74	printa(" %-6d  %-26s %-10s %-22s %@8d\n", @calls);
75}
76