php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
mysqlnd_debug.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Andrey Hristov <andrey@php.net> |
14 | Ulf Wendel <uw@php.net> |
15 +----------------------------------------------------------------------+
16*/
17
18#ifndef MYSQLND_DEBUG_H
19#define MYSQLND_DEBUG_H
20
21#include "mysqlnd_alloc.h"
22#include "zend_stack.h"
23
25{
26 enum_func_status (*open)(MYSQLND_DEBUG * self, bool reopen);
27 void (*set_mode)(MYSQLND_DEBUG * self, const char * const mode);
28 enum_func_status (*log)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
29 unsigned int level, const char * type, const char *message);
31 MYSQLND_DEBUG * self, unsigned int line, const char * const file,
32 unsigned int level, const char * type, const char *format, ...)
34 bool (*func_enter)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
35 const char * const func_name, unsigned int func_name_len);
36 enum_func_status (*func_leave)(MYSQLND_DEBUG * self, unsigned int line, const char * const file, uint64_t call_time);
39};
40
41
56
58{
60 struct
61 {
62 MYSQLND_DEBUG * (*trace_instance_init)(const char * skip_functions[]);
64};
65
67
68PHPAPI MYSQLND_DEBUG * mysqlnd_debug_init(const char * skip_functions[]);
69
70#define MYSQLND_DEBUG_DUMP_TIME 1
71#define MYSQLND_DEBUG_DUMP_TRACE 2
72#define MYSQLND_DEBUG_DUMP_PID 4
73#define MYSQLND_DEBUG_DUMP_LINE 8
74#define MYSQLND_DEBUG_DUMP_FILE 16
75#define MYSQLND_DEBUG_DUMP_LEVEL 32
76#define MYSQLND_DEBUG_APPEND 64
77#define MYSQLND_DEBUG_FLUSH 128
78#define MYSQLND_DEBUG_TRACE_MEMORY_CALLS 256
79#define MYSQLND_DEBUG_PROFILE_CALLS 512
80
81
82#if defined(__GNUC__) || defined(PHP_WIN32)
83#ifdef PHP_WIN32
84#include "win32/time.h"
85#else
86#include <sys/time.h>
87#endif
88
89#ifndef MYSQLND_PROFILING_DISABLED
90#define DBG_PROFILE_TIMEVAL_TO_DOUBLE(tp) ((tp.tv_sec * 1000000LL)+ tp.tv_usec)
91#define DBG_PROFILE_START_TIME() gettimeofday(&__dbg_prof_tp, NULL); __dbg_prof_start = DBG_PROFILE_TIMEVAL_TO_DOUBLE(__dbg_prof_tp);
92#define DBG_PROFILE_END_TIME(duration) gettimeofday(&__dbg_prof_tp, NULL); (duration) = (DBG_PROFILE_TIMEVAL_TO_DOUBLE(__dbg_prof_tp) - __dbg_prof_start);
93#else
94#define DBG_PROFILE_TIMEVAL_TO_DOUBLE(tp)
95#define DBG_PROFILE_START_TIME()
96#define DBG_PROFILE_END_TIME(duration)
97#endif
98
99#define DBG_INF_EX(dbg_obj, msg) do { if (dbg_skip_trace == FALSE && (dbg_obj)) (dbg_obj)->m->log((dbg_obj), __LINE__, __FILE__, -1, "info : ", (msg)); } while (0)
100#define DBG_ERR_EX(dbg_obj, msg) do { if (dbg_skip_trace == FALSE && (dbg_obj)) (dbg_obj)->m->log((dbg_obj), __LINE__, __FILE__, -1, "error: ", (msg)); } while (0)
101#define DBG_INF_FMT_EX(dbg_obj, ...) do { if (dbg_skip_trace == FALSE && (dbg_obj)) (dbg_obj)->m->log_va((dbg_obj), __LINE__, __FILE__, -1, "info : ", __VA_ARGS__); } while (0)
102#define DBG_ERR_FMT_EX(dbg_obj, ...) do { if (dbg_skip_trace == FALSE && (dbg_obj)) (dbg_obj)->m->log_va((dbg_obj), __LINE__, __FILE__, -1, "error: ", __VA_ARGS__); } while (0)
103
104#define DBG_BLOCK_ENTER_EX(dbg_obj, block_name) DBG_BLOCK_ENTER_EX2((dbg_obj), (MYSQLND_DEBUG *) NULL, (block_name))
105#define DBG_BLOCK_LEAVE_EX(dbg_obj) DBG_BLOCK_LEAVE_EX2((dbg_obj), (MYSQLND_DEBUG *) NULL)
106
107#define DBG_BLOCK_ENTER_EX2(dbg_obj1, dbg_obj2, block_name) \
108 { \
109 DBG_ENTER_EX2((dbg_obj1), (dbg_obj2), (block_name));
110
111#define DBG_BLOCK_LEAVE_EX2(dbg_obj1, dbg_obj2) \
112 DBG_LEAVE_EX2((dbg_obj1), (dbg_obj2), ;) \
113 } \
114
115
116#define DBG_ENTER_EX(dbg_obj, func_name) DBG_ENTER_EX2((dbg_obj), (MYSQLND_DEBUG *) NULL, (func_name))
117#define DBG_LEAVE_EX(dbg_obj, leave) DBG_LEAVE_EX2((dbg_obj), (MYSQLND_DEBUG *) NULL, leave)
118
119#define DBG_ENTER_EX2(dbg_obj1, dbg_obj2, func_name) \
120 struct timeval __dbg_prof_tp = {0}; \
121 uint64_t __dbg_prof_start = 0; /* initialization is needed */ \
122 bool dbg_skip_trace = TRUE; \
123 ((void)__dbg_prof_start); \
124 if ((dbg_obj1)) { \
125 dbg_skip_trace = !(dbg_obj1)->m->func_enter((dbg_obj1), __LINE__, __FILE__, func_name, strlen(func_name)); \
126 } \
127 if ((dbg_obj2)) { \
128 dbg_skip_trace |= !(dbg_obj2)->m->func_enter((dbg_obj2), __LINE__, __FILE__, func_name, strlen(func_name)); \
129 } \
130 if (dbg_skip_trace) { \
131 /* EMPTY */ ; /* shut compiler's mouth */ \
132 } \
133 do { \
134 if (((dbg_obj1) && ((dbg_obj1)->flags & MYSQLND_DEBUG_PROFILE_CALLS)) || \
135 ((dbg_obj2) && ((dbg_obj2)->flags & MYSQLND_DEBUG_PROFILE_CALLS))) \
136 { \
137 DBG_PROFILE_START_TIME(); \
138 } \
139 } while (0);
140
141#define DBG_LEAVE_EX2(dbg_obj1, dbg_obj2, leave) \
142 do { \
143 uint64_t this_call_duration = 0; \
144 if (((dbg_obj1) && ((dbg_obj1)->flags & MYSQLND_DEBUG_PROFILE_CALLS)) || \
145 ((dbg_obj2) && ((dbg_obj2)->flags & MYSQLND_DEBUG_PROFILE_CALLS))) \
146 { \
147 DBG_PROFILE_END_TIME(this_call_duration); \
148 } \
149 if ((dbg_obj1)) { \
150 (dbg_obj1)->m->func_leave((dbg_obj1), __LINE__, __FILE__, this_call_duration); \
151 } \
152 if ((dbg_obj2)) { \
153 (dbg_obj2)->m->func_leave((dbg_obj2), __LINE__, __FILE__, this_call_duration); \
154 } \
155 leave \
156 } while (0);
157
158
159#define DBG_RETURN_EX(dbg_obj, value) DBG_LEAVE_EX((dbg_obj), return (value);)
160#define DBG_VOID_RETURN_EX(dbg_obj) DBG_LEAVE_EX((dbg_obj), return;)
161
162#define DBG_RETURN_EX2(dbg_obj1, dbg_obj2, value) DBG_LEAVE_EX2((dbg_obj1), (dbg_obj2), return (value);)
163#define DBG_VOID_RETURN_EX2(dbg_obj1, dbg_obj2) DBG_LEAVE_EX2((dbg_obj1), (dbg_obj2), return;)
164
165
166
167#else /* defined(__GNUC__) || defined(PHP_WIN32) */
168static inline void DBG_INF_EX(MYSQLND_DEBUG * dbg_obj, const char * const msg) {}
169static inline void DBG_ERR_EX(MYSQLND_DEBUG * dbg_obj, const char * const msg) {}
170static inline void DBG_INF_FMT_EX(MYSQLND_DEBUG * dbg_obj, ...) {}
171static inline void DBG_ERR_FMT_EX(MYSQLND_DEBUG * dbg_obj, ...) {}
172static inline void DBG_ENTER_EX(MYSQLND_DEBUG * dbg_obj, const char * const func_name) {}
173#define DBG_BLOCK_ENTER(bname) {
174#define DBG_RETURN_EX(dbg_obj, value) return (value)
175#define DBG_VOID_RETURN_EX(dbg_obj) return
176#define DBG_BLOCK_LEAVE_EX(dbg_obj) }
177
178#endif
179
180#if MYSQLND_DBG_ENABLED == 1
181
182#define DBG_INF(msg) DBG_INF_EX(MYSQLND_G(dbg), (msg))
183#define DBG_ERR(msg) DBG_ERR_EX(MYSQLND_G(dbg), (msg))
184#define DBG_INF_FMT(...) DBG_INF_FMT_EX(MYSQLND_G(dbg), __VA_ARGS__)
185#define DBG_ERR_FMT(...) DBG_ERR_FMT_EX(MYSQLND_G(dbg), __VA_ARGS__)
186
187#define DBG_ENTER(func_name) DBG_ENTER_EX(MYSQLND_G(dbg), (func_name))
188#define DBG_BLOCK_ENTER(bname) DBG_BLOCK_ENTER_EX(MYSQLND_G(dbg), (bname))
189#define DBG_RETURN(value) DBG_RETURN_EX(MYSQLND_G(dbg), (value))
190#define DBG_VOID_RETURN DBG_VOID_RETURN_EX(MYSQLND_G(dbg))
191#define DBG_BLOCK_LEAVE DBG_BLOCK_LEAVE_EX(MYSQLND_G(dbg))
192
193
194#define TRACE_ALLOC_INF(msg) DBG_INF_EX(MYSQLND_G(trace_alloc), (msg))
195#define TRACE_ALLOC_ERR(msg) DBG_ERR_EX(MYSQLND_G(trace_alloc), (msg))
196#define TRACE_ALLOC_INF_FMT(...) DBG_INF_FMT_EX(MYSQLND_G(trace_alloc), __VA_ARGS__)
197#define TRACE_ALLOC_ERR_FMT(...) DBG_ERR_FMT_EX(MYSQLND_G(trace_alloc), __VA_ARGS__)
198
199#define TRACE_ALLOC_ENTER(func_name) DBG_ENTER_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc), (func_name))
200#define TRACE_ALLOC_BLOCK_ENTER(bname) DBG_BLOCK_ENTER_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc), (bname))
201#define TRACE_ALLOC_RETURN(value) DBG_RETURN_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc), (value))
202#define TRACE_ALLOC_VOID_RETURN DBG_VOID_RETURN_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc))
203#define TRACE_ALLOC_BLOCK_LEAVE DBG_BLOCK_LEAVE_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc))
204
205#elif MYSQLND_DBG_ENABLED == 0
206
207static inline void DBG_INF(const char * const msg) {}
208static inline void DBG_ERR(const char * const msg) {}
209static inline void DBG_INF_FMT(const char * const format, ...) {}
210static inline void DBG_ERR_FMT(const char * const format, ...) {}
211static inline void DBG_ENTER(const char * const func_name) {}
212#define DBG_BLOCK_ENTER(bname) {
213#define DBG_RETURN(value) return (value)
214#define DBG_VOID_RETURN return
215#define DBG_BLOCK_LEAVE }
216
217
218static inline void TRACE_ALLOC_INF(const char * const msg) {}
219static inline void TRACE_ALLOC_ERR(const char * const msg) {}
220static inline void TRACE_ALLOC_INF_FMT(const char * const format, ...) {}
221static inline void TRACE_ALLOC_ERR_FMT(const char * const format, ...) {}
222static inline void TRACE_ALLOC_ENTER(const char * const func_name) {}
223#define TRACE_ALLOC_BLOCK_ENTER(bname) {
224#define TRACE_ALLOC_RETURN(value) return (value)
225#define TRACE_ALLOC_VOID_RETURN return
226#define TRACE_ALLOC_BLOCK_LEAVE }
227
228#endif
229
230#endif /* MYSQLND_DEBUG_H */
file(string $filename, int $flags=0, $context=null)
printf(string $format, mixed ... $values)
zend_ffi_type * type
Definition ffi.c:3812
char * mode
PHPAPI MYSQLND_DEBUG * mysqlnd_debug_init(const char *skip_functions[])
void mysqlnd_debug_trace_plugin_register(void)
enum func_status enum_func_status
struct st_mysqlnd_debug MYSQLND_DEBUG
#define PHPAPI
Definition php.h:71
int line
Definition php_ffi.h:54
struct _php_stream php_stream
Definition php_streams.h:96
char * msg
Definition phpdbg.h:289
const char * func_name
size_t func_name_len
enum_func_status(* close)(MYSQLND_DEBUG *self)
void(* set_mode)(MYSQLND_DEBUG *self, const char *const mode)
enum_func_status(* free_handle)(MYSQLND_DEBUG *self)
enum_func_status bool(* func_enter)(MYSQLND_DEBUG *self, unsigned int line, const char *const file, const char *const func_name, unsigned int func_name_len)
enum_func_status(* log_va)(MYSQLND_DEBUG *self, unsigned int line, const char *const file, unsigned int level, const char *type, const char *format,...) ZEND_ATTRIBUTE_FORMAT(printf
enum_func_status(* log)(MYSQLND_DEBUG *self, unsigned int line, const char *const file, unsigned int level, const char *type, const char *message)
enum_func_status(* func_leave)(MYSQLND_DEBUG *self, unsigned int line, const char *const file, uint64_t call_time)
enum_func_status(* open)(MYSQLND_DEBUG *self, bool reopen)
zend_stack call_stack
const char ** skip_functions
php_stream * stream
unsigned int nest_level_limit
HashTable not_filtered_functions
zend_stack call_time_stack
HashTable function_profiles
struct st_mysqlnd_debug_methods * m
unsigned int flags
struct st_mysqlnd_plugin_trace_log::@135250356370041002364233320207075236242207017335 methods
struct st_mysqlnd_plugin_header plugin_header
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
#define ZEND_ATTRIBUTE_FORMAT(type, idx, first)
struct _zend_stack zend_stack
struct _zend_array HashTable
Definition zend_types.h:386