Changeset 204
- Timestamp:
- 2006-10-01T10:57:51+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
coverager.c (modified) (13 diffs)
-
coverager.h (modified) (2 diffs)
-
xcache-zh-gb2312.ini (modified) (1 diff)
-
xcache.c (modified) (4 diffs)
-
xcache.ini (modified) (1 diff)
-
xcache_globals.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/coverager.c
r201 r204 16 16 #define PCOV_HEADER_MAGIC 0x564f4350 17 17 18 char *xc_coveragedump_dir = NULL;18 static char *xc_coveragedump_dir = NULL; 19 19 static zend_compile_file_t *origin_compile_file; 20 20 … … 193 193 } 194 194 /* }}} */ 195 void xc_coverager_request_init(TSRMLS_D) /* {{{ */ 196 { 197 if (XG(coveragedumper)) { 195 196 static void xc_coverager_initenv(TSRMLS_D) /* {{{ */ 197 { 198 if (!XG(coverages)) { 198 199 XG(coverages) = emalloc(sizeof(HashTable)); 199 200 zend_hash_init(XG(coverages), 0, NULL, xc_destroy_coverage, 0); … … 201 202 } 202 203 /* }}} */ 203 void xc_coverager_request_shutdown(TSRMLS_D) /* {{{ */ 204 static void xc_coverager_clean(TSRMLS_D) /* {{{ */ 205 { 206 if (XG(coverages)) { 207 zend_hash_destroy(XG(coverages)); 208 efree(XG(coverages)); 209 XG(coverages) = NULL; 210 } 211 } 212 /* }}} */ 213 214 static void xc_coverager_enable(TSRMLS_D) /* {{{ */ 215 { 216 XG(coverage_enabled) = 1; 217 } 218 /* }}} */ 219 static void xc_coverager_disable(TSRMLS_D) /* {{{ */ 220 { 221 XG(coverage_enabled) = 0; 222 } 223 /* }}} */ 224 225 void xc_coverager_request_init(TSRMLS_D) /* {{{ */ 226 { 227 if (XG(coveragedumper)) { 228 xc_coverager_enable(TSRMLS_C); 229 xc_coverager_initenv(TSRMLS_C); 230 CG(extended_info) = 1; 231 } 232 else { 233 XG(coverage_enabled) = 0; 234 } 235 } 236 /* }}} */ 237 static void xc_coverager_autodump(TSRMLS_D) /* {{{ */ 204 238 { 205 239 coverager_t *pcov; … … 208 242 int dumpdir_len, outfilelen, alloc_len = 0; 209 243 uint size; 210 211 if (!XG(coverages)) { 212 return; 213 } 214 if (XG(coveragedumper)) { 244 HashPosition pos; 245 246 if (XG(coverages) && xc_coveragedump_dir) { 215 247 dumpdir_len = strlen(xc_coveragedump_dir); 216 248 alloc_len = dumpdir_len + 1 + 128; … … 218 250 strcpy(outfilename, xc_coveragedump_dir); 219 251 220 zend_hash_internal_pointer_reset (XG(coverages));221 while (zend_hash_get_current_data (XG(coverages), (void **) &pcov) == SUCCESS) {222 zend_hash_get_current_key_ex(XG(coverages), &s, &size, NULL, 0, NULL);252 zend_hash_internal_pointer_reset_ex(XG(coverages), &pos); 253 while (zend_hash_get_current_data_ex(XG(coverages), (void **) &pcov, &pos) == SUCCESS) { 254 zend_hash_get_current_key_ex(XG(coverages), &s, &size, NULL, 0, &pos); 223 255 outfilelen = dumpdir_len + size + 5; 224 256 if (alloc_len < outfilelen) { … … 233 265 #endif 234 266 xc_coverager_save_cov(ZSTR_S(s), outfilename, *pcov TSRMLS_CC); 235 zend_hash_move_forward (XG(coverages));267 zend_hash_move_forward_ex(XG(coverages), &pos); 236 268 } 237 269 efree(outfilename); 238 270 } 239 240 zend_hash_destroy(XG(coverages)); 241 efree(XG(coverages)); 242 XG(coverages) = NULL; 271 } 272 /* }}} */ 273 static void xc_coverager_dump(zval *return_value TSRMLS_DC) /* {{{ */ 274 { 275 coverager_t *pcov; 276 HashPosition pos; 277 278 if (XG(coverages)) { 279 array_init(return_value); 280 281 zend_hash_internal_pointer_reset_ex(XG(coverages), &pos); 282 while (zend_hash_get_current_data_ex(XG(coverages), (void **) &pcov, &pos) == SUCCESS) { 283 zval *lines; 284 long *phits; 285 coverager_t cov; 286 HashPosition pos2; 287 zstr filename; 288 uint size; 289 290 cov = *pcov; 291 zend_hash_get_current_key_ex(XG(coverages), &filename, &size, NULL, 0, &pos); 292 293 MAKE_STD_ZVAL(lines); 294 array_init(lines); 295 zend_hash_internal_pointer_reset_ex(cov, &pos2); 296 while (zend_hash_get_current_data_ex(cov, (void**)&phits, &pos2) == SUCCESS) { 297 long hits = *phits; 298 add_index_long(lines, pos2->h, hits >= 0 ? hits : 0); 299 zend_hash_move_forward_ex(cov, &pos2); 300 } 301 add_assoc_zval_ex(return_value, ZSTR_S(filename), strlen(ZSTR_S(filename)) + 1, lines); 302 303 zend_hash_move_forward_ex(XG(coverages), &pos); 304 } 305 } 306 else { 307 RETVAL_NULL(); 308 } 309 } 310 /* }}} */ 311 void xc_coverager_request_shutdown(TSRMLS_D) /* {{{ */ 312 { 313 if (XG(coveragedumper)) { 314 xc_coverager_autodump(TSRMLS_C); 315 xc_coverager_clean(TSRMLS_C); 316 } 243 317 } 244 318 /* }}} */ … … 351 425 352 426 op_array = origin_compile_file(h, type TSRMLS_CC); 353 if (XG(coveragedumper) && XG(coverages) && op_array) { 354 xc_coverager_init_compile_result(op_array TSRMLS_CC); 427 if (op_array) { 428 if (XG(coveragedumper)) { 429 xc_coverager_initenv(TSRMLS_C); 430 xc_coverager_init_compile_result(op_array TSRMLS_CC); 431 } 355 432 } 356 433 return op_array; … … 363 440 TSRMLS_FETCH(); 364 441 365 if (XG(coverage dumper) && XG(coverages)) {442 if (XG(coverages) && XG(coverage_enabled)) { 366 443 int size = xc_coverager_get_op_array_size_no_tail(op_array); 367 444 int oplineno = (*EG(opline_ptr)) - op_array->opcodes; … … 376 453 int xc_coverager_init(int module_number TSRMLS_DC) /* {{{ */ 377 454 { 378 if (xc_coveragedump_dir) { 455 origin_compile_file = zend_compile_file; 456 zend_compile_file = xc_compile_file_for_coverage; 457 458 if (cfg_get_string("xcache.coveragedump_directory", &xc_coveragedump_dir) == SUCCESS && xc_coveragedump_dir) { 379 459 int len = strlen(xc_coveragedump_dir); 380 460 if (len) { … … 383 463 } 384 464 } 385 } 386 if (xc_coveragedump_dir && xc_coveragedump_dir[0]) { 387 origin_compile_file = zend_compile_file; 388 zend_compile_file = xc_compile_file_for_coverage; 389 CG(extended_info) = 1; 390 } 465 if (!strlen(xc_coveragedump_dir)) { 466 xc_coveragedump_dir = NULL; 467 } 468 } 469 391 470 return SUCCESS; 392 471 } … … 398 477 } 399 478 if (xc_coveragedump_dir) { 400 pefree(xc_coveragedump_dir, 1);401 479 xc_coveragedump_dir = NULL; 402 480 } … … 405 483 406 484 /* user api */ 407 PHP_FUNCTION(xcache_coverager_decode) /* {{{ */ 485 /* {{{ proto array xcache_coverager_decode(string data) 486 * decode specified data which is saved by auto dumper to array 487 */ 488 PHP_FUNCTION(xcache_coverager_decode) 408 489 { 409 490 char *str; … … 434 515 } 435 516 /* }}} */ 436 517 /* {{{ proto void xcache_coverager_start([bool clean = true]) 518 * starts coverager data collecting 519 */ 520 PHP_FUNCTION(xcache_coverager_start) 521 { 522 zend_bool clean = 1; 523 524 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean) == FAILURE) { 525 return; 526 } 527 528 if (clean) { 529 xc_coverager_clean(TSRMLS_C); 530 } 531 532 if (XG(coveragedumper)) { 533 xc_coverager_enable(TSRMLS_C); 534 } 535 else { 536 php_error(E_WARNING, "You can only start coverager after you set 'xcache.coveragedumper' to 'On' in ini"); 537 } 538 } 539 /* }}} */ 540 /* {{{ proto void xcache_coverager_stop([bool clean = false]) 541 * stop coverager data collecting 542 */ 543 PHP_FUNCTION(xcache_coverager_stop) 544 { 545 zend_bool clean = 0; 546 547 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean) == FAILURE) { 548 return; 549 } 550 551 xc_coverager_disable(TSRMLS_C); 552 if (clean) { 553 xc_coverager_clean(TSRMLS_C); 554 } 555 } 556 /* }}} */ 557 /* {{{ proto array xcache_coverager_get([bool clean = false]) 558 * get coverager data collected 559 */ 560 PHP_FUNCTION(xcache_coverager_get) 561 { 562 zend_bool clean = 0; 563 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean) == FAILURE) { 564 return; 565 } 566 567 xc_coverager_dump(return_value TSRMLS_CC); 568 if (clean) { 569 xc_coverager_clean(TSRMLS_C); 570 } 571 } 572 /* }}} */ -
trunk/coverager.h
r27 r204 1 1 #include "php.h" 2 2 #include "xcache.h" 3 4 extern char *xc_coveragedump_dir;5 3 6 4 void xc_coverager_handle_ext_stmt(zend_op_array *op_array, zend_uchar op); … … 10 8 void xc_coverager_request_shutdown(TSRMLS_D); 11 9 PHP_FUNCTION(xcache_coverager_decode); 10 PHP_FUNCTION(xcache_coverager_start); 11 PHP_FUNCTION(xcache_coverager_stop); 12 PHP_FUNCTION(xcache_coverager_get); -
trunk/xcache-zh-gb2312.ini
r177 r204 66 66 67 67 [xcache.coverager] 68 ; ÇëÈ·±£±¾Ä¿Â¼Äܱ» coverage viewer ½Å±¾¶ÁÈ¡ (×¢Òâ open_basedir)69 xcache.coveragedump_directory = "/tmp/pcov/"70 68 71 69 ; Èç¹û xcache.coveragedump_directory ÉèÖÃΪ¿ÕÔò±¾ÉèÖÃ×Ô¶¯Îª Off 72 xcache.coveragedumper = Off 70 xcache.coverager = Off 71 72 ; ÇëÈ·±£±¾Ä¿Â¼Äܱ» coverage viewer ½Å±¾¶ÁÈ¡ (×¢Òâ open_basedir) 73 ; ÒÀÀµÓÚ xcache.coverager=On 74 xcache.coveragedump_directory = "" -
trunk/xcache.c
r202 r204 2026 2026 #ifdef HAVE_XCACHE_COVERAGER 2027 2027 PHP_FE(xcache_coverager_decode, NULL) 2028 PHP_FE(xcache_coverager_start, NULL) 2029 PHP_FE(xcache_coverager_stop, NULL) 2030 PHP_FE(xcache_coverager_get, NULL) 2028 2031 #endif 2029 2032 PHP_FE(xcache_get_special_value, NULL) … … 2158 2161 STD_PHP_INI_BOOLEAN("xcache.var_ttl", "0", PHP_INI_ALL, OnUpdateLong, var_ttl, zend_xcache_globals, xcache_globals) 2159 2162 #ifdef HAVE_XCACHE_COVERAGER 2160 PHP_INI_ENTRY1 ("xcache.coveragedump_directory", "/tmp/pcov/", PHP_INI_SYSTEM, xc_OnUpdateString, &xc_coveragedump_dir)2161 STD_PHP_INI_BOOLEAN("xcache.coveragedumper" , "0", PHP_INI_ALL, OnUpdateBool, coveragedumper, zend_xcache_globals, xcache_globals)2163 STD_PHP_INI_BOOLEAN("xcache.coverager" , "0", PHP_INI_ALL, OnUpdateBool, coverager, zend_xcache_globals, xcache_globals) 2164 PHP_INI_ENTRY1 ("xcache.coveragedump_directory", "", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL) 2162 2165 #endif 2163 2166 PHP_INI_END() … … 2170 2173 int left, len; 2171 2174 xc_shm_scheme_t *scheme; 2175 char *covdumpdir; 2172 2176 2173 2177 php_info_print_table_start(); … … 2207 2211 2208 2212 #ifdef HAVE_XCACHE_COVERAGER 2209 php_info_print_table_row(2, "Coverage Dumper", XG(coveragedumper) && xc_coveragedump_dir && xc_coveragedump_dir[0] ? "enabled" : "disabled"); 2213 if (cfg_get_string("xcache.coveragedump_directory", &covdumpdir) != SUCCESS || !covdumpdir[0]) { 2214 covdumpdir = NULL; 2215 } 2216 php_info_print_table_row(2, "Coverage Auto Dumper", XG(coverager) && covdumpdir ? "enabled" : "disabled"); 2210 2217 #endif 2211 2218 php_info_print_table_end(); -
trunk/xcache.ini
r177 r204 64 64 65 65 [xcache.coverager] 66 ; per request settings 67 ; enable coverage data collecting for xcache.coveragedump_directory and xcache_coverager_start/stop/get/clean() functions (will hurt executing performance) 68 xcache.coverager = Off 69 66 70 ; ini only settings 67 ; make sure it's readable (care open_basedir) coverage viewer script 68 xcache.coveragedump_directory = "/tmp/pcov/" 69 70 ; per request settings, will be auto disabled if xcache.coveragedump_directory is not set 71 xcache.coveragedumper = Off 71 ; make sure it's readable (care open_basedir) by coverage viewer script 72 ; requires xcache.coverager=On 73 xcache.coveragedump_directory = "" -
trunk/xcache_globals.h
r165 r204 7 7 #endif 8 8 #ifdef HAVE_XCACHE_COVERAGER 9 zend_bool coveragedumper; 9 zend_bool coverager; 10 zend_bool coverage_enabled; 10 11 HashTable *coverages; /* coverages[file][line] = times */ 11 12 #endif
Note: See TracChangeset
for help on using the changeset viewer.

