Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Tracy/Debugger.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class Debugger
/** @var int timestamp with microseconds of the start of the request */
public static $time;

/** @var float of CPU usage of the start of the request */
public static $rusage;

/** @bool of availability of getrusage function */
public static $getrusage;

/** @var string URI pattern mask to open editor */
public static $editor = 'editor://open/?file=%file&line=%line';

Expand Down Expand Up @@ -135,6 +141,13 @@ public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL)
self::$obLevel = ob_get_level();
error_reporting(E_ALL);

// get initial rusage for CPU output in info panel
self::$getrusage = function_exists('getrusage');
if(self::$getrusage) {
$dat = getrusage();
self::$rusage = $dat["ru_utime.tv_sec"]*1e6+$dat["ru_utime.tv_usec"];
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be skipped in production mode? Also your coding style is not correct.


if ($mode !== NULL || self::$productionMode === NULL) {
self::$productionMode = is_bool($mode) ? $mode : !self::detectDebugMode($mode);
}
Expand Down
16 changes: 16 additions & 0 deletions src/Tracy/assets/Bar/info.panel.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,25 @@ namespace Tracy;

use Tracy;

if(Debugger::$getrusage) {
$dat = getrusage();
$dat["ru_utime.tv_usec"] = ($dat["ru_utime.tv_sec"]*1e6 + $dat["ru_utime.tv_usec"]) - Debugger::$rusage;
$time = ($this->time) * 1000000;
// cpu per request
if($time > 0) {
$cpu = sprintf("%01.2f", ($dat["ru_utime.tv_usec"] / $time) * 100) . '%';
} else {
$cpu = '0.00%';
}
}
else {
$cpu = 'Not Available';
}

$info = array_filter([
'Execution time' => number_format($this->time * 1000, 1, '.', ' ') . ' ms',
'Peak of allocated memory' => number_format(memory_get_peak_usage() / 1000000, 2, '.', ' ') . ' MB',
'CPU' => $cpu,
'Included files' => count(get_included_files()),
'Classes + interfaces + traits' => count(get_declared_classes()) . ' + '
. count(get_declared_interfaces()) . ' + ' . count(get_declared_traits()),
Expand Down