1#!/usr/sbin/dtrace -Zs 2/* 3 * php_flowtime.d - snoop PHP functions with flow and delta times. 4 * Written for the PHP DTrace provider. 5 * 6 * $Id: php_flowtime.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $ 7 * 8 * This traces shell activity from PHP programs on the system that are 9 * running with PHP provider support. 10 * 11 * USAGE: php_flowtime.d # hit Ctrl-C to end 12 * 13 * This watches PHP function entries and returns, and indents child 14 * function calls. 15 * 16 * FIELDS: 17 * C CPU-id 18 * TIME(us) Time since boot, us 19 * FILE Filename that this function belongs to 20 * DELTA(us) Elapsed time from previous line to this line 21 * FUNC PHP function name 22 * 23 * LEGEND: 24 * -> function entry 25 * <- function return 26 * 27 * Filename and function names are printed if available. 28 * 29 * WARNING: Watch the first column carefully, it prints the CPU-id. If it 30 * changes, then it is very likely that the output has been shuffled. 31 * 32 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 33 * 34 * CDDL HEADER START 35 * 36 * The contents of this file are subject to the terms of the 37 * Common Development and Distribution License, Version 1.0 only 38 * (the "License"). You may not use this file except in compliance 39 * with the License. 40 * 41 * You can obtain a copy of the license at Docs/cddl1.txt 42 * or http://www.opensolaris.org/os/licensing. 43 * See the License for the specific language governing permissions 44 * and limitations under the License. 45 * 46 * CDDL HEADER END 47 * 48 * 09-Sep-2007 Brendan Gregg Created this. 49 */ 50 51#pragma D option quiet 52#pragma D option switchrate=10 53 54self int depth; 55 56self int last; 57 58dtrace:::BEGIN 59{ 60 printf("%3s %-16s %-16s %9s -- %s\n", "C", "TIME(us)", "FILE", 61 "DELTA(us)", "FUNC"); 62} 63 64php*:::function-entry, 65php*:::function-return 66/self->last == 0/ 67{ 68 self->last = timestamp; 69} 70 71php*:::function-entry 72/arg0/ 73{ 74 this->delta = (timestamp - self->last) / 1000; 75 printf("%3d %-16d %-16s %9d %*s-> %s\n", cpu, timestamp / 1000, 76 basename(copyinstr(arg1)), this->delta, self->depth * 2, "", 77 copyinstr(arg0)); 78 self->depth++; 79 self->last = timestamp; 80} 81 82php*:::function-return 83/arg0/ 84{ 85 this->delta = (timestamp - self->last) / 1000; 86 self->depth -= self->depth > 0 ? 1 : 0; 87 printf("%3d %-16d %-16s %9d %*s<- %s\n", cpu, timestamp / 1000, 88 basename(copyinstr(arg1)), this->delta, self->depth * 2, "", 89 copyinstr(arg0)); 90 self->last = timestamp; 91} 92