public function display($tpl = null)
 {
     xdebug_start_trace(JPATH_COMPONENT . '/views/xdebug/function_trace');
     $data = $this->get('Data');
     $this->assign('data', $data);
     parent::display($tpl);
     xdebug_stop_trace();
 }
示例#2
0
 public function stop()
 {
     if (static::$file) {
         xdebug_stop_trace();
         static::$file = null;
     }
 }
示例#3
0
 protected function tearDown()
 {
     if ($this->stopTraceOnTearDown) {
         xdebug_stop_trace();
         $this->stopTraceOnTearDown = false;
     }
 }
示例#4
0
文件: xdebug.php 项目: alencarmo/OCF
function traceStop()
{
    if (!function_exists('xdebug_is_enabled') || !xdebug_is_enabled()) {
        return;
    }
    xdebug_stop_trace();
}
示例#5
0
文件: Debug.php 项目: zucchi/zucchi
 public static function stopTrace()
 {
     if (!extension_loaded('xdebug')) {
         throw new \RuntimeException('XDebug must be installed to use this function');
     }
     \xdebug_stop_trace();
 }
示例#6
0
 public function flush()
 {
     xdebug_stop_trace();
     echo "\n\n", 'Generating tracing reports from file ', $this->traceFile, ':', "\n";
     echo '  Class Diagram ...';
     $builder = $this->parse();
     $builder->build()->write('build/logs/class_diagram.dot');
     echo ' done', "\n";
 }
示例#7
0
文件: log.php 项目: Borvik/Munla
 /**
  * If an XDebug trace is running, this stops the trace.
  * 
  * @param bool $showAsDebug  If true, outputs the trace file as debug information (assuming displayDebug is used)
  * 
  * @return void
  */
 public static function end_trace($showAsDebug = false)
 {
     if (function_exists('xdebug_stop_trace')) {
         $file = xdebug_get_tracefile_name();
         xdebug_stop_trace();
         if ($showAsDebug === true) {
             $trace = file_get_contents($file);
             self::debug($trace);
         }
     }
 }
 /**
  * shutdown function to generate profile report 
  */
 function kataSmallProfile()
 {
     xdebug_stop_trace();
     $lines = file($GLOBALS['kataSmallProfileFile'] . '.xt');
     unlink($GLOBALS['kataSmallProfileFile'] . '.xt');
     array_shift($lines);
     //version
     array_shift($lines);
     //trace start
     array_pop($lines);
     //exit
     array_pop($lines);
     //trace end
     $lastLine = array_pop($lines);
     //dummy
     $temp = explode("\t", $lines[2]);
     $endTime = $temp[3];
     $temp = explode("\t", $lastLine);
     $totalTime = $temp[3] - $endTime;
     unset($temp);
     $callStack = array();
     $outCnt = array();
     $out = array();
     foreach ($lines as $line) {
         $line = explode("\t", $line);
         if (1 == $line[2]) {
             $retLine = array_pop($callStack);
             if ($retLine[6] == 1) {
                 //user func
                 $time = $line[3] - $retLine[3];
                 $outCnt[$retLine[5]] = (empty($outCnt[$retLine[5]]) ? 0 : $outCnt[$retLine[5]]) + 1;
                 $out[$retLine[5]] = (empty($out[$retLine[5]]) ? 0 : $out[$retLine[5]]) + $time;
             }
             continue;
         }
         if (substr($line[8], 0, strlen(ROOT)) != ROOT) {
             continue;
         }
         if (0 == $line[2]) {
             // entry
             $callStack[] = $line;
         }
     }
     arsort($out);
     $tdCell = '<td style="border:1px solid red;padding:2px;">';
     echo '<table style="border:1px solid red;color:black;background-color:#e8e8e8;border-collapse:collapse;">';
     echo '<tr>' . $tdCell . 'What</td>' . $tdCell . 'x times</td>' . $tdCell . 'ms total</td></tr>';
     foreach ($out as $n => $v) {
         echo '<tr>' . $tdCell . '<pre class="c1">' . $n . '</pre></td>' . $tdCell . $outCnt[$n] . '</td>' . $tdCell . $v . ' ms</td></tr>';
     }
     echo "<tr>{$tdCell} Total (before destroy)</td>{$tdCell}</td>{$tdCell} {$totalTime} ms</td></tr>";
     echo '</table>';
 }
