Permalink
Browse files

Start with making the profiler startable from everywhere.

  • Loading branch information...
1 parent 06fb878 commit 414420c29b949796de9c4938a0328f3c2f1349cc @derickr committed May 21, 2012
Showing with 51 additions and 2 deletions.
  1. +1 −0 php_xdebug.h
  2. +16 −2 xdebug.c
  3. +32 −0 xdebug_profiler.c
  4. +2 −0 xdebug_profiler.h
View
1 php_xdebug.h
@@ -250,6 +250,7 @@ ZEND_BEGIN_MODULE_GLOBALS(xdebug)
char *profiler_output_name; /* "pid" or "crc32" */
zend_bool profiler_enable_trigger;
zend_bool profiler_append;
+ int profiler_start_level;
/* profiler globals */
zend_bool profiler_enabled;
View
18 xdebug.c
@@ -114,6 +114,7 @@ zend_function_entry xdebug_functions[] = {
PHP_FE(xdebug_stop_trace, NULL)
PHP_FE(xdebug_get_tracefile_name, NULL)
+ PHP_FE(xdebug_profiler_start, NULL)
PHP_FE(xdebug_get_profiler_filename, NULL)
PHP_FE(xdebug_dump_aggr_profiling_data, NULL)
PHP_FE(xdebug_clear_aggr_profiling_data, NULL)
@@ -1324,6 +1325,7 @@ void xdebug_execute(zend_op_array *op_array TSRMLS_DC)
) {
if (xdebug_profiler_init((char *) op_array->filename TSRMLS_CC) == SUCCESS) {
XG(profiler_enabled) = 1;
+ XG(profiler_start_level) = 0;
}
}
}
@@ -1391,7 +1393,13 @@ void xdebug_execute(zend_op_array *op_array TSRMLS_DC)
xdebug_old_execute(op_array TSRMLS_CC);
if (XG(profiler_enabled)) {
- xdebug_profiler_function_user_end(fse, op_array TSRMLS_CC);
+ printf("CHECK: FSE: %d SL: %d\n", fse->level, XG(profiler_start_level));
+ if (fse->level == XG(profiler_start_level)) {
+ xdebug_profiler_deinit(TSRMLS_C);
+ XG(profiler_enabled) = 0;
+ } else {
+ xdebug_profiler_function_user_end(fse, op_array TSRMLS_CC);
+ }
}
xdebug_trace_function_end(fse, function_nr TSRMLS_CC);
@@ -1484,7 +1492,13 @@ void xdebug_execute_internal(zend_execute_data *current_execute_data, int return
}
if (XG(profiler_enabled)) {
- xdebug_profiler_function_internal_end(fse TSRMLS_CC);
+ printf("CHECK: FSE: %d SL: %d\n", fse->level, XG(profiler_start_level));
+ if (fse->level == XG(profiler_start_level)) {
+ xdebug_profiler_deinit(TSRMLS_C);
+ XG(profiler_enabled) = 0;
+ } else {
+ xdebug_profiler_function_internal_end(fse TSRMLS_CC);
+ }
}
/* Restore SOAP situation if needed */
View
32 xdebug_profiler.c
@@ -96,6 +96,9 @@ void xdebug_profiler_deinit(TSRMLS_D)
for (le = XDEBUG_LLIST_TAIL(XG(stack)); le != NULL; le = XDEBUG_LLIST_PREV(le)) {
fse = XDEBUG_LLIST_VALP(le);
+ if (fse->level < XG(profiler_start_level)) {
+ continue;
+ }
if (fse->user_defined == XDEBUG_INTERNAL) {
xdebug_profiler_function_internal_end(fse TSRMLS_CC);
} else {
@@ -125,6 +128,7 @@ void xdebug_profiler_function_user_begin(function_stack_entry *fse TSRMLS_DC)
{
fse->profile.time = 0;
fse->profile.mark = xdebug_get_utime();
+ printf("\tU ENTER FOR L %d (%s)\n", fse->level, fse->function.function);
}
@@ -231,17 +235,20 @@ void xdebug_profiler_function_user_end(function_stack_entry *fse, zend_op_array*
}
fprintf(XG(profile_file), "\n");
fflush(XG(profile_file));
+ printf("\tU EXIT FOR L %d (%s)\n", fse->level, fse->function.function);
}
void xdebug_profiler_function_internal_begin(function_stack_entry *fse TSRMLS_DC)
{
+ printf("I");
xdebug_profiler_function_user_begin(fse TSRMLS_CC);
}
void xdebug_profiler_function_internal_end(function_stack_entry *fse TSRMLS_DC)
{
+ printf("I");
xdebug_profiler_function_user_end(fse, NULL TSRMLS_CC);
}
@@ -300,3 +307,28 @@ int xdebug_profiler_output_aggr_data(const char *prefix TSRMLS_DC)
fprintf(stderr, "wrote info for %d entries to %s\n", zend_hash_num_elements(&XG(aggr_calls)), filename);
return SUCCESS;
}
+
+PHP_FUNCTION(xdebug_profiler_start)
+{
+ function_stack_entry *fse;
+ xdebug_llist_element *le;
+
+ if (XG(profiler_enabled)) {
+ RETURN_FALSE;
+ }
+
+ xdebug_profiler_init("TESTING" TSRMLS_CC);
+
+ le = XDEBUG_LLIST_TAIL(XG(stack));
+ fse = XDEBUG_LLIST_VALP(le);
+
+ XG(profiler_enabled) = 1;
+ XG(profiler_start_level) = fse->level - 1;
+
+printf("START LEVEL %d\n", fse->level);
+
+ xdebug_profiler_function_user_begin(fse);
+ if (fse->prev) {
+ xdebug_profiler_function_user_begin(fse->prev);
+ }
+}
View
2 xdebug_profiler.h
@@ -36,4 +36,6 @@ void xdebug_profiler_function_internal_end(function_stack_entry *fse TSRMLS_DC);
void xdebug_profile_call_entry_dtor(void *dummy, void *elem);
void xdebug_profile_aggr_call_entry_dtor(void *elem);
+PHP_FUNCTION(xdebug_profiler_start);
+
#endif

0 comments on commit 414420c

Please sign in to comment.