From c081ce628f0d76d44784d7bb8e06428b06142ac0 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 3 Jan 2014 11:08:10 +0800 Subject: Bump year --- ext/mysqlnd/mysqlnd_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/mysqlnd/mysqlnd_debug.c') diff --git a/ext/mysqlnd/mysqlnd_debug.c b/ext/mysqlnd/mysqlnd_debug.c index 5e617f5b2b..9fbcc4768f 100644 --- a/ext/mysqlnd/mysqlnd_debug.c +++ b/ext/mysqlnd/mysqlnd_debug.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 2006-2013 The PHP Group | + | Copyright (c) 2006-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | -- cgit v1.2.1 From e6e5d3535dc767cadd9d962e41dd837bd58a2ad3 Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Mon, 19 May 2014 20:32:41 +0300 Subject: remove mysqlnd_bt.c as it a long dead code --- ext/mysqlnd/mysqlnd_debug.c | 1 - 1 file changed, 1 deletion(-) (limited to 'ext/mysqlnd/mysqlnd_debug.c') diff --git a/ext/mysqlnd/mysqlnd_debug.c b/ext/mysqlnd/mysqlnd_debug.c index 9fbcc4768f..296a31dfb0 100644 --- a/ext/mysqlnd/mysqlnd_debug.c +++ b/ext/mysqlnd/mysqlnd_debug.c @@ -792,7 +792,6 @@ static struct st_mysqlnd_plugin_trace_log mysqlnd_plugin_trace_log_plugin = }, {/* methods */ mysqlnd_debug_init, - mysqlnd_get_backtrace } }; -- cgit v1.2.1 From 6288bb8ffefe9cf9648b8d2190729c087b5c2586 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Tue, 17 Jun 2014 17:50:54 +0800 Subject: Refactoring mysqlnd (incompleted, only mysqlnd ext compilable) --- ext/mysqlnd/mysqlnd_debug.c | 50 +++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) (limited to 'ext/mysqlnd/mysqlnd_debug.c') diff --git a/ext/mysqlnd/mysqlnd_debug.c b/ext/mysqlnd/mysqlnd_debug.c index 296a31dfb0..413ba30088 100644 --- a/ext/mysqlnd/mysqlnd_debug.c +++ b/ext/mysqlnd/mysqlnd_debug.c @@ -269,11 +269,11 @@ MYSQLND_METHOD(mysqlnd_debug, func_enter)(MYSQLND_DEBUG * self, const char ** p = self->skip_functions; while (*p) { if (*p == func_name) { - zend_stack_push(&self->call_stack, "", sizeof("")); + zend_stack_push(&self->call_stack, ""); #ifndef MYSQLND_PROFILING_DISABLED if (self->flags & MYSQLND_DEBUG_PROFILE_CALLS) { uint64_t some_time = 0; - zend_stack_push(&self->call_time_stack, &some_time, sizeof(some_time)); + zend_stack_push(&self->call_time_stack, &some_time); } #endif return FALSE; @@ -282,16 +282,16 @@ MYSQLND_METHOD(mysqlnd_debug, func_enter)(MYSQLND_DEBUG * self, } } - zend_stack_push(&self->call_stack, func_name, func_name_len + 1); + zend_stack_push(&self->call_stack, func_name); #ifndef MYSQLND_PROFILING_DISABLED if (self->flags & MYSQLND_DEBUG_PROFILE_CALLS) { uint64_t some_time = 0; - zend_stack_push(&self->call_time_stack, &some_time, sizeof(some_time)); + zend_stack_push(&self->call_time_stack, &some_time); } #endif if (zend_hash_num_elements(&self->not_filtered_functions) && - 0 == zend_hash_exists(&self->not_filtered_functions, func_name, strlen(func_name) + 1)) + 0 == zend_hash_str_exists(&self->not_filtered_functions, func_name, strlen(func_name))) { return FALSE; } @@ -336,11 +336,11 @@ MYSQLND_METHOD(mysqlnd_debug, func_leave)(MYSQLND_DEBUG * self, unsigned int lin return PASS; } - zend_stack_top(&self->call_stack, (void **)&func_name); + func_name = zend_stack_top(&self->call_stack); #ifndef MYSQLND_PROFILING_DISABLED if (profile_calls) { - zend_stack_top(&self->call_time_stack, (void **)&mine_non_own_time_ptr); + mine_non_own_time_ptr = zend_stack_top(&self->call_time_stack); mine_non_own_time = *mine_non_own_time_ptr; zend_stack_del_top(&self->call_time_stack); /* callee - removing ourselves */ } @@ -349,7 +349,7 @@ MYSQLND_METHOD(mysqlnd_debug, func_leave)(MYSQLND_DEBUG * self, unsigned int lin if (func_name[0] == '\0') { ; /* don't log that function */ } else if (!zend_hash_num_elements(&self->not_filtered_functions) || - 1 == zend_hash_exists(&self->not_filtered_functions, func_name, strlen(func_name) + 1)) + 1 == zend_hash_str_exists(&self->not_filtered_functions, func_name, strlen(func_name))) { #ifndef MYSQLND_PROFILING_DISABLED if (FALSE == profile_calls) { @@ -367,7 +367,7 @@ MYSQLND_METHOD(mysqlnd_debug, func_leave)(MYSQLND_DEBUG * self, unsigned int lin func_name, (unsigned int) call_time, (unsigned int) own_time, (unsigned int) mine_non_own_time ); - if (SUCCESS == zend_hash_find(&self->function_profiles, func_name, func_name_len + 1, (void **) &f_profile)) { + if ((f_profile = zend_hash_str_find_ptr(&self->function_profiles, func_name, func_name_len)) != NULL) { /* found */ if (f_profile) { if (mine_non_own_time < f_profile->min_in_calls) { @@ -411,16 +411,16 @@ MYSQLND_METHOD(mysqlnd_debug, func_leave)(MYSQLND_DEBUG * self, unsigned int lin f_profile->min_total = f_profile->max_total = f_profile->avg_total = call_time; f_profile->min_own = f_profile->max_own = f_profile->avg_own = own_time; f_profile->calls = 1; - zend_hash_add(&self->function_profiles, func_name, func_name_len+1, f_profile, sizeof(struct st_mysqlnd_dbg_function_profile), NULL); + zend_hash_str_add_mem(&self->function_profiles, func_name, func_name_len, f_profile, sizeof(struct st_mysqlnd_dbg_function_profile)); } if ((uint) zend_stack_count(&self->call_time_stack)) { uint64_t parent_non_own_time = 0; - zend_stack_top(&self->call_time_stack, (void **)&parent_non_own_time_ptr); + parent_non_own_time_ptr = zend_stack_top(&self->call_time_stack); parent_non_own_time = *parent_non_own_time_ptr; parent_non_own_time += call_time; zend_stack_del_top(&self->call_time_stack); /* the caller */ - zend_stack_push(&self->call_time_stack, &parent_non_own_time, sizeof(parent_non_own_time)); /* add back the caller */ + zend_stack_push(&self->call_time_stack, &parent_non_own_time); /* add back the caller */ } } #endif @@ -440,29 +440,22 @@ MYSQLND_METHOD(mysqlnd_debug, close)(MYSQLND_DEBUG * self) #ifndef MYSQLND_PROFILING_DISABLED if (!(self->flags & MYSQLND_DEBUG_FLUSH) && (self->flags & MYSQLND_DEBUG_PROFILE_CALLS)) { struct st_mysqlnd_dbg_function_profile * f_profile; - HashPosition pos_values; + zend_string *string_key = NULL; self->m->log_va(self, __LINE__, __FILE__, 0, "info : ", "number of functions: %d", zend_hash_num_elements(&self->function_profiles)); - zend_hash_internal_pointer_reset_ex(&self->function_profiles, &pos_values); - while (zend_hash_get_current_data_ex(&self->function_profiles, (void **) &f_profile, &pos_values) == SUCCESS) { - char *string_key = NULL; - uint string_key_len; - ulong num_key; - - zend_hash_get_current_key_ex(&self->function_profiles, &string_key, &string_key_len, &num_key, 0, &pos_values); - + ZEND_HASH_FOREACH_STR_KEY_PTR(&self->function_profiles, string_key, f_profile) { self->m->log_va(self, __LINE__, __FILE__, -1, "info : ", "%-40s\tcalls=%5llu own_slow=%5llu in_calls_slow=%5llu total_slow=%5llu" " min_own=%5llu max_own=%7llu avg_own=%7llu " " min_in_calls=%5llu max_in_calls=%7llu avg_in_calls=%7llu" " min_total=%5llu max_total=%7llu avg_total=%7llu" - ,string_key + ,string_key->val ,(uint64_t) f_profile->calls ,(uint64_t) f_profile->own_underporm_calls ,(uint64_t) f_profile->in_calls_underporm_calls ,(uint64_t) f_profile->total_underporm_calls - + ,(uint64_t) f_profile->min_own ,(uint64_t) f_profile->max_own ,(uint64_t) f_profile->avg_own @@ -473,8 +466,7 @@ MYSQLND_METHOD(mysqlnd_debug, close)(MYSQLND_DEBUG * self) ,(uint64_t) f_profile->max_total ,(uint64_t) f_profile->avg_total ); - zend_hash_move_forward_ex(&self->function_profiles, &pos_values); - } + } ZEND_HASH_FOREACH_END(); } #endif @@ -592,8 +584,8 @@ MYSQLND_METHOD(mysqlnd_debug, set_mode)(MYSQLND_DEBUG * self, const char * const memcpy(func_name, mode + i + 1, func_name_len); func_name[func_name_len] = '\0'; - zend_hash_add_empty_element(&self->not_filtered_functions, - func_name, func_name_len + 1); + zend_hash_str_add_empty_element(&self->not_filtered_functions, + func_name, func_name_len); i = j; } if (mode[j] == ':') { @@ -730,8 +722,8 @@ mysqlnd_debug_init(const char * skip_functions[] TSRMLS_DC) #endif ret->nest_level_limit = 0; ret->pid = getpid(); - zend_stack_init(&ret->call_stack); - zend_stack_init(&ret->call_time_stack); + zend_stack_init(&ret->call_stack, sizeof(char *)); + zend_stack_init(&ret->call_time_stack, sizeof(uint64_t)); zend_hash_init(&ret->not_filtered_functions, 0, NULL, NULL, 0); zend_hash_init(&ret->function_profiles, 0, NULL, NULL, 0); -- cgit v1.2.1 From c25828e41ea1e558c10ac57a703406315cc2831c Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 25 Jun 2014 12:33:35 +0800 Subject: Fixed stack usage --- ext/mysqlnd/mysqlnd_debug.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'ext/mysqlnd/mysqlnd_debug.c') diff --git a/ext/mysqlnd/mysqlnd_debug.c b/ext/mysqlnd/mysqlnd_debug.c index 413ba30088..92121cf247 100644 --- a/ext/mysqlnd/mysqlnd_debug.c +++ b/ext/mysqlnd/mysqlnd_debug.c @@ -26,6 +26,7 @@ #include "mysqlnd_debug.h" static const char * const mysqlnd_debug_default_trace_file = "/tmp/mysqlnd.trace"; +static const char * const mysqlnd_debug_empty_string = ""; #ifdef ZTS #define MYSQLND_ZTS(self) TSRMLS_D = (self)->TSRMLS_C @@ -269,7 +270,7 @@ MYSQLND_METHOD(mysqlnd_debug, func_enter)(MYSQLND_DEBUG * self, const char ** p = self->skip_functions; while (*p) { if (*p == func_name) { - zend_stack_push(&self->call_stack, ""); + zend_stack_push(&self->call_stack, &mysqlnd_debug_empty_string); #ifndef MYSQLND_PROFILING_DISABLED if (self->flags & MYSQLND_DEBUG_PROFILE_CALLS) { uint64_t some_time = 0; @@ -282,7 +283,7 @@ MYSQLND_METHOD(mysqlnd_debug, func_enter)(MYSQLND_DEBUG * self, } } - zend_stack_push(&self->call_stack, func_name); + zend_stack_push(&self->call_stack, &func_name); #ifndef MYSQLND_PROFILING_DISABLED if (self->flags & MYSQLND_DEBUG_PROFILE_CALLS) { uint64_t some_time = 0; @@ -324,7 +325,7 @@ struct st_mysqlnd_dbg_function_profile { static enum_func_status MYSQLND_METHOD(mysqlnd_debug, func_leave)(MYSQLND_DEBUG * self, unsigned int line, const char * const file, uint64_t call_time) { - char *func_name; + char **func_name; uint64_t * parent_non_own_time_ptr = NULL, * mine_non_own_time_ptr = NULL; uint64_t mine_non_own_time = 0; zend_bool profile_calls = self->flags & MYSQLND_DEBUG_PROFILE_CALLS? TRUE:FALSE; @@ -346,28 +347,28 @@ MYSQLND_METHOD(mysqlnd_debug, func_leave)(MYSQLND_DEBUG * self, unsigned int lin } #endif - if (func_name[0] == '\0') { + if ((*func_name)[0] == '\0') { ; /* don't log that function */ } else if (!zend_hash_num_elements(&self->not_filtered_functions) || - 1 == zend_hash_str_exists(&self->not_filtered_functions, func_name, strlen(func_name))) + 1 == zend_hash_str_exists(&self->not_filtered_functions, (*func_name), strlen((*func_name)))) { #ifndef MYSQLND_PROFILING_DISABLED if (FALSE == profile_calls) { #endif - self->m->log_va(self, line, file, zend_stack_count(&self->call_stack) - 1, NULL, "<%s", func_name); + self->m->log_va(self, line, file, zend_stack_count(&self->call_stack) - 1, NULL, "<%s", *func_name); #ifndef MYSQLND_PROFILING_DISABLED } else { struct st_mysqlnd_dbg_function_profile f_profile_stack = {0}; struct st_mysqlnd_dbg_function_profile * f_profile = NULL; uint64_t own_time = call_time - mine_non_own_time; - uint func_name_len = strlen(func_name); + uint func_name_len = strlen(*func_name); self->m->log_va(self, line, file, zend_stack_count(&self->call_stack) - 1, NULL, "<%s (total=%u own=%u in_calls=%u)", - func_name, (unsigned int) call_time, (unsigned int) own_time, (unsigned int) mine_non_own_time + *func_name, (unsigned int) call_time, (unsigned int) own_time, (unsigned int) mine_non_own_time ); - if ((f_profile = zend_hash_str_find_ptr(&self->function_profiles, func_name, func_name_len)) != NULL) { + if ((f_profile = zend_hash_str_find_ptr(&self->function_profiles, *func_name, func_name_len)) != NULL) { /* found */ if (f_profile) { if (mine_non_own_time < f_profile->min_in_calls) { @@ -411,7 +412,7 @@ MYSQLND_METHOD(mysqlnd_debug, func_leave)(MYSQLND_DEBUG * self, unsigned int lin f_profile->min_total = f_profile->max_total = f_profile->avg_total = call_time; f_profile->min_own = f_profile->max_own = f_profile->avg_own = own_time; f_profile->calls = 1; - zend_hash_str_add_mem(&self->function_profiles, func_name, func_name_len, f_profile, sizeof(struct st_mysqlnd_dbg_function_profile)); + zend_hash_str_add_mem(&self->function_profiles, *func_name, func_name_len, f_profile, sizeof(struct st_mysqlnd_dbg_function_profile)); } if ((uint) zend_stack_count(&self->call_time_stack)) { uint64_t parent_non_own_time = 0; -- cgit v1.2.1 From d0cb715373c3fbe9dc095378ec5ed8c71f799f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Schl=C3=BCter?= Date: Fri, 19 Sep 2014 18:33:14 +0200 Subject: s/PHP 5/PHP 7/ --- ext/mysqlnd/mysqlnd_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext/mysqlnd/mysqlnd_debug.c') diff --git a/ext/mysqlnd/mysqlnd_debug.c b/ext/mysqlnd/mysqlnd_debug.c index 92121cf247..f1fde4efbb 100644 --- a/ext/mysqlnd/mysqlnd_debug.c +++ b/ext/mysqlnd/mysqlnd_debug.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 2006-2014 The PHP Group | +----------------------------------------------------------------------+ -- cgit v1.2.1