From bb4085972bbdf713736ab6c6d03a884992fd888c Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 19 Sep 2009 20:13:37 +0100 Subject: [PATCH] code coverage stuff --- core/util.inc.php | 21 +++++++++++++++++++++ index.php | 2 ++ 2 files changed, 23 insertions(+) diff --git a/core/util.inc.php b/core/util.inc.php index 9005f71c..c74231f5 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -803,4 +803,25 @@ function _end_cache() { } } } + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ +* Code coverage * +\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +function _start_debug() { + if(function_exists("xdebug_start_code_coverage")) { + #xdebug_start_code_coverage(XDEBUG_CC_UNUSED|XDEBUG_CC_DEAD_CODE); + xdebug_start_code_coverage(XDEBUG_CC_UNUSED); + } +} + +function _end_debug() { + if(function_exists("xdebug_get_code_coverage")) { + if(!file_exists("data/coverage")) mkdir("data/coverage"); + $n = 0; + $t = time(); + while(file_exists("data/coverage/$t.$n.log")) $n++; + file_put_contents("data/coverage/$t.$n.log", serialize(xdebug_get_code_coverage())); + } +} ?> diff --git a/index.php b/index.php index 4ab4bb1a..325abe87 100644 --- a/index.php +++ b/index.php @@ -64,6 +64,7 @@ if(!file_exists("config.php")) { require_once "config.php"; require_once "core/util.inc.php"; +if(DEBUG) {_start_debug();} _version_check(); _sanitise_environment(); _start_cache(); @@ -147,4 +148,5 @@ catch(Exception $e) { EOD; } +if(DEBUG) {_end_debug();} ?>