Commit: 6e648e934052c784eeb7ee3784aea0cf52bf4898
Author: andrey <and...@php.net> Wed, 27 Jun 2012 16:51:07 +0300
Parents: a027ba3afe8b6f5144f928f510d9af8ffe10a532
Branches: master
Link:
http://git.php.net/?p=php-src.git;a=commitdiff;h=6e648e934052c784eeb7ee3784aea0cf52bf4898
Log:
trace allocations in a file
Changed paths:
M ext/mysqlnd/mysqlnd.h
M ext/mysqlnd/mysqlnd_alloc.c
M ext/mysqlnd/mysqlnd_debug.c
M ext/mysqlnd/mysqlnd_debug.h
M ext/mysqlnd/php_mysqlnd.c
diff --git a/ext/mysqlnd/mysqlnd.h b/ext/mysqlnd/mysqlnd.h
index 33338cf..30d4257 100644
--- a/ext/mysqlnd/mysqlnd.h
+++ b/ext/mysqlnd/mysqlnd.h
@@ -262,8 +262,10 @@ PHPAPI void
_mysqlnd_get_client_stats(zval *return_value TSRMLS_DC ZEND_FILE_L
ZEND_BEGIN_MODULE_GLOBALS(mysqlnd)
zend_bool collect_statistics;
zend_bool collect_memory_statistics;
- char* debug; /* The actual string */
- MYSQLND_DEBUG *dbg; /* The DBG object */
+ char * debug; /* The actual string */
+ char * trace_alloc_settings; /* The actual string */
+ MYSQLND_DEBUG * dbg; /* The DBG object for standard tracing */
+ MYSQLND_DEBUG * trace_alloc; /* The DBG object for allocation
tracing */
long net_cmd_buffer_size;
long net_read_buffer_size;
long log_mask;
diff --git a/ext/mysqlnd/mysqlnd_alloc.c b/ext/mysqlnd/mysqlnd_alloc.c
index f156137..65423e4 100644
--- a/ext/mysqlnd/mysqlnd_alloc.c
+++ b/ext/mysqlnd/mysqlnd_alloc.c
@@ -81,9 +81,9 @@ void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D)
#if PHP_DEBUG
long * threshold = &MYSQLND_G(debug_emalloc_fail_threshold);
#endif
- DBG_ENTER(mysqlnd_emalloc_name);
+ TRACE_ALLOC_ENTER(mysqlnd_emalloc_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
#if PHP_DEBUG
/* -1 is also "true" */
@@ -97,13 +97,13 @@ void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D)
}
#endif
- DBG_INF_FMT("size=%lu ptr=%p", size, ret);
+ TRACE_ALLOC_INF_FMT("size=%lu ptr=%p", size, ret);
if (ret && collect_memory_statistics) {
*(size_t *) ret = size;
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_EMALLOC_COUNT,
1, STAT_MEM_EMALLOC_AMOUNT, size);
}
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
@@ -116,8 +116,9 @@ void * _mysqlnd_pemalloc(size_t size, zend_bool persistent
MYSQLND_MEM_D)
#if PHP_DEBUG
long * threshold = persistent?
&MYSQLND_G(debug_malloc_fail_threshold):&MYSQLND_G(debug_emalloc_fail_threshold);
#endif
- DBG_ENTER(mysqlnd_pemalloc_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_ENTER(mysqlnd_pemalloc_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d persistent=%u",
+ strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno,persistent);
#if PHP_DEBUG
/* -1 is also "true" */
@@ -131,7 +132,7 @@ void * _mysqlnd_pemalloc(size_t size, zend_bool persistent
MYSQLND_MEM_D)
}
#endif
- DBG_INF_FMT("size=%lu ptr=%p persistent=%u", size, ret, persistent);
+ TRACE_ALLOC_INF_FMT("size=%lu ptr=%p persistent=%u", size, ret,
persistent);
if (ret && collect_memory_statistics) {
enum mysqlnd_collected_stats s1 = persistent?
STAT_MEM_MALLOC_COUNT:STAT_MEM_EMALLOC_COUNT;
@@ -140,7 +141,7 @@ void * _mysqlnd_pemalloc(size_t size, zend_bool persistent
MYSQLND_MEM_D)
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(s1, 1, s2, size);
}
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
@@ -153,9 +154,9 @@ void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size
MYSQLND_MEM_D)
#if PHP_DEBUG
long * threshold = &MYSQLND_G(debug_ecalloc_fail_threshold);
#endif
- DBG_ENTER(mysqlnd_ecalloc_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
- DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));
+ TRACE_ALLOC_ENTER(mysqlnd_ecalloc_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));
#if PHP_DEBUG
/* -1 is also "true" */
@@ -169,13 +170,13 @@ void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size
MYSQLND_MEM_D)
}
#endif
- DBG_INF_FMT("after : %lu", zend_memory_usage(FALSE TSRMLS_CC));
- DBG_INF_FMT("size=%lu ptr=%p", size, ret);
+ TRACE_ALLOC_INF_FMT("after : %lu", zend_memory_usage(FALSE TSRMLS_CC));
+ TRACE_ALLOC_INF_FMT("size=%lu ptr=%p", size, ret);
if (ret && collect_memory_statistics) {
*(size_t *) ret = size;
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_ECALLOC_COUNT,
1, STAT_MEM_ECALLOC_AMOUNT, size);
}
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
@@ -188,8 +189,9 @@ void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size,
zend_bool persistent M
#if PHP_DEBUG
long * threshold = persistent?
&MYSQLND_G(debug_calloc_fail_threshold):&MYSQLND_G(debug_ecalloc_fail_threshold);
#endif
- DBG_ENTER(mysqlnd_pecalloc_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_ENTER(mysqlnd_pecalloc_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d persistent=%u",
+ strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno, persistent);
#if PHP_DEBUG
/* -1 is also "true" */
@@ -203,7 +205,7 @@ void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size,
zend_bool persistent M
}
#endif
- DBG_INF_FMT("size=%lu ptr=%p", size, ret);
+ TRACE_ALLOC_INF_FMT("size=%lu ptr=%p", size, ret);
if (ret && collect_memory_statistics) {
enum mysqlnd_collected_stats s1 = persistent?
STAT_MEM_CALLOC_COUNT:STAT_MEM_ECALLOC_COUNT;
@@ -212,7 +214,7 @@ void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size,
zend_bool persistent M
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(s1, 1, s2, size);
}
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
@@ -226,9 +228,9 @@ void * _mysqlnd_erealloc(void *ptr, size_t new_size
MYSQLND_MEM_D)
#if PHP_DEBUG
long * threshold = &MYSQLND_G(debug_erealloc_fail_threshold);
#endif
- DBG_ENTER(mysqlnd_erealloc_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
- DBG_INF_FMT("ptr=%p old_size=%lu, new_size=%lu", ptr, old_size,
new_size);
+ TRACE_ALLOC_ENTER(mysqlnd_erealloc_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu, new_size=%lu", ptr, old_size,
new_size);
#if PHP_DEBUG
/* -1 is also "true" */
@@ -242,12 +244,12 @@ void * _mysqlnd_erealloc(void *ptr, size_t new_size
MYSQLND_MEM_D)
}
#endif
- DBG_INF_FMT("new_ptr=%p", (char*)ret);
+ TRACE_ALLOC_INF_FMT("new_ptr=%p", (char*)ret);
if (ret && collect_memory_statistics) {
*(size_t *) ret = new_size;
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_EREALLOC_COUNT,
1, STAT_MEM_EREALLOC_AMOUNT, new_size);
}
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
@@ -261,9 +263,9 @@ void * _mysqlnd_perealloc(void *ptr, size_t new_size,
zend_bool persistent MYSQL
#if PHP_DEBUG
long * threshold = persistent?
&MYSQLND_G(debug_realloc_fail_threshold):&MYSQLND_G(debug_erealloc_fail_threshold);
#endif
- DBG_ENTER(mysqlnd_perealloc_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
- DBG_INF_FMT("ptr=%p old_size=%lu new_size=%lu persistent=%u", ptr,
old_size, new_size, persistent);
+ TRACE_ALLOC_ENTER(mysqlnd_perealloc_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_INF_FMT("ptr=%p old_size=%lu new_size=%lu persistent=%u",
ptr, old_size, new_size, persistent);
#if PHP_DEBUG
/* -1 is also "true" */
@@ -277,7 +279,7 @@ void * _mysqlnd_perealloc(void *ptr, size_t new_size,
zend_bool persistent MYSQL
}
#endif
- DBG_INF_FMT("new_ptr=%p", (char*)ret);
+ TRACE_ALLOC_INF_FMT("new_ptr=%p", (char*)ret);
if (ret && collect_memory_statistics) {
enum mysqlnd_collected_stats s1 = persistent?
STAT_MEM_REALLOC_COUNT:STAT_MEM_EREALLOC_COUNT;
@@ -285,7 +287,7 @@ void * _mysqlnd_perealloc(void *ptr, size_t new_size,
zend_bool persistent MYSQL
*(size_t *) ret = new_size;
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(s1, 1, s2, new_size);
}
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
@@ -295,14 +297,14 @@ void _mysqlnd_efree(void *ptr MYSQLND_MEM_D)
{
size_t free_amount = 0;
zend_bool collect_memory_statistics =
MYSQLND_G(collect_memory_statistics);
- DBG_ENTER(mysqlnd_efree_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
- DBG_INF_FMT("ptr=%p", ptr);
+ TRACE_ALLOC_ENTER(mysqlnd_efree_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_INF_FMT("ptr=%p", ptr);
if (ptr) {
if (collect_memory_statistics) {
free_amount = *(size_t *)(((char*)ptr) -
sizeof(size_t));
- DBG_INF_FMT("ptr=%p size=%u", ((char*)ptr) -
sizeof(size_t), (unsigned int) free_amount);
+ TRACE_ALLOC_INF_FMT("ptr=%p size=%u", ((char*)ptr) -
sizeof(size_t), (unsigned int) free_amount);
}
_efree(REAL_PTR(ptr) ZEND_FILE_LINE_CC
ZEND_FILE_LINE_ORIG_RELAY_CC);
}
@@ -310,7 +312,7 @@ void _mysqlnd_efree(void *ptr MYSQLND_MEM_D)
if (collect_memory_statistics) {
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_EFREE_COUNT, 1,
STAT_MEM_EFREE_AMOUNT, free_amount);
}
- DBG_VOID_RETURN;
+ TRACE_ALLOC_VOID_RETURN;
}
/* }}} */
@@ -320,14 +322,14 @@ void _mysqlnd_pefree(void *ptr, zend_bool persistent
MYSQLND_MEM_D)
{
size_t free_amount = 0;
zend_bool collect_memory_statistics =
MYSQLND_G(collect_memory_statistics);
- DBG_ENTER(mysqlnd_pefree_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
- DBG_INF_FMT("ptr=%p persistent=%u", ptr, persistent);
+ TRACE_ALLOC_ENTER(mysqlnd_pefree_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_INF_FMT("ptr=%p persistent=%u", ptr, persistent);
if (ptr) {
if (collect_memory_statistics) {
free_amount = *(size_t *)(((char*)ptr) -
sizeof(size_t));
- DBG_INF_FMT("ptr=%p size=%u", ((char*)ptr) -
sizeof(size_t), (unsigned int) free_amount);
+ TRACE_ALLOC_INF_FMT("ptr=%p size=%u", ((char*)ptr) -
sizeof(size_t), (unsigned int) free_amount);
}
(persistent) ? free(REAL_PTR(ptr)) : _efree(REAL_PTR(ptr)
ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}
@@ -336,7 +338,7 @@ void _mysqlnd_pefree(void *ptr, zend_bool persistent
MYSQLND_MEM_D)
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(persistent?
STAT_MEM_FREE_COUNT:STAT_MEM_EFREE_COUNT, 1,
persistent? STAT_MEM_FREE_AMOUNT:STAT_MEM_EFREE_AMOUNT, free_amount);
}
- DBG_VOID_RETURN;
+ TRACE_ALLOC_VOID_RETURN;
}
/* }}} */
@@ -349,8 +351,8 @@ void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D)
#if PHP_DEBUG
long * threshold = &MYSQLND_G(debug_malloc_fail_threshold);
#endif
- DBG_ENTER(mysqlnd_malloc_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_ENTER(mysqlnd_malloc_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
#if PHP_DEBUG
/* -1 is also "true" */
@@ -364,12 +366,12 @@ void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D)
}
#endif
- DBG_INF_FMT("size=%lu ptr=%p", size, ret);
+ TRACE_ALLOC_INF_FMT("size=%lu ptr=%p", size, ret);
if (ret && collect_memory_statistics) {
*(size_t *) ret = size;
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_MALLOC_COUNT, 1,
STAT_MEM_MALLOC_AMOUNT, size);
}
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
@@ -382,8 +384,8 @@ void * _mysqlnd_calloc(unsigned int nmemb, size_t size
MYSQLND_MEM_D)
#if PHP_DEBUG
long * threshold = &MYSQLND_G(debug_calloc_fail_threshold);
#endif
- DBG_ENTER(mysqlnd_calloc_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_ENTER(mysqlnd_calloc_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
#if PHP_DEBUG
/* -1 is also "true" */
@@ -397,12 +399,12 @@ void * _mysqlnd_calloc(unsigned int nmemb, size_t size
MYSQLND_MEM_D)
}
#endif
- DBG_INF_FMT("size=%lu ptr=%p", size, ret);
+ TRACE_ALLOC_INF_FMT("size=%lu ptr=%p", size, ret);
if (ret && collect_memory_statistics) {
*(size_t *) ret = size;
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_CALLOC_COUNT, 1,
STAT_MEM_CALLOC_AMOUNT, size);
}
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
@@ -415,10 +417,10 @@ void * _mysqlnd_realloc(void *ptr, size_t new_size
MYSQLND_MEM_D)
#if PHP_DEBUG
long * threshold = &MYSQLND_G(debug_realloc_fail_threshold);
#endif
- DBG_ENTER(mysqlnd_realloc_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
- DBG_INF_FMT("ptr=%p new_size=%lu ", new_size, ptr);
- DBG_INF_FMT("before: %lu", zend_memory_usage(TRUE TSRMLS_CC));
+ TRACE_ALLOC_ENTER(mysqlnd_realloc_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_INF_FMT("ptr=%p new_size=%lu ", new_size, ptr);
+ TRACE_ALLOC_INF_FMT("before: %lu", zend_memory_usage(TRUE TSRMLS_CC));
#if PHP_DEBUG
/* -1 is also "true" */
@@ -432,13 +434,13 @@ void * _mysqlnd_realloc(void *ptr, size_t new_size
MYSQLND_MEM_D)
}
#endif
- DBG_INF_FMT("new_ptr=%p", (char*)ret);
+ TRACE_ALLOC_INF_FMT("new_ptr=%p", (char*)ret);
if (ret && collect_memory_statistics) {
*(size_t *) ret = new_size;
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_REALLOC_COUNT,
1, STAT_MEM_REALLOC_AMOUNT, new_size);
}
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
@@ -448,14 +450,14 @@ void _mysqlnd_free(void *ptr MYSQLND_MEM_D)
{
size_t free_amount = 0;
zend_bool collect_memory_statistics =
MYSQLND_G(collect_memory_statistics);
- DBG_ENTER(mysqlnd_free_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
- DBG_INF_FMT("ptr=%p", ptr);
+ TRACE_ALLOC_ENTER(mysqlnd_free_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_INF_FMT("ptr=%p", ptr);
if (ptr) {
if (collect_memory_statistics) {
free_amount = *(size_t *)(((char*)ptr) -
sizeof(size_t));
- DBG_INF_FMT("ptr=%p size=%u", ((char*)ptr) -
sizeof(size_t), (unsigned int) free_amount);
+ TRACE_ALLOC_INF_FMT("ptr=%p size=%u", ((char*)ptr) -
sizeof(size_t), (unsigned int) free_amount);
}
free(REAL_PTR(ptr));
}
@@ -463,7 +465,7 @@ void _mysqlnd_free(void *ptr MYSQLND_MEM_D)
if (collect_memory_statistics) {
MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_FREE_COUNT, 1,
STAT_MEM_FREE_AMOUNT, free_amount);
}
- DBG_VOID_RETURN;
+ TRACE_ALLOC_VOID_RETURN;
}
/* }}} */
@@ -477,9 +479,9 @@ char * _mysqlnd_pestrndup(const char * const ptr, size_t
length, zend_bool persi
{
char * ret;
zend_bool collect_memory_statistics =
MYSQLND_G(collect_memory_statistics);
- DBG_ENTER(mysqlnd_pestrndup_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
- DBG_INF_FMT("ptr=%p", ptr);
+ TRACE_ALLOC_ENTER(mysqlnd_pestrndup_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_INF_FMT("ptr=%p", ptr);
ret = (persistent) ? __zend_malloc(REAL_SIZE(length + 1)) :
_emalloc(REAL_SIZE(length + 1) ZEND_FILE_LINE_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
{
@@ -497,7 +499,7 @@ char * _mysqlnd_pestrndup(const char * const ptr, size_t
length, zend_bool persi
MYSQLND_INC_GLOBAL_STATISTIC(persistent? STAT_MEM_STRNDUP_COUNT
: STAT_MEM_ESTRNDUP_COUNT);
}
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
@@ -509,9 +511,9 @@ char * _mysqlnd_pestrdup(const char * const ptr, zend_bool
persistent MYSQLND_ME
smart_str tmp_str = {0, 0, 0};
const char * p = ptr;
zend_bool collect_memory_statistics =
MYSQLND_G(collect_memory_statistics);
- DBG_ENTER(mysqlnd_pestrdup_name);
- DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_orig_filename,
PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
- DBG_INF_FMT("ptr=%p", ptr);
+ TRACE_ALLOC_ENTER(mysqlnd_pestrdup_name);
+ TRACE_ALLOC_INF_FMT("file=%-15s line=%4d",
strrchr(__zend_orig_filename, PHP_DIR_SEPARATOR) + 1, __zend_orig_lineno);
+ TRACE_ALLOC_INF_FMT("ptr=%p", ptr);
do {
smart_str_appendc(&tmp_str, *p);
} while (*p++);
@@ -525,7 +527,7 @@ char * _mysqlnd_pestrdup(const char * const ptr, zend_bool
persistent MYSQLND_ME
}
smart_str_free(&tmp_str);
- DBG_RETURN(FAKE_PTR(ret));
+ TRACE_ALLOC_RETURN(FAKE_PTR(ret));
}
/* }}} */
diff --git a/ext/mysqlnd/mysqlnd_debug.c b/ext/mysqlnd/mysqlnd_debug.c
index 5c77b42..cf355d2 100644
--- a/ext/mysqlnd/mysqlnd_debug.c
+++ b/ext/mysqlnd/mysqlnd_debug.c
@@ -745,21 +745,26 @@ mysqlnd_debug_init(const char * skip_functions[]
TSRMLS_DC)
PHPAPI void _mysqlnd_debug(const char * mode TSRMLS_DC)
{
#if PHP_DEBUG
- MYSQLND_DEBUG *dbg = MYSQLND_G(dbg);
+ MYSQLND_DEBUG * dbg = MYSQLND_G(dbg);
if (!dbg) {
- MYSQLND_G(dbg) = dbg =
mysqlnd_debug_init(mysqlnd_debug_std_no_trace_funcs TSRMLS_CC);
- if (!dbg) {
- return;
+ struct st_mysqlnd_plugin_trace_log * trace_log_plugin =
mysqlnd_plugin_find("debug_trace");
+ if (trace_log_plugin) {
+ dbg =
trace_log_plugin->methods.trace_instance_init(mysqlnd_debug_std_no_trace_funcs
TSRMLS_CC);
+ if (!dbg) {
+ return;
+ }
+ MYSQLND_G(dbg) = dbg;
}
}
-
- dbg->m->close(dbg);
- dbg->m->set_mode(dbg, mode);
- while (zend_stack_count(&dbg->call_stack)) {
- zend_stack_del_top(&dbg->call_stack);
- }
- while (zend_stack_count(&dbg->call_time_stack)) {
- zend_stack_del_top(&dbg->call_time_stack);
+ if (dbg) {
+ dbg->m->close(dbg);
+ dbg->m->set_mode(dbg, mode);
+ while (zend_stack_count(&dbg->call_stack)) {
+ zend_stack_del_top(&dbg->call_stack);
+ }
+ while (zend_stack_count(&dbg->call_time_stack)) {
+ zend_stack_del_top(&dbg->call_time_stack);
+ }
}
#endif
}
diff --git a/ext/mysqlnd/mysqlnd_debug.h b/ext/mysqlnd/mysqlnd_debug.h
index 5d2d1d2..3441dc7 100644
--- a/ext/mysqlnd/mysqlnd_debug.h
+++ b/ext/mysqlnd/mysqlnd_debug.h
@@ -101,44 +101,63 @@ PHPAPI char * mysqlnd_get_backtrace(uint max_levels,
size_t * length TSRMLS_DC);
#define DBG_INF_FMT_EX(dbg_obj, ...) do { if (dbg_skip_trace == FALSE)
(dbg_obj)->m->log_va((dbg_obj), __LINE__, __FILE__, -1, "info : ",
__VA_ARGS__); } while (0)
#define DBG_ERR_FMT_EX(dbg_obj, ...) do { if (dbg_skip_trace == FALSE)
(dbg_obj)->m->log_va((dbg_obj), __LINE__, __FILE__, -1, "error: ",
__VA_ARGS__); } while (0)
-#define DBG_BLOCK_ENTER_EX(dbg_obj, block_name) \
+#define DBG_BLOCK_ENTER_EX(dbg_obj, block_name) DBG_BLOCK_ENTER_EX2((dbg_obj),
NULL, (block_name))
+#define DBG_BLOCK_LEAVE_EX(dbg_obj)
DBG_BLOCK_LEAVE_EX2((dbg_obj))
+
+#define DBG_BLOCK_ENTER_EX2(dbg_obj1, dbg_obj2, block_name) \
{ \
- DBG_ENTER_EX(dbg_obj, (block_name));
+ DBG_ENTER_EX2((dbg_obj1), (db_obj2), (block_name));
-#define DBG_BLOCK_LEAVE_EX(dbg_obj) \
- DBG_LEAVE_EX((dbg_obj), ;) \
+#define DBG_BLOCK_LEAVE_EX2(dbg_obj1, dbg_obj2) \
+ DBG_LEAVE_EX2((dbg_obj1), (dbg_obj2), ;) \
} \
-#define DBG_ENTER_EX(dbg_obj, func_name) \
+#define DBG_ENTER_EX(dbg_obj, func_name) DBG_ENTER_EX2((dbg_obj),
(MYSQLND_DEBUG *) NULL, (func_name))
+#define DBG_LEAVE_EX(dbg_obj, leave) DBG_LEAVE_EX2((dbg_obj),
(MYSQLND_DEBUG *) NULL, leave)
+
+#define DBG_ENTER_EX2(dbg_obj1, dbg_obj2, func_name) \
struct timeval __dbg_prof_tp = {0}; \
uint64_t __dbg_prof_start = 0; /*
initialization is needed */ \
zend_bool dbg_skip_trace = TRUE; \
- if ((dbg_obj)) { \
- dbg_skip_trace =
!(dbg_obj)->m->func_enter((dbg_obj), __LINE__, __FILE__, func_name,
strlen(func_name)); \
+ if ((dbg_obj1)) { \
+ dbg_skip_trace =
!(dbg_obj1)->m->func_enter((dbg_obj1), __LINE__, __FILE__, func_name,
strlen(func_name)); \
+ } \
+ if ((dbg_obj2)) { \
+ dbg_skip_trace =
!(dbg_obj2)->m->func_enter((dbg_obj2), __LINE__, __FILE__, func_name,
strlen(func_name)); \
} \
- if (dbg_skip_trace); /* shut compiler's
mouth */ \
+ if (dbg_skip_trace); /* shut compiler's
mouth */\
do { \
- if ((dbg_obj) &&
(dbg_obj)->flags & MYSQLND_DEBUG_PROFILE_CALLS) { \
+ if (((dbg_obj1) &&
(dbg_obj1)->flags & MYSQLND_DEBUG_PROFILE_CALLS) || \
+ ((dbg_obj2) &&
(dbg_obj2)->flags & MYSQLND_DEBUG_PROFILE_CALLS)) \
+ { \
DBG_PROFILE_START_TIME(); \
} \
} while (0);
-#define DBG_LEAVE_EX(dbg_obj, leave) \
+#define DBG_LEAVE_EX2(dbg_obj1, dbg_obj2, leave) \
do {\
- if ((dbg_obj)) { \
- uint64_t this_call_duration = 0; \
- if ((dbg_obj)->flags &
MYSQLND_DEBUG_PROFILE_CALLS) { \
-
DBG_PROFILE_END_TIME(this_call_duration); \
- } \
- (dbg_obj)->m->func_leave((dbg_obj),
__LINE__, __FILE__, this_call_duration); \
+ uint64_t this_call_duration = 0; \
+ if (((dbg_obj1) && (dbg_obj1)->flags &
MYSQLND_DEBUG_PROFILE_CALLS) || \
+ ((dbg_obj2) && (dbg_obj2)->flags &
MYSQLND_DEBUG_PROFILE_CALLS)) \
+ { \
+
DBG_PROFILE_END_TIME(this_call_duration); \
+ } \
+ if ((dbg_obj1)) { \
+ (dbg_obj1)->m->func_leave((dbg_obj1),
__LINE__, __FILE__, this_call_duration); \
+ } \
+ if ((dbg_obj2)) { \
+ (dbg_obj2)->m->func_leave((dbg_obj2),
__LINE__, __FILE__, this_call_duration); \
} \
leave \
} while (0);
-#define DBG_RETURN_EX(dbg_obj, value) DBG_LEAVE_EX(dbg_obj, return (value);)
-#define DBG_VOID_RETURN_EX(dbg_obj) DBG_LEAVE_EX(dbg_obj, return;)
+#define DBG_RETURN_EX(dbg_obj, value) DBG_LEAVE_EX((dbg_obj), return
(value);)
+#define DBG_VOID_RETURN_EX(dbg_obj) DBG_LEAVE_EX((dbg_obj),
return;)
+
+#define DBG_RETURN_EX2(dbg_obj1, dbg_obj2, value)
DBG_LEAVE_EX2((dbg_obj1), (dbg_obj2), return (value);)
+#define DBG_VOID_RETURN_EX2(dbg_obj1, dbg_obj2)
DBG_LEAVE_EX2((dbg_obj1), (dbg_obj2), return;)
@@ -168,6 +187,18 @@ static inline void DBG_ENTER_EX(MYSQLND_DEBUG * dbg_obj,
const char * const func
#define DBG_VOID_RETURN
DBG_VOID_RETURN_EX(MYSQLND_G(dbg))
#define DBG_BLOCK_LEAVE
DBG_BLOCK_LEAVE_EX(MYSQLND_G(dbg))
+
+#define TRACE_ALLOC_INF(msg)
DBG_INF_EX(MYSQLND_G(trace_alloc), (msg))
+#define TRACE_ALLOC_ERR(msg)
DBG_ERR_EX(MYSQLND_G(trace_alloc), (msg))
+#define TRACE_ALLOC_INF_FMT(...)
DBG_INF_FMT_EX(MYSQLND_G(trace_alloc), __VA_ARGS__)
+#define TRACE_ALLOC_ERR_FMT(...)
DBG_ERR_FMT_EX(MYSQLND_G(trace_alloc), __VA_ARGS__)
+
+#define TRACE_ALLOC_ENTER(func_name) DBG_ENTER_EX2(MYSQLND_G(dbg),
MYSQLND_G(trace_alloc), (func_name))
+#define TRACE_ALLOC_BLOCK_ENTER(bname) DBG_BLOCK_ENTER_EX2(MYSQLND_G(dbg),
MYSQLND_G(trace_alloc), (bname))
+#define TRACE_ALLOC_RETURN(value) DBG_RETURN_EX2(MYSQLND_G(dbg),
MYSQLND_G(trace_alloc), (value))
+#define TRACE_ALLOC_VOID_RETURN
DBG_VOID_RETURN_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc))
+#define TRACE_ALLOC_BLOCK_LEAVE
DBG_BLOCK_LEAVE_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc))
+
#elif MYSQLND_DBG_ENABLED == 0
static inline void DBG_INF(const char * const msg) {}
@@ -176,10 +207,21 @@ static inline void DBG_INF_FMT(const char * const format,
...) {}
static inline void DBG_ERR_FMT(const char * const format, ...) {}
static inline void DBG_ENTER(const char * const func_name) {}
#define DBG_BLOCK_ENTER(bname) {
-#define DBG_RETURN(value) return (value)
-#define DBG_VOID_RETURN return
+#define DBG_RETURN(value) return (value)
+#define DBG_VOID_RETURN return
#define DBG_BLOCK_LEAVE }
+
+static inline void TRACE_ALLOC_INF(const char * const msg) {}
+static inline void TRACE_ALLOC_ERR(const char * const msg) {}
+static inline void TRACE_ALLOC_INF_FMT(const char * const format, ...) {}
+static inline void TRACE_ALLOC_ERR_FMT(const char * const format, ...) {}
+static inline void TRACE_ALLOC_ENTER(const char * const func_name) {}
+#define TRACE_ALLOC_BLOCK_ENTER(bname) {
+#define TRACE_ALLOC_RETURN(value) return (value)
+#define TRACE_ALLOC_VOID_RETURN return
+#define TRACE_ALLOC_BLOCK_LEAVE }
+
#endif
#endif /* MYSQLND_DEBUG_H */
diff --git a/ext/mysqlnd/php_mysqlnd.c b/ext/mysqlnd/php_mysqlnd.c
index 20fcc5e..0a8fd60 100644
--- a/ext/mysqlnd/php_mysqlnd.c
+++ b/ext/mysqlnd/php_mysqlnd.c
@@ -221,6 +221,8 @@ static PHP_GINIT_FUNCTION(mysqlnd)
mysqlnd_globals->collect_memory_statistics = FALSE;
mysqlnd_globals->debug = NULL; /* The actual string */
mysqlnd_globals->dbg = NULL; /* The DBG object*/
+ mysqlnd_globals->trace_alloc_settings = NULL;
+ mysqlnd_globals->trace_alloc = NULL;
mysqlnd_globals->net_cmd_buffer_size = MYSQLND_NET_CMD_BUFFER_MIN_SIZE;
mysqlnd_globals->net_read_buffer_size = 32768;
mysqlnd_globals->net_read_timeout = 31536000;
@@ -253,6 +255,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("mysqlnd.collect_statistics", "1",
PHP_INI_ALL, OnUpdateBool, collect_statistics, zend_mysqlnd_globals,
mysqlnd_globals)
STD_PHP_INI_BOOLEAN("mysqlnd.collect_memory_statistics", "0",
PHP_INI_SYSTEM, OnUpdateBool, collect_memory_statistics,
zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.debug",
NULL, PHP_INI_SYSTEM, OnUpdateString, debug, zend_mysqlnd_globals,
mysqlnd_globals)
+ STD_PHP_INI_ENTRY("mysqlnd.trace_alloc", NULL,
PHP_INI_SYSTEM, OnUpdateString, trace_alloc_settings, zend_mysqlnd_globals,
mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.net_cmd_buffer_size",
MYSQLND_NET_CMD_BUFFER_MIN_SIZE_STR, PHP_INI_ALL,
OnUpdateNetCmdBufferSize, net_cmd_buffer_size, zend_mysqlnd_globals,
mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.net_read_buffer_size",
"32768",PHP_INI_ALL, OnUpdateLong, net_read_buffer_size,
zend_mysqlnd_globals, mysqlnd_globals)
STD_PHP_INI_ENTRY("mysqlnd.net_read_timeout", "31536000",
PHP_INI_SYSTEM, OnUpdateLong, net_read_timeout, zend_mysqlnd_globals,
mysqlnd_globals)
@@ -306,11 +309,14 @@ static PHP_RINIT_FUNCTION(mysqlnd)
MYSQLND_G(dbg) = NULL;
if (trace_log_plugin) {
MYSQLND_DEBUG * dbg =
trace_log_plugin->methods.trace_instance_init(mysqlnd_debug_std_no_trace_funcs
TSRMLS_CC);
- if (!dbg) {
+ MYSQLND_DEBUG * trace_alloc =
trace_log_plugin->methods.trace_instance_init(NULL TSRMLS_CC);
+ if (!dbg || !trace_alloc) {
return FAILURE;
}
dbg->m->set_mode(dbg, MYSQLND_G(debug));
+ trace_alloc->m->set_mode(trace_alloc,
MYSQLND_G(trace_alloc_settings));
MYSQLND_G(dbg) = dbg;
+ MYSQLND_G(trace_alloc) = trace_alloc;
}
}
return SUCCESS;
@@ -324,13 +330,19 @@ static PHP_RINIT_FUNCTION(mysqlnd)
*/
static PHP_RSHUTDOWN_FUNCTION(mysqlnd)
{
- MYSQLND_DEBUG *dbg = MYSQLND_G(dbg);
+ MYSQLND_DEBUG * dbg = MYSQLND_G(dbg);
+ MYSQLND_DEBUG * trace_alloc = MYSQLND_G(trace_alloc);
DBG_ENTER("RSHUTDOWN");
if (dbg) {
dbg->m->close(dbg);
dbg->m->free_handle(dbg);
MYSQLND_G(dbg) = NULL;
}
+ if (trace_alloc) {
+ trace_alloc->m->close(trace_alloc);
+ trace_alloc->m->free_handle(trace_alloc);
+ MYSQLND_G(trace_alloc) = NULL;
+ }
return SUCCESS;
}
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php