@@ -31,6 +31,10 @@ extern zend_module_entry xhprof_module_entry;
3131#include "TSRM.h"
3232#endif
3333
34+ #if PHP_VERSION_ID >= 80000
35+ #include "zend_observer.h"
36+ #endif
37+
3438
3539/**
3640 * **********************
@@ -39,7 +43,7 @@ extern zend_module_entry xhprof_module_entry;
3943 */
4044
4145/* XHProf version */
42- #define XHPROF_VERSION "2.2.3 "
46+ #define XHPROF_VERSION "2.3.0-dev "
4347
4448#define XHPROF_FUNC_HASH_COUNTERS_SIZE 1024
4549
@@ -80,60 +84,6 @@ extern zend_module_entry xhprof_module_entry;
8084 typedef unsigned char uint8 ;
8185#endif
8286
83- /*
84- * Start profiling - called just before calling the actual function
85- * NOTE: PLEASE MAKE SURE TSRMLS_CC IS AVAILABLE IN THE CONTEXT
86- * OF THE FUNCTION WHERE THIS MACRO IS CALLED.
87- * TSRMLS_CC CAN BE MADE AVAILABLE VIA TSRMLS_DC IN THE
88- * CALLING FUNCTION OR BY CALLING TSRMLS_FETCH()
89- * TSRMLS_FETCH() IS RELATIVELY EXPENSIVE.
90- */
91- #define BEGIN_PROFILING (entries , symbol , profile_curr , execute_data ) \
92- do { \
93- /* Use a hash code for zend_string. */ \
94- zend_ulong hash_code = ZSTR_HASH (symbol ); \
95- profile_curr = !hp_ignore_entry_work (hash_code , symbol ); \
96- if (profile_curr ) { \
97- if (execute_data != NULL ) { \
98- symbol = hp_get_trace_callback (symbol , execute_data ); \
99- } \
100- hp_entry_t * cur_entry = hp_fast_alloc_hprof_entry (); \
101- (cur_entry )-> hash_code = hash_code % XHPROF_FUNC_HASH_COUNTERS_SIZE ; \
102- (cur_entry )-> name_hprof = symbol ; \
103- (cur_entry )-> prev_hprof = (* (entries )); \
104- /* Call the universal callback */ \
105- hp_mode_common_beginfn ((entries ), (cur_entry )); \
106- /* Call the mode's beginfn callback */ \
107- XHPROF_G (mode_cb ).begin_fn_cb ((entries ), (cur_entry )); \
108- /* Update entries linked list */ \
109- (* (entries )) = (cur_entry ); \
110- } \
111- } while (0 )
112-
113- /*
114- * Stop profiling - called just after calling the actual function
115- * NOTE: PLEASE MAKE SURE TSRMLS_CC IS AVAILABLE IN THE CONTEXT
116- * OF THE FUNCTION WHERE THIS MACRO IS CALLED.
117- * TSRMLS_CC CAN BE MADE AVAILABLE VIA TSRMLS_DC IN THE
118- * CALLING FUNCTION OR BY CALLING TSRMLS_FETCH()
119- * TSRMLS_FETCH() IS RELATIVELY EXPENSIVE.
120- */
121- #define END_PROFILING (entries , profile_curr ) \
122- do { \
123- if (profile_curr) { \
124- hp_entry_t *cur_entry; \
125- /* Call the mode's endfn callback. */ \
126- /* NOTE(cjiang): we want to call this 'end_fn_cb' before */ \
127- /* 'hp_mode_common_endfn' to avoid including the time in */ \
128- /* 'hp_mode_common_endfn' in the profiling results. */ \
129- XHPROF_G (mode_cb ).end_fn_cb ((entries )); \
130- cur_entry = (* (entries )); \
131- /* Free top entry and update entries linked list */ \
132- (* (entries )) = (* (entries ))-> prev_hprof ; \
133- hp_fast_free_hprof_entry (cur_entry ); \
134- } \
135- } while (0 )
136-
13787/* Bloom filter for function names to be ignored */
13888#define INDEX_2_BYTE (index ) (index >> 3)
13989#define INDEX_2_BIT (index ) (1 << (index & 0x7));
@@ -156,6 +106,9 @@ typedef struct hp_entry_t {
156106 zend_ulong tsc_start ; /* start value for TSC counter */
157107 zend_ulong cpu_start ;
158108 zend_ulong hash_code ; /* hash_code for the function name */
109+ #if PHP_VERSION_ID >= 80000
110+ int is_trace ;
111+ #endif
159112} hp_entry_t ;
160113
161114typedef struct hp_ignored_functions {
@@ -176,9 +129,6 @@ typedef void (*hp_end_function_cb) (hp_entry_t **entries);
176129 * GLOBAL STATIC VARIABLES
177130 * ***********************
178131 */
179- /* Pointer to the original execute function */
180- static void (* _zend_execute_ex ) (zend_execute_data * execute_data );
181- ZEND_DLEXPORT void hp_execute_ex (zend_execute_data * execute_data );
182132
183133/* Pointer to the origianl execute_internal function */
184134static void (* _zend_execute_internal ) (zend_execute_data * data , zval * return_value );
@@ -188,13 +138,22 @@ ZEND_DLEXPORT void hp_execute_internal(zend_execute_data *execute_data, zval *re
188138static zend_op_array * (* _zend_compile_file ) (zend_file_handle * file_handle , int type );
189139ZEND_DLEXPORT zend_op_array * hp_compile_file (zend_file_handle * file_handle , int type );
190140
191- /* Pointer to the original compile string function (used by eval) */
192141#if PHP_VERSION_ID < 80000
142+ /* Pointer to the original compile string function (used by eval) */
193143static zend_op_array * (* _zend_compile_string ) (zval * source_string , char * filename );
194144ZEND_DLEXPORT zend_op_array * hp_compile_string (zval * source_string , char * filename );
145+
146+ /* Pointer to the original execute function */
147+ static void (* _zend_execute_ex ) (zend_execute_data * execute_data );
148+ ZEND_DLEXPORT void hp_execute_ex (zend_execute_data * execute_data );
195149#else
150+ /* Pointer to the original compile string function (used by eval) */
196151static zend_op_array * (* _zend_compile_string ) (zend_string * source_string , const char * filename );
197152ZEND_DLEXPORT zend_op_array * hp_compile_string (zend_string * source_string , const char * filename );
153+
154+ static zend_observer_fcall_handlers tracer_observer (zend_execute_data * execute_data );
155+ static void tracer_observer_begin (zend_execute_data * ex );
156+ static void tracer_observer_end (zend_execute_data * ex , zval * return_value );
198157#endif
199158
200159/**
@@ -211,7 +170,6 @@ static void hp_end();
211170static inline zend_ulong cycle_timer ();
212171
213172static void hp_free_the_free_list ();
214- static hp_entry_t * hp_fast_alloc_hprof_entry ();
215173static void hp_fast_free_hprof_entry (hp_entry_t * p );
216174
217175static void incr_us_interval (struct timeval * start , zend_ulong incr );
@@ -220,7 +178,6 @@ static void hp_get_ignored_functions_from_arg(zval *args);
220178
221179static inline void hp_array_del (zend_string * * names );
222180
223- zend_string * hp_get_trace_callback (zend_string * symbol , zend_execute_data * data );
224181void hp_init_trace_callbacks ();
225182
226183double get_timebase_conversion ();
@@ -311,5 +268,4 @@ PHP_FUNCTION(xhprof_sample_disable);
311268#endif
312269
313270extern ZEND_DECLARE_MODULE_GLOBALS (xhprof );
314-
315271#endif /* PHP_XHPROF_H */
0 commit comments