php_flow.d revision 256281
1323136Sdes#!/usr/sbin/dtrace -Zs 257429Smarkm/* 357429Smarkm * php_flow.d - snoop PHP execution showing function flow. 457429Smarkm * Written for the PHP DTrace provider. 557429Smarkm * 657429Smarkm * $Id: php_flow.d 53 2007-09-24 04:58:38Z brendan $ 757429Smarkm * 865674Skris * This traces PHP activity from all PHP programs on the system 965674Skris * running with PHP provider support. 1065674Skris * 1165674Skris * USAGE: php_flow.d # hit Ctrl-C to end 1265674Skris * 1365674Skris * This watches PHP function entries and returns, and indents child 1457429Smarkm * function calls. 1557429Smarkm * 1657429Smarkm * FIELDS: 17263691Sdes * C CPU-id 1857429Smarkm * TIME(us) Time since boot, us 19162856Sdes * FILE Filename that this function belongs to 20162856Sdes * FUNC Function name 21162856Sdes * 22162856Sdes * LEGEND: 23162856Sdes * -> function entry 24162856Sdes * <- function return 25162856Sdes * 2660576Skris * WARNING: Watch the first column carefully, it prints the CPU-id. If it 27162856Sdes * changes, then it is very likely that the output has been shuffled. 28162856Sdes * 29261320Sdes * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 30162856Sdes * 31162856Sdes * CDDL HEADER START 32162856Sdes * 33204917Sdes * The contents of this file are subject to the terms of the 34162856Sdes * Common Development and Distribution License, Version 1.0 only 35162856Sdes * (the "License"). You may not use this file except in compliance 36162856Sdes * with the License. 37162856Sdes * 38162856Sdes * You can obtain a copy of the license at Docs/cddl1.txt 39221420Sdes * or http://www.opensolaris.org/os/licensing. 40162856Sdes * See the License for the specific language governing permissions 41162856Sdes * and limitations under the License. 42162856Sdes * 43162856Sdes * CDDL HEADER END 44162856Sdes * 45162856Sdes * 09-Sep-2007 Brendan Gregg Created this. 46162856Sdes */ 47162856Sdes 48162856Sdes#pragma D option quiet 4976262Sgreen#pragma D option switchrate=10 5057429Smarkm 5160576Skrisself int depth; 5257429Smarkm 5357429Smarkmdtrace:::BEGIN 5457429Smarkm{ 5558585Skris printf("%3s %-16s %-16s -- %s\n", "C", "TIME(us)", "FILE", "FUNC"); 5660576Skris} 5758585Skris 5876262Sgreenphp*:::function-entry 59294328Sdes/arg0/ 6076262Sgreen{ 6176262Sgreen printf("%3d %-16d %-16s %*s-> %s\n", cpu, timestamp / 1000, 62124211Sdes basename(copyinstr(arg1)), self->depth * 2, "", copyinstr(arg0)); 63261320Sdes self->depth++; 64204917Sdes} 65162856Sdes 66294332Sdesphp*:::function-return 67294332Sdes/arg0/ 68296633Sdes{ 69124211Sdes self->depth -= self->depth > 0 ? 1 : 0; 7060576Skris printf("%3d %-16d %-16s %*s<- %s\n", cpu, timestamp / 1000, 7160576Skris basename(copyinstr(arg1)), self->depth * 2, "", copyinstr(arg0)); 72294328Sdes} 7357429Smarkm