Changeset 204 for trunk/coverager.c
- Timestamp:
- 2006-10-01T10:57:51+02:00 (7 years ago)
- File:
-
- 1 edited
-
trunk/coverager.c (modified) (13 diffs)
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 /* }}} */
Note: See TracChangeset
for help on using the changeset viewer.

