cvs: pear(ZEND_ENGINE_2) /PECL/apd Makefile.in apd_summary.c php_apd.c php_apd.h

From: Date: Sun, 22 Jun 2003 23:05:12 +0000
Subject: cvs: pear(ZEND_ENGINE_2) /PECL/apd Makefile.in apd_summary.c php_apd.c php_apd.h
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-293@lists.php.net to get a copy of this message
sterling Sun Jun 22 19:05:12 2003 EDT Added files: (Branch: ZEND_ENGINE_2) /pear/PECL/apd apd_summary.c Modified files: /pear/PECL/apd Makefile.in php_apd.c php_apd.h Log: separate out the apd summary stuff to a separate file. Try and get recursive timings working. Currently has memory overruns, but commit so other eyes can see the problem.

Index: pear/PECL/apd/Makefile.in diff -u pear/PECL/apd/Makefile.in:1.1.1.1.4.2 pear/PECL/apd/Makefile.in:1.1.1.1.4.3 --- pear/PECL/apd/Makefile.in:1.1.1.1.4.2 Wed Jun 18 13:17:22 2003 +++ pear/PECL/apd/Makefile.in Sun Jun 22 19:05:11 2003 @@ -8,7 +8,7 @@ PHP_SRC_DIR = LTLIBRARY_NAME = libapd.la -LTLIBRARY_SOURCES = php_apd.c apd_lib.c opcode.c apd_array.c +LTLIBRARY_SOURCES = php_apd.c apd_lib.c opcode.c apd_array.c apd_summary.c LTLIBRARY_SHARED_NAME = php_apd.la LTLIBRARY_SHARED_LIBADD = $(TRACE_SHARED_LIBADD) Index: pear/PECL/apd/php_apd.c diff -u pear/PECL/apd/php_apd.c:1.52.2.18 pear/PECL/apd/php_apd.c:1.52.2.19 --- pear/PECL/apd/php_apd.c:1.52.2.18 Fri Jun 20 23:10:20 2003 +++ pear/PECL/apd/php_apd.c Sun Jun 22 19:05:11 2003 @@ -78,9 +78,6 @@ {NULL, NULL, NULL} }; -/* Declare global structure. */ -ZEND_DECLARE_MODULE_GLOBALS(apd); - void apd_pprof_fprintf(const char* fmt, ...); long diff_times(struct timeval a, struct timeval b) @@ -89,274 +86,6 @@ retval += (a.tv_usec - b.tv_usec); return retval; -} - -/** - * Output sent directly to the browser - */ -static void -apd_summary_output_header(void) -{ - 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); -} - -static 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); -} - -static void -apd_summary_output_elapsed_time(int usert, int systemt, int realt) -{ - apd_fcall_t *cc; - TSRMLS_FETCH(); - - /* Individual */ - cc = APD_GLOBALS(summary).current_fcall; - if (cc == NULL) { - return; - } - cc->usertime += usert; - cc->systemtime += systemt; - cc->realtime += realt; -} - -static 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; -} - - -static void -apd_summary_output_enter_function(int index, int filenum, int linenum) -{ - apd_function_entry_t *function_entry; - 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++; - - APD_GLOBALS(summary).current_fcall = fcall; -} - -static void -apd_summary_output_exit_function(int index, int mem) -{ - TSRMLS_FETCH(); - - if (!APD_GLOBALS(summary).current_fcall) { - return; - } - - APD_GLOBALS(summary).current_fcall->memory += mem; - APD_GLOBALS(summary).current_fcall = NULL; -} - - -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); - } -} - -static 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); -} - -static 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); - } - } -} - - -static 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; - 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_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, basename(file_entry->filename)); - 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; - } - php_printf("</table>\n"); } /** Index: pear/PECL/apd/php_apd.h diff -u pear/PECL/apd/php_apd.h:1.19.2.9 pear/PECL/apd/php_apd.h:1.19.2.10 --- pear/PECL/apd/php_apd.h:1.19.2.9 Fri Jun 20 21:25:42 2003 +++ pear/PECL/apd/php_apd.h Sun Jun 22 19:05:12 2003 @@ -21,13 +21,14 @@ #ifndef PHP_APD_H #define PHP_APD_H +#include "php.h" + #if PHP_WIN32 #include "config.w32.h" #else #include "php_config.h" #endif -#include "php.h" #include "php_ini.h" #include "php_globals.h" #include "apd_array.h" @@ -47,6 +48,7 @@ #include <netinet/tcp.h> #include <sys/time.h> #include <sys/times.h> +#include <sys/resource.h> #include <unistd.h> #else /* windows */ /* these are from ext/socket -- probably worth just copying the files into apd? */ @@ -136,10 +138,18 @@ typedef struct { apd_array_t functions; apd_array_t files; - apd_fcall_t *current_fcall; + zend_llist call_list; char *caller; } apd_summary_t; +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_declare_function(int, const char *, int); +void apd_summary_output_enter_function(int, int, int); +void apd_summary_output_exit_function(int, int); +void apd_summary_output_footer(void); + typedef void (*apd_output_header_func_t)(void); typedef void (*apd_output_file_reference_func_t)(int, const char *); @@ -183,6 +193,9 @@ apd_output_handlers output; apd_summary_t summary; ZEND_END_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) Index: pear/PECL/apd/apd_summary.c +++ pear/PECL/apd/apd_summary.c
« previous php.pecl.cvs (#293) next »