Annotation of embedaddon/php/ext/mysqlnd/mysqlnd_debug.h, revision 1.1.1.1
1.1 misho 1: /*
2: +----------------------------------------------------------------------+
3: | PHP Version 5 |
4: +----------------------------------------------------------------------+
5: | Copyright (c) 2006-2012 The PHP Group |
6: +----------------------------------------------------------------------+
7: | This source file is subject to version 3.01 of the PHP license, |
8: | that is bundled with this package in the file LICENSE, and is |
9: | available through the world-wide-web at the following url: |
10: | http://www.php.net/license/3_01.txt |
11: | If you did not receive a copy of the PHP license and are unable to |
12: | obtain it through the world-wide-web, please send a note to |
13: | license@php.net so we can mail you a copy immediately. |
14: +----------------------------------------------------------------------+
15: | Authors: Georg Richter <georg@mysql.com> |
16: | Andrey Hristov <andrey@mysql.com> |
17: | Ulf Wendel <uwendel@mysql.com> |
18: +----------------------------------------------------------------------+
19: */
20:
21: /* $Id: mysqlnd_debug.h 321634 2012-01-01 13:15:04Z felipe $ */
22:
23: #ifndef MYSQLND_DEBUG_H
24: #define MYSQLND_DEBUG_H
25:
26: #include "zend_stack.h"
27:
28: struct st_mysqlnd_debug_methods
29: {
30: enum_func_status (*open)(MYSQLND_DEBUG * self, zend_bool reopen);
31: void (*set_mode)(MYSQLND_DEBUG * self, const char * const mode);
32: enum_func_status (*log)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
33: unsigned int level, const char * type, const char *message);
34: enum_func_status (*log_va)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
35: unsigned int level, const char * type, const char *format, ...);
36: zend_bool (*func_enter)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
37: const char * const func_name, unsigned int func_name_len);
38: enum_func_status (*func_leave)(MYSQLND_DEBUG * self, unsigned int line, const char * const file, uint64_t call_time);
39: enum_func_status (*close)(MYSQLND_DEBUG * self);
40: enum_func_status (*free_handle)(MYSQLND_DEBUG * self);
41: };
42:
43:
44: struct st_mysqlnd_debug
45: {
46: php_stream *stream;
47: #ifdef ZTS
48: TSRMLS_D;
49: #endif
50: unsigned int flags;
51: unsigned int nest_level_limit;
52: int pid;
53: char * file_name;
54: zend_stack call_stack;
55: zend_stack call_time_stack;
56: HashTable not_filtered_functions;
57: HashTable function_profiles;
58: struct st_mysqlnd_debug_methods *m;
59: const char ** skip_functions;
60: };
61:
62: PHPAPI extern const char * mysqlnd_debug_std_no_trace_funcs[];
63:
64: PHPAPI MYSQLND_DEBUG * mysqlnd_debug_init(const char * skip_functions[] TSRMLS_DC);
65:
66: PHPAPI char * mysqlnd_get_backtrace(uint max_levels, size_t * length TSRMLS_DC);
67:
68: #if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 1400))
69: #ifdef PHP_WIN32
70: #include "win32/time.h"
71: #elif defined(NETWARE)
72: #include <sys/timeval.h>
73: #include <sys/time.h>
74: #else
75: #include <sys/time.h>
76: #endif
77:
78: #ifndef MYSQLND_PROFILING_DISABLED
79: #define DBG_PROFILE_TIMEVAL_TO_DOUBLE(tp) ((tp.tv_sec * 1000000LL)+ tp.tv_usec)
80: #define DBG_PROFILE_START_TIME() gettimeofday(&__dbg_prof_tp, NULL); __dbg_prof_start = DBG_PROFILE_TIMEVAL_TO_DOUBLE(__dbg_prof_tp);
81: #define DBG_PROFILE_END_TIME(duration) gettimeofday(&__dbg_prof_tp, NULL); (duration) = (DBG_PROFILE_TIMEVAL_TO_DOUBLE(__dbg_prof_tp) - __dbg_prof_start);
82: #else
83: #define DBG_PROFILE_TIMEVAL_TO_DOUBLE(tp)
84: #define DBG_PROFILE_START_TIME()
85: #define DBG_PROFILE_END_TIME(duration)
86: #endif
87:
88: #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)
89: #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)
90: #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)
91: #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)
92:
93: #define DBG_BLOCK_ENTER_EX(dbg_obj, block_name) \
94: { \
95: DBG_ENTER_EX(dbg_obj, (block_name));
96:
97: #define DBG_BLOCK_LEAVE_EX(dbg_obj) \
98: DBG_LEAVE_EX((dbg_obj), ;) \
99: } \
100:
101:
102: #define DBG_ENTER_EX(dbg_obj, func_name) \
103: struct timeval __dbg_prof_tp = {0}; \
104: uint64_t __dbg_prof_start = 0; /* initialization is needed */ \
105: zend_bool dbg_skip_trace = TRUE; \
106: if ((dbg_obj)) { \
107: dbg_skip_trace = !(dbg_obj)->m->func_enter((dbg_obj), __LINE__, __FILE__, func_name, strlen(func_name)); \
108: } \
109: do { \
110: if ((dbg_obj) && (dbg_obj)->flags & MYSQLND_DEBUG_PROFILE_CALLS) { \
111: DBG_PROFILE_START_TIME(); \
112: } \
113: } while (0);
114:
115: #define DBG_LEAVE_EX(dbg_obj, leave) \
116: do {\
117: if ((dbg_obj)) { \
118: uint64_t this_call_duration = 0; \
119: if ((dbg_obj)->flags & MYSQLND_DEBUG_PROFILE_CALLS) { \
120: DBG_PROFILE_END_TIME(this_call_duration); \
121: } \
122: (dbg_obj)->m->func_leave((dbg_obj), __LINE__, __FILE__, this_call_duration); \
123: } \
124: leave \
125: } while (0);
126:
127: #define DBG_RETURN_EX(dbg_obj, value) DBG_LEAVE_EX(dbg_obj, return (value);)
128:
129: #define DBG_VOID_RETURN_EX(dbg_obj) DBG_LEAVE_EX(dbg_obj, return;)
130:
131:
132:
133: #else
134: static inline void DBG_INF_EX(MYSQLND_DEBUG * dbg_obj, const char * const msg) {}
135: static inline void DBG_ERR_EX(MYSQLND_DEBUG * dbg_obj, const char * const msg) {}
136: static inline void DBG_INF_FMT_EX(MYSQLND_DEBUG * dbg_obj, ...) {}
137: static inline void DBG_ERR_FMT_EX(MYSQLND_DEBUG * dbg_obj, ...) {}
138: static inline void DBG_ENTER_EX(MYSQLND_DEBUG * dbg_obj, const char * const func_name) {}
139: #define DBG_BLOCK_ENTER(bname) {
140: #define DBG_RETURN_EX(dbg_obj, value) return (value)
141: #define DBG_VOID_RETURN_EX(dbg_obj) return
142: #define DBG_BLOCK_LEAVE_EX(dbg_obj) }
143:
144: #endif /* defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 1400)) */
145:
146: #if MYSQLND_DBG_ENABLED == 1
147:
148: #define DBG_INF(msg) DBG_INF_EX(MYSQLND_G(dbg), (msg))
149: #define DBG_ERR(msg) DBG_ERR_EX(MYSQLND_G(dbg), (msg))
150: #define DBG_INF_FMT(...) DBG_INF_FMT_EX(MYSQLND_G(dbg), __VA_ARGS__)
151: #define DBG_ERR_FMT(...) DBG_ERR_FMT_EX(MYSQLND_G(dbg), __VA_ARGS__)
152:
153: #define DBG_ENTER(func_name) DBG_ENTER_EX(MYSQLND_G(dbg), (func_name))
154: #define DBG_BLOCK_ENTER(bname) DBG_BLOCK_ENTER_EX(MYSQLND_G(dbg), (bname))
155: #define DBG_RETURN(value) DBG_RETURN_EX(MYSQLND_G(dbg), (value))
156: #define DBG_VOID_RETURN DBG_VOID_RETURN_EX(MYSQLND_G(dbg))
157: #define DBG_BLOCK_LEAVE DBG_BLOCK_LEAVE_EX(MYSQLND_G(dbg))
158:
159: #elif MYSQLND_DBG_ENABLED == 0
160:
161:
162:
163: static inline void DBG_INF(const char * const msg) {}
164: static inline void DBG_ERR(const char * const msg) {}
165: static inline void DBG_INF_FMT(const char * const format, ...) {}
166: static inline void DBG_ERR_FMT(const char * const format, ...) {}
167: static inline void DBG_ENTER(const char * const func_name) {}
168: #define DBG_BLOCK_ENTER(bname) {
169: #define DBG_RETURN(value) return (value)
170: #define DBG_VOID_RETURN return
171: #define DBG_BLOCK_LEAVE }
172:
173: #endif
174:
175:
176: #define MYSQLND_MEM_D TSRMLS_DC ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC
177: #define MYSQLND_MEM_C TSRMLS_CC ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC
178:
179: struct st_mysqlnd_allocator_methods
180: {
181: void * (*m_emalloc)(size_t size MYSQLND_MEM_D);
182: void * (*m_pemalloc)(size_t size, zend_bool persistent MYSQLND_MEM_D);
183: void * (*m_ecalloc)(unsigned int nmemb, size_t size MYSQLND_MEM_D);
184: void * (*m_pecalloc)(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D);
185: void * (*m_erealloc)(void *ptr, size_t new_size MYSQLND_MEM_D);
186: void * (*m_perealloc)(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D);
187: void (*m_efree)(void *ptr MYSQLND_MEM_D);
188: void (*m_pefree)(void *ptr, zend_bool persistent MYSQLND_MEM_D);
189: void * (*m_malloc)(size_t size MYSQLND_MEM_D);
190: void * (*m_calloc)(unsigned int nmemb, size_t size MYSQLND_MEM_D);
191: void * (*m_realloc)(void *ptr, size_t new_size MYSQLND_MEM_D);
192: void (*m_free)(void *ptr MYSQLND_MEM_D);
193: char * (*m_pestrndup)(const char * const ptr, size_t size, zend_bool persistent MYSQLND_MEM_D);
194: char * (*m_pestrdup)(const char * const ptr, zend_bool persistent MYSQLND_MEM_D);
195: };
196:
197: PHPAPI extern struct st_mysqlnd_allocator_methods mysqlnd_allocator;
198:
199:
200: PHPAPI void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D);
201: PHPAPI void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D);
202: PHPAPI void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D);
203: PHPAPI void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D);
204: PHPAPI void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D);
205: PHPAPI void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D);
206: PHPAPI void _mysqlnd_efree(void *ptr MYSQLND_MEM_D);
207: PHPAPI void _mysqlnd_pefree(void *ptr, zend_bool persistent MYSQLND_MEM_D);
208: PHPAPI void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D);
209: PHPAPI void * _mysqlnd_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D);
210: PHPAPI void * _mysqlnd_realloc(void *ptr, size_t new_size MYSQLND_MEM_D);
211: PHPAPI void _mysqlnd_free(void *ptr MYSQLND_MEM_D);
212: PHPAPI char * _mysqlnd_pestrndup(const char * const ptr, size_t size, zend_bool persistent MYSQLND_MEM_D);
213: PHPAPI char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_MEM_D);
214:
215:
216: #define mnd_emalloc(size) mysqlnd_allocator.m_emalloc((size) MYSQLND_MEM_C)
217: #define mnd_pemalloc(size, pers) mysqlnd_allocator.m_pemalloc((size), (pers) MYSQLND_MEM_C)
218: #define mnd_ecalloc(nmemb, size) mysqlnd_allocator.m_ecalloc((nmemb), (size) MYSQLND_MEM_C)
219: #define mnd_pecalloc(nmemb, size, p) mysqlnd_allocator.m_pecalloc((nmemb), (size), (p) MYSQLND_MEM_C)
220: #define mnd_erealloc(ptr, new_size) mysqlnd_allocator.m_erealloc((ptr), (new_size) MYSQLND_MEM_C)
221: #define mnd_perealloc(ptr, new_size, p) mysqlnd_allocator.m_perealloc((ptr), (new_size), (p) MYSQLND_MEM_C)
222: #define mnd_efree(ptr) mysqlnd_allocator.m_efree((ptr) MYSQLND_MEM_C)
223: #define mnd_pefree(ptr, pers) mysqlnd_allocator.m_pefree((ptr), (pers) MYSQLND_MEM_C)
224: #define mnd_malloc(size) mysqlnd_allocator.m_malloc((size) MYSQLND_MEM_C)
225: #define mnd_calloc(nmemb, size) mysqlnd_allocator.m_calloc((nmemb), (size) MYSQLND_MEM_C)
226: #define mnd_realloc(ptr, new_size) mysqlnd_allocator.m_realloc((ptr), (new_size) MYSQLND_MEM_C)
227: #define mnd_free(ptr) mysqlnd_allocator.m_free((ptr) MYSQLND_MEM_C)
228: #define mnd_pestrndup(ptr, size, pers) mysqlnd_allocator.m_pestrndup((ptr), (size), (pers) MYSQLND_MEM_C)
229: #define mnd_pestrdup(ptr, pers) mysqlnd_allocator.m_pestrdup((ptr), (pers) MYSQLND_MEM_C)
230:
231: #endif /* MYSQLND_DEBUG_H */
232:
233: /*
234: * Local variables:
235: * tab-width: 4
236: * c-basic-offset: 4
237: * End:
238: * vim600: noet sw=4 ts=4 fdm=marker
239: * vim<600: noet sw=4 ts=4
240: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>