cvs: pecl /apd README apd_array.c apd_array.h apd_summary.c config.m4 opcode.c opcode.h php_apd.c php_apd.h pprof2calltree win32compat.c win32compat.h
| From: | George Schlossnagle | Date: | Wed, 10 Mar 2004 16:40:55 +0000 |
| Subject: | cvs: pecl /apd README apd_array.c apd_array.h apd_summary.c config.m4 opcode.c opcode.h php_apd.c php_apd.h pprof2calltree win32compat.c win32compat.h | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-1039@lists.php.net to get a copy of this message | ||
gschlossnagle Wed Mar 10 11:40:55 2004 EDT
Removed files:
/pecl/apd opcode.c opcode.h
Modified files:
/pecl/apd apd_array.c apd_array.h apd_summary.c pprof2calltree
README config.m4 php_apd.c php_apd.h win32compat.c
win32compat.h
Log:
Move from ZEND_ENGINE_2 branch
http://cvs.php.net/diff.php/pecl/apd/apd_array.c?r1=1.1&r2=1.2&ty=u Index: pecl/apd/apd_array.c diff -u /dev/null pecl/apd/apd_array.c:1.2 --- /dev/null Wed Mar 10 11:40:55 2004 +++ pecl/apd/apd_array.c Wed Mar 10 11:40:55 2004 @@ -0,0 +1,147 @@ +/* + +----------------------------------------------------------------------+ + | APD Profiler & Debugger | + +----------------------------------------------------------------------+ + | Copyright (c) 2003 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Sterling Hughes <sterling@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include <stdlib.h> +#include "apd_array.h" +#include "php.h" + +/** + * Its not a queue, its not a stack, its a sequential a cheap array + * designed so that one uses sequential indexes for writes and random + * access on gets. + * + * It handles reallocation and bounds checking, but that's about it. + * + * Its well suited for apd's needs, but use this code at your own peril, + * as general usage will certainly come back and bite you in the butt. + * + * -Sterling, 06/2003 + */ + +void +apd_array_init(apd_array_t *a, long alloc, double blocksize) +{ + a->alloced = alloc; + a->size = 0; + a->blocksize = blocksize; + /** + * largest is used by apd_array_append() + * initial element is -1, so if its used in an empty array + * 0 is the initial index + */ + a->largest = -1; + + a->blob = (void **) ecalloc(sizeof(void *), a->alloced); +} + +inline void +_grow_array(apd_array_t *a) +{ + long oldalloc; + long i; + + oldalloc = a->alloced; + + a->alloced = (long) (a->blocksize * (double) a->alloced); + a->blob = (void **) erealloc(a->blob, a->alloced * sizeof(void *)); + + for (i = oldalloc; i < a->alloced; i++) { + a->blob[i] = NULL; + } +} + +int +apd_array_append(apd_array_t *a, void *ptr) +{ + apd_array_set(a, a->largest+1, ptr); +} + +int +apd_array_set(apd_array_t *a, long index, void *ptr) +{ + if (a == NULL || index < 0) { + return 0; + } + + if (a->alloced < index) { + _grow_array(a); + } + + a->blob[index] = ptr; + if (ptr) { + a->size++; + if (a->largest < index) { + a->largest = index; + } + } else { + long i; + + a->size--; + + for (i = 0; i < a->alloced; i++) { + if (a->blob[i] != NULL) { + a->largest = i; + } + } + } +} + +void * +apd_array_get(apd_array_t *a, long index) +{ + if (a == NULL || index > a->alloced || index < 0) { + return NULL; + } + + return a->blob[index]; +} + +void +apd_array_clean(apd_array_t *a, apd_array_dtor_t dtor) +{ + long i; + + for (i = 0; i < a->alloced; i++) { + if (a->blob[i] != NULL) { + dtor(a->blob[i]); + a->blob[i] = NULL; + } + } +} + +void +apd_array_destroy(apd_array_t *a, apd_array_dtor_t dtor) +{ + if (dtor) { + apd_array_clean(a, dtor); + } + + efree(a->blob); + memset(a, 0, sizeof(apd_array_t)); +} + + +/** + * Local Variables: + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim600:fdm=marker + * vim:noet:sw=4:ts=4 + */ http://cvs.php.net/diff.php/pecl/apd/apd_array.h?r1=1.1&r2=1.2&ty=u Index: pecl/apd/apd_array.h diff -u /dev/null pecl/apd/apd_array.h:1.2 --- /dev/null Wed Mar 10 11:40:55 2004 +++ pecl/apd/apd_array.h Wed Mar 10 11:40:55 2004 @@ -0,0 +1,48 @@ +/* + +----------------------------------------------------------------------+ + | APD Profiler & Debugger | + +----------------------------------------------------------------------+ + | Copyright (c) 2003 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Sterling Hughes <sterling@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifndef APD_ARRAY_H +#define APD_ARRAY_H + +typedef struct { + void **blob; + long size; + long alloced; + long blocksize; + long largest; +} apd_array_t; + +typedef void (*apd_array_dtor_t)(void *); + +void apd_array_init(apd_array_t *, long, double); +int apd_array_set(apd_array_t *, long, void *); +void *apd_array_get(apd_array_t *, long); +void apd_array_clean(apd_array_t *, apd_array_dtor_t); +void apd_array_destroy(apd_array_t *, apd_array_dtor_t); + +#endif + +/** + * Local Variables: + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim600:fdm=marker + * vim:noet:sw=4:ts=4 + */ http://cvs.php.net/diff.php/pecl/apd/apd_summary.c?r1=1.1&r2=1.2&ty=u Index: pecl/apd/apd_summary.c diff -u /dev/null pecl/apd/apd_summary.c:1.2 --- /dev/null Wed Mar 10 11:40:55 2004 +++ pecl/apd/apd_summary.c Wed Mar 10 11:40:55 2004 @@ -0,0 +1,321 @@ +/* + +----------------------------------------------------------------------+ + | APD Profiler & Debugger | + +----------------------------------------------------------------------+ + | Copyright (c) 2001-2003 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Sterling Hughes <sterling@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include "php_apd.h" + +void +apd_summary_output_header() +{ + apd_file_entry_t *file_entry; + apd_function_entry_t *function_entry; + apd_fcall_t *fcall; + TSRMLS_FETCH(); + + APD_GLOBALS(summary).caller = zend_get_executed_filename(TSRMLS_C); + apd_array_init(&APD_GLOBALS(summary).files, 5, 1.5); + apd_array_init(&APD_GLOBALS(summary).functions, 20, 1.5); + zend_llist_init(&APD_GLOBALS(summary).call_list, sizeof(void *), NULL, 0); +} + +void +apd_summary_output_file_reference(int id, const char *filename) +{ + apd_file_entry_t *file_entry; + TSRMLS_FETCH(); + + file_entry = emalloc(sizeof(apd_file_entry_t)); + file_entry->id = id; + file_entry->filename = estrdup(filename); + + apd_array_set(&APD_GLOBALS(summary).files, id, file_entry); +} + +void +apd_summary_output_elapsed_time(int filenum, int linenum, int usert, int systemt, int realt) +{ + zend_llist *list; + zend_llist_position l; + apd_fcall_t *cc; + TSRMLS_FETCH(); + + list = &APD_GLOBALS(summary).call_list; + + cc = zend_llist_get_first_ex(list, &l); + while (cc) { + cc->usertime += usert; + cc->systemtime += systemt; + cc->realtime += realt; + + cc = zend_llist_get_next_ex(list, &l); + } +} + +void +apd_summary_output_declare_function(int index, const char *fname, int type) +{ + apd_function_entry_t *function_entry; + TSRMLS_FETCH(); + + function_entry = ecalloc(1, sizeof(apd_function_entry_t)); + function_entry->name = estrdup(fname); + function_entry->id = index; + function_entry->type = type; + + apd_array_set(&APD_GLOBALS(summary).functions, index, function_entry); +} + +inline apd_fcall_t * +find_fcall(apd_coverage_t *coverage, int filenum, int linenum) +{ + apd_fcall_t *fcall; + int i; + + for (fcall = coverage->head; fcall != NULL; fcall = fcall->next) { + if (fcall->file == filenum && fcall->line == linenum) { + return fcall; + } + } + + return NULL; +} + +inline void +append_fcall(apd_coverage_t *coverage, apd_fcall_t *fcall) +{ + coverage->size++; + + if (coverage->head == NULL) { + coverage->head = coverage->tail = fcall; + return; + } + + coverage->tail->next = fcall; + fcall->prev = coverage->tail; + coverage->tail = fcall; +} + + +void +apd_summary_output_enter_function(int index, int filenum, int linenum) +{ + apd_function_entry_t *function_entry; + apd_coverage_t *coverage; + apd_fcall_t *fcall; + TSRMLS_FETCH(); + + if (index == 1) { + return; + } + + function_entry = apd_array_get(&APD_GLOBALS(summary).functions, index); + if (function_entry == NULL) { + php_error(E_WARNING, "Couldn't find function entry by index %d", index); + return; + } + + fcall = find_fcall(&function_entry->coverage, filenum, linenum); + if (!fcall) { + fcall = ecalloc(1, sizeof(apd_fcall_t)); + fcall->line = linenum; + fcall->file = filenum; + fcall->entry = function_entry; + + append_fcall(&function_entry->coverage, fcall); + } + fcall->calls++; + + zend_llist_add_element(&APD_GLOBALS(summary).call_list, &fcall); +} + +static int +compare_fcall(void *e1, void *e2) +{ + apd_fcall_t *a = e1; + apd_fcall_t *b = e2; + + if (a->entry == b->entry && a->file == b->file && a->line == b->line) { + return 1; + } + + return 0; +} + +void +apd_summary_output_exit_function(int index, int mem) +{ + apd_fcall_t *fcall; + void *entry; + TSRMLS_FETCH(); + + entry = apd_array_get(&APD_GLOBALS(summary).functions, index); + if (entry == NULL) { + return; + } + + zend_llist_del_element(&APD_GLOBALS(summary).call_list, entry, compare_fcall); +} + +inline void +copy_fcall(apd_fcall_t **a, apd_fcall_t *b) +{ + *a = emalloc(sizeof(apd_fcall_t)); + memcpy(*a, b, sizeof(apd_fcall_t)); + (*a)->prev = NULL; + (*a)->next = NULL; +} + +inline void +place_best_slot(apd_coverage_t *summary, apd_fcall_t *fc, long max) +{ + apd_fcall_t *current = NULL; + apd_fcall_t *nfc; + int is_bigger = 0; + + current = summary->head; + while (current) { + if (fc->cumulative >= current->cumulative) { + is_bigger = 1; + break; + } + + current = current->next; + } + + if (current == NULL) { + current = summary->tail; + } + + copy_fcall(&nfc, fc); + + if (!current) { + summary->head = nfc; + summary->tail = nfc; + } else if (current == summary->tail && !is_bigger) { + nfc->prev = current; + nfc->next = NULL; + current->next = nfc; + + summary->tail = nfc; + } else { + nfc->next = current; + nfc->prev = current->prev; + if (current->prev) { + current->prev->next = nfc; + } else { + summary->head = nfc; + } + current->prev = nfc; + } + + if (++summary->size > max) { + current = summary->tail; + if (current->prev) { + current->prev->next = NULL; + } + summary->tail = current->prev; + efree(current); + } +} + +inline void +add_fcall_summary(apd_coverage_t *summary, apd_fcall_t *fc, long max) +{ + fc->cumulative = fc->realtime + fc->usertime + fc->systemtime; + place_best_slot(summary, fc, max); +} + +inline void +find_expensive(apd_coverage_t *summary, long max TSRMLS_DC) +{ + apd_array_t *functions; + apd_function_entry_t *function_entry; + apd_fcall_t *fcall; + long i; + + functions = &APD_GLOBALS(summary).functions; + for (i = 0; i < functions->alloced; ++i) { + function_entry = (apd_function_entry_t *) apd_array_get(functions, i); + if (function_entry == NULL) { + continue; + } + + for (fcall = function_entry->coverage.head; fcall != NULL; fcall = fcall->next) { + add_fcall_summary(summary, fcall, max); + } + } +} + + +void +apd_summary_output_footer(void) +{ + apd_fcall_t *fcall; + apd_function_entry_t *function_entry; + apd_file_entry_t *file_entry; + char *shortname; + apd_coverage_t coverage; + char *ret; + int ret_len; + TSRMLS_FETCH(); + + memset(&coverage, 0, sizeof(apd_coverage_t)); + + php_printf("<table border=\"1\" width=\"100%\">\n"); + php_printf("<tr>\n"); + php_printf("<th>Function</th>\n"); + php_printf("<th>File</th>\n"); + php_printf("<th>Line</th>\n"); + php_printf("<th># of calls</th>\n"); + php_printf("<th>User</th>\n"); + php_printf("<th>System</th>\n"); + php_printf("<th>Real</th>\n"); + php_printf("</tr>\n"); + + find_expensive(&coverage, 20 TSRMLS_CC); + fcall = coverage.head; + while (fcall) { + function_entry = fcall->entry; + file_entry = apd_array_get(&APD_GLOBALS(summary).files, fcall->file); + php_basename(file_entry->filename, strlen(file_entry->filename), NULL, 0, &ret, &ret_len TSRMLS_CC); + php_printf("<tr>\n"); + php_printf("<td>%s</td>\n", function_entry->name); + php_printf("<td><abbr title=\"%s\">%s</abbr></td>\n", file_entry->filename, ret); + php_printf("<td>%d</td>\n", fcall->line); + php_printf("<td>%d</td>\n", fcall->calls); + php_printf("<td>%4.2f</td>\n", (double) fcall->usertime / 1000000); + php_printf("<td>%4.2f</td>\n", (double) fcall->systemtime / 1000000); + php_printf("<td>%4.2f</td>\n", (double) fcall->realtime / 1000000); + php_printf("</tr>\n"); + + fcall = fcall->next; +// efree(ret); + } + php_printf("</table>\n"); + + zend_llist_clean(&APD_GLOBALS(summary).call_list); +} + +/** + * Local Variables: + * indent-tabs-mode: t + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600:fdm=marker; + * vim:noet:sw=4:ts=4; + */ http://cvs.php.net/diff.php/pecl/apd/pprof2calltree?r1=1.1&r2=1.2&ty=u Index: pecl/apd/pprof2calltree diff -u /dev/null pecl/apd/pprof2calltree:1.2 --- /dev/null Wed Mar 10 11:40:55 2004 +++ pecl/apd/pprof2calltree Wed Mar 10 11:40:55 2004 @@ -0,0 +1,173 @@ +#!/usr/bin/env php +<?php + +require "Console/Getopt.php"; +//error_reporting(0); + +$con = new Console_Getopt; +$args = $con->readPHPArgv(); +array_shift($args); +$shortoptions = 'f:'; +$retval = $con->getopt( $args, $shortoptions); +if(is_object($retval)) { + usage(); +} +foreach ($retval[0] as $kv_array) { + $opt[$kv_array[0]] = $kv_array[1]; +} +if(!$opt['f']) { + usage(); +} +if(!file_exists($opt['f'])) { + print "Trace file ${opt['f']} does not exist\n"; + exit; +} +$IN = fopen($opt['f'], "r"); +if(!$IN) { + print "Trace file ${opt['f']} could not be opened\n"; + exit; +} + +$path_parts = pathinfo($opt['f']); +$outfile = "cachegrind.out.".$path_parts['basename']; +$OUT = fopen($outfile, "w"); +if(!$OUT) { + print "Destination file $outfile could not be opened.\n"; + exit; +} + +while(($line = fgets($IN)) !== false) { + $line = rtrim($line); + if($line == "END_HEADER") { + break; + } +} +$tree = array(); +$callstack = array(); +while(($line = fgets($IN)) !== false) { + $line = rtrim($line); + $args = explode(" ", $line); + if($args[0] == '!') { + $file_lookup[$args[1]] = $args[2]; + } + else if($args[0] == '&') { + $function_lookup[$args[1]] = $args[2]; + $function_type[$args[1]] = ($args[3] == 2)?"USER":"INTERNAL"; + } + else if($args[0] == '+') { + $val = array(function_id => $args[1], + file_id => $args[2], + line => $args[3], + cost => 0); + array_push($callstack, $val); + } + else if($args[0] == '-') { + // retrieve $called to discard + $called = array_pop($callstack); + // retrieve $caller for reference + $caller = array_pop($callstack); + $called_id = $called['function_id']; + + // Set meta data if not already set' + if(!array_key_exists($called_id, $tree)) { + $tree[$called_id] = $called; + // initialize these to 0 + $tree[$called_id]['cost_per_line'] = array(); + } + if($caller !== null) { + $caller['child_calls']++; + $caller_id = $caller['function_id']; + if(!array_key_exists($caller_id, $tree)) { + $tree[$caller_id] = $caller; + } + $caller['cost'] += $called['cost']; + $tree[$caller_id]['called_funcs'][$tree[$caller_id]['call_counter']++][$called_id][$called['file_id']][$called['line']] += $called['cost']; + array_push($callstack, $caller); + } + if(is_array($called['cost_per_line'])) { + foreach($called[cost_per_line] as $file => $lines) { + foreach($lines as $line => $cost) { + $tree[$called_id]['cost_per_line'][$file][$line] += $cost; + } + } + } + } + else if($args[0] == '@') { + $called = array_pop($callstack); + switch(count($args)) { + case 6: + $file = $args[1]; + $line = $args[2]; + $real_tm = $args[5]; + break; + case 4: + $file = $called['file_id']; + $line = $called['line']; + $real_tm = $args[3]; + break; + + } + $called['cost_per_line'][$file][$line] += $real_tm; + $called['cost'] += $real_tm; + $total_cost += $real_tm; + array_push($callstack, $called); + } +} + +ob_start(); +print "events: Tick\n"; +print "summary: $total_cost\n"; +printf("cmd: %s\n", $file_lookup[1]); +print "\n"; + +foreach($tree as $caller => $data) { + $filename = $file_lookup[$data['file_id']]?$file_lookup[$data['file_id']]:"???"; + printf("ob=%s\n", $function_type[$caller]); + printf("fl=%s\n", $filename); + printf("fn=%s\n", $function_lookup[$caller]); + if(is_array($data['cost_per_line'])) { + foreach($data['cost_per_line'] as $file => $lines) { + foreach($lines as $line => $cost) { + print "$line $cost\n"; + } + } + } + else if ($data['cost']) { + printf("COST %s %s\n", $items['line'], $items['cost']); + } + else { + print_r($items); + } + if(is_array($data['called_funcs'])) { + foreach($data['called_funcs'] as $counter => $items) { + foreach($items as $called_id => $costs) { + if(is_array($costs)) { + printf("cfn=%s\n", $function_lookup[$called_id]); + foreach($costs as $file => $lines) { + printf("cfi=%s\ncalls=1\n", $file_lookup[$file]); + foreach($lines as $line => $cost) { + print "$line $cost\n"; + } + } + } + } + } + } + print "\n"; +} +print "\ntotals=$total_cost\n"; +$buffer = ob_get_clean(); +print "Writing kcachegrind compatible output to $outfile\n"; +fwrite($OUT, $buffer); + +function usage() +{ + print <<<EOD +pprof2calltree -f <tracefile> + +EOD; + exit(1); + + +} +?> http://cvs.php.net/diff.php/pecl/apd/README?r1=1.15&r2=1.16&ty=u Index: pecl/apd/README diff -u pecl/apd/README:1.15 pecl/apd/README:1.16 --- pecl/apd/README:1.15 Wed Apr 2 09:39:54 2003 +++ pecl/apd/README Wed Mar 10 11:40:55 2004 @@ -31,6 +31,7 @@ zend_extension = /absolute/path/to/apd.so apd.dumpdir = /absolute/path/to/trace/directory + apd.statement_trace = 0 Depending on your PHP build, the zend_extension directive can be one of the following: @@ -47,6 +48,10 @@ This can either be an absolute path or a relative path. Relative means always relative to your where from you run your executeable. + apd.statement_trace: + + Whether or not to do per-line tracings. There is a performance + impact to enabling this. *** NOTE ****************************************************************** * @@ -89,7 +94,7 @@ apd_set_pprof_trace(); - This will generate a pprof.<pid> file in your apd.dumpdir. The format + This will generate a pprof.<pid>.<ext> file in your apd.dumpdir. The format of this file is as follows: ! 1 simple.php @@ -113,7 +118,7 @@ + shows a function being entered and the file index and line number it was called on. - shows a function being exited. @ shows a time elapsed in the form - @ process_user_clock_t process_system_clock_t process_real_clock_t + @ file_id line_id process_user_clock_t process_system_clock_t process_real_clock_t The syntax of the file is largely for informational purposes, it's not designed for human consumption. To extract human-readable information from the trace, use @@ -134,6 +139,7 @@ Display options -c Display Real time elapsed alongside call tree. + -m Display file locations as well. -i Suppress reporting for php builtin functions -O <cnt> Specifies maximum number of subroutines to display. (default 15) -t Display compressed call tree. @@ -141,11 +147,11 @@ Thus, to get basic output on the trace, we would do -pprofp -u /tmp/pprof.<pid> +pprofp -u /tmp/pprof.<pid>.<ext> and we get something like: -10:33:29(george@ballista)[~/pear/PECL/apd]> pprofp -u /tmp/pprof.23424 +10:33:29(george@ballista)[~/pear/PECL/apd]> pprofp -u /tmp/pprof.23424.0 Trace for /data/storage/mirrors/www.php.net/index.php Total Elapsed Time = 0.09 @@ -181,7 +187,7 @@ This sorts output based on the usertime spent in subroutines, and ommits a call tree. If we added a -t -10:38:30(george@ballista)[~/pear/PECL/apd]> pprofp -u -t /tmp/pprof.23424 +10:38:30(george@ballista)[~/pear/PECL/apd]> pprofp -u -t /tmp/pprof.23424.0 ... @@ -189,95 +195,26 @@ - -How to use PHP-APD in your scripts (old style) +KCachegrind compatible output ----------------------------------------------------------------------------- * +APD can convert it's pprof data files to a format readable by +kcachegrind. kcachegrind is an amazing graphical profiler, available +here: http://kcachegrind.sourceforge.net/. + +To perform the conversion, run - In your PHP script, add the following line: +pprof2calltree -f /path/to/pprofp.<pid>.<ext> - apd_set_session_trace(N); +This will generate a file in your local directory called - where N is an integer which is formed by masking together the following - values: +cachegrind.out.pprof.<pid>.<ext> - FUNCTION_TRACE 1 - ARGS_TRACE 2 - ASSIGNMENT_TRACE 4 - STATEMENT_TRACE 8 - MEMORY_TRACE 16 - TIMING_TRACE 32 - SUMMARY_TRACE 64 - - I would seriously not recommend using MEMORY_TRACE. It is very slow and - does not appear to be accurate (great, huh?) also ASSIGNMENT_TRACE is not - implemented. So, to turn on all functional traces (TIMING, FUNCTIONS, ARGS - SUMMARY (like strace -c)) use: - - apd_set_session_trace(99); - - - Now run your script. - - - The dump output will be writting to: - - <apd.dumpdir>/apd_dump_<pid> - - The output itself will look something like: - -16:37:51(george@wasabi)[~/src/apd]> cat /tmp/apd_dump_31994 - - -APD - Advanced PHP Debugger Trace File ---------------------------------------------------------------------------- -Process Pid (31994) -Trace Begun at Fri Aug 10 16:37:45 2001 ---------------------------------------------------------------------------- -( 0.000000): apd_set_session_trace called at somewhere -( 0.001482): apd_set_session_trace() returned. Elapsed (997475865.364909) -( 0.001563): getcwd() /opt/apache/htdocs/a.php:4 -( 0.001628): getcwd() returned. Elapsed (0.000065) -( 0.001819): require() /opt/apache/htdocs/a.php:6 - ++ argv[0] $(??) = /tmp/a.php -( 0.002231): getcwd() /tmp/a.php:3 -( 0.002290): getcwd() returned. Elapsed (0.000059) -( 0.002375): include_once() /tmp/a.php:4 - ++ argv[0] $(??) = /tmp/aa.php -( 0.003276): include_once() returned. Elapsed (0.000901) -( 0.003334): require() returned. Elapsed (0.001515) -( 0.003381): require_once() /opt/apache/htdocs/a.php:7 - ++ argv[0] $(??) = /tmp/aa.php -( 0.003515): require_once() returned. Elapsed (0.000134) -( 0.003564): include() /opt/apache/htdocs/a.php:8 - ++ argv[0] $(??) = /tmp/b.php -( 0.003792): include() returned. Elapsed (0.000228) -( 0.018341): RSHUTDOWN called - end of trace ---------------------------------------------------------------------------- -Process Pid (31994) -Trace Ended at Fri Aug 10 16:37:45 2001 ---------------------------------------------------------------------------- +You can then load this file with kcachegrind as follows: +kcachegrind cachegrind.out.pprof.<pid>.<ext> Implemented Debugging Functions ----------------------------------------------------------------------------- * - - array apd_callstack() - Returns the current call stack as an array (very cool). - - apd_cluck([string warning[,string line delimiter]) - Behaves like perl's Carp::cluck. Throw a warning and a callstack. - The default line delimiter is "<BR />\n". - - apd_croak([string error[, string line delimiter]]) - Behaves like perl's Carp::croak. Throw an error, a callstack and then - exit. The default line delimiter is "<BR />\n". - - array apd_dump_regular_resources() - Return all current regular resources as an array. - - array apd_dump_persistent_resources() - Return all persistent resources as an array. - override_function(string func_name, string func_args, string func_code): Syntax similar to create_function(). Overrides built-in functions (replaces them in the symbol table). http://cvs.php.net/diff.php/pecl/apd/config.m4?r1=1.1.1.1&r2=1.2&ty=u Index: pecl/apd/config.m4 diff -u pecl/apd/config.m4:1.1.1.1 pecl/apd/config.m4:1.2 --- pecl/apd/config.m4:1.1.1.1 Thu Jul 26 17:42:16 2001 +++ pecl/apd/config.m4 Wed Mar 10 11:40:55 2004 @@ -20,6 +20,6 @@ AC_DEFINE(HAVE_APD, 1, [ ]) dnl Write more examples of tests here... - PHP_EXTENSION(apd, $ext_shared) + PHP_NEW_EXTENSION(apd, php_apd.c apd_lib.c apd_array.c apd_summary.c, $ext_shared) fi http://cvs.php.net/diff.php/pecl/apd/php_apd.c?r1=1.55&r2=1.56&ty=u Index: pecl/apd/php_apd.c diff -u pecl/apd/php_apd.c:1.55 pecl/apd/php_apd.c:1.56 --- pecl/apd/php_apd.c:1.55 Tue Dec 23 20:13:21 2003 +++ pecl/apd/php_apd.c Wed Mar 10 11:40:55 2004 @@ -1,23 +1,23 @@ /* +----------------------------------------------------------------------+ - | APD Profiler & Debugger | + | APD Profiler & Debugger | +----------------------------------------------------------------------+ - | Copyright (c) 2001-2003 Community Connect Inc. | + | Copyright (c) 2001-2003 Community Connect Inc. | +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Daniel Cowgill <dcowgill@communityconnect.com> | - | George Schlossnagle <george@lethargy.org> | - | Sterling Hughes <sterling@php.net> | + | Authors: Daniel Cowgill <dcowgill@communityconnect.com> | + | George Schlossnagle <george@lethargy.org> | + | Sterling Hughes <sterling@php.net> | +----------------------------------------------------------------------+ */ - + #include "php_apd.h" #ifdef PHP_WIN32 #include "win32compat.h" @@ -31,11 +31,12 @@ #endif #include "apd_lib.h" -#include "opcode.h" #include "zend_API.h" #include "zend_hash.h" #include "zend_alloc.h" #include "zend_operators.h" +#include "zend_globals.h" +#include "zend_compile.h" #include <assert.h> #include <stdarg.h> #include <sys/types.h> @@ -61,6 +62,9 @@ #endif ZEND_DLEXPORT void (*old_execute)(zend_op_array *op_array TSRMLS_DC); +ZEND_DLEXPORT void onStatement(zend_op_array *op_array TSRMLS_DC); +ZEND_DECLARE_MODULE_GLOBALS(apd); + /* This comes from php install tree. */ #include "ext/standard/info.h" @@ -71,14 +75,15 @@ PHP_FE(rename_function, NULL) PHP_FE(apd_set_pprof_trace, NULL) PHP_FE(apd_set_browser_trace, NULL) - PHP_FE(apd_set_session_trace_socket, NULL) - PHP_FE(apd_breakpoint, NULL) - PHP_FE(apd_continue, NULL) - PHP_FE(apd_echo, NULL) + PHP_FE(apd_set_session_trace_socket, NULL) + PHP_FE(apd_breakpoint, NULL) + PHP_FE(apd_continue, NULL) + PHP_FE(apd_echo, NULL) {NULL, NULL, NULL} }; void apd_pprof_fprintf(const char* fmt, ...); +static void log_time(TSRMLS_D); long diff_times(struct timeval a, struct timeval b) { @@ -108,9 +113,9 @@ } static void -apd_pprof_output_elapsed_time(int usert, int systemt, int realt) +apd_pprof_output_elapsed_time(int filenum, int linenum, int usert, int systemt, int realt) { - apd_pprof_fprintf("@ %ld %ld %ld\n", usert, systemt, realt); + apd_pprof_fprintf("@ %d %d %ld %ld %ld\n", filenum, linenum, usert, systemt, realt); } static void @@ -151,8 +156,8 @@ apd_pprof_fprintf("END_TRACE\n"); apd_pprof_fprintf("total_user=%ld\ntotal_sys=%ld\ntotal_wall=%ld\n", - diff_times(end_ru.ru_utime, APD_GLOBALS(first_ru).ru_utime), - diff_times(end_ru.ru_stime, APD_GLOBALS(first_ru).ru_stime), + diff_times(end_ru.ru_utime, APD_GLOBALS(first_ru).ru_utime), + diff_times(end_ru.ru_stime, APD_GLOBALS(first_ru).ru_stime), diff_times(end_clock, APD_GLOBALS(first_clock))); apd_pprof_fprintf("END_FOOTER\n"); } @@ -165,7 +170,7 @@ { va_list args; char* newStr; - TSRMLS_FETCH(); + TSRMLS_FETCH(); va_start(args, fmt); newStr = apd_sprintf_real(fmt, args); va_end(args); @@ -286,7 +291,7 @@ { char *funcname = NULL; int curSize = 0; - zend_execute_data *execd; + zend_execute_data *execd = NULL; char *tmpfname; char *classname; int classnameLen; @@ -339,7 +344,7 @@ } } else { - funcname = estrdup("???"); + funcname = estrdup("main"); } return funcname; } @@ -361,6 +366,7 @@ APD_GLOBALS(output).file_reference(*filenum, filename); zend_hash_add(APD_GLOBALS(file_summary), (char *) filename, strlen(filename) + 1, filenum, sizeof(int), NULL); } + APD_GLOBALS(current_file_index) = *filenum; if (zend_hash_find(APD_GLOBALS(function_summary), (char *) fname, strlen(fname)+1, (void *) &function_index) == SUCCESS) { APD_GLOBALS(output).enter_function(*function_index, *filenum, linenum); @@ -390,40 +396,44 @@ #if MEMORY_LIMIT allocated = AG(memory_limit); #endif - + log_time(TSRMLS_C); + if (zend_hash_find(APD_GLOBALS(function_summary), fname, strlen(fname) + 1, (void *) &function_index) == SUCCESS) { + APD_GLOBALS(output).exit_function(*function_index, allocated); + } else { + function_index = (int *) emalloc(sizeof(int)); + *function_index = ++APD_GLOBALS(function_index); + zend_hash_add(APD_GLOBALS(function_summary), fname, strlen(fname)+1, function_index, sizeof(int), NULL); + APD_GLOBALS(output).exit_function(*function_index, allocated); + } +} + +static void log_time(TSRMLS_D) +{ + struct timeval clock; + struct rusage wall_ru; + gettimeofday(&clock, NULL); getrusage(RUSAGE_SELF, &wall_ru); if (APD_GLOBALS(function_index) > 1) { + long utime, stime, rtime; utime = diff_times(wall_ru.ru_utime, APD_GLOBALS(last_ru).ru_utime); stime = diff_times(wall_ru.ru_stime, APD_GLOBALS(last_ru).ru_stime); rtime = diff_times(clock, APD_GLOBALS(last_clock)); if(utime || stime || rtime) { - APD_GLOBALS(output).elapsed_time(utime, stime, rtime); + APD_GLOBALS(output).elapsed_time(APD_GLOBALS(current_file_index), zend_get_executed_lineno(TSRMLS_C), utime, stime, rtime); } } APD_GLOBALS(last_ru) = wall_ru; APD_GLOBALS(last_clock) = clock; - if (zend_hash_find(APD_GLOBALS(function_summary), fname, strlen(fname) + 1, (void *) &function_index) == SUCCESS) { - APD_GLOBALS(output).exit_function(*function_index, allocated); - } else { - function_index = (int *) emalloc(sizeof(int)); - *function_index = ++APD_GLOBALS(function_index); - zend_hash_add(APD_GLOBALS(function_summary), fname, strlen(fname)+1, function_index, sizeof(int), NULL); - APD_GLOBALS(output).exit_function(*function_index, allocated); - } } /* -------------------------------------------------------------------------- - Error Tracing - --------------------------------------------------------------------------- Module Entry --------------------------------------------------------------------------- */ zend_module_entry apd_module_entry = { -#if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, -#endif "APD", apd_functions, PHP_MINIT(apd), @@ -431,14 +441,9 @@ PHP_RINIT(apd), PHP_RSHUTDOWN(apd), PHP_MINFO(apd), - NULL, - NULL, -#if ZEND_MODULE_API_NO >= 20010901 - NO_VERSION_YET, /* extension version number (string) */ -#endif - STANDARD_MODULE_PROPERTIES_EX + NO_VERSION_YET, /* extension version number (string) */ + STANDARD_MODULE_PROPERTIES }; -ZEND_DECLARE_MODULE_GLOBALS(apd); #if COMPILE_DL_APD ZEND_GET_MODULE(apd) @@ -462,6 +467,7 @@ PHP_INI_BEGIN() PHP_INI_ENTRY("apd.dumpdir", NULL, PHP_INI_ALL, set_dumpdir) + STD_PHP_INI_ENTRY("apd.statement_tracing", "0", PHP_INI_ALL, OnUpdateLong, statement_tracing, zend_apd_globals, apd_globals) PHP_INI_END() @@ -471,7 +477,7 @@ static void php_apd_init_globals(zend_apd_globals *apd_globals) { - memset(apd_globals, 0, sizeof(zend_apd_globals)); + memset(apd_globals, 0, sizeof(zend_apd_globals)); apd_globals->function_summary = (HashTable *) malloc(sizeof(HashTable)); apd_globals->file_summary = (HashTable *) malloc(sizeof(HashTable)); @@ -491,28 +497,9 @@ { ZEND_INIT_MODULE_GLOBALS(apd, php_apd_init_globals, php_apd_free_globals); REGISTER_INI_ENTRIES(); - REGISTER_LONG_CONSTANT("APD_AF_UNIX", AF_UNIX, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_AF_INET", AF_INET, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_FUNCTION_TRACE", FUNCTION_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_ARGS_TRACE", ARGS_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_ASSIGNMENT_TRACE", ASSIGNMENT_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_STATEMENT_TRACE", STATEMENT_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_MEMORY_TRACE", MEMORY_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_TIMING_TRACE", TIMING_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_SUMMARY_TRACE", SUMMARY_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_ERROR_TRACE", ERROR_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_PROF_TRACE", PROF_TRACE, CONST_CS | CONST_PERSISTENT); -#ifdef TRACE_ZEND_COMPILE /* we can trace the time to compile things. */ - /* gettimeofday(&APD_GLOBALS(last_call), NULL); */ - old_compile_file = zend_compile_file; - zend_compile_file = apd_compile_file; -#endif old_execute = zend_execute; zend_execute = apd_execute; - /* if the zend_execute_internal pointer exists, use it to trace 'built-ins*/ -#if ZEND_EXTENSION_API_NO>=20020731 zend_execute_internal = apd_execute_internal; -#endif return SUCCESS; } @@ -524,14 +511,13 @@ void **p; int argCount; zval **object_ptr_ptr; - - fname = apd_get_active_function_name(op_array TSRMLS_CC); - trace_function_entry(EG(function_table), fname, ZEND_USER_FUNCTION, + fname = apd_get_active_function_name(op_array TSRMLS_CC); + trace_function_entry(EG(function_table), fname, ZEND_USER_FUNCTION, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C)); - old_execute(op_array TSRMLS_CC); - trace_function_exit(fname); - efree(fname); + old_execute(op_array TSRMLS_CC); + trace_function_exit(fname); + efree(fname); apd_interactive(); } @@ -542,9 +528,11 @@ void **p; int argCount; zval **object_ptr_ptr; + zend_execute_data *execd; - fname = apd_get_active_function_name(EG(current_execute_data)->op_array TSRMLS_CC); - trace_function_entry(EG(function_table), fname, ZEND_INTERNAL_FUNCTION, + execd = executor_globals.current_execute_data; + fname = apd_get_active_function_name(execd->op_array TSRMLS_CC); + trace_function_entry(EG(function_table), fname, ZEND_INTERNAL_FUNCTION, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C)); execute_internal(execute_data_ptr, return_value_used TSRMLS_CC); @@ -567,7 +555,6 @@ APD_GLOBALS(dump_file) = stderr; APD_GLOBALS(dump_sock_id) = 0; - APD_GLOBALS(bitmask) = 0; APD_GLOBALS(interactive_mode) = 0; APD_GLOBALS(ignore_interactive) = 0; gettimeofday(&APD_GLOBALS(last_clock), NULL); @@ -587,7 +574,7 @@ PHP_RSHUTDOWN_FUNCTION(apd) { - APD_GLOBALS(output).footer(); +// APD_GLOBALS(output).footer(); if (APD_GLOBALS(pprof_file)) { fclose(APD_GLOBALS(pprof_file)); } @@ -600,7 +587,7 @@ zend_hash_clean(APD_GLOBALS(function_summary)); zend_hash_clean(APD_GLOBALS(file_summary)); - + APD_GLOBALS(counter)++; return SUCCESS; } @@ -667,7 +654,7 @@ RETURN_FALSE; } RETURN_TRUE; - } + } else { RETURN_FALSE; } @@ -727,7 +714,7 @@ RETURN_TRUE; } -void apd_pprof_header(TSRMLS_D) { +void apd_pprof_header(char *ent_fname TSRMLS_DC) { char *fname = "main"; char *filename; int linenum, *filenum, *fnum; @@ -748,6 +735,13 @@ APD_GLOBALS(output).file_reference(*filenum, filename); APD_GLOBALS(output).declare_function(*fnum, fname, ZEND_USER_FUNCTION); APD_GLOBALS(output).enter_function(*fnum, *filenum, linenum); + + fnum = (int *) emalloc(sizeof(int)); + *fnum = APD_GLOBALS(function_index)++; + zend_hash_add(APD_GLOBALS(function_summary), ent_fname, strlen(ent_fname)+1, fnum, sizeof(int), NULL); + + APD_GLOBALS(output).declare_function(*fnum, ent_fname, ZEND_USER_FUNCTION); + APD_GLOBALS(output).enter_function(*fnum, *filenum, linenum); } PHP_FUNCTION(apd_set_browser_trace) @@ -766,7 +760,7 @@ APD_GLOBALS(output).enter_function = apd_summary_output_enter_function; APD_GLOBALS(output).exit_function = apd_summary_output_exit_function; - apd_pprof_header(TSRMLS_C); + apd_pprof_header("apd_set_broswer_trace" TSRMLS_CC); } PHP_FUNCTION(apd_set_pprof_trace) @@ -775,7 +769,7 @@ int socketd = 0; int path_len; char *dumpdir; - char *path; + char path[MAXPATHLEN]; zval **z_dumpdir; if(ZEND_NUM_ARGS() > 1 ) @@ -805,15 +799,12 @@ dumpdir = Z_STRVAL_PP(z_dumpdir); } - path_len = strlen(dumpdir) + 1 + strlen("pprof.") + 5; - path = (char *) emalloc((path_len + 1)* sizeof(char) ); - snprintf(path, path_len + 1, "%s/pprof.%05d", dumpdir, getpid()); + snprintf(path, MAXPATHLEN, "%s/pprof.%05d.%d", dumpdir, getpid(), APD_GLOBALS(counter)); if((APD_GLOBALS(pprof_file) = fopen(path, "a")) == NULL) { zend_error(E_ERROR, "%s() failed to open %s for tracing", get_active_function_name(TSRMLS_C), path); } - efree(path); - apd_pprof_header(TSRMLS_C); + apd_pprof_header("apd_set_pprof_trace" TSRMLS_CC); } @@ -828,18 +819,16 @@ int sock_domain; int sock_port; - int bitmask; int connect_result; struct sockaddr_in si; struct sockaddr_un su; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "slll", &address,&address_len, &sock_domain, &sock_port,&bitmask) == FAILURE) + "slll", &address,&address_len, &sock_domain, &sock_port) == FAILURE) { return; } - APD_GLOBALS(bitmask) = bitmask; APD_GLOBALS(dump_file)=NULL; /* now for the socket stuff */ @@ -906,12 +895,10 @@ PHP_FUNCTION(apd_breakpoint) { - int bitmask; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &bitmask) == FAILURE) { + "l") == FAILURE) { return; } - APD_GLOBALS(bitmask) = bitmask; APD_GLOBALS(interactive_mode) = 1; RETURN_TRUE; } @@ -922,12 +909,6 @@ PHP_FUNCTION(apd_continue) { - int bitmask; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &bitmask) == FAILURE) { - return; - } - APD_GLOBALS(bitmask) = bitmask; APD_GLOBALS(interactive_mode) = 0; RETURN_TRUE; } @@ -946,7 +927,7 @@ return; } if (str_len > 0) { - /* php_error(E_WARNING, "apd echoing %s", str); */ + /* php_error(E_WARNING, "apd echoing %s", str); */ if ( APD_GLOBALS(dump_sock_id) > 0) { #ifndef PHP_WIN32 /* Unix bit */ @@ -959,7 +940,7 @@ #endif } apd_dump_fprintf("%s\n",str); - /* efree(str); */ + /* efree(str); */ } RETURN_TRUE; @@ -975,23 +956,16 @@ ZEND_DLEXPORT void onStatement(zend_op_array *op_array) { TSRMLS_FETCH(); - if (APD_GLOBALS(ignore_interactive) == 1) return; - if(APD_GLOBALS(bitmask) & STATEMENT_TRACE) { - apd_dump_fprintf("statement: %s:%d\n", - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C)); - apd_interactive(); - } + if(APD_GLOBALS(pproftrace) && APD_GLOBALS(statement_tracing)) { + log_time(TSRMLS_C); + } } -/* --------------------------------------------------------------------------- - Zend Extension Support - --------------------------------------------------------------------------- */ - int apd_zend_startup(zend_extension *extension) { TSRMLS_FETCH(); CG(extended_info) = 1; /* XXX: this is ridiculous */ +fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); return zend_startup_module(&apd_module_entry); } @@ -1013,21 +987,17 @@ "", apd_zend_startup, apd_zend_shutdown, - NULL, // activate_func_t - NULL, // deactivate_func_t - NULL, // message_handler_func_t - NULL, // op_array_handler_func_t - NULL, // statement_handler_func_t - NULL, // fcall_begin_handler_func_t - NULL, // fcall_end_handler_func_t - NULL, // op_array_ctor_func_t - NULL, // op_array_dtor_func_t -#ifdef COMPAT_ZEND_EXTENSION_PROPERTIES - NULL, // api_no_check + NULL, // activate_func_t + NULL, // deactivate_func_t + NULL, // message_handler_func_t + NULL, // op_array_handler_func_t + onStatement, // statement_handler_func_t + NULL, // fcall_begin_handler_func_t + NULL, // fcall_end_handler_func_t + NULL, // op_array_ctor_func_t + NULL, // op_array_dtor_func_t + NULL, // api_no_check COMPAT_ZEND_EXTENSION_PROPERTIES -#else - STANDARD_ZEND_EXTENSION_PROPERTIES -#endif }; /** http://cvs.php.net/diff.php/pecl/apd/php_apd.h?r1=1.20&r2=1.21&ty=u Index: pecl/apd/php_apd.h diff -u pecl/apd/php_apd.h:1.20 pecl/apd/php_apd.h:1.21 --- pecl/apd/php_apd.h:1.20 Tue Dec 23 20:13:21 2003 +++ pecl/apd/php_apd.h Wed Mar 10 11:40:55 2004 @@ -145,7 +145,7 @@ void apd_summary_output_header(void); void apd_summary_output_file_reference(int, const char *); -void apd_summary_output_elapsed_time(int, int, int); +void apd_summary_output_elapsed_time(int, int, int, int, int); void apd_summary_output_declare_function(int, const char *, int); void apd_summary_output_enter_function(int, int, int); void apd_summary_output_exit_function(int, int); @@ -154,7 +154,7 @@ typedef void (*apd_output_header_func_t)(void); typedef void (*apd_output_file_reference_func_t)(int, const char *); -typedef void (*apd_output_elapsed_time_func_t)(int, int, int); +typedef void (*apd_output_elapsed_time_func_t)(int, int, int, int, int); typedef void (*apd_output_declare_function_func_t)(int, const char *, int); typedef void (*apd_output_function_enter_func_t)(int, int, int); typedef void (*apd_output_function_exit_func_t)(int, int); @@ -171,6 +171,7 @@ } apd_output_handlers; ZEND_BEGIN_MODULE_GLOBALS(apd) + int counter; void* stack; HashTable* function_summary; HashTable* file_summary; @@ -178,13 +179,13 @@ FILE* dump_file; /* FILE for dumping session traces to */ FILE* pprof_file; /* File for profiling output */ int dump_sock_id; /* Socket for dumping data to */ - struct timeval first_clock; - struct timeval last_clock; + struct timeval first_clock; + struct timeval last_clock; struct rusage first_ru; struct rusage last_ru; int function_index; /* current index of functions for pprof tracing */ int file_index; /* current index of functions for pprof tracing */ - long bitmask; /* Bitmask for determining what gets logged */ + int current_file_index; long pproftrace; /* Flag for whether we are doing profiling */ void* last_mem_header; /* tail of persistent zend_mem_header list */ void* last_pmem_header; /* tail of persistent zend_mem_header list */ @@ -193,10 +194,12 @@ int allocated_memory; apd_output_handlers output; apd_summary_t summary; + int statement_tracing; ZEND_END_MODULE_GLOBALS(apd) +PHPAPI ZEND_EXTERN_MODULE_GLOBALS(apd) + /* Declare global structure. */ -ZEND_DECLARE_MODULE_GLOBALS(apd); #ifdef ZTS #define APD_GLOBALS(v) TSRMG(apd_globals_id, zend_apd_globals *, v) http://cvs.php.net/diff.php/pecl/apd/win32compat.c?r1=1.5&r2=1.6&ty=u Index: pecl/apd/win32compat.c diff -u pecl/apd/win32compat.c:1.5 pecl/apd/win32compat.c:1.6 --- pecl/apd/win32compat.c:1.5 Tue Dec 23 20:13:21 2003 +++ pecl/apd/win32compat.c Wed Mar 10 11:40:55 2004 @@ -12,7 +12,7 @@ * * *****************************************************************************/ -/* $Id: win32compat.c,v 1.5 2003/12/24 01:13:21 gschlossnagle Exp $ */ +/* $Id: win32compat.c,v 1.6 2004/03/10 16:40:55 gschlossnagle Exp $ */ #include "win32compat.h" http://cvs.php.net/diff.php/pecl/apd/win32compat.h?r1=1.5&r2=1.6&ty=u Index: pecl/apd/win32compat.h diff -u pecl/apd/win32compat.h:1.5 pecl/apd/win32compat.h:1.6 --- pecl/apd/win32compat.h:1.5 Tue Dec 23 20:13:21 2003 +++ pecl/apd/win32compat.h Wed Mar 10 11:40:55 2004 @@ -15,7 +15,7 @@ * * *****************************************************************************/ -/* $Id: win32compat.h,v 1.5 2003/12/24 01:13:21 gschlossnagle Exp $ */ +/* $Id: win32compat.h,v 1.6 2004/03/10 16:40:55 gschlossnagle Exp $ */ /* Include stuff ************************************************************ */
http://cvs.php.net/diff.php/pecl/apd/apd_array.c?r1=1.1&r2=1.2&ty=u Index: pecl/apd/apd_array.c diff -u /dev/null pecl/apd/apd_array.c:1.2 --- /dev/null Wed Mar 10 11:40:55 2004 +++ pecl/apd/apd_array.c Wed Mar 10 11:40:55 2004 @@ -0,0 +1,147 @@ +/* + +----------------------------------------------------------------------+ + | APD Profiler & Debugger | + +----------------------------------------------------------------------+ + | Copyright (c) 2003 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Sterling Hughes <sterling@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include <stdlib.h> +#include "apd_array.h" +#include "php.h" + +/** + * Its not a queue, its not a stack, its a sequential a cheap array + * designed so that one uses sequential indexes for writes and random + * access on gets. + * + * It handles reallocation and bounds checking, but that's about it. + * + * Its well suited for apd's needs, but use this code at your own peril, + * as general usage will certainly come back and bite you in the butt. + * + * -Sterling, 06/2003 + */ + +void +apd_array_init(apd_array_t *a, long alloc, double blocksize) +{ + a->alloced = alloc; + a->size = 0; + a->blocksize = blocksize; + /** + * largest is used by apd_array_append() + * initial element is -1, so if its used in an empty array + * 0 is the initial index + */ + a->largest = -1; + + a->blob = (void **) ecalloc(sizeof(void *), a->alloced); +} + +inline void +_grow_array(apd_array_t *a) +{ + long oldalloc; + long i; + + oldalloc = a->alloced; + + a->alloced = (long) (a->blocksize * (double) a->alloced); + a->blob = (void **) erealloc(a->blob, a->alloced * sizeof(void *)); + + for (i = oldalloc; i < a->alloced; i++) { + a->blob[i] = NULL; + } +} + +int +apd_array_append(apd_array_t *a, void *ptr) +{ + apd_array_set(a, a->largest+1, ptr); +} + +int +apd_array_set(apd_array_t *a, long index, void *ptr) +{ + if (a == NULL || index < 0) { + return 0; + } + + if (a->alloced < index) { + _grow_array(a); + } + + a->blob[index] = ptr; + if (ptr) { + a->size++; + if (a->largest < index) { + a->largest = index; + } + } else { + long i; + + a->size--; + + for (i = 0; i < a->alloced; i++) { + if (a->blob[i] != NULL) { + a->largest = i; + } + } + } +} + +void * +apd_array_get(apd_array_t *a, long index) +{ + if (a == NULL || index > a->alloced || index < 0) { + return NULL; + } + + return a->blob[index]; +} + +void +apd_array_clean(apd_array_t *a, apd_array_dtor_t dtor) +{ + long i; + + for (i = 0; i < a->alloced; i++) { + if (a->blob[i] != NULL) { + dtor(a->blob[i]); + a->blob[i] = NULL; + } + } +} + +void +apd_array_destroy(apd_array_t *a, apd_array_dtor_t dtor) +{ + if (dtor) { + apd_array_clean(a, dtor); + } + + efree(a->blob); + memset(a, 0, sizeof(apd_array_t)); +} + + +/** + * Local Variables: + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim600:fdm=marker + * vim:noet:sw=4:ts=4 + */ http://cvs.php.net/diff.php/pecl/apd/apd_array.h?r1=1.1&r2=1.2&ty=u Index: pecl/apd/apd_array.h diff -u /dev/null pecl/apd/apd_array.h:1.2 --- /dev/null Wed Mar 10 11:40:55 2004 +++ pecl/apd/apd_array.h Wed Mar 10 11:40:55 2004 @@ -0,0 +1,48 @@ +/* + +----------------------------------------------------------------------+ + | APD Profiler & Debugger | + +----------------------------------------------------------------------+ + | Copyright (c) 2003 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Sterling Hughes <sterling@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifndef APD_ARRAY_H +#define APD_ARRAY_H + +typedef struct { + void **blob; + long size; + long alloced; + long blocksize; + long largest; +} apd_array_t; + +typedef void (*apd_array_dtor_t)(void *); + +void apd_array_init(apd_array_t *, long, double); +int apd_array_set(apd_array_t *, long, void *); +void *apd_array_get(apd_array_t *, long); +void apd_array_clean(apd_array_t *, apd_array_dtor_t); +void apd_array_destroy(apd_array_t *, apd_array_dtor_t); + +#endif + +/** + * Local Variables: + * indent-tabs-mode: t + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim600:fdm=marker + * vim:noet:sw=4:ts=4 + */ http://cvs.php.net/diff.php/pecl/apd/apd_summary.c?r1=1.1&r2=1.2&ty=u Index: pecl/apd/apd_summary.c diff -u /dev/null pecl/apd/apd_summary.c:1.2 --- /dev/null Wed Mar 10 11:40:55 2004 +++ pecl/apd/apd_summary.c Wed Mar 10 11:40:55 2004 @@ -0,0 +1,321 @@ +/* + +----------------------------------------------------------------------+ + | APD Profiler & Debugger | + +----------------------------------------------------------------------+ + | Copyright (c) 2001-2003 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Sterling Hughes <sterling@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include "php_apd.h" + +void +apd_summary_output_header() +{ + apd_file_entry_t *file_entry; + apd_function_entry_t *function_entry; + apd_fcall_t *fcall; + TSRMLS_FETCH(); + + APD_GLOBALS(summary).caller = zend_get_executed_filename(TSRMLS_C); + apd_array_init(&APD_GLOBALS(summary).files, 5, 1.5); + apd_array_init(&APD_GLOBALS(summary).functions, 20, 1.5); + zend_llist_init(&APD_GLOBALS(summary).call_list, sizeof(void *), NULL, 0); +} + +void +apd_summary_output_file_reference(int id, const char *filename) +{ + apd_file_entry_t *file_entry; + TSRMLS_FETCH(); + + file_entry = emalloc(sizeof(apd_file_entry_t)); + file_entry->id = id; + file_entry->filename = estrdup(filename); + + apd_array_set(&APD_GLOBALS(summary).files, id, file_entry); +} + +void +apd_summary_output_elapsed_time(int filenum, int linenum, int usert, int systemt, int realt) +{ + zend_llist *list; + zend_llist_position l; + apd_fcall_t *cc; + TSRMLS_FETCH(); + + list = &APD_GLOBALS(summary).call_list; + + cc = zend_llist_get_first_ex(list, &l); + while (cc) { + cc->usertime += usert; + cc->systemtime += systemt; + cc->realtime += realt; + + cc = zend_llist_get_next_ex(list, &l); + } +} + +void +apd_summary_output_declare_function(int index, const char *fname, int type) +{ + apd_function_entry_t *function_entry; + TSRMLS_FETCH(); + + function_entry = ecalloc(1, sizeof(apd_function_entry_t)); + function_entry->name = estrdup(fname); + function_entry->id = index; + function_entry->type = type; + + apd_array_set(&APD_GLOBALS(summary).functions, index, function_entry); +} + +inline apd_fcall_t * +find_fcall(apd_coverage_t *coverage, int filenum, int linenum) +{ + apd_fcall_t *fcall; + int i; + + for (fcall = coverage->head; fcall != NULL; fcall = fcall->next) { + if (fcall->file == filenum && fcall->line == linenum) { + return fcall; + } + } + + return NULL; +} + +inline void +append_fcall(apd_coverage_t *coverage, apd_fcall_t *fcall) +{ + coverage->size++; + + if (coverage->head == NULL) { + coverage->head = coverage->tail = fcall; + return; + } + + coverage->tail->next = fcall; + fcall->prev = coverage->tail; + coverage->tail = fcall; +} + + +void +apd_summary_output_enter_function(int index, int filenum, int linenum) +{ + apd_function_entry_t *function_entry; + apd_coverage_t *coverage; + apd_fcall_t *fcall; + TSRMLS_FETCH(); + + if (index == 1) { + return; + } + + function_entry = apd_array_get(&APD_GLOBALS(summary).functions, index); + if (function_entry == NULL) { + php_error(E_WARNING, "Couldn't find function entry by index %d", index); + return; + } + + fcall = find_fcall(&function_entry->coverage, filenum, linenum); + if (!fcall) { + fcall = ecalloc(1, sizeof(apd_fcall_t)); + fcall->line = linenum; + fcall->file = filenum; + fcall->entry = function_entry; + + append_fcall(&function_entry->coverage, fcall); + } + fcall->calls++; + + zend_llist_add_element(&APD_GLOBALS(summary).call_list, &fcall); +} + +static int +compare_fcall(void *e1, void *e2) +{ + apd_fcall_t *a = e1; + apd_fcall_t *b = e2; + + if (a->entry == b->entry && a->file == b->file && a->line == b->line) { + return 1; + } + + return 0; +} + +void +apd_summary_output_exit_function(int index, int mem) +{ + apd_fcall_t *fcall; + void *entry; + TSRMLS_FETCH(); + + entry = apd_array_get(&APD_GLOBALS(summary).functions, index); + if (entry == NULL) { + return; + } + + zend_llist_del_element(&APD_GLOBALS(summary).call_list, entry, compare_fcall); +} + +inline void +copy_fcall(apd_fcall_t **a, apd_fcall_t *b) +{ + *a = emalloc(sizeof(apd_fcall_t)); + memcpy(*a, b, sizeof(apd_fcall_t)); + (*a)->prev = NULL; + (*a)->next = NULL; +} + +inline void +place_best_slot(apd_coverage_t *summary, apd_fcall_t *fc, long max) +{ + apd_fcall_t *current = NULL; + apd_fcall_t *nfc; + int is_bigger = 0; + + current = summary->head; + while (current) { + if (fc->cumulative >= current->cumulative) { + is_bigger = 1; + break; + } + + current = current->next; + } + + if (current == NULL) { + current = summary->tail; + } + + copy_fcall(&nfc, fc); + + if (!current) { + summary->head = nfc; + summary->tail = nfc; + } else if (current == summary->tail && !is_bigger) { + nfc->prev = current; + nfc->next = NULL; + current->next = nfc; + + summary->tail = nfc; + } else { + nfc->next = current; + nfc->prev = current->prev; + if (current->prev) { + current->prev->next = nfc; + } else { + summary->head = nfc; + } + current->prev = nfc; + } + + if (++summary->size > max) { + current = summary->tail; + if (current->prev) { + current->prev->next = NULL; + } + summary->tail = current->prev; + efree(current); + } +} + +inline void +add_fcall_summary(apd_coverage_t *summary, apd_fcall_t *fc, long max) +{ + fc->cumulative = fc->realtime + fc->usertime + fc->systemtime; + place_best_slot(summary, fc, max); +} + +inline void +find_expensive(apd_coverage_t *summary, long max TSRMLS_DC) +{ + apd_array_t *functions; + apd_function_entry_t *function_entry; + apd_fcall_t *fcall; + long i; + + functions = &APD_GLOBALS(summary).functions; + for (i = 0; i < functions->alloced; ++i) { + function_entry = (apd_function_entry_t *) apd_array_get(functions, i); + if (function_entry == NULL) { + continue; + } + + for (fcall = function_entry->coverage.head; fcall != NULL; fcall = fcall->next) { + add_fcall_summary(summary, fcall, max); + } + } +} + + +void +apd_summary_output_footer(void) +{ + apd_fcall_t *fcall; + apd_function_entry_t *function_entry; + apd_file_entry_t *file_entry; + char *shortname; + apd_coverage_t coverage; + char *ret; + int ret_len; + TSRMLS_FETCH(); + + memset(&coverage, 0, sizeof(apd_coverage_t)); + + php_printf("<table border=\"1\" width=\"100%\">\n"); + php_printf("<tr>\n"); + php_printf("<th>Function</th>\n"); + php_printf("<th>File</th>\n"); + php_printf("<th>Line</th>\n"); + php_printf("<th># of calls</th>\n"); + php_printf("<th>User</th>\n"); + php_printf("<th>System</th>\n"); + php_printf("<th>Real</th>\n"); + php_printf("</tr>\n"); + + find_expensive(&coverage, 20 TSRMLS_CC); + fcall = coverage.head; + while (fcall) { + function_entry = fcall->entry; + file_entry = apd_array_get(&APD_GLOBALS(summary).files, fcall->file); + php_basename(file_entry->filename, strlen(file_entry->filename), NULL, 0, &ret, &ret_len TSRMLS_CC); + php_printf("<tr>\n"); + php_printf("<td>%s</td>\n", function_entry->name); + php_printf("<td><abbr title=\"%s\">%s</abbr></td>\n", file_entry->filename, ret); + php_printf("<td>%d</td>\n", fcall->line); + php_printf("<td>%d</td>\n", fcall->calls); + php_printf("<td>%4.2f</td>\n", (double) fcall->usertime / 1000000); + php_printf("<td>%4.2f</td>\n", (double) fcall->systemtime / 1000000); + php_printf("<td>%4.2f</td>\n", (double) fcall->realtime / 1000000); + php_printf("</tr>\n"); + + fcall = fcall->next; +// efree(ret); + } + php_printf("</table>\n"); + + zend_llist_clean(&APD_GLOBALS(summary).call_list); +} + +/** + * Local Variables: + * indent-tabs-mode: t + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600:fdm=marker; + * vim:noet:sw=4:ts=4; + */ http://cvs.php.net/diff.php/pecl/apd/pprof2calltree?r1=1.1&r2=1.2&ty=u Index: pecl/apd/pprof2calltree diff -u /dev/null pecl/apd/pprof2calltree:1.2 --- /dev/null Wed Mar 10 11:40:55 2004 +++ pecl/apd/pprof2calltree Wed Mar 10 11:40:55 2004 @@ -0,0 +1,173 @@ +#!/usr/bin/env php +<?php + +require "Console/Getopt.php"; +//error_reporting(0); + +$con = new Console_Getopt; +$args = $con->readPHPArgv(); +array_shift($args); +$shortoptions = 'f:'; +$retval = $con->getopt( $args, $shortoptions); +if(is_object($retval)) { + usage(); +} +foreach ($retval[0] as $kv_array) { + $opt[$kv_array[0]] = $kv_array[1]; +} +if(!$opt['f']) { + usage(); +} +if(!file_exists($opt['f'])) { + print "Trace file ${opt['f']} does not exist\n"; + exit; +} +$IN = fopen($opt['f'], "r"); +if(!$IN) { + print "Trace file ${opt['f']} could not be opened\n"; + exit; +} + +$path_parts = pathinfo($opt['f']); +$outfile = "cachegrind.out.".$path_parts['basename']; +$OUT = fopen($outfile, "w"); +if(!$OUT) { + print "Destination file $outfile could not be opened.\n"; + exit; +} + +while(($line = fgets($IN)) !== false) { + $line = rtrim($line); + if($line == "END_HEADER") { + break; + } +} +$tree = array(); +$callstack = array(); +while(($line = fgets($IN)) !== false) { + $line = rtrim($line); + $args = explode(" ", $line); + if($args[0] == '!') { + $file_lookup[$args[1]] = $args[2]; + } + else if($args[0] == '&') { + $function_lookup[$args[1]] = $args[2]; + $function_type[$args[1]] = ($args[3] == 2)?"USER":"INTERNAL"; + } + else if($args[0] == '+') { + $val = array(function_id => $args[1], + file_id => $args[2], + line => $args[3], + cost => 0); + array_push($callstack, $val); + } + else if($args[0] == '-') { + // retrieve $called to discard + $called = array_pop($callstack); + // retrieve $caller for reference + $caller = array_pop($callstack); + $called_id = $called['function_id']; + + // Set meta data if not already set' + if(!array_key_exists($called_id, $tree)) { + $tree[$called_id] = $called; + // initialize these to 0 + $tree[$called_id]['cost_per_line'] = array(); + } + if($caller !== null) { + $caller['child_calls']++; + $caller_id = $caller['function_id']; + if(!array_key_exists($caller_id, $tree)) { + $tree[$caller_id] = $caller; + } + $caller['cost'] += $called['cost']; + $tree[$caller_id]['called_funcs'][$tree[$caller_id]['call_counter']++][$called_id][$called['file_id']][$called['line']] += $called['cost']; + array_push($callstack, $caller); + } + if(is_array($called['cost_per_line'])) { + foreach($called[cost_per_line] as $file => $lines) { + foreach($lines as $line => $cost) { + $tree[$called_id]['cost_per_line'][$file][$line] += $cost; + } + } + } + } + else if($args[0] == '@') { + $called = array_pop($callstack); + switch(count($args)) { + case 6: + $file = $args[1]; + $line = $args[2]; + $real_tm = $args[5]; + break; + case 4: + $file = $called['file_id']; + $line = $called['line']; + $real_tm = $args[3]; + break; + + } + $called['cost_per_line'][$file][$line] += $real_tm; + $called['cost'] += $real_tm; + $total_cost += $real_tm; + array_push($callstack, $called); + } +} + +ob_start(); +print "events: Tick\n"; +print "summary: $total_cost\n"; +printf("cmd: %s\n", $file_lookup[1]); +print "\n"; + +foreach($tree as $caller => $data) { + $filename = $file_lookup[$data['file_id']]?$file_lookup[$data['file_id']]:"???"; + printf("ob=%s\n", $function_type[$caller]); + printf("fl=%s\n", $filename); + printf("fn=%s\n", $function_lookup[$caller]); + if(is_array($data['cost_per_line'])) { + foreach($data['cost_per_line'] as $file => $lines) { + foreach($lines as $line => $cost) { + print "$line $cost\n"; + } + } + } + else if ($data['cost']) { + printf("COST %s %s\n", $items['line'], $items['cost']); + } + else { + print_r($items); + } + if(is_array($data['called_funcs'])) { + foreach($data['called_funcs'] as $counter => $items) { + foreach($items as $called_id => $costs) { + if(is_array($costs)) { + printf("cfn=%s\n", $function_lookup[$called_id]); + foreach($costs as $file => $lines) { + printf("cfi=%s\ncalls=1\n", $file_lookup[$file]); + foreach($lines as $line => $cost) { + print "$line $cost\n"; + } + } + } + } + } + } + print "\n"; +} +print "\ntotals=$total_cost\n"; +$buffer = ob_get_clean(); +print "Writing kcachegrind compatible output to $outfile\n"; +fwrite($OUT, $buffer); + +function usage() +{ + print <<<EOD +pprof2calltree -f <tracefile> + +EOD; + exit(1); + + +} +?> http://cvs.php.net/diff.php/pecl/apd/README?r1=1.15&r2=1.16&ty=u Index: pecl/apd/README diff -u pecl/apd/README:1.15 pecl/apd/README:1.16 --- pecl/apd/README:1.15 Wed Apr 2 09:39:54 2003 +++ pecl/apd/README Wed Mar 10 11:40:55 2004 @@ -31,6 +31,7 @@ zend_extension = /absolute/path/to/apd.so apd.dumpdir = /absolute/path/to/trace/directory + apd.statement_trace = 0 Depending on your PHP build, the zend_extension directive can be one of the following: @@ -47,6 +48,10 @@ This can either be an absolute path or a relative path. Relative means always relative to your where from you run your executeable. + apd.statement_trace: + + Whether or not to do per-line tracings. There is a performance + impact to enabling this. *** NOTE ****************************************************************** * @@ -89,7 +94,7 @@ apd_set_pprof_trace(); - This will generate a pprof.<pid> file in your apd.dumpdir. The format + This will generate a pprof.<pid>.<ext> file in your apd.dumpdir. The format of this file is as follows: ! 1 simple.php @@ -113,7 +118,7 @@ + shows a function being entered and the file index and line number it was called on. - shows a function being exited. @ shows a time elapsed in the form - @ process_user_clock_t process_system_clock_t process_real_clock_t + @ file_id line_id process_user_clock_t process_system_clock_t process_real_clock_t The syntax of the file is largely for informational purposes, it's not designed for human consumption. To extract human-readable information from the trace, use @@ -134,6 +139,7 @@ Display options -c Display Real time elapsed alongside call tree. + -m Display file locations as well. -i Suppress reporting for php builtin functions -O <cnt> Specifies maximum number of subroutines to display. (default 15) -t Display compressed call tree. @@ -141,11 +147,11 @@ Thus, to get basic output on the trace, we would do -pprofp -u /tmp/pprof.<pid> +pprofp -u /tmp/pprof.<pid>.<ext> and we get something like: -10:33:29(george@ballista)[~/pear/PECL/apd]> pprofp -u /tmp/pprof.23424 +10:33:29(george@ballista)[~/pear/PECL/apd]> pprofp -u /tmp/pprof.23424.0 Trace for /data/storage/mirrors/www.php.net/index.php Total Elapsed Time = 0.09 @@ -181,7 +187,7 @@ This sorts output based on the usertime spent in subroutines, and ommits a call tree. If we added a -t -10:38:30(george@ballista)[~/pear/PECL/apd]> pprofp -u -t /tmp/pprof.23424 +10:38:30(george@ballista)[~/pear/PECL/apd]> pprofp -u -t /tmp/pprof.23424.0 ... @@ -189,95 +195,26 @@ - -How to use PHP-APD in your scripts (old style) +KCachegrind compatible output ----------------------------------------------------------------------------- * +APD can convert it's pprof data files to a format readable by +kcachegrind. kcachegrind is an amazing graphical profiler, available +here: http://kcachegrind.sourceforge.net/. + +To perform the conversion, run - In your PHP script, add the following line: +pprof2calltree -f /path/to/pprofp.<pid>.<ext> - apd_set_session_trace(N); +This will generate a file in your local directory called - where N is an integer which is formed by masking together the following - values: +cachegrind.out.pprof.<pid>.<ext> - FUNCTION_TRACE 1 - ARGS_TRACE 2 - ASSIGNMENT_TRACE 4 - STATEMENT_TRACE 8 - MEMORY_TRACE 16 - TIMING_TRACE 32 - SUMMARY_TRACE 64 - - I would seriously not recommend using MEMORY_TRACE. It is very slow and - does not appear to be accurate (great, huh?) also ASSIGNMENT_TRACE is not - implemented. So, to turn on all functional traces (TIMING, FUNCTIONS, ARGS - SUMMARY (like strace -c)) use: - - apd_set_session_trace(99); - - - Now run your script. - - - The dump output will be writting to: - - <apd.dumpdir>/apd_dump_<pid> - - The output itself will look something like: - -16:37:51(george@wasabi)[~/src/apd]> cat /tmp/apd_dump_31994 - - -APD - Advanced PHP Debugger Trace File ---------------------------------------------------------------------------- -Process Pid (31994) -Trace Begun at Fri Aug 10 16:37:45 2001 ---------------------------------------------------------------------------- -( 0.000000): apd_set_session_trace called at somewhere -( 0.001482): apd_set_session_trace() returned. Elapsed (997475865.364909) -( 0.001563): getcwd() /opt/apache/htdocs/a.php:4 -( 0.001628): getcwd() returned. Elapsed (0.000065) -( 0.001819): require() /opt/apache/htdocs/a.php:6 - ++ argv[0] $(??) = /tmp/a.php -( 0.002231): getcwd() /tmp/a.php:3 -( 0.002290): getcwd() returned. Elapsed (0.000059) -( 0.002375): include_once() /tmp/a.php:4 - ++ argv[0] $(??) = /tmp/aa.php -( 0.003276): include_once() returned. Elapsed (0.000901) -( 0.003334): require() returned. Elapsed (0.001515) -( 0.003381): require_once() /opt/apache/htdocs/a.php:7 - ++ argv[0] $(??) = /tmp/aa.php -( 0.003515): require_once() returned. Elapsed (0.000134) -( 0.003564): include() /opt/apache/htdocs/a.php:8 - ++ argv[0] $(??) = /tmp/b.php -( 0.003792): include() returned. Elapsed (0.000228) -( 0.018341): RSHUTDOWN called - end of trace ---------------------------------------------------------------------------- -Process Pid (31994) -Trace Ended at Fri Aug 10 16:37:45 2001 ---------------------------------------------------------------------------- +You can then load this file with kcachegrind as follows: +kcachegrind cachegrind.out.pprof.<pid>.<ext> Implemented Debugging Functions ----------------------------------------------------------------------------- * - - array apd_callstack() - Returns the current call stack as an array (very cool). - - apd_cluck([string warning[,string line delimiter]) - Behaves like perl's Carp::cluck. Throw a warning and a callstack. - The default line delimiter is "<BR />\n". - - apd_croak([string error[, string line delimiter]]) - Behaves like perl's Carp::croak. Throw an error, a callstack and then - exit. The default line delimiter is "<BR />\n". - - array apd_dump_regular_resources() - Return all current regular resources as an array. - - array apd_dump_persistent_resources() - Return all persistent resources as an array. - override_function(string func_name, string func_args, string func_code): Syntax similar to create_function(). Overrides built-in functions (replaces them in the symbol table). http://cvs.php.net/diff.php/pecl/apd/config.m4?r1=1.1.1.1&r2=1.2&ty=u Index: pecl/apd/config.m4 diff -u pecl/apd/config.m4:1.1.1.1 pecl/apd/config.m4:1.2 --- pecl/apd/config.m4:1.1.1.1 Thu Jul 26 17:42:16 2001 +++ pecl/apd/config.m4 Wed Mar 10 11:40:55 2004 @@ -20,6 +20,6 @@ AC_DEFINE(HAVE_APD, 1, [ ]) dnl Write more examples of tests here... - PHP_EXTENSION(apd, $ext_shared) + PHP_NEW_EXTENSION(apd, php_apd.c apd_lib.c apd_array.c apd_summary.c, $ext_shared) fi http://cvs.php.net/diff.php/pecl/apd/php_apd.c?r1=1.55&r2=1.56&ty=u Index: pecl/apd/php_apd.c diff -u pecl/apd/php_apd.c:1.55 pecl/apd/php_apd.c:1.56 --- pecl/apd/php_apd.c:1.55 Tue Dec 23 20:13:21 2003 +++ pecl/apd/php_apd.c Wed Mar 10 11:40:55 2004 @@ -1,23 +1,23 @@ /* +----------------------------------------------------------------------+ - | APD Profiler & Debugger | + | APD Profiler & Debugger | +----------------------------------------------------------------------+ - | Copyright (c) 2001-2003 Community Connect Inc. | + | Copyright (c) 2001-2003 Community Connect Inc. | +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Authors: Daniel Cowgill <dcowgill@communityconnect.com> | - | George Schlossnagle <george@lethargy.org> | - | Sterling Hughes <sterling@php.net> | + | Authors: Daniel Cowgill <dcowgill@communityconnect.com> | + | George Schlossnagle <george@lethargy.org> | + | Sterling Hughes <sterling@php.net> | +----------------------------------------------------------------------+ */ - + #include "php_apd.h" #ifdef PHP_WIN32 #include "win32compat.h" @@ -31,11 +31,12 @@ #endif #include "apd_lib.h" -#include "opcode.h" #include "zend_API.h" #include "zend_hash.h" #include "zend_alloc.h" #include "zend_operators.h" +#include "zend_globals.h" +#include "zend_compile.h" #include <assert.h> #include <stdarg.h> #include <sys/types.h> @@ -61,6 +62,9 @@ #endif ZEND_DLEXPORT void (*old_execute)(zend_op_array *op_array TSRMLS_DC); +ZEND_DLEXPORT void onStatement(zend_op_array *op_array TSRMLS_DC); +ZEND_DECLARE_MODULE_GLOBALS(apd); + /* This comes from php install tree. */ #include "ext/standard/info.h" @@ -71,14 +75,15 @@ PHP_FE(rename_function, NULL) PHP_FE(apd_set_pprof_trace, NULL) PHP_FE(apd_set_browser_trace, NULL) - PHP_FE(apd_set_session_trace_socket, NULL) - PHP_FE(apd_breakpoint, NULL) - PHP_FE(apd_continue, NULL) - PHP_FE(apd_echo, NULL) + PHP_FE(apd_set_session_trace_socket, NULL) + PHP_FE(apd_breakpoint, NULL) + PHP_FE(apd_continue, NULL) + PHP_FE(apd_echo, NULL) {NULL, NULL, NULL} }; void apd_pprof_fprintf(const char* fmt, ...); +static void log_time(TSRMLS_D); long diff_times(struct timeval a, struct timeval b) { @@ -108,9 +113,9 @@ } static void -apd_pprof_output_elapsed_time(int usert, int systemt, int realt) +apd_pprof_output_elapsed_time(int filenum, int linenum, int usert, int systemt, int realt) { - apd_pprof_fprintf("@ %ld %ld %ld\n", usert, systemt, realt); + apd_pprof_fprintf("@ %d %d %ld %ld %ld\n", filenum, linenum, usert, systemt, realt); } static void @@ -151,8 +156,8 @@ apd_pprof_fprintf("END_TRACE\n"); apd_pprof_fprintf("total_user=%ld\ntotal_sys=%ld\ntotal_wall=%ld\n", - diff_times(end_ru.ru_utime, APD_GLOBALS(first_ru).ru_utime), - diff_times(end_ru.ru_stime, APD_GLOBALS(first_ru).ru_stime), + diff_times(end_ru.ru_utime, APD_GLOBALS(first_ru).ru_utime), + diff_times(end_ru.ru_stime, APD_GLOBALS(first_ru).ru_stime), diff_times(end_clock, APD_GLOBALS(first_clock))); apd_pprof_fprintf("END_FOOTER\n"); } @@ -165,7 +170,7 @@ { va_list args; char* newStr; - TSRMLS_FETCH(); + TSRMLS_FETCH(); va_start(args, fmt); newStr = apd_sprintf_real(fmt, args); va_end(args); @@ -286,7 +291,7 @@ { char *funcname = NULL; int curSize = 0; - zend_execute_data *execd; + zend_execute_data *execd = NULL; char *tmpfname; char *classname; int classnameLen; @@ -339,7 +344,7 @@ } } else { - funcname = estrdup("???"); + funcname = estrdup("main"); } return funcname; } @@ -361,6 +366,7 @@ APD_GLOBALS(output).file_reference(*filenum, filename); zend_hash_add(APD_GLOBALS(file_summary), (char *) filename, strlen(filename) + 1, filenum, sizeof(int), NULL); } + APD_GLOBALS(current_file_index) = *filenum; if (zend_hash_find(APD_GLOBALS(function_summary), (char *) fname, strlen(fname)+1, (void *) &function_index) == SUCCESS) { APD_GLOBALS(output).enter_function(*function_index, *filenum, linenum); @@ -390,40 +396,44 @@ #if MEMORY_LIMIT allocated = AG(memory_limit); #endif - + log_time(TSRMLS_C); + if (zend_hash_find(APD_GLOBALS(function_summary), fname, strlen(fname) + 1, (void *) &function_index) == SUCCESS) { + APD_GLOBALS(output).exit_function(*function_index, allocated); + } else { + function_index = (int *) emalloc(sizeof(int)); + *function_index = ++APD_GLOBALS(function_index); + zend_hash_add(APD_GLOBALS(function_summary), fname, strlen(fname)+1, function_index, sizeof(int), NULL); + APD_GLOBALS(output).exit_function(*function_index, allocated); + } +} + +static void log_time(TSRMLS_D) +{ + struct timeval clock; + struct rusage wall_ru; + gettimeofday(&clock, NULL); getrusage(RUSAGE_SELF, &wall_ru); if (APD_GLOBALS(function_index) > 1) { + long utime, stime, rtime; utime = diff_times(wall_ru.ru_utime, APD_GLOBALS(last_ru).ru_utime); stime = diff_times(wall_ru.ru_stime, APD_GLOBALS(last_ru).ru_stime); rtime = diff_times(clock, APD_GLOBALS(last_clock)); if(utime || stime || rtime) { - APD_GLOBALS(output).elapsed_time(utime, stime, rtime); + APD_GLOBALS(output).elapsed_time(APD_GLOBALS(current_file_index), zend_get_executed_lineno(TSRMLS_C), utime, stime, rtime); } } APD_GLOBALS(last_ru) = wall_ru; APD_GLOBALS(last_clock) = clock; - if (zend_hash_find(APD_GLOBALS(function_summary), fname, strlen(fname) + 1, (void *) &function_index) == SUCCESS) { - APD_GLOBALS(output).exit_function(*function_index, allocated); - } else { - function_index = (int *) emalloc(sizeof(int)); - *function_index = ++APD_GLOBALS(function_index); - zend_hash_add(APD_GLOBALS(function_summary), fname, strlen(fname)+1, function_index, sizeof(int), NULL); - APD_GLOBALS(output).exit_function(*function_index, allocated); - } } /* -------------------------------------------------------------------------- - Error Tracing - --------------------------------------------------------------------------- Module Entry --------------------------------------------------------------------------- */ zend_module_entry apd_module_entry = { -#if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, -#endif "APD", apd_functions, PHP_MINIT(apd), @@ -431,14 +441,9 @@ PHP_RINIT(apd), PHP_RSHUTDOWN(apd), PHP_MINFO(apd), - NULL, - NULL, -#if ZEND_MODULE_API_NO >= 20010901 - NO_VERSION_YET, /* extension version number (string) */ -#endif - STANDARD_MODULE_PROPERTIES_EX + NO_VERSION_YET, /* extension version number (string) */ + STANDARD_MODULE_PROPERTIES }; -ZEND_DECLARE_MODULE_GLOBALS(apd); #if COMPILE_DL_APD ZEND_GET_MODULE(apd) @@ -462,6 +467,7 @@ PHP_INI_BEGIN() PHP_INI_ENTRY("apd.dumpdir", NULL, PHP_INI_ALL, set_dumpdir) + STD_PHP_INI_ENTRY("apd.statement_tracing", "0", PHP_INI_ALL, OnUpdateLong, statement_tracing, zend_apd_globals, apd_globals) PHP_INI_END() @@ -471,7 +477,7 @@ static void php_apd_init_globals(zend_apd_globals *apd_globals) { - memset(apd_globals, 0, sizeof(zend_apd_globals)); + memset(apd_globals, 0, sizeof(zend_apd_globals)); apd_globals->function_summary = (HashTable *) malloc(sizeof(HashTable)); apd_globals->file_summary = (HashTable *) malloc(sizeof(HashTable)); @@ -491,28 +497,9 @@ { ZEND_INIT_MODULE_GLOBALS(apd, php_apd_init_globals, php_apd_free_globals); REGISTER_INI_ENTRIES(); - REGISTER_LONG_CONSTANT("APD_AF_UNIX", AF_UNIX, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_AF_INET", AF_INET, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_FUNCTION_TRACE", FUNCTION_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_ARGS_TRACE", ARGS_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_ASSIGNMENT_TRACE", ASSIGNMENT_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_STATEMENT_TRACE", STATEMENT_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_MEMORY_TRACE", MEMORY_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_TIMING_TRACE", TIMING_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_SUMMARY_TRACE", SUMMARY_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_ERROR_TRACE", ERROR_TRACE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("APD_PROF_TRACE", PROF_TRACE, CONST_CS | CONST_PERSISTENT); -#ifdef TRACE_ZEND_COMPILE /* we can trace the time to compile things. */ - /* gettimeofday(&APD_GLOBALS(last_call), NULL); */ - old_compile_file = zend_compile_file; - zend_compile_file = apd_compile_file; -#endif old_execute = zend_execute; zend_execute = apd_execute; - /* if the zend_execute_internal pointer exists, use it to trace 'built-ins*/ -#if ZEND_EXTENSION_API_NO>=20020731 zend_execute_internal = apd_execute_internal; -#endif return SUCCESS; } @@ -524,14 +511,13 @@ void **p; int argCount; zval **object_ptr_ptr; - - fname = apd_get_active_function_name(op_array TSRMLS_CC); - trace_function_entry(EG(function_table), fname, ZEND_USER_FUNCTION, + fname = apd_get_active_function_name(op_array TSRMLS_CC); + trace_function_entry(EG(function_table), fname, ZEND_USER_FUNCTION, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C)); - old_execute(op_array TSRMLS_CC); - trace_function_exit(fname); - efree(fname); + old_execute(op_array TSRMLS_CC); + trace_function_exit(fname); + efree(fname); apd_interactive(); } @@ -542,9 +528,11 @@ void **p; int argCount; zval **object_ptr_ptr; + zend_execute_data *execd; - fname = apd_get_active_function_name(EG(current_execute_data)->op_array TSRMLS_CC); - trace_function_entry(EG(function_table), fname, ZEND_INTERNAL_FUNCTION, + execd = executor_globals.current_execute_data; + fname = apd_get_active_function_name(execd->op_array TSRMLS_CC); + trace_function_entry(EG(function_table), fname, ZEND_INTERNAL_FUNCTION, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C)); execute_internal(execute_data_ptr, return_value_used TSRMLS_CC); @@ -567,7 +555,6 @@ APD_GLOBALS(dump_file) = stderr; APD_GLOBALS(dump_sock_id) = 0; - APD_GLOBALS(bitmask) = 0; APD_GLOBALS(interactive_mode) = 0; APD_GLOBALS(ignore_interactive) = 0; gettimeofday(&APD_GLOBALS(last_clock), NULL); @@ -587,7 +574,7 @@ PHP_RSHUTDOWN_FUNCTION(apd) { - APD_GLOBALS(output).footer(); +// APD_GLOBALS(output).footer(); if (APD_GLOBALS(pprof_file)) { fclose(APD_GLOBALS(pprof_file)); } @@ -600,7 +587,7 @@ zend_hash_clean(APD_GLOBALS(function_summary)); zend_hash_clean(APD_GLOBALS(file_summary)); - + APD_GLOBALS(counter)++; return SUCCESS; } @@ -667,7 +654,7 @@ RETURN_FALSE; } RETURN_TRUE; - } + } else { RETURN_FALSE; } @@ -727,7 +714,7 @@ RETURN_TRUE; } -void apd_pprof_header(TSRMLS_D) { +void apd_pprof_header(char *ent_fname TSRMLS_DC) { char *fname = "main"; char *filename; int linenum, *filenum, *fnum; @@ -748,6 +735,13 @@ APD_GLOBALS(output).file_reference(*filenum, filename); APD_GLOBALS(output).declare_function(*fnum, fname, ZEND_USER_FUNCTION); APD_GLOBALS(output).enter_function(*fnum, *filenum, linenum); + + fnum = (int *) emalloc(sizeof(int)); + *fnum = APD_GLOBALS(function_index)++; + zend_hash_add(APD_GLOBALS(function_summary), ent_fname, strlen(ent_fname)+1, fnum, sizeof(int), NULL); + + APD_GLOBALS(output).declare_function(*fnum, ent_fname, ZEND_USER_FUNCTION); + APD_GLOBALS(output).enter_function(*fnum, *filenum, linenum); } PHP_FUNCTION(apd_set_browser_trace) @@ -766,7 +760,7 @@ APD_GLOBALS(output).enter_function = apd_summary_output_enter_function; APD_GLOBALS(output).exit_function = apd_summary_output_exit_function; - apd_pprof_header(TSRMLS_C); + apd_pprof_header("apd_set_broswer_trace" TSRMLS_CC); } PHP_FUNCTION(apd_set_pprof_trace) @@ -775,7 +769,7 @@ int socketd = 0; int path_len; char *dumpdir; - char *path; + char path[MAXPATHLEN]; zval **z_dumpdir; if(ZEND_NUM_ARGS() > 1 ) @@ -805,15 +799,12 @@ dumpdir = Z_STRVAL_PP(z_dumpdir); } - path_len = strlen(dumpdir) + 1 + strlen("pprof.") + 5; - path = (char *) emalloc((path_len + 1)* sizeof(char) ); - snprintf(path, path_len + 1, "%s/pprof.%05d", dumpdir, getpid()); + snprintf(path, MAXPATHLEN, "%s/pprof.%05d.%d", dumpdir, getpid(), APD_GLOBALS(counter)); if((APD_GLOBALS(pprof_file) = fopen(path, "a")) == NULL) { zend_error(E_ERROR, "%s() failed to open %s for tracing", get_active_function_name(TSRMLS_C), path); } - efree(path); - apd_pprof_header(TSRMLS_C); + apd_pprof_header("apd_set_pprof_trace" TSRMLS_CC); } @@ -828,18 +819,16 @@ int sock_domain; int sock_port; - int bitmask; int connect_result; struct sockaddr_in si; struct sockaddr_un su; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "slll", &address,&address_len, &sock_domain, &sock_port,&bitmask) == FAILURE) + "slll", &address,&address_len, &sock_domain, &sock_port) == FAILURE) { return; } - APD_GLOBALS(bitmask) = bitmask; APD_GLOBALS(dump_file)=NULL; /* now for the socket stuff */ @@ -906,12 +895,10 @@ PHP_FUNCTION(apd_breakpoint) { - int bitmask; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &bitmask) == FAILURE) { + "l") == FAILURE) { return; } - APD_GLOBALS(bitmask) = bitmask; APD_GLOBALS(interactive_mode) = 1; RETURN_TRUE; } @@ -922,12 +909,6 @@ PHP_FUNCTION(apd_continue) { - int bitmask; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "l", &bitmask) == FAILURE) { - return; - } - APD_GLOBALS(bitmask) = bitmask; APD_GLOBALS(interactive_mode) = 0; RETURN_TRUE; } @@ -946,7 +927,7 @@ return; } if (str_len > 0) { - /* php_error(E_WARNING, "apd echoing %s", str); */ + /* php_error(E_WARNING, "apd echoing %s", str); */ if ( APD_GLOBALS(dump_sock_id) > 0) { #ifndef PHP_WIN32 /* Unix bit */ @@ -959,7 +940,7 @@ #endif } apd_dump_fprintf("%s\n",str); - /* efree(str); */ + /* efree(str); */ } RETURN_TRUE; @@ -975,23 +956,16 @@ ZEND_DLEXPORT void onStatement(zend_op_array *op_array) { TSRMLS_FETCH(); - if (APD_GLOBALS(ignore_interactive) == 1) return; - if(APD_GLOBALS(bitmask) & STATEMENT_TRACE) { - apd_dump_fprintf("statement: %s:%d\n", - zend_get_executed_filename(TSRMLS_C), - zend_get_executed_lineno(TSRMLS_C)); - apd_interactive(); - } + if(APD_GLOBALS(pproftrace) && APD_GLOBALS(statement_tracing)) { + log_time(TSRMLS_C); + } } -/* --------------------------------------------------------------------------- - Zend Extension Support - --------------------------------------------------------------------------- */ - int apd_zend_startup(zend_extension *extension) { TSRMLS_FETCH(); CG(extended_info) = 1; /* XXX: this is ridiculous */ +fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); return zend_startup_module(&apd_module_entry); } @@ -1013,21 +987,17 @@ "", apd_zend_startup, apd_zend_shutdown, - NULL, // activate_func_t - NULL, // deactivate_func_t - NULL, // message_handler_func_t - NULL, // op_array_handler_func_t - NULL, // statement_handler_func_t - NULL, // fcall_begin_handler_func_t - NULL, // fcall_end_handler_func_t - NULL, // op_array_ctor_func_t - NULL, // op_array_dtor_func_t -#ifdef COMPAT_ZEND_EXTENSION_PROPERTIES - NULL, // api_no_check + NULL, // activate_func_t + NULL, // deactivate_func_t + NULL, // message_handler_func_t + NULL, // op_array_handler_func_t + onStatement, // statement_handler_func_t + NULL, // fcall_begin_handler_func_t + NULL, // fcall_end_handler_func_t + NULL, // op_array_ctor_func_t + NULL, // op_array_dtor_func_t + NULL, // api_no_check COMPAT_ZEND_EXTENSION_PROPERTIES -#else - STANDARD_ZEND_EXTENSION_PROPERTIES -#endif }; /** http://cvs.php.net/diff.php/pecl/apd/php_apd.h?r1=1.20&r2=1.21&ty=u Index: pecl/apd/php_apd.h diff -u pecl/apd/php_apd.h:1.20 pecl/apd/php_apd.h:1.21 --- pecl/apd/php_apd.h:1.20 Tue Dec 23 20:13:21 2003 +++ pecl/apd/php_apd.h Wed Mar 10 11:40:55 2004 @@ -145,7 +145,7 @@ void apd_summary_output_header(void); void apd_summary_output_file_reference(int, const char *); -void apd_summary_output_elapsed_time(int, int, int); +void apd_summary_output_elapsed_time(int, int, int, int, int); void apd_summary_output_declare_function(int, const char *, int); void apd_summary_output_enter_function(int, int, int); void apd_summary_output_exit_function(int, int); @@ -154,7 +154,7 @@ typedef void (*apd_output_header_func_t)(void); typedef void (*apd_output_file_reference_func_t)(int, const char *); -typedef void (*apd_output_elapsed_time_func_t)(int, int, int); +typedef void (*apd_output_elapsed_time_func_t)(int, int, int, int, int); typedef void (*apd_output_declare_function_func_t)(int, const char *, int); typedef void (*apd_output_function_enter_func_t)(int, int, int); typedef void (*apd_output_function_exit_func_t)(int, int); @@ -171,6 +171,7 @@ } apd_output_handlers; ZEND_BEGIN_MODULE_GLOBALS(apd) + int counter; void* stack; HashTable* function_summary; HashTable* file_summary; @@ -178,13 +179,13 @@ FILE* dump_file; /* FILE for dumping session traces to */ FILE* pprof_file; /* File for profiling output */ int dump_sock_id; /* Socket for dumping data to */ - struct timeval first_clock; - struct timeval last_clock; + struct timeval first_clock; + struct timeval last_clock; struct rusage first_ru; struct rusage last_ru; int function_index; /* current index of functions for pprof tracing */ int file_index; /* current index of functions for pprof tracing */ - long bitmask; /* Bitmask for determining what gets logged */ + int current_file_index; long pproftrace; /* Flag for whether we are doing profiling */ void* last_mem_header; /* tail of persistent zend_mem_header list */ void* last_pmem_header; /* tail of persistent zend_mem_header list */ @@ -193,10 +194,12 @@ int allocated_memory; apd_output_handlers output; apd_summary_t summary; + int statement_tracing; ZEND_END_MODULE_GLOBALS(apd) +PHPAPI ZEND_EXTERN_MODULE_GLOBALS(apd) + /* Declare global structure. */ -ZEND_DECLARE_MODULE_GLOBALS(apd); #ifdef ZTS #define APD_GLOBALS(v) TSRMG(apd_globals_id, zend_apd_globals *, v) http://cvs.php.net/diff.php/pecl/apd/win32compat.c?r1=1.5&r2=1.6&ty=u Index: pecl/apd/win32compat.c diff -u pecl/apd/win32compat.c:1.5 pecl/apd/win32compat.c:1.6 --- pecl/apd/win32compat.c:1.5 Tue Dec 23 20:13:21 2003 +++ pecl/apd/win32compat.c Wed Mar 10 11:40:55 2004 @@ -12,7 +12,7 @@ * * *****************************************************************************/ -/* $Id: win32compat.c,v 1.5 2003/12/24 01:13:21 gschlossnagle Exp $ */ +/* $Id: win32compat.c,v 1.6 2004/03/10 16:40:55 gschlossnagle Exp $ */ #include "win32compat.h" http://cvs.php.net/diff.php/pecl/apd/win32compat.h?r1=1.5&r2=1.6&ty=u Index: pecl/apd/win32compat.h diff -u pecl/apd/win32compat.h:1.5 pecl/apd/win32compat.h:1.6 --- pecl/apd/win32compat.h:1.5 Tue Dec 23 20:13:21 2003 +++ pecl/apd/win32compat.h Wed Mar 10 11:40:55 2004 @@ -15,7 +15,7 @@ * * *****************************************************************************/ -/* $Id: win32compat.h,v 1.5 2003/12/24 01:13:21 gschlossnagle Exp $ */ +/* $Id: win32compat.h,v 1.6 2004/03/10 16:40:55 gschlossnagle Exp $ */ /* Include stuff ************************************************************ */