示例#9
0
 static function stop()
 {
     if (ini_get('xdebug.auto_trace')) {
         return;
     }
     if (!self::$running) {
         throw new \BadMethodCallException();
     }
     xdebug_stop_trace();
     foreach (self::$iniRestore as $k => $v) {
         ini_set($k, $v);
     }
     self::$iniRestore = [];
     self::$running = false;
 }
示例#10
0
文件: Index.php 项目: btweedy/foresmo
 protected function _preRender()
 {
     parent::_preRender();
     if (Solar_Config::get('Foresmo', 'dev')) {
         xdebug_stop_trace();
         $trace_file = explode("\n", file_get_contents('/var/www/foresmo/tmp/trace.xt'));
         $trace_file_count = count($trace_file);
         $trace_dump = array();
         $defined_funcs = get_defined_functions();
         foreach ($trace_file as $line => $value) {
             if ($line == 0 || $line >= $trace_file_count - 4 || strstr($value, 'include(') || strstr($value, 'require(')) {
                 continue;
             }
             $tl = explode('-> ', $value);
             $tl = explode(' ', $tl[1]);
             if (!in_array(str_replace('()', '', $tl[0]), $defined_funcs['internal']) && strstr($tl[0], 'Foresmo') && !in_array($tl[0], $trace_dump)) {
                 $trace_dump[] = $tl[0];
             }
         }
         $tests = array();
         // Lets organize our trace dump calls to that we can easily check/run tests
         foreach ($trace_dump as $call) {
             if (strstr($call, '->')) {
                 $class_method = explode('->', $call);
             } else {
                 $class_method = explode('::', $call);
             }
             if (!isset($tests[$class_method[0]])) {
                 $tests[$class_method[0]] = array($class_method[1]);
             } else {
                 $tests[$class_method[0]][] = $class_method[1];
             }
         }
         var_dump($trace_dump);
         var_dump($tests);
         die;
     }
 }
