| 35 | | #if defined(DEBUG) || defined(TEST_PERFORMANCE) || defined(PROFILE_OPCODES) |
|---|
| 36 | | |
|---|
| 37 | | extern FILE *F_fp; |
|---|
| 38 | | |
|---|
| 39 | | void |
|---|
| 40 | | binary_print (char *p, int len) |
|---|
| 41 | | { |
|---|
| 42 | | while (len--) |
|---|
| 43 | | { |
|---|
| 44 | | fputc (*p++, F_fp); |
|---|
| 45 | | } |
|---|
| 46 | | fputc ('\n', F_fp); |
|---|
| 47 | | } |
|---|
| 48 | | |
|---|
| 49 | | void |
|---|
| 50 | | log_hashkeys (char *p, HashTable * ht) |
|---|
| 51 | | { |
|---|
| 52 | | Bucket *b; |
|---|
| 53 | | int i = 0; |
|---|
| 54 | | |
|---|
| 55 | | b = ht->pListHead; |
|---|
| 56 | | |
|---|
| 57 | | fputs (p, F_fp); |
|---|
| 58 | | while (b) |
|---|
| 59 | | { |
|---|
| 60 | | fprintf (F_fp, "[%d] ", i); |
|---|
| 61 | | binary_print (b->arKey, b->nKeyLength); |
|---|
| 62 | | |
|---|
| 63 | | b = b->pListNext; |
|---|
| 64 | | i++; |
|---|
| 65 | | } |
|---|
| 66 | | } |
|---|
| 67 | | |
|---|
| 68 | | void |
|---|
| 69 | | pad (TSRMLS_D) |
|---|
| 70 | | { |
|---|
| 71 | | int i = MMCG (xpad); |
|---|
| 72 | | while (i-- > 0) |
|---|
| 73 | | { |
|---|
| 74 | | fputc ('\t', F_fp); |
|---|
| 75 | | } |
|---|
| 76 | | } |
|---|
| 77 | | |
|---|
| 78 | | void |
|---|
| 79 | | start_time (struct timeval *tvstart) |
|---|
| 80 | | { |
|---|
| 81 | | gettimeofday (tvstart, NULL); |
|---|
| 82 | | } |
|---|
| 83 | | |
|---|
| 84 | | long |
|---|
| 85 | | elapsed_time (struct timeval *tvstart) |
|---|
| 86 | | { |
|---|
| 87 | | struct timeval tvend; |
|---|
| 88 | | int sec, usec; |
|---|
| 89 | | gettimeofday (&tvend, NULL); |
|---|
| 90 | | sec = tvend.tv_sec - tvstart->tv_sec; |
|---|
| 91 | | usec = tvend.tv_usec - tvstart->tv_usec; |
|---|
| 92 | | return sec * 1000000 + usec; |
|---|
| 93 | | } |
|---|
| 94 | | #endif /* #if defined(DEBUG) || defined(TEST_PERFORMANCE) || defined(PROFILE_OPCODES) */ |
|---|
| 95 | | |
|---|
| 96 | | void |
|---|
| 97 | | debug_printf (char *format, ...) |
|---|
| 98 | | { |
|---|
| 99 | | char output_buf[512]; |
|---|
| 100 | | va_list args; |
|---|
| 101 | | |
|---|
| 102 | | va_start (args, format); |
|---|
| 103 | | vsnprintf (output_buf, sizeof (output_buf), format, args); |
|---|
| 104 | | va_end (args); |
|---|
| | 39 | FILE *F_fp = NULL; |
|---|
| | 40 | long eaccelerator_debug = 0; |
|---|
| | 41 | |
|---|
| | 42 | /** |
|---|
| | 43 | * Init the debug system. This must be called before any debug |
|---|
| | 44 | * functions are used. |
|---|
| | 45 | */ |
|---|
| | 46 | void ea_debug_init (TSRMLS_D) |
|---|
| | 47 | { |
|---|
| | 48 | /* register ini entries */ |
|---|
| | 49 | REGISTER_MAIN_LONG_CONSTANT ("EA_LOG", EA_LOG, CONST_PERSISTENT | CONST_CS); |
|---|
| | 50 | REGISTER_MAIN_LONG_CONSTANT ("EA_DEBUG", EA_DEBUG, CONST_PERSISTENT | CONST_CS); |
|---|
| | 51 | REGISTER_MAIN_LONG_CONSTANT ("EA_PROFILE_OPCODES", EA_PROFILE_OPCODES, |
|---|
| | 52 | CONST_PERSISTENT | CONST_CS); |
|---|
| | 53 | REGISTER_MAIN_LONG_CONSTANT ("EA_TEST_PERFORMANCE", EA_TEST_PERFORMANCE, |
|---|
| | 54 | CONST_PERSISTENT | CONST_CS); |
|---|
| | 55 | REGISTER_MAIN_LONG_CONSTANT ("EA_LOG_HASHKEYS", EA_LOG_HASHKEYS, |
|---|
| | 56 | CONST_PERSISTENT | CONST_CS); |
|---|
| | 57 | |
|---|
| | 58 | F_fp = fopen (MMCG (eaccelerator_log_file), "a"); |
|---|
| | 59 | if (!F_fp) |
|---|
| | 60 | F_fp = stderr; |
|---|
| | 61 | } |
|---|
| | 62 | |
|---|
| | 63 | /** |
|---|
| | 64 | * Close the debug system. |
|---|
| | 65 | */ |
|---|
| | 66 | void ea_debug_shutdown () |
|---|
| | 67 | { |
|---|
| | 68 | fflush (F_fp); |
|---|
| | 69 | fclose (F_fp); |
|---|
| | 70 | F_fp = NULL; |
|---|
| | 71 | } |
|---|
| | 72 | |
|---|
| | 73 | /** |
|---|
| | 74 | * Print a log message that will be print when the debug level is |
|---|
| | 75 | * equal to EA_LOG. This function is always called even if ea isn't |
|---|
| | 76 | * compiled with DEBUG and the log level is not equal to EA_LOG. |
|---|
| | 77 | */ |
|---|
| | 78 | void ea_debug_log (char *format, ...) |
|---|
| | 79 | { |
|---|
| | 80 | if (eaccelerator_debug & EA_LOG) { |
|---|
| | 81 | char output_buf[512]; |
|---|
| | 82 | va_list args; |
|---|
| | 83 | |
|---|
| | 84 | va_start (args, format); |
|---|
| | 85 | vsnprintf (output_buf, sizeof (output_buf), format, args); |
|---|
| | 86 | va_end (args); |
|---|
| 107 | | OutputDebugString (output_buf); |
|---|
| 108 | | /* zend_printf("EACCELERATOR: %s<br>\n",output_buf);*/ |
|---|
| 109 | | #else |
|---|
| 110 | | fputs (output_buf, stderr); |
|---|
| 111 | | #endif |
|---|
| 112 | | } |
|---|
| | 89 | OutputDebugString (*output_buf); |
|---|
| | 90 | #else |
|---|
| | 91 | fputs (output_buf, F_fp); |
|---|
| | 92 | fflush (F_fp); |
|---|
| | 93 | #endif |
|---|
| | 94 | } |
|---|
| | 95 | } |
|---|
| | 96 | |
|---|
| | 97 | /** |
|---|
| | 98 | * Output an error message to stderr. This message are always printed |
|---|
| | 99 | * no matter what log level is used. |
|---|
| | 100 | */ |
|---|
| | 101 | void ea_debug_error (char *format, ...) |
|---|
| | 102 | { |
|---|
| | 103 | char output_buf[512]; |
|---|
| | 104 | va_list args; |
|---|
| | 105 | |
|---|
| | 106 | va_start (args, format); |
|---|
| | 107 | vsnprintf (output_buf, sizeof (output_buf), format, args); |
|---|
| | 108 | va_end (args); |
|---|
| | 109 | |
|---|
| | 110 | #ifdef ZEND_WIN32 |
|---|
| | 111 | OutputDebugString (*buffer); |
|---|
| | 112 | #else |
|---|
| | 113 | fputs (output_buf, stderr); |
|---|
| | 114 | fflush (stderr); |
|---|
| | 115 | #endif |
|---|
| | 116 | } |
|---|
| | 117 | |
|---|
| | 118 | /* |
|---|
| | 119 | * All these functions aren't compiled when eA isn't compiled with DEBUG. They |
|---|
| | 120 | * are replaced with function with no body, so it's optimized away by the compiler. |
|---|
| | 121 | * Even if the debug level is ok. |
|---|
| | 122 | */ |
|---|
| | 123 | |
|---|
| | 124 | /** |
|---|
| | 125 | * Print a debug message |
|---|
| | 126 | */ |
|---|
| | 127 | #ifdef DEBUG |
|---|
| | 128 | void ea_debug_printf (long debug_level, char *format, ...) |
|---|
| | 129 | { |
|---|
| | 130 | if (eaccelerator_debug & debug_level) { |
|---|
| | 131 | char output_buf[512]; |
|---|
| | 132 | va_list args; |
|---|
| | 133 | |
|---|
| | 134 | va_start (args, format); |
|---|
| | 135 | vsnprintf (output_buf, sizeof (output_buf), format, args); |
|---|
| | 136 | va_end (args); |
|---|
| | 137 | |
|---|
| | 138 | fputs (output_buf, F_fp); |
|---|
| | 139 | fflush (F_fp); |
|---|
| | 140 | } |
|---|
| | 141 | } |
|---|
| | 142 | #else |
|---|
| | 143 | void ea_debug_printf (long debug_level, char *format, ...) |
|---|
| | 144 | { |
|---|
| | 145 | } |
|---|
| | 146 | #endif |
|---|
| | 147 | |
|---|
| | 148 | /** |
|---|
| | 149 | * Put a debug message |
|---|
| | 150 | */ |
|---|
| | 151 | #ifdef DEBUG |
|---|
| | 152 | void ea_debug_put (long debug_level, char *message) |
|---|
| | 153 | { |
|---|
| | 154 | if (debug_level & eaccelerator_debug) { |
|---|
| | 155 | fputs (message, F_fp); |
|---|
| | 156 | fflush (F_fp); |
|---|
| | 157 | } |
|---|
| | 158 | } |
|---|
| | 159 | #else |
|---|
| | 160 | void ea_debug_put (long debug_level, char *message) |
|---|
| | 161 | { |
|---|
| | 162 | } |
|---|
| | 163 | #endif |
|---|
| | 164 | |
|---|
| | 165 | /** |
|---|
| | 166 | * Print a binary message |
|---|
| | 167 | */ |
|---|
| | 168 | #ifdef DEBUG |
|---|
| | 169 | void ea_debug_binary_print (long debug_level, char *p, int len) |
|---|
| | 170 | { |
|---|
| | 171 | if (eaccelerator_debug & debug_level) { |
|---|
| | 172 | while (len--) { |
|---|
| | 173 | fputc (*p++, F_fp); |
|---|
| | 174 | } |
|---|
| | 175 | fputc ('\n', F_fp); |
|---|
| | 176 | fflush (F_fp); |
|---|
| | 177 | } |
|---|
| | 178 | } |
|---|
| | 179 | #else |
|---|
| | 180 | void ea_debug_binary_print (long debug_level, char *p, int len) |
|---|
| | 181 | { |
|---|
| | 182 | } |
|---|
| | 183 | #endif |
|---|
| | 184 | |
|---|
| | 185 | /** |
|---|
| | 186 | * Log a hashkey |
|---|
| | 187 | */ |
|---|
| | 188 | #ifdef DEBUG |
|---|
| | 189 | void ea_debug_log_hashkeys (char *p, HashTable * ht) |
|---|
| | 190 | { |
|---|
| | 191 | if (eaccelerator_debug & EA_LOG_HASHKEYS) { |
|---|
| | 192 | Bucket *b; |
|---|
| | 193 | int i = 0; |
|---|
| | 194 | |
|---|
| | 195 | b = ht->pListHead; |
|---|
| | 196 | |
|---|
| | 197 | fputs (p, F_fp); |
|---|
| | 198 | while (b) { |
|---|
| | 199 | fprintf (F_fp, "[%d] ", i); |
|---|
| | 200 | ea_debug_binary_print (EA_LOG_HASHKEYS, b->arKey, b->nKeyLength); |
|---|
| | 201 | |
|---|
| | 202 | b = b->pListNext; |
|---|
| | 203 | i++; |
|---|
| | 204 | } |
|---|
| | 205 | fflush (F_fp); |
|---|
| | 206 | } |
|---|
| | 207 | } |
|---|
| | 208 | #else |
|---|
| | 209 | void ea_debug_log_hashkeys (char *p, HashTable * ht) |
|---|
| | 210 | { |
|---|
| | 211 | } |
|---|
| | 212 | #endif |
|---|
| | 213 | |
|---|
| | 214 | /** |
|---|
| | 215 | * Pad the message with the current pad level. |
|---|
| | 216 | */ |
|---|
| | 217 | #ifdef DEBUG |
|---|
| | 218 | void ea_debug_pad (long debug_level TSRMLS_DC) |
|---|
| | 219 | { |
|---|
| | 220 | if (eaccelerator_debug & debug_level) { |
|---|
| | 221 | int i = MMCG (xpad); |
|---|
| | 222 | while (i-- > 0) { |
|---|
| | 223 | fputc ('\t', F_fp); |
|---|
| | 224 | } |
|---|
| | 225 | } |
|---|
| | 226 | } |
|---|
| | 227 | #else |
|---|
| | 228 | void ea_debug_pad (long debug_level TSRMLS_DC) |
|---|
| | 229 | { |
|---|
| | 230 | } |
|---|
| | 231 | #endif |
|---|
| | 232 | |
|---|
| | 233 | void ea_debug_start_time (struct timeval *tvstart) |
|---|
| | 234 | { |
|---|
| | 235 | gettimeofday (tvstart, NULL); |
|---|
| | 236 | } |
|---|
| | 237 | |
|---|
| | 238 | long ea_debug_elapsed_time (struct timeval *tvstart) |
|---|
| | 239 | { |
|---|
| | 240 | struct timeval tvend; |
|---|
| | 241 | int sec, usec; |
|---|
| | 242 | gettimeofday (&tvend, NULL); |
|---|
| | 243 | sec = tvend.tv_sec - tvstart->tv_sec; |
|---|
| | 244 | usec = tvend.tv_usec - tvstart->tv_usec; |
|---|
| | 245 | return sec * 1000000 + usec; |
|---|
| | 246 | } |
|---|
| | 247 | |
|---|
| | 248 | #endif /* #ifdef HAVE_EACCELERATOR */ |
|---|