PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/mysqlnd - mysqlnd_debug.h (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 7 7 100.0 %
Date: 2015-05-21 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 2006-2015 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$ */
      22             : 
      23             : #ifndef MYSQLND_DEBUG_H
      24             : #define MYSQLND_DEBUG_H
      25             : 
      26             : #include "mysqlnd_alloc.h"
      27             : #include "zend_stack.h"
      28             : 
      29             : struct st_mysqlnd_debug_methods
      30             : {
      31             :         enum_func_status (*open)(MYSQLND_DEBUG * self, zend_bool reopen);
      32             :         void                     (*set_mode)(MYSQLND_DEBUG * self, const char * const mode);
      33             :         enum_func_status (*log)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
      34             :                                                         unsigned int level, const char * type, const char *message);
      35             :         enum_func_status (*log_va)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
      36             :                                                            unsigned int level, const char * type, const char *format, ...);
      37             :         zend_bool (*func_enter)(MYSQLND_DEBUG * self, unsigned int line, const char * const file,
      38             :                                                         const char * const func_name, unsigned int func_name_len);
      39             :         enum_func_status (*func_leave)(MYSQLND_DEBUG * self, unsigned int line, const char * const file, uint64_t call_time);
      40             :         enum_func_status (*close)(MYSQLND_DEBUG * self);
      41             :         enum_func_status (*free_handle)(MYSQLND_DEBUG * self);
      42             : };
      43             : 
      44             : 
      45             : struct st_mysqlnd_debug
      46             : {
      47             :         php_stream      *stream;
      48             :         unsigned int flags;
      49             :         unsigned int nest_level_limit;
      50             :         int pid;
      51             :         char * file_name;
      52             :         zend_stack call_stack;
      53             :         zend_stack call_time_stack;
      54             :         HashTable not_filtered_functions;
      55             :         HashTable function_profiles;
      56             :         struct st_mysqlnd_debug_methods *m;
      57             :         const char ** skip_functions;
      58             : };
      59             : 
      60             : struct st_mysqlnd_plugin_trace_log
      61             : {
      62             :         struct st_mysqlnd_plugin_header plugin_header;
      63             :         struct
      64             :         {
      65             :                 MYSQLND_DEBUG * (*trace_instance_init)(const char * skip_functions[]);
      66             :         } methods;
      67             : };
      68             : 
      69             : void mysqlnd_debug_trace_plugin_register(void);
      70             : 
      71             : PHPAPI MYSQLND_DEBUG * mysqlnd_debug_init(const char * skip_functions[]);
      72             : 
      73             : 
      74             : #if defined(__GNUC__) || defined(PHP_WIN32)
      75             : #ifdef PHP_WIN32
      76             : #include "win32/time.h"
      77             : #elif defined(NETWARE)
      78             : #include <sys/timeval.h>
      79             : #include <sys/time.h>
      80             : #else
      81             : #include <sys/time.h>
      82             : #endif
      83             : 
      84             : #ifndef MYSQLND_PROFILING_DISABLED
      85             : #define DBG_PROFILE_TIMEVAL_TO_DOUBLE(tp)       ((tp.tv_sec * 1000000LL)+ tp.tv_usec)
      86             : #define DBG_PROFILE_START_TIME()                gettimeofday(&__dbg_prof_tp, NULL); __dbg_prof_start = DBG_PROFILE_TIMEVAL_TO_DOUBLE(__dbg_prof_tp);
      87             : #define DBG_PROFILE_END_TIME(duration)  gettimeofday(&__dbg_prof_tp, NULL); (duration) = (DBG_PROFILE_TIMEVAL_TO_DOUBLE(__dbg_prof_tp) - __dbg_prof_start);
      88             : #else
      89             : #define DBG_PROFILE_TIMEVAL_TO_DOUBLE(tp)
      90             : #define DBG_PROFILE_START_TIME()
      91             : #define DBG_PROFILE_END_TIME(duration)
      92             : #endif
      93             : 
      94             : #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)
      95             : #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)
      96             : #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)
      97             : #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)
      98             : 
      99             : #define DBG_BLOCK_ENTER_EX(dbg_obj, block_name) DBG_BLOCK_ENTER_EX2((dbg_obj), (MYSQLND_DEBUG *) NULL, (block_name))
     100             : #define DBG_BLOCK_LEAVE_EX(dbg_obj)                             DBG_BLOCK_LEAVE_EX2((dbg_obj), (MYSQLND_DEBUG *) NULL)
     101             : 
     102             : #define DBG_BLOCK_ENTER_EX2(dbg_obj1, dbg_obj2, block_name) \
     103             :                 { \
     104             :                         DBG_ENTER_EX2((dbg_obj1), (dbg_obj2), (block_name));
     105             : 
     106             : #define DBG_BLOCK_LEAVE_EX2(dbg_obj1, dbg_obj2) \
     107             :                         DBG_LEAVE_EX2((dbg_obj1), (dbg_obj2), ;) \
     108             :                 } \
     109             : 
     110             : 
     111             : #define DBG_ENTER_EX(dbg_obj, func_name)        DBG_ENTER_EX2((dbg_obj), (MYSQLND_DEBUG *) NULL, (func_name))
     112             : #define DBG_LEAVE_EX(dbg_obj, leave)            DBG_LEAVE_EX2((dbg_obj), (MYSQLND_DEBUG *) NULL, leave)
     113             : 
     114             : #define DBG_ENTER_EX2(dbg_obj1, dbg_obj2, func_name) \
     115             :                                         struct timeval __dbg_prof_tp = {0}; \
     116             :                                         uint64_t __dbg_prof_start = 0; /* initialization is needed */ \
     117             :                                         zend_bool dbg_skip_trace = TRUE; \
     118             :                                         if ((dbg_obj1)) { \
     119             :                                                 dbg_skip_trace = !(dbg_obj1)->m->func_enter((dbg_obj1), __LINE__, __FILE__, func_name, strlen(func_name)); \
     120             :                                         } \
     121             :                                         if ((dbg_obj2)) { \
     122             :                                                 dbg_skip_trace |= !(dbg_obj2)->m->func_enter((dbg_obj2), __LINE__, __FILE__, func_name, strlen(func_name)); \
     123             :                                         } \
     124             :                                         if (dbg_skip_trace) \
     125             :                                                 /* EMPTY */ ; /* shut compiler's mouth */       \
     126             :                                         do { \
     127             :                                                 if (((dbg_obj1) && (dbg_obj1)->flags & MYSQLND_DEBUG_PROFILE_CALLS) || \
     128             :                                                         ((dbg_obj2) && (dbg_obj2)->flags & MYSQLND_DEBUG_PROFILE_CALLS)) \
     129             :                                                 { \
     130             :                                                         DBG_PROFILE_START_TIME(); \
     131             :                                                 } \
     132             :                                         } while (0);
     133             : 
     134             : #define DBG_LEAVE_EX2(dbg_obj1, dbg_obj2, leave)        \
     135             :                         do {\
     136             :                                 uint64_t this_call_duration = 0; \
     137             :                                 if (((dbg_obj1) && (dbg_obj1)->flags & MYSQLND_DEBUG_PROFILE_CALLS) || \
     138             :                                         ((dbg_obj2) && (dbg_obj2)->flags & MYSQLND_DEBUG_PROFILE_CALLS)) \
     139             :                                 { \
     140             :                                         DBG_PROFILE_END_TIME(this_call_duration); \
     141             :                                 } \
     142             :                                 if ((dbg_obj1)) { \
     143             :                                         (dbg_obj1)->m->func_leave((dbg_obj1), __LINE__, __FILE__, this_call_duration); \
     144             :                                 } \
     145             :                                 if ((dbg_obj2)) { \
     146             :                                         (dbg_obj2)->m->func_leave((dbg_obj2), __LINE__, __FILE__, this_call_duration); \
     147             :                                 } \
     148             :                                 leave \
     149             :                         } while (0);
     150             : 
     151             : 
     152             : #define DBG_RETURN_EX(dbg_obj, value)           DBG_LEAVE_EX((dbg_obj), return (value);)
     153             : #define DBG_VOID_RETURN_EX(dbg_obj)                     DBG_LEAVE_EX((dbg_obj), return;)
     154             : 
     155             : #define DBG_RETURN_EX2(dbg_obj1, dbg_obj2, value)       DBG_LEAVE_EX2((dbg_obj1), (dbg_obj2), return (value);)
     156             : #define DBG_VOID_RETURN_EX2(dbg_obj1, dbg_obj2)         DBG_LEAVE_EX2((dbg_obj1), (dbg_obj2), return;)
     157             : 
     158             : 
     159             : 
     160             : #else  /* defined(__GNUC__) || defined(PHP_WIN32) */
     161             : static inline void DBG_INF_EX(MYSQLND_DEBUG * dbg_obj, const char * const msg) {}
     162             : static inline void DBG_ERR_EX(MYSQLND_DEBUG * dbg_obj, const char * const msg) {}
     163             : static inline void DBG_INF_FMT_EX(MYSQLND_DEBUG * dbg_obj, ...) {}
     164             : static inline void DBG_ERR_FMT_EX(MYSQLND_DEBUG * dbg_obj, ...) {}
     165             : static inline void DBG_ENTER_EX(MYSQLND_DEBUG * dbg_obj, const char * const func_name) {}
     166             : #define DBG_BLOCK_ENTER(bname)                  {
     167             : #define DBG_RETURN_EX(dbg_obj, value)   return (value)
     168             : #define DBG_VOID_RETURN_EX(dbg_obj)             return
     169             : #define DBG_BLOCK_LEAVE_EX(dbg_obj)             }
     170             : 
     171             : #endif
     172             : 
     173             : #if MYSQLND_DBG_ENABLED == 1
     174             : 
     175             : #define DBG_INF(msg)            DBG_INF_EX(MYSQLND_G(dbg), (msg))
     176             : #define DBG_ERR(msg)            DBG_ERR_EX(MYSQLND_G(dbg), (msg))
     177             : #define DBG_INF_FMT(...)        DBG_INF_FMT_EX(MYSQLND_G(dbg), __VA_ARGS__)
     178             : #define DBG_ERR_FMT(...)        DBG_ERR_FMT_EX(MYSQLND_G(dbg), __VA_ARGS__)
     179             : 
     180             : #define DBG_ENTER(func_name)    DBG_ENTER_EX(MYSQLND_G(dbg), (func_name))
     181             : #define DBG_BLOCK_ENTER(bname)  DBG_BLOCK_ENTER_EX(MYSQLND_G(dbg), (bname))
     182             : #define DBG_RETURN(value)               DBG_RETURN_EX(MYSQLND_G(dbg), (value))
     183             : #define DBG_VOID_RETURN                 DBG_VOID_RETURN_EX(MYSQLND_G(dbg))
     184             : #define DBG_BLOCK_LEAVE                 DBG_BLOCK_LEAVE_EX(MYSQLND_G(dbg))
     185             : 
     186             : 
     187             : #define TRACE_ALLOC_INF(msg)                    DBG_INF_EX(MYSQLND_G(trace_alloc), (msg))
     188             : #define TRACE_ALLOC_ERR(msg)                    DBG_ERR_EX(MYSQLND_G(trace_alloc), (msg))
     189             : #define TRACE_ALLOC_INF_FMT(...)                DBG_INF_FMT_EX(MYSQLND_G(trace_alloc), __VA_ARGS__)
     190             : #define TRACE_ALLOC_ERR_FMT(...)                DBG_ERR_FMT_EX(MYSQLND_G(trace_alloc), __VA_ARGS__)
     191             : 
     192             : #define TRACE_ALLOC_ENTER(func_name)    DBG_ENTER_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc), (func_name))
     193             : #define TRACE_ALLOC_BLOCK_ENTER(bname)  DBG_BLOCK_ENTER_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc), (bname))
     194             : #define TRACE_ALLOC_RETURN(value)               DBG_RETURN_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc), (value))
     195             : #define TRACE_ALLOC_VOID_RETURN                 DBG_VOID_RETURN_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc))
     196             : #define TRACE_ALLOC_BLOCK_LEAVE                 DBG_BLOCK_LEAVE_EX2(MYSQLND_G(dbg), MYSQLND_G(trace_alloc))
     197             : 
     198             : #elif MYSQLND_DBG_ENABLED == 0
     199             : 
     200      339558 : static inline void DBG_INF(const char * const msg) {}
     201          60 : static inline void DBG_ERR(const char * const msg) {}
     202     3662567 : static inline void DBG_INF_FMT(const char * const format, ...) {}
     203         899 : static inline void DBG_ERR_FMT(const char * const format, ...) {}
     204     4291075 : static inline void DBG_ENTER(const char * const func_name) {}
     205             : #define DBG_BLOCK_ENTER(bname)  {
     206             : #define DBG_RETURN(value)                       return (value)
     207             : #define DBG_VOID_RETURN                         return
     208             : #define DBG_BLOCK_LEAVE                 }
     209             : 
     210             : 
     211             : static inline void TRACE_ALLOC_INF(const char * const msg) {}
     212             : static inline void TRACE_ALLOC_ERR(const char * const msg) {}
     213      976400 : static inline void TRACE_ALLOC_INF_FMT(const char * const format, ...) {}
     214             : static inline void TRACE_ALLOC_ERR_FMT(const char * const format, ...) {}
     215      926719 : static inline void TRACE_ALLOC_ENTER(const char * const func_name) {}
     216             : #define TRACE_ALLOC_BLOCK_ENTER(bname)  {
     217             : #define TRACE_ALLOC_RETURN(value)                       return (value)
     218             : #define TRACE_ALLOC_VOID_RETURN                         return
     219             : #define TRACE_ALLOC_BLOCK_LEAVE                 }
     220             : 
     221             : #endif
     222             : 
     223             : #endif /* MYSQLND_DEBUG_H */
     224             : 
     225             : /*
     226             :  * Local variables:
     227             :  * tab-width: 4
     228             :  * c-basic-offset: 4
     229             :  * End:
     230             :  * vim600: noet sw=4 ts=4 fdm=marker
     231             :  * vim<600: noet sw=4 ts=4
     232             :  */

Generated by: LCOV version 1.10

Generated at Thu, 21 May 2015 19:58:59 +0000 (21 hours ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.