缘起
正文
1. 下载xhprof源代码: http://pecl.php.net/package/xhprof
2. 参看: xhprof-x.x.x/extention/xhprof.c 中函数:hp_begin
说明: xhprof 代理了zend的一些函数,在这些函数的开始和结束记录所关心的信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
/** * This function gets called once when xhprof gets enabled. * It replaces all the functions like zend_execute, zend_execute_internal, * etc that needs to be instrumented with their corresponding proxies. */ static void hp_begin(long level, long xhprof_flags TSRMLS_DC) { if (!hp_globals.enabled) { int hp_profile_flag = 1; hp_globals.enabled = 1; hp_globals.xhprof_flags = (uint32)xhprof_flags; /* Replace zend_compile with our proxy */ _zend_compile_file = zend_compile_file; zend_compile_file = hp_compile_file; /* Replace zend_execute with our proxy */ _zend_execute = zend_execute; zend_execute = hp_execute; /* Replace zend_execute_internal with our proxy */ _zend_execute_internal = zend_execute_internal; if (!(hp_globals.xhprof_flags & XHPROF_FLAGS_NO_BUILTINS)) { /* if NO_BUILTINS is not set (i.e. user wants to profile builtins), * then we intercept internal (builtin) function calls. */ zend_execute_internal = hp_execute_internal; } |