示例#11
0
文件: Profiler.php 项目: kingsj/core
 /**
  * Log same time range
  *
  * @param string  $timePoint  Time range name
  * @param boolean $additional Additional metric flag OPTIONAL
  *
  * @return void
  */
 public function log($timePoint, $additional = false)
 {
     if (!isset($this->points[$timePoint])) {
         $this->points[$timePoint] = array('start' => microtime(true), 'open' => true, 'time' => 0);
         if (self::$useXdebugStackTrace) {
             xdebug_start_trace(LC_DIR_LOG . $timePoint . '.' . microtime(true), XDEBUG_TRACE_COMPUTERIZED);
         }
     } elseif ($this->points[$timePoint]['open']) {
         $range = microtime(true) - $this->points[$timePoint]['start'];
         if ($additional) {
             $this->points[$timePoint]['time'] += $range;
         } else {
             $this->points[$timePoint]['time'] = $range;
         }
         $this->points[$timePoint]['open'] = false;
         if (self::$useXdebugStackTrace) {
             @xdebug_stop_trace();
         }
     } else {
         $this->points[$timePoint]['start'] = microtime(true);
         $this->points[$timePoint]['open'] = true;
         if (self::$useXdebugStackTrace) {
             xdebug_start_trace(LC_DIR_VAR . 'log' . LC_DS . $timePoint . '.' . microtime(true), XDEBUG_TRACE_COMPUTERIZED);
         }
     }
 }
 function process($tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace)
 {
     switch ($functionName) {
         case $this->TimingPointName:
             $children = $functionChildren;
             $parameters = $functionParameters;
             $id = false;
             if (isset($parameters["id"])) {
                 $id = $tpl->elementValue($parameters["id"], $rootNamespace, $currentNamespace, $functionPlacement);
             }
             $startDescription = "debug-timing-point START: {$id}";
             eZDebug::addTimingPoint($startDescription);
             if (is_array($children)) {
                 foreach (array_keys($children) as $childKey) {
                     $child =& $children[$childKey];
                     $tpl->processNode($child, $textElements, $rootNamespace, $currentNamespace);
                 }
             }
             $endDescription = "debug-timing-point END: {$id}";
             eZDebug::addTimingPoint($endDescription);
             break;
         case $this->AccumulatorName:
             $children = $functionChildren;
             $parameters = $functionParameters;
             $id = false;
             if (isset($parameters["id"])) {
                 $id = $tpl->elementValue($parameters["id"], $rootNamespace, $currentNamespace, $functionPlacement);
             }
             $name = false;
             if (isset($parameters["name"])) {
                 $name = $tpl->elementValue($parameters["name"], $rootNamespace, $currentNamespace, $functionPlacement);
             }
             // Assign a name (as $functionName) which will be used in the debug output.
             $name = ($name === false and $id === false) ? $functionName : $name;
             // To uniquely identify this accumulator.
             $id = $id === false ? uniqID($functionName . '_') : $id;
             eZDebug::accumulatorStart($id, 'Debug-Accumulator', $name);
             if (is_array($children)) {
                 foreach (array_keys($children) as $childKey) {
                     $child =& $children[$childKey];
                     $tpl->processNode($child, $textElements, $rootNamespace, $currentNamespace);
                 }
             }
             eZDebug::accumulatorStop($id);
             break;
         case $this->LogName:
             $parameters = $functionParameters;
             if (isset($parameters['var'])) {
                 $var = $tpl->elementValue($parameters['var'], $rootNamespace, $currentNamespace, $functionPlacement);
             }
             if (isset($parameters['msg'])) {
                 $msg = $tpl->elementValue($parameters['msg'], $rootNamespace, $currentNamespace, $functionPlacement);
             }
             if (isset($var) && isset($msg)) {
                 eZDebug::writeDebug($var, $msg);
             } elseif (isset($msg)) {
                 eZDebug::writeDebug($msg);
             } elseif (isset($var)) {
                 eZDebug::writeDebug($var);
             }
             break;
         case $this->TraceName:
             $children = $functionChildren;
             $id = false;
             // If we have XDebug we start the trace, execute children and stop it
             // if not we just execute the children as normal
             if (extension_loaded('xdebug')) {
                 $parameters = $functionParameters;
                 if (isset($parameters["id"])) {
                     $id = $tpl->elementValue($parameters["id"], $rootNamespace, $currentNamespace, $functionPlacement);
                 }
                 if (!$id) {
                     $id = 'template-debug';
                 }
                 // If we already have a file, make sure it is truncated
                 if (file_exists($id . '.xt')) {
                     $fd = fopen($id, '.xt', 'w');
                     fclose($fd);
                 }
                 xdebug_start_trace($id);
                 if (is_array($children)) {
                     foreach (array_keys($children) as $childKey) {
                         $child =& $children[$childKey];
                         $tpl->processNode($child, $textElements, $rootNamespace, $currentNamespace);
                     }
                 }
                 xdebug_stop_trace();
             } elseif (is_array($children)) {
                 foreach (array_keys($children) as $childKey) {
                     $child =& $children[$childKey];
                     $tpl->processNode($child, $textElements, $rootNamespace, $currentNamespace);
                 }
             }
             break;
     }
 }
示例#13
0
<?php

