Back to index

php5  5.3.10
mysqlnd_debug.h
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 2006-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Authors: Georg Richter <georg@mysql.com>                             |
00016   |          Andrey Hristov <andrey@mysql.com>                           |
00017   |          Ulf Wendel <uwendel@mysql.com>                              |
00018   +----------------------------------------------------------------------+
00019 */
00020 
00021 /* $Id: mysqlnd_debug.h 321634 2012-01-01 13:15:04Z felipe $ */
00022 
00023 #ifndef MYSQLND_DEBUG_H
00024 #define MYSQLND_DEBUG_H
00025 
00026 #include "zend_stack.h"
00027 
00028 struct st_mysqlnd_debug_methods
00029 {
00030        enum_func_status (*open)(MYSQLND_DEBUG * self, zend_bool reopen);
00031        void                  (*set_mode)(MYSQLND_DEBUG * self, const char * const mode);
00032        enum_func_status (*log)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
00033                                                  unsigned int level, const char * type, const char *message);
00034        enum_func_status (*log_va)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
00035                                                     unsigned int level, const char * type, const char *format, ...);
00036        zend_bool (*func_enter)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
00037                                                  const char * const func_name, unsigned int func_name_len);
00038        enum_func_status (*func_leave)(MYSQLND_DEBUG * self, unsigned int line, const char * const file, uint64_t call_time);
00039        enum_func_status (*close)(MYSQLND_DEBUG * self);
00040        enum_func_status (*free_handle)(MYSQLND_DEBUG * self);
00041 };
00042 
00043 
00044 struct st_mysqlnd_debug
00045 {
00046        php_stream    *stream;
00047 #ifdef ZTS
00048        TSRMLS_D;
00049 #endif
00050        unsigned int flags;
00051        unsigned int nest_level_limit;
00052        int pid;
00053        char * file_name;
00054        zend_stack call_stack;
00055        zend_stack call_time_stack; 
00056        HashTable not_filtered_functions;
00057        HashTable function_profiles;
00058        struct st_mysqlnd_debug_methods *m;
00059        const char ** skip_functions;
00060 };
00061 
00062 PHPAPI extern const char * mysqlnd_debug_std_no_trace_funcs[];
00063 
00064 PHPAPI MYSQLND_DEBUG * mysqlnd_debug_init(const char * skip_functions[] TSRMLS_DC);
00065 
00066 PHPAPI char * mysqlnd_get_backtrace(uint max_levels, size_t * length TSRMLS_DC);
00067 
00068 #if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 1400))
00069 #ifdef PHP_WIN32
00070 #include "win32/time.h"
00071 #elif defined(NETWARE)
00072 #include <sys/timeval.h>
00073 #include <sys/time.h>
00074 #else
00075 #include <sys/time.h>
00076 #endif
00077 
00078 #ifndef MYSQLND_PROFILING_DISABLED
00079 #define DBG_PROFILE_TIMEVAL_TO_DOUBLE(tp) ((tp.tv_sec * 1000000LL)+ tp.tv_usec)
00080 #define DBG_PROFILE_START_TIME()          gettimeofday(&__dbg_prof_tp, NULL); __dbg_prof_start = DBG_PROFILE_TIMEVAL_TO_DOUBLE(__dbg_prof_tp);
00081 #define DBG_PROFILE_END_TIME(duration)    gettimeofday(&__dbg_prof_tp, NULL); (duration) = (DBG_PROFILE_TIMEVAL_TO_DOUBLE(__dbg_prof_tp) - __dbg_prof_start);
00082 #else
00083 #define DBG_PROFILE_TIMEVAL_TO_DOUBLE(tp)
00084 #define DBG_PROFILE_START_TIME()
00085 #define DBG_PROFILE_END_TIME(duration)
00086 #endif
00087 
00088 #define DBG_INF_EX(dbg_obj, msg)          do { if (dbg_skip_trace == FALSE) (dbg_obj)->m->log((dbg_obj), __LINE__, __FILE__, -1, "info : ", (msg)); } while (0)
00089 #define DBG_ERR_EX(dbg_obj, msg)          do { if (dbg_skip_trace == FALSE) (dbg_obj)->m->log((dbg_obj), __LINE__, __FILE__, -1, "error: ", (msg)); } while (0)
00090 #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)
00091 #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)
00092 
00093 #define DBG_BLOCK_ENTER_EX(dbg_obj, block_name) \
00094               { \
00095                      DBG_ENTER_EX(dbg_obj, (block_name));
00096 
00097 #define DBG_BLOCK_LEAVE_EX(dbg_obj) \
00098                      DBG_LEAVE_EX((dbg_obj), ;) \
00099               } \
00100        
00101 
00102 #define DBG_ENTER_EX(dbg_obj, func_name) \
00103                                    struct timeval __dbg_prof_tp = {0}; \
00104                                    uint64_t __dbg_prof_start = 0; /* initialization is needed */ \
00105                                    zend_bool dbg_skip_trace = TRUE; \
00106                                    if ((dbg_obj)) { \
00107                                           dbg_skip_trace = !(dbg_obj)->m->func_enter((dbg_obj), __LINE__, __FILE__, func_name, strlen(func_name)); \
00108                                    } \
00109                                    do { \
00110                                           if ((dbg_obj) && (dbg_obj)->flags & MYSQLND_DEBUG_PROFILE_CALLS) { \
00111                                                  DBG_PROFILE_START_TIME(); \
00112                                           } \
00113                                    } while (0); 
00114 
00115 #define DBG_LEAVE_EX(dbg_obj, leave)      \
00116                      do {\
00117                             if ((dbg_obj)) { \
00118                                    uint64_t this_call_duration = 0; \
00119                                    if ((dbg_obj)->flags & MYSQLND_DEBUG_PROFILE_CALLS) { \
00120                                           DBG_PROFILE_END_TIME(this_call_duration); \
00121                                    } \
00122                                    (dbg_obj)->m->func_leave((dbg_obj), __LINE__, __FILE__, this_call_duration); \
00123                             } \
00124                             leave \
00125                      } while (0);
00126 
00127 #define DBG_RETURN_EX(dbg_obj, value) DBG_LEAVE_EX(dbg_obj, return (value);)
00128 
00129 #define DBG_VOID_RETURN_EX(dbg_obj) DBG_LEAVE_EX(dbg_obj, return;)
00130 
00131 
00132 
00133 #else
00134 static inline void DBG_INF_EX(MYSQLND_DEBUG * dbg_obj, const char * const msg) {}
00135 static inline void DBG_ERR_EX(MYSQLND_DEBUG * dbg_obj, const char * const msg) {}
00136 static inline void DBG_INF_FMT_EX(MYSQLND_DEBUG * dbg_obj, ...) {}
00137 static inline void DBG_ERR_FMT_EX(MYSQLND_DEBUG * dbg_obj, ...) {}
00138 static inline void DBG_ENTER_EX(MYSQLND_DEBUG * dbg_obj, const char * const func_name) {}
00139 #define DBG_BLOCK_ENTER(bname)                   {
00140 #define DBG_RETURN_EX(dbg_obj, value)     return (value)
00141 #define DBG_VOID_RETURN_EX(dbg_obj)              return
00142 #define DBG_BLOCK_LEAVE_EX(dbg_obj)              }
00143 
00144 #endif /* defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 1400)) */
00145 
00146 #if MYSQLND_DBG_ENABLED == 1
00147 
00148 #define DBG_INF(msg)        DBG_INF_EX(MYSQLND_G(dbg), (msg))
00149 #define DBG_ERR(msg)        DBG_ERR_EX(MYSQLND_G(dbg), (msg))
00150 #define DBG_INF_FMT(...)    DBG_INF_FMT_EX(MYSQLND_G(dbg), __VA_ARGS__)
00151 #define DBG_ERR_FMT(...)    DBG_ERR_FMT_EX(MYSQLND_G(dbg), __VA_ARGS__)
00152 
00153 #define DBG_ENTER(func_name)       DBG_ENTER_EX(MYSQLND_G(dbg), (func_name))
00154 #define DBG_BLOCK_ENTER(bname)     DBG_BLOCK_ENTER_EX(MYSQLND_G(dbg), (bname))
00155 #define DBG_RETURN(value)          DBG_RETURN_EX(MYSQLND_G(dbg), (value))
00156 #define DBG_VOID_RETURN                   DBG_VOID_RETURN_EX(MYSQLND_G(dbg))
00157 #define DBG_BLOCK_LEAVE                   DBG_BLOCK_LEAVE_EX(MYSQLND_G(dbg))
00158 
00159 #elif MYSQLND_DBG_ENABLED == 0
00160 
00161 
00162 
00163 static inline void DBG_INF(const char * const msg) {}
00164 static inline void DBG_ERR(const char * const msg) {}
00165 static inline void DBG_INF_FMT(const char * const format, ...) {}
00166 static inline void DBG_ERR_FMT(const char * const format, ...) {}
00167 static inline void DBG_ENTER(const char * const func_name) {}
00168 #define DBG_BLOCK_ENTER(bname)     {
00169 #define DBG_RETURN(value)          return (value)
00170 #define DBG_VOID_RETURN                   return
00171 #define DBG_BLOCK_LEAVE                   }
00172 
00173 #endif
00174 
00175 
00176 #define MYSQLND_MEM_D       TSRMLS_DC ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC
00177 #define MYSQLND_MEM_C       TSRMLS_CC ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC
00178 
00179 struct st_mysqlnd_allocator_methods
00180 {
00181        void * (*m_emalloc)(size_t size MYSQLND_MEM_D);
00182        void * (*m_pemalloc)(size_t size, zend_bool persistent MYSQLND_MEM_D);
00183        void * (*m_ecalloc)(unsigned int nmemb, size_t size MYSQLND_MEM_D);
00184        void * (*m_pecalloc)(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D);
00185        void * (*m_erealloc)(void *ptr, size_t new_size MYSQLND_MEM_D);
00186        void * (*m_perealloc)(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D);
00187        void   (*m_efree)(void *ptr MYSQLND_MEM_D);
00188        void   (*m_pefree)(void *ptr, zend_bool persistent MYSQLND_MEM_D);
00189        void * (*m_malloc)(size_t size MYSQLND_MEM_D);
00190        void * (*m_calloc)(unsigned int nmemb, size_t size MYSQLND_MEM_D);
00191        void * (*m_realloc)(void *ptr, size_t new_size MYSQLND_MEM_D);
00192        void   (*m_free)(void *ptr MYSQLND_MEM_D);
00193        char * (*m_pestrndup)(const char * const ptr, size_t size, zend_bool persistent MYSQLND_MEM_D);
00194        char * (*m_pestrdup)(const char * const ptr, zend_bool persistent MYSQLND_MEM_D);
00195 };
00196 
00197 PHPAPI extern struct st_mysqlnd_allocator_methods mysqlnd_allocator;
00198 
00199 
00200 PHPAPI void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D);
00201 PHPAPI void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D);
00202 PHPAPI void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D);
00203 PHPAPI void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D);
00204 PHPAPI void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D);
00205 PHPAPI void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D);
00206 PHPAPI void          _mysqlnd_efree(void *ptr MYSQLND_MEM_D);
00207 PHPAPI void          _mysqlnd_pefree(void *ptr, zend_bool persistent MYSQLND_MEM_D);
00208 PHPAPI void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D);
00209 PHPAPI void * _mysqlnd_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D);
00210 PHPAPI void * _mysqlnd_realloc(void *ptr, size_t new_size MYSQLND_MEM_D);
00211 PHPAPI void          _mysqlnd_free(void *ptr MYSQLND_MEM_D);
00212 PHPAPI char * _mysqlnd_pestrndup(const char * const ptr, size_t size, zend_bool persistent MYSQLND_MEM_D);
00213 PHPAPI char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_MEM_D);
00214 
00215 
00216 #define mnd_emalloc(size)                        mysqlnd_allocator.m_emalloc((size) MYSQLND_MEM_C)
00217 #define mnd_pemalloc(size, pers)          mysqlnd_allocator.m_pemalloc((size), (pers) MYSQLND_MEM_C)
00218 #define mnd_ecalloc(nmemb, size)          mysqlnd_allocator.m_ecalloc((nmemb), (size) MYSQLND_MEM_C)
00219 #define mnd_pecalloc(nmemb, size, p)      mysqlnd_allocator.m_pecalloc((nmemb), (size), (p) MYSQLND_MEM_C)
00220 #define mnd_erealloc(ptr, new_size)              mysqlnd_allocator.m_erealloc((ptr), (new_size) MYSQLND_MEM_C)
00221 #define mnd_perealloc(ptr, new_size, p)   mysqlnd_allocator.m_perealloc((ptr), (new_size), (p) MYSQLND_MEM_C)
00222 #define mnd_efree(ptr)                                  mysqlnd_allocator.m_efree((ptr) MYSQLND_MEM_C)
00223 #define mnd_pefree(ptr, pers)                    mysqlnd_allocator.m_pefree((ptr), (pers) MYSQLND_MEM_C)
00224 #define mnd_malloc(size)                         mysqlnd_allocator.m_malloc((size) MYSQLND_MEM_C)
00225 #define mnd_calloc(nmemb, size)                  mysqlnd_allocator.m_calloc((nmemb), (size) MYSQLND_MEM_C)
00226 #define mnd_realloc(ptr, new_size)        mysqlnd_allocator.m_realloc((ptr), (new_size) MYSQLND_MEM_C)
00227 #define mnd_free(ptr)                                   mysqlnd_allocator.m_free((ptr) MYSQLND_MEM_C)
00228 #define mnd_pestrndup(ptr, size, pers)    mysqlnd_allocator.m_pestrndup((ptr), (size), (pers) MYSQLND_MEM_C)
00229 #define mnd_pestrdup(ptr, pers)                  mysqlnd_allocator.m_pestrdup((ptr), (pers) MYSQLND_MEM_C)
00230 
00231 #endif /* MYSQLND_DEBUG_H */
00232 
00233 /*
00234  * Local variables:
00235  * tab-width: 4
00236  * c-basic-offset: 4
00237  * End:
00238  * vim600: noet sw=4 ts=4 fdm=marker
00239  * vim<600: noet sw=4 ts=4
00240  */