1235368Sgnn#!/usr/sbin/dtrace -Zs 2235368Sgnn/* 3235368Sgnn * php_calldist.d - measure PHP elapsed times for functions. 4235368Sgnn * Written for the PHP DTrace provider. 5235368Sgnn * 6235368Sgnn * $Id: php_calldist.d 53 2007-09-24 04:58:38Z brendan $ 7235368Sgnn * 8235368Sgnn * This traces PHP activity from all programs running on the system with 9235368Sgnn * PHP provider support. 10235368Sgnn * 11235368Sgnn * USAGE: php_calldist.d # hit Ctrl-C to end 12235368Sgnn * 13235368Sgnn * This script prints distribution plots of elapsed time for PHP 14235368Sgnn * operations. Use php_calltime.d for summary reports. 15235368Sgnn * 16235368Sgnn * FIELDS: 17235368Sgnn * 1 Filename of the PHP program 18235368Sgnn * 2 Type of call (func) 19235368Sgnn * 3 Name of call 20235368Sgnn * 21235368Sgnn * Filename and function names are printed if available. 22235368Sgnn * 23235368Sgnn * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 24235368Sgnn * 25235368Sgnn * CDDL HEADER START 26235368Sgnn * 27235368Sgnn * The contents of this file are subject to the terms of the 28235368Sgnn * Common Development and Distribution License, Version 1.0 only 29235368Sgnn * (the "License"). You may not use this file except in compliance 30235368Sgnn * with the License. 31235368Sgnn * 32235368Sgnn * You can obtain a copy of the license at Docs/cddl1.txt 33235368Sgnn * or http://www.opensolaris.org/os/licensing. 34235368Sgnn * See the License for the specific language governing permissions 35235368Sgnn * and limitations under the License. 36235368Sgnn * 37235368Sgnn * CDDL HEADER END 38235368Sgnn * 39235368Sgnn * 09-Sep-2007 Brendan Gregg Created this. 40235368Sgnn */ 41235368Sgnn 42235368Sgnn#pragma D option quiet 43235368Sgnn 44235368Sgnndtrace:::BEGIN 45235368Sgnn{ 46235368Sgnn printf("Tracing... Hit Ctrl-C to end.\n"); 47235368Sgnn} 48235368Sgnn 49235368Sgnnphp*:::function-entry 50235368Sgnn/arg0/ 51235368Sgnn{ 52235368Sgnn self->depth++; 53235368Sgnn self->exclude[self->depth] = 0; 54235368Sgnn self->function[self->depth] = timestamp; 55235368Sgnn} 56235368Sgnn 57235368Sgnnphp*:::function-return 58235368Sgnn/arg0 && self->function[self->depth]/ 59235368Sgnn{ 60235368Sgnn this->elapsed_incl = timestamp - self->function[self->depth]; 61235368Sgnn this->elapsed_excl = this->elapsed_incl - self->exclude[self->depth]; 62235368Sgnn self->function[self->depth] = 0; 63235368Sgnn self->exclude[self->depth] = 0; 64235368Sgnn this->file = basename(copyinstr(arg1)); 65235368Sgnn this->name = copyinstr(arg0); 66235368Sgnn 67235368Sgnn @types_incl[this->file, "func", this->name] = 68235368Sgnn quantize(this->elapsed_incl / 1000); 69235368Sgnn @types_excl[this->file, "func", this->name] = 70235368Sgnn quantize(this->elapsed_excl / 1000); 71235368Sgnn 72235368Sgnn self->depth--; 73235368Sgnn self->exclude[self->depth] += this->elapsed_incl; 74235368Sgnn} 75235368Sgnn 76235368Sgnndtrace:::END 77235368Sgnn{ 78235368Sgnn printf("\nExclusive function elapsed times (us),\n"); 79235368Sgnn printa(" %s, %s, %s %@d\n", @types_excl); 80235368Sgnn 81235368Sgnn printf("\nInclusive function elapsed times (us),\n"); 82235368Sgnn printa(" %s, %s, %s %@d\n", @types_incl); 83235368Sgnn} 84