Menu

[r26]: / branches / phpcoverage-0.8.2 / src / remote / XdebugTraceReader.php  Maximize  Restore  History

Download this file

126 lines (111 with data), 3.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
* $Id$
*
* Copyright(c) 2004-2006, SpikeSource Inc. All Rights Reserved.
* Licensed under the Open Software License version 2.1
* (See http://www.spikesource.com/license.html)
*/
?>
<?php
/**
* Reader that parses Xdebug Trace data.
*
* @author Nimish Pachapurkar <npac@spikesource.com>
* @version $Revision: $
* @package SpikePHPCoverage_Parser
*/
class XdebugTraceReader {
/*{{{ Members */
protected $traceFilePath;
protected $handle;
protected $coverage = array();
/*}}}*/
/*{{{ Constructor */
/**
* Constructor
*
* @param $traceFilePath Path of the Xdebug trace file
* @access public
*/
public function __construct($traceFilePath) {
$this->traceFilePath = $traceFilePath;
}
/*}}}*/
/*{{{ protected function openTraceFile() */
/**
* Opens the trace file
*
* @return Boolean True on success, false on failure.
* @access protected
*/
protected function openTraceFile() {
$this->handle = fopen($this->traceFilePath, "r");
return !empty($this->handle);
}
/*}}}*/
/*{{{ public function parseTraceFile() */
/**
* Parses the trace file
*
* @return Boolean True on success, false on failure.
* @access public
*/
public function parseTraceFile() {
if(!$this->openTraceFile()) {
error_log("[XdebugTraceReader::parseTraceFile()] Unable to read trace file.");
return false;
}
while(!feof($this->handle)) {
$line = fgets($this->handle);
// echo "Line: " . $line . "\n";
$this->processTraceLine($line);
}
fclose($this->handle);
return true;
}
/*}}}*/
/*{{{ protected function processTraceLine() */
/**
* Process a give trace line
*
* @param $line Line from a trace file
* @return Boolean True on success, false on failure
* @access protected
*/
protected function processTraceLine($line) {
$dataparts = explode("\t", $line);
// print_r($dataparts);
$cnt = count($dataparts);
if($cnt < 2) {
return false;
}
if(!file_exists($dataparts[$cnt-2])) {
// echo "No file: " . $dataparts[$cnt-2] . "\n";
return false;
}
// Trim the entries
$dataparts[$cnt-2] = trim($dataparts[$cnt-2]);
$dataparts[$cnt-1] = trim($dataparts[$cnt-1]);
if(!isset($this->coverage[$dataparts[$cnt-2]][$dataparts[$cnt-1]])) {
$this->coverage[$dataparts[$cnt-2]][$dataparts[$cnt-1]] = 1;
}
else {
$this->coverage[$dataparts[$cnt-2]][$dataparts[$cnt-1]] ++;
}
return true;
}
/*}}}*/
/*{{{ public function getCoverageData() */
/**
* Returns the coverage array
*
* @return Array Array of coverage data from parsing.
* @access public
*/
public function getCoverageData() {
return $this->coverage;
}
/*}}}*/
}
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.