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