Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/xhprof-0.9.2/extension/xhprof.c')
-rwxr-xr-xtests/lib/xhprof-0.9.2/extension/xhprof.c155
1 files changed, 131 insertions, 24 deletions
diff --git a/tests/lib/xhprof-0.9.2/extension/xhprof.c b/tests/lib/xhprof-0.9.2/extension/xhprof.c
index eabb165084..a053ede861 100755
--- a/tests/lib/xhprof-0.9.2/extension/xhprof.c
+++ b/tests/lib/xhprof-0.9.2/extension/xhprof.c
@@ -28,6 +28,7 @@
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_xhprof.h"
+#include "zend_extensions.h"
#include <sys/time.h>
#include <sys/resource.h>
#include <stdlib.h>
@@ -47,7 +48,7 @@
#elif __APPLE__
/*
* Patch for compiling in Mac OS X Leopard
- * @author Svilen Spasov <s.spasov@gmail.com>
+ * @author Svilen Spasov <s.spasov@gmail.com>
*/
# include <mach/mach_init.h>
# include <mach/thread_policy.h>
@@ -232,17 +233,29 @@ typedef struct hp_global_t {
/* XHProf global state */
static hp_global_t hp_globals;
+#if PHP_VERSION_ID < 50500
/* Pointer to the original execute function */
static ZEND_DLEXPORT void (*_zend_execute) (zend_op_array *ops TSRMLS_DC);
/* Pointer to the origianl execute_internal function */
static ZEND_DLEXPORT void (*_zend_execute_internal) (zend_execute_data *data,
int ret TSRMLS_DC);
+#else
+/* Pointer to the original execute function */
+static void (*_zend_execute_ex) (zend_execute_data *execute_data TSRMLS_DC);
+
+/* Pointer to the origianl execute_internal function */
+static void (*_zend_execute_internal) (zend_execute_data *data,
+ struct _zend_fcall_info *fci, int ret TSRMLS_DC);
+#endif
/* Pointer to the original compile function */
static zend_op_array * (*_zend_compile_file) (zend_file_handle *file_handle,
int type TSRMLS_DC);
+/* Pointer to the original compile string function (used by eval) */
+static zend_op_array * (*_zend_compile_string) (zval *source_string, char *filename TSRMLS_DC);
+
/* Bloom filter for function names to be ignored */
#define INDEX_2_BYTE(index) (index >> 3)
#define INDEX_2_BIT(index) (1 << (index & 0x7));
@@ -280,6 +293,30 @@ static inline zval *hp_zval_at_key(char *key,
static inline char **hp_strings_in_zval(zval *values);
static inline void hp_array_del(char **name_array);
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_xhprof_enable, 0, 0, 0)
+ ZEND_ARG_INFO(0, flags)
+ ZEND_ARG_INFO(0, options)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_xhprof_disable, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_xhprof_sample_enable, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_xhprof_sample_disable, 0)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+/**
+ * *********************
+ * FUNCTION PROTOTYPES
+ * *********************
+ */
+int restore_cpu_affinity(cpu_set_t * prev_mask);
+int bind_to_cpu(uint32 cpu_id);
+
/**
* *********************
* PHP EXTENSION GLOBALS
@@ -287,10 +324,10 @@ static inline void hp_array_del(char **name_array);
*/
/* List of functions implemented/exposed by xhprof */
zend_function_entry xhprof_functions[] = {
- PHP_FE(xhprof_enable, NULL)
- PHP_FE(xhprof_disable, NULL)
- PHP_FE(xhprof_sample_enable, NULL)
- PHP_FE(xhprof_sample_disable, NULL)
+ PHP_FE(xhprof_enable, arginfo_xhprof_enable)
+ PHP_FE(xhprof_disable, arginfo_xhprof_disable)
+ PHP_FE(xhprof_sample_enable, arginfo_xhprof_sample_enable)
+ PHP_FE(xhprof_sample_disable, arginfo_xhprof_sample_disable)
{NULL, NULL, NULL}
};
@@ -735,7 +772,6 @@ void hp_clean_profiler_state(TSRMLS_D) {
size_t hp_get_entry_name(hp_entry_t *entry,
char *result_buf,
size_t result_len) {
- size_t len = 0;
/* Validate result_len */
if (result_len <= 1) {
@@ -765,7 +801,7 @@ size_t hp_get_entry_name(hp_entry_t *entry,
/**
* Check if this entry should be ignored, first with a conservative Bloomish
* filter then with an exact check against the function names.
- *
+ *
* @author mpal
*/
int hp_ignore_entry_work(uint8 hash_code, char *curr_func) {
@@ -786,7 +822,7 @@ int hp_ignore_entry_work(uint8 hash_code, char *curr_func) {
inline int hp_ignore_entry(uint8 hash_code, char *curr_func) {
/* First check if ignoring functions is enabled */
- return hp_globals.ignored_function_names != NULL &&
+ return hp_globals.ignored_function_names != NULL &&
hp_ignore_entry_work(hash_code, curr_func);
}
@@ -853,8 +889,8 @@ size_t hp_get_function_stack(hp_entry_t *entry,
* a pointer to one-level directory and basefile name
* (d/foo.php) in the same string.
*/
-static char *hp_get_base_filename(char *filename) {
- char *ptr;
+static const char *hp_get_base_filename(const char *filename) {
+ const char *ptr;
int found = 0;
if (!filename)
@@ -882,8 +918,8 @@ static char *hp_get_base_filename(char *filename) {
*/
static char *hp_get_function_name(zend_op_array *ops TSRMLS_DC) {
zend_execute_data *data;
- char *func = NULL;
- char *cls = NULL;
+ const char *func = NULL;
+ const char *cls = NULL;
char *ret = NULL;
int len;
zend_function *curr_func;
@@ -920,14 +956,17 @@ static char *hp_get_function_name(zend_op_array *ops TSRMLS_DC) {
}
} else {
long curr_op;
- int desc_len;
- char *desc;
int add_filename = 0;
/* we are dealing with a special directive/function like
* include, eval, etc.
*/
+#if ZEND_EXTENSION_API_NO >= 220100525
+ curr_op = data->opline->extended_value;
+#else
curr_op = data->opline->op2.u.constant.value.lval;
+#endif
+
switch (curr_op) {
case ZEND_EVAL:
func = "eval";
@@ -958,7 +997,7 @@ static char *hp_get_function_name(zend_op_array *ops TSRMLS_DC) {
* you'll see something like "run_init::foo.php" in your reports.
*/
if (add_filename){
- char *filename;
+ const char *filename;
int len;
filename = hp_get_base_filename((curr_func->op_array).filename);
len = strlen("run_init") + strlen(filename) + 3;
@@ -1516,8 +1555,6 @@ zval * hp_mode_shared_endfn_cb(hp_entry_t *top,
zval *counts;
uint64 tsc_end;
- double gtod_value, rdtsc_value;
-
/* Get end tsc counter */
tsc_end = cycle_timer();
@@ -1601,18 +1638,31 @@ void hp_mode_sampled_endfn_cb(hp_entry_t **entries TSRMLS_DC) {
*
* @author hzhao, kannan
*/
+#if PHP_VERSION_ID < 50500
ZEND_DLEXPORT void hp_execute (zend_op_array *ops TSRMLS_DC) {
+#else
+ZEND_DLEXPORT void hp_execute_ex (zend_execute_data *execute_data TSRMLS_DC) {
+ zend_op_array *ops = execute_data->op_array;
+#endif
char *func = NULL;
int hp_profile_flag = 1;
func = hp_get_function_name(ops TSRMLS_CC);
if (!func) {
+#if PHP_VERSION_ID < 50500
_zend_execute(ops TSRMLS_CC);
+#else
+ _zend_execute_ex(execute_data TSRMLS_CC);
+#endif
return;
}
BEGIN_PROFILING(&hp_globals.entries, func, hp_profile_flag);
+#if PHP_VERSION_ID < 50500
_zend_execute(ops TSRMLS_CC);
+#else
+ _zend_execute_ex(execute_data TSRMLS_CC);
+#endif
if (hp_globals.entries) {
END_PROFILING(&hp_globals.entries, hp_profile_flag);
}
@@ -1621,7 +1671,6 @@ ZEND_DLEXPORT void hp_execute (zend_op_array *ops TSRMLS_DC) {
#undef EX
#define EX(element) ((execute_data)->element)
-#define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset))
/**
* Very similar to hp_execute. Proxy for zend_execute_internal().
@@ -1629,8 +1678,18 @@ ZEND_DLEXPORT void hp_execute (zend_op_array *ops TSRMLS_DC) {
*
* @author hzhao, kannan
*/
+
+#if PHP_VERSION_ID < 50500
+#define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset))
+
ZEND_DLEXPORT void hp_execute_internal(zend_execute_data *execute_data,
int ret TSRMLS_DC) {
+#else
+#define EX_T(offset) (*EX_TMP_VAR(execute_data, offset))
+
+ZEND_DLEXPORT void hp_execute_internal(zend_execute_data *execute_data,
+ struct _zend_fcall_info *fci, int ret TSRMLS_DC) {
+#endif
zend_execute_data *current_data;
char *func = NULL;
int hp_profile_flag = 1;
@@ -1645,16 +1704,29 @@ ZEND_DLEXPORT void hp_execute_internal(zend_execute_data *execute_data,
if (!_zend_execute_internal) {
/* no old override to begin with. so invoke the builtin's implementation */
zend_op *opline = EX(opline);
+#if ZEND_EXTENSION_API_NO >= 220100525
+ temp_variable *retvar = &EX_T(opline->result.var);
+ ((zend_internal_function *) EX(function_state).function)->handler(
+ opline->extended_value,
+ retvar->var.ptr,
+ (EX(function_state).function->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) ?
+ &retvar->var.ptr:NULL,
+ EX(object), ret TSRMLS_CC);
+#else
((zend_internal_function *) EX(function_state).function)->handler(
opline->extended_value,
EX_T(opline->result.u.var).var.ptr,
EX(function_state).function->common.return_reference ?
&EX_T(opline->result.u.var).var.ptr:NULL,
EX(object), ret TSRMLS_CC);
-
+#endif
} else {
/* call the old override */
+#if PHP_VERSION_ID < 50500
_zend_execute_internal(execute_data, ret TSRMLS_CC);
+#else
+ _zend_execute_internal(execute_data, fci, ret TSRMLS_CC);
+#endif
}
if (func) {
@@ -1674,7 +1746,7 @@ ZEND_DLEXPORT void hp_execute_internal(zend_execute_data *execute_data,
ZEND_DLEXPORT zend_op_array* hp_compile_file(zend_file_handle *file_handle,
int type TSRMLS_DC) {
- char *filename;
+ const char *filename;
char *func;
int len;
zend_op_array *ret;
@@ -1695,6 +1767,29 @@ ZEND_DLEXPORT zend_op_array* hp_compile_file(zend_file_handle *file_handle,
return ret;
}
+/**
+ * Proxy for zend_compile_string(). Used to profile PHP eval compilation time.
+ */
+ZEND_DLEXPORT zend_op_array* hp_compile_string(zval *source_string, char *filename TSRMLS_DC) {
+
+ char *func;
+ int len;
+ zend_op_array *ret;
+ int hp_profile_flag = 1;
+
+ len = strlen("eval") + strlen(filename) + 3;
+ func = (char *)emalloc(len);
+ snprintf(func, len, "eval::%s", filename);
+
+ BEGIN_PROFILING(&hp_globals.entries, func, hp_profile_flag);
+ ret = _zend_compile_string(source_string, filename TSRMLS_CC);
+ if (hp_globals.entries) {
+ END_PROFILING(&hp_globals.entries, hp_profile_flag);
+ }
+
+ efree(func);
+ return ret;
+}
/**
* **************************
@@ -1718,9 +1813,18 @@ static void hp_begin(long level, long xhprof_flags TSRMLS_DC) {
_zend_compile_file = zend_compile_file;
zend_compile_file = hp_compile_file;
+ /* Replace zend_compile_string with our proxy */
+ _zend_compile_string = zend_compile_string;
+ zend_compile_string = hp_compile_string;
+
/* Replace zend_execute with our proxy */
+#if PHP_VERSION_ID < 50500
_zend_execute = zend_execute;
zend_execute = hp_execute;
+#else
+ _zend_execute_ex = zend_execute_ex;
+ zend_execute_ex = hp_execute_ex;
+#endif
/* Replace zend_execute_internal with our proxy */
_zend_execute_internal = zend_execute_internal;
@@ -1783,8 +1887,6 @@ static void hp_end(TSRMLS_D) {
* hp_begin() and restores the original values.
*/
static void hp_stop(TSRMLS_D) {
- zval *ret;
- char *out_url;
int hp_profile_flag = 1;
/* End any unfinished calls */
@@ -1793,9 +1895,14 @@ static void hp_stop(TSRMLS_D) {
}
/* Remove proxies, restore the originals */
+#if PHP_VERSION_ID < 50500
zend_execute = _zend_execute;
+#else
+ zend_execute_ex = _zend_execute_ex;
+#endif
zend_execute_internal = _zend_execute_internal;
zend_compile_file = _zend_compile_file;
+ zend_compile_string = _zend_compile_string;
/* Resore cpu affinity. */
restore_cpu_affinity(&hp_globals.prev_mask);
@@ -1812,8 +1919,8 @@ static void hp_stop(TSRMLS_D) {
*/
/** Look in the PHP assoc array to find a key and return the zval associated
- * with it.
- *
+ * with it.
+ *
* @author mpal
**/
static zval *hp_zval_at_key(char *key,