include_once __DIR__ . '/vendor/autoload.php';
$appConfig = $appConfig = array('modules' => array(), 'module_listener_options' => array('module_paths' => array('./vendor'), 'config_glob_paths' => array('config/autoload/{,*.}{global,local}.php')));
if (!is_dir(__DIR__ . '/trace')) {
    mkdir(__DIR__ . '/trace');
}
ini_set('xdebug.show_mem_delta', '1');
for ($t = 0; $t < 5; $t++) {
    xdebug_start_trace(sprintf('%s/trace/%d', __DIR__, $t + 1));
    $app = \Zend\Mvc\Application::init($appConfig);
    xdebug_stop_trace();
    \Zend\EventManager\StaticEventManager::resetInstance();
    $app = null;
}
示例#14
0
 /**
  * Stop xdebug trace. Call startXDTrace() first.
  * @param string $file (default = STDOUT)
  */
 public function stopXDTrace($file = 'php://STDOUT')
 {
     $trace_file = xdebug_get_tracefile_name();
     xdebug_stop_trace();
     if (!$trace_file || !$file) {
         return;
     }
     $fh = fopen($trace_file, 'r');
     fgets($fh);
     // ignore first line
     $trace_buildin = array('microtime()', 'memory_get_usage()', 'xdebug_call_class()', 'xdebug_call_function()', 'xdebug_call_line()', 'xdebug_call_file()', 'xdebug_stop_trace()');
     $trace_func = array('rkphplib\\Profiler->log()');
     $buildin_list = array('time', 'in_array', 'is_object', 'is_array', 'is_null', 'array_push', 'join', 'preg_match', 'array_keys', 'array_shift', 'array_pop', 'array_push', 'strpos', 'preg_split', 'count', 'substr', 'mb_substr', 'basename', 'str_replace', 'mysqli->real_escape_string', 'mysqli->mysqli', 'mysqli->real_query', 'mysqli->set_charset', 'mysqli->query', 'mysqli_result->fetch_assoc', 'mysqli_result->close', 'mysqli->prepare', 'mysqli_stmt->bind_param', 'mysqli_stmt->execute', 'mysqli_stmt->close', 'ReflectionClass->__construct', 'ReflectionClass->getMethod', 'ReflectionMethod->invokeArgs');
     $buildin = array();
     foreach ($buildin_list as $func) {
         $buildin[$func . '()'] = 0;
     }
     $custom = array();
     $last = array(0, 0, '', '');
     while ($line = fgets($fh)) {
         $col = preg_split("/ +/", trim($line));
         if (empty($col[4])) {
             continue;
         }
         if (in_array($col[3], $trace_buildin)) {
             $last = $col;
             continue;
         }
         if (in_array($col[3], $trace_func)) {
             // ToDo ... ignore following
             continue;
         }
         if (isset($buildin[$col[3]])) {
             $buildin[$col[3]]++;
         } else {
             if (!isset($custom[$col[3]])) {
                 $custom[$col[3]] = array('call' => 0, 'time' => 0, 'mem' => 0);
             }
             $custom[$col[3]]['call']++;
             // ToDo ... collect following
             $custom[$col[3]]['time'] = 0;
             $custom[$col[3]]['mem'] = 0;
         }
         $last = $col;
     }
     fclose($fh);
     $fh = fopen($file, 'a');
     fwrite($fh, "\nBuildIn Functions:\n");
     foreach ($buildin as $func => $call) {
         if ($call > 10) {
             fprintf($fh, "%10s%50s\n", $call . 'x ', $func);
         }
     }
     fwrite($fh, "\nCustom Functions:\n");
     foreach ($custom as $func => $info) {
         if ($info['call'] > 0) {
             $c = $info['call'];
             fprintf($fh, "%10s%50s%16s%16s\n", $c . 'x ', $func, round($info['time'] / $c, 4) . ' s', round($info['mem'] / $c, 0) . ' b');
         }
     }
     fclose($fh);
 }
示例#15
0
 /**
  * Stops trace.
  * This is for temporary use when debugging.
  * DO NOT CHECK IN A CALL TO THIS FUNCTION.
  */
 public static function stopTrace()
 {
     xdebug_stop_trace();
 }
 /**
  * shutdown function to generate profile report 
  */
 function kataSmallProfile()
 {
     xdebug_stop_trace();
     $lines = file($GLOBALS['kataSmallProfileFile'] . '.xt');
     unlink($GLOBALS['kataSmallProfileFile'] . '.xt');
     array_shift($lines);
     //version
     array_shift($lines);
     //trace start
     array_pop($lines);
     //exit
     array_pop($lines);
     //trace end
     $lastLine = array_pop($lines);
     //dummy
     $temp = explode("\t", $lines[2]);
     $endTime = $temp[3];
     $temp = explode("\t", $lastLine);
     $totalTime = $temp[3] - $endTime;
     unset($temp);
     $callStack = array();
     $outCnt = array();
     $out = array();
     foreach ($lines as $line) {
         $line = explode("\t", $line);
         if (1 == $line[2]) {
             $retLine = array_pop($callStack);
             if ($retLine[6] == 1) {
                 //user func
                 $time = $line[3] - $retLine[3];
                 $outCnt[$retLine[5]] = (empty($outCnt[$retLine[5]]) ? 0 : $outCnt[$retLine[5]]) + 1;
                 $out[$retLine[5]] = (empty($out[$retLine[5]]) ? 0 : $out[$retLine[5]]) + $time;
             }
             continue;
         }
         if (substr($line[8], 0, strlen(ROOT)) != ROOT) {
             continue;
         }
         if (0 == $line[2]) {
             // entry
             $callStack[] = $line;
         }
     }
     arsort($out);
     // if PROFILE_LOG_MINIMUM is defined, only log request with a minimum runtime (in s)
     $logMinimum = defined('PROFILE_LOG_MINIMUM') ? PROFILE_LOG_MINIMUM : 0;
     $log = '';
     $timePerBlock = $totalTime / 50;
     foreach ($out as $n => $v) {
         // ignore dispatcher...
         if ($n == 'dispatcher->dispatch' || $n == 'require') {
             continue;
         }
         if ($v >= $logMinimum) {
             $sl = strlen($n);
             $tTimes = max(1, 6 - (int) ($sl / 8));
             $log .= $outCnt[$n] . "\t" . $n;
             for ($i = 0; $i < $tTimes; $i++) {
                 $log .= "\t";
             }
             $log .= number_format($v, 3) . "s ";
             $dl = '';
             for ($i = 0; $i < (int) ($v / $timePerBlock); $i++) {
                 //$dl .= chr(0xDB);
                 if ($i % 10 == 9) {
                     $dl .= '|';
                 }
                 $dl .= '~';
             }
             if (!empty($dl)) {
                 $log .= $dl;
             }
             $log .= "\n";
         }
     }
     if (!empty($log)) {
         $log = "===============================================================\n" . date("d.m. H:i:s") . "\n" . $_SERVER['REQUEST_URI'] . "\nTotal: " . $totalTime . "s" . "\n---------------------------------------------------------------\n" . $log . "===============================================================\n\n";
         file_put_contents($GLOBALS['kataProfileLogFile'], $log, FILE_APPEND);
     }
 }
