cvs: pecl(ZEND_ENGINE_2) /apd README apd_summary.c config.m4 php_apd.c php_apd.h pprof2calltree pprofp
| From: | George Schlossnagle | Date: | Mon, 08 Mar 2004 20:28:23 +0000 |
| Subject: | cvs: pecl(ZEND_ENGINE_2) /apd README apd_summary.c config.m4 php_apd.c php_apd.h pprof2calltree pprofp | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-1023@lists.php.net to get a copy of this message | ||
gschlossnagle Mon Mar 8 15:28:23 2004 EDT
Added files: (Branch: ZEND_ENGINE_2)
/pecl/apd pprof2calltree
Modified files:
/pecl/apd README apd_summary.c config.m4 php_apd.c php_apd.h pprofp
Log:
o Fixes for ZE2
o Added statement level tracing toggleable with ini setting
apd.statement_tracing=[01]
o Added line numbers to all timings
o Fixed callstack issue where apd_set_pprof_trace was popped off callstack
but never pushed on.
o Added valgrind-compatible output conversion script pprof2calltree
http://cvs.php.net/diff.php/pecl/apd/README?r1=1.15&r2=1.15.2.1&ty=u Index: pecl/apd/README diff -u pecl/apd/README:1.15 pecl/apd/README:1.15.2.1 --- pecl/apd/README:1.15 Wed Apr 2 09:39:54 2003 +++ pecl/apd/README Mon Mar 8 15:28:22 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/apd_summary.c?r1=1.1.2.2&r2=1.1.2.3&ty=u Index: pecl/apd/apd_summary.c diff -u pecl/apd/apd_summary.c:1.1.2.2 pecl/apd/apd_summary.c:1.1.2.3 --- pecl/apd/apd_summary.c:1.1.2.2 Wed Jul 2 02:39:06 2003 +++ pecl/apd/apd_summary.c Mon Mar 8 15:28:22 2004 @@ -19,7 +19,7 @@ #include "php_apd.h" void -apd_summary_output_header(void) +apd_summary_output_header() { apd_file_entry_t *file_entry; apd_function_entry_t *function_entry; @@ -46,7 +46,7 @@ } void -apd_summary_output_elapsed_time(int usert, int systemt, int realt) +apd_summary_output_elapsed_time(int filenum, int linenum, int usert, int systemt, int realt) { zend_llist *list; zend_llist_position l; @@ -303,7 +303,7 @@ php_printf("</tr>\n"); fcall = fcall->next; - efree(ret); +// efree(ret); } php_printf("</table>\n"); http://cvs.php.net/diff.php/pecl/apd/config.m4?r1=1.1.1.1&r2=1.1.1.1.4.1&ty=u Index: pecl/apd/config.m4 diff -u pecl/apd/config.m4:1.1.1.1 pecl/apd/config.m4:1.1.1.1.4.1 --- pecl/apd/config.m4:1.1.1.1 Thu Jul 26 17:42:16 2001 +++ pecl/apd/config.m4 Mon Mar 8 15:28:22 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.52.2.20&r2=1.52.2.21&ty=u Index: pecl/apd/php_apd.c diff -u pecl/apd/php_apd.c:1.52.2.20 pecl/apd/php_apd.c:1.52.2.21 --- pecl/apd/php_apd.c:1.52.2.20 Wed Jul 2 02:39:06 2003 +++ pecl/apd/php_apd.c Mon Mar 8 15:28:22 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(); 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(); + 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() +{ + 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 + NO_VERSION_YET, /* extension version number (string) */ STANDARD_MODULE_PROPERTIES_EX }; -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_C); } 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_C); } @@ -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,19 +956,11 @@ 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(); + } } -/* --------------------------------------------------------------------------- - Zend Extension Support - --------------------------------------------------------------------------- */ - int apd_zend_startup(zend_extension *extension) { TSRMLS_FETCH(); @@ -1013,21 +986,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.19.2.11&r2=1.19.2.12&ty=u Index: pecl/apd/php_apd.h diff -u pecl/apd/php_apd.h:1.19.2.11 pecl/apd/php_apd.h:1.19.2.12 --- pecl/apd/php_apd.h:1.19.2.11 Wed Jul 2 02:39:06 2003 +++ pecl/apd/php_apd.h Mon Mar 8 15:28:22 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; @@ -184,7 +185,7 @@ 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/pprofp?r1=1.11.2.1&r2=1.11.2.2&ty=u Index: pecl/apd/pprofp diff -u pecl/apd/pprofp:1.11.2.1 pecl/apd/pprofp:1.11.2.2 --- pecl/apd/pprofp:1.11.2.1 Tue Jun 17 13:49:09 2003 +++ pecl/apd/pprofp Mon Mar 8 15:28:22 2004 @@ -100,7 +100,10 @@ continue; } if( $token == '@') { - list($t_utime, $t_stime, $t_rtime) = preg_split("/ /", $data); + list($file_no, $line_no, $ut, $st, $rt) = preg_split("/ /", $data); + $t_utime += $ut; + $t_stime += $st; + $t_rtime += $rt; continue; } if ($token == '-') {
http://cvs.php.net/diff.php/pecl/apd/README?r1=1.15&r2=1.15.2.1&ty=u Index: pecl/apd/README diff -u pecl/apd/README:1.15 pecl/apd/README:1.15.2.1 --- pecl/apd/README:1.15 Wed Apr 2 09:39:54 2003 +++ pecl/apd/README Mon Mar 8 15:28:22 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/apd_summary.c?r1=1.1.2.2&r2=1.1.2.3&ty=u Index: pecl/apd/apd_summary.c diff -u pecl/apd/apd_summary.c:1.1.2.2 pecl/apd/apd_summary.c:1.1.2.3 --- pecl/apd/apd_summary.c:1.1.2.2 Wed Jul 2 02:39:06 2003 +++ pecl/apd/apd_summary.c Mon Mar 8 15:28:22 2004 @@ -19,7 +19,7 @@ #include "php_apd.h" void -apd_summary_output_header(void) +apd_summary_output_header() { apd_file_entry_t *file_entry; apd_function_entry_t *function_entry; @@ -46,7 +46,7 @@ } void -apd_summary_output_elapsed_time(int usert, int systemt, int realt) +apd_summary_output_elapsed_time(int filenum, int linenum, int usert, int systemt, int realt) { zend_llist *list; zend_llist_position l; @@ -303,7 +303,7 @@ php_printf("</tr>\n"); fcall = fcall->next; - efree(ret); +// efree(ret); } php_printf("</table>\n"); http://cvs.php.net/diff.php/pecl/apd/config.m4?r1=1.1.1.1&r2=1.1.1.1.4.1&ty=u Index: pecl/apd/config.m4 diff -u pecl/apd/config.m4:1.1.1.1 pecl/apd/config.m4:1.1.1.1.4.1 --- pecl/apd/config.m4:1.1.1.1 Thu Jul 26 17:42:16 2001 +++ pecl/apd/config.m4 Mon Mar 8 15:28:22 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.52.2.20&r2=1.52.2.21&ty=u Index: pecl/apd/php_apd.c diff -u pecl/apd/php_apd.c:1.52.2.20 pecl/apd/php_apd.c:1.52.2.21 --- pecl/apd/php_apd.c:1.52.2.20 Wed Jul 2 02:39:06 2003 +++ pecl/apd/php_apd.c Mon Mar 8 15:28:22 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(); 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(); + 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() +{ + 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 + NO_VERSION_YET, /* extension version number (string) */ STANDARD_MODULE_PROPERTIES_EX }; -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_C); } 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_C); } @@ -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,19 +956,11 @@ 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(); + } } -/* --------------------------------------------------------------------------- - Zend Extension Support - --------------------------------------------------------------------------- */ - int apd_zend_startup(zend_extension *extension) { TSRMLS_FETCH(); @@ -1013,21 +986,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.19.2.11&r2=1.19.2.12&ty=u Index: pecl/apd/php_apd.h diff -u pecl/apd/php_apd.h:1.19.2.11 pecl/apd/php_apd.h:1.19.2.12 --- pecl/apd/php_apd.h:1.19.2.11 Wed Jul 2 02:39:06 2003 +++ pecl/apd/php_apd.h Mon Mar 8 15:28:22 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; @@ -184,7 +185,7 @@ 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/pprofp?r1=1.11.2.1&r2=1.11.2.2&ty=u Index: pecl/apd/pprofp diff -u pecl/apd/pprofp:1.11.2.1 pecl/apd/pprofp:1.11.2.2 --- pecl/apd/pprofp:1.11.2.1 Tue Jun 17 13:49:09 2003 +++ pecl/apd/pprofp Mon Mar 8 15:28:22 2004 @@ -100,7 +100,10 @@ continue; } if( $token == '@') { - list($t_utime, $t_stime, $t_rtime) = preg_split("/ /", $data); + list($file_no, $line_no, $ut, $st, $rt) = preg_split("/ /", $data); + $t_utime += $ut; + $t_stime += $st; + $t_rtime += $rt; continue; } if ($token == '-') {