summaryrefslogtreecommitdiff
path: root/ext/mysqlnd/mysqlnd_debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mysqlnd/mysqlnd_debug.c')
-rw-r--r--ext/mysqlnd/mysqlnd_debug.c62
1 files changed, 27 insertions, 35 deletions
diff --git a/ext/mysqlnd/mysqlnd_debug.c b/ext/mysqlnd/mysqlnd_debug.c
index 9fbcc4768f..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,11 +270,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, &mysqlnd_debug_empty_string);
#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 +283,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;
}
@@ -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;
@@ -336,38 +337,38 @@ 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 */
}
#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_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) {
#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 (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 +412,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 +441,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 +467,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 +585,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 +723,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);
@@ -792,7 +785,6 @@ static struct st_mysqlnd_plugin_trace_log mysqlnd_plugin_trace_log_plugin =
},
{/* methods */
mysqlnd_debug_init,
- mysqlnd_get_backtrace
}
};