示例#17
0
<?php

function start_trace()
{
    xdebug_start_trace('/tmp/trace.%p');
}
start_trace();
require __DIR__ . '/tracing.inc';
$file = xdebug_stop_trace();
var_dump(file_get_contents($file));
示例#18
0
// pid
var_dump(xdebug_start_trace("/tmp/trace-%p"));
var_dump(xdebug_stop_trace());
// random
var_dump(xdebug_start_trace("/tmp/trace-%r"));
var_dump(xdebug_stop_trace());
// script name
var_dump(xdebug_start_trace("/tmp/trace-%s"));
var_dump(xdebug_stop_trace());
// timestamp (sec)
var_dump(xdebug_start_trace("/tmp/trace-%t"));
var_dump(xdebug_stop_trace());
// timestamp (microseconds)
var_dump(xdebug_start_trace("/tmp/trace-%u"));
var_dump(xdebug_stop_trace());
// $_SERVER['HTTP_HOST']
var_dump(xdebug_start_trace("/tmp/trace-%H"));
var_dump(xdebug_stop_trace());
// $_SERVER['REQUEST_URI']
var_dump(xdebug_start_trace("/tmp/trace-%R"));
var_dump(xdebug_stop_trace());
// $_SERVER['UNIQUE_ID']
var_dump(xdebug_start_trace("/tmp/trace-%U"));
var_dump(xdebug_stop_trace());
// session id
var_dump(xdebug_start_trace("/tmp/trace-%S"));
var_dump(xdebug_stop_trace());
// Literal %
var_dump(xdebug_start_trace("/tmp/trace-%%"));
var_dump(xdebug_stop_trace());
示例#19
0
 /**
  * stop_trace - turn off xdebug trace
  *
  * Requires xdebug extension
  *
  * @return void
  */
 public static function stopTrace()
 {
     if (function_exists('xdebug_stop_trace')) {
         xdebug_stop_trace();
     }
 }
 /**
  * On test end
  * @param  \PHPUnit_Framework_Test $test
  * @param  string $time Time taken for test to execute.
  */
 public function endTest(\PHPUnit_Framework_Test $test, $time)
 {
     if (!$this->shouldListen()) {
         return;
     }
     xdebug_stop_trace();
     $traceFilePath = $this->getTraceFullPath() . '.xt';
     $trace = file_get_contents($traceFilePath);
     foreach ($this->searchPatterns as $searchPattern) {
         $foundPattern = $this->find($trace, $searchPattern);
         if ($foundPattern) {
             $this->addSearchResult($searchPattern, $foundPattern);
         } else {
             unlink($traceFilePath);
         }
     }
 }