Xdebug document (5) code coverage analysis and xdebug document

Source: Internet
Author: User

Xdebug document (5) code coverage analysis and xdebug document

Code overwrite analysis allows you to know which line (or segment) of the script is being executed during the request.

Settings

Xdebug. coverage_enable

Type:Boolean, Default value:1, Starts

Xdebug> = 2.2

If it is set to 0, Xdebug does not set the built-in structure to allow code analysis, which can accelerate xdebug faster, but the code coverage analysis will not work.

Related functions BooleanXdebug_code_coverage_started ()

Return a Boolean value to check whether the code overwrite analysis has started.

Example:

<?php    var_dump(xdebug_code_coverage_started());    xdebug_start_code_coverage();    var_dump(xdebug_code_coverage_started());?>  

 

Returns:

bool(false)
bool(true)
 

 

ArrayXdebug_get_code_coverage ()

Returns the line containing the script in the structure (including the referenced file. The following code overwrites a specified file:

Example:

<?php    xdebug_start_code_coverage();    function a($a) {        echo $a * 2.5;    }    function b($count) {        for ($i = 0; $i < $count; $i++) {            a($i + 0.17);        }    }    b(6);    b(10);    var_dump(xdebug_get_code_coverage());?>  

 

Returns:

Array

'/Home/httpd/html/test/xdebug/docs/xdebug_get_code_coverage.php' =>

Array

5 => int 1

6 => int 1

7 => int 1

9 => int 1

10 => int 1

11 => int 1

12 => int 1

13 => int 1

15 => int 1

16 => int 1

18 => int 1

VoidXdebug_start_code_coverage ([Int options])

Start code coverage analysis

This function starts to collect code overwrite information. This information is formed by two-dimensional arrays, and the one-dimensional Index is the second-level index of the execution file name as the row number. The element value indicates whether the row is executed or whether it has rows that cannot be reached.

Values returned for each row:

  • 1: This row has been executed
  • -1: The row is not executed.
  • -2: This row does not have executable code.

-The value 1 is returned only when XDEBUG_CC_UNUSED is enabled. The value-2 is returned only when XDEBUG_CC_UNUSED and XDEBUG_CC_DEAD_CODE are enabled at the same time.

The function has two options with enumerated values:

XDEBUG_CC_UNUSED

Enable detection code and describe the code that can be executed. If this option is not specified, the returned array only contains the actually executed row number.

XDEBUG_CC_DEAD_CODE

Start an additional analysis to explain which code can be executed.

If these options are enabled, code overwrite analysis is greatly slowed down.

The following example shows how to use the options:

Example:

<?phpxdebug_start_code_coverage( XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );?>

 

VoidXdebug_stop_code_coverage ([Int cleanup = true])

Stop code coverage analysis

This function stops collecting information, which is cleared in memory. If you pass the "false" parameter, the Code overwrite information will not be cleared and you can use it again.Xdebug_start_code_coverage ()Recover information collection.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.