Debugger optimizations

This commit is contained in:
Matias Griese 2018-10-16 13:12:26 +03:00
parent f43ab0ed59
commit eb97964a00
6 changed files with 51 additions and 21 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env php
<?php
define('GRAV_CLI', true);
\define('GRAV_CLI', true);
\define('GRAV_REQUEST_TIME', microtime(true));
if (!file_exists(__DIR__ . '/../vendor')){
require_once __DIR__ . '/../system/src/Grav/Common/Composer.php';
@ -20,7 +21,7 @@ if (!file_exists(__DIR__ . '/../vendor')){
use Symfony\Component\Console\Application;
use Grav\Common\Grav;
$autoload = require_once(__DIR__ . '/../vendor/autoload.php');
$autoload = require __DIR__ . '/../vendor/autoload.php';
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));

View File

@ -1,6 +1,7 @@
#!/usr/bin/env php
<?php
define('GRAV_CLI', true);
\define('GRAV_CLI', true);
\define('GRAV_REQUEST_TIME', microtime(true));
if (!file_exists(__DIR__ . '/../vendor')){
require_once __DIR__ . '/../system/src/Grav/Common/Composer.php';
@ -18,7 +19,7 @@ if (!file_exists(__DIR__ . '/../vendor')){
echo "\n\n";
}
$autoload = require_once(__DIR__ . '/../vendor/autoload.php');
$autoload = require __DIR__ . '/../vendor/autoload.php';
Grav::instance(array('loader' => $autoload));
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {

View File

@ -1,6 +1,7 @@
#!/usr/bin/env php
<?php
define('GRAV_CLI', true);
\define('GRAV_CLI', true);
\define('GRAV_REQUEST_TIME', microtime(true));
if (!file_exists(__DIR__ . '/../vendor')) {
require_once __DIR__ . '/../system/src/Grav/Common/Composer.php';
@ -24,7 +25,7 @@ use Grav\Common\Grav;
use Grav\Common\Config\Setup;
use Grav\Common\Filesystem\Folder;
$autoload = require_once(__DIR__ . '/../vendor/autoload.php');
$autoload = require __DIR__ . '/../vendor/autoload.php';
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
@ -83,10 +84,10 @@ $output->getFormatter()->setStyle('white', new OutputFormatterStyle('white', nul
if (!$name) {
$output->writeln('');
$output->writeln("<red>Usage:</red>");
$output->writeln('<red>Usage:</red>');
$output->writeln(" {$bin} [slug] [command] [arguments]");
$output->writeln('');
$output->writeln("<red>Example:</red>");
$output->writeln('<red>Example:</red>');
$output->writeln(" {$bin} error log -l 1 --trace");
$list = Folder::all('plugins://', ['compare' => 'Pathname', 'pattern' => '/\/cli\/' . $pattern . '$/usm', 'levels' => 2]);
@ -104,7 +105,7 @@ if (!$name) {
}
$available[] = $entry;
$output->writeln(' ' . $index . ". <red>" . str_pad($entry, 15) . "</red> <white>${bin} ${entry} list</white>");
$output->writeln(' ' . $index . '. <red>' . str_pad($entry, 15) . "</red> <white>${bin} ${entry} list</white>");
}
}

View File

@ -9,6 +9,7 @@
namespace Grav;
\define('GRAV_REQUEST_TIME', microtime(true));
\define('GRAV_PHP_MIN', '7.1.3');
if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {

View File

@ -11,7 +11,7 @@ namespace Grav\Common;
class Composer
{
/** @const Default composer location */
const DEFAULT_PATH = "bin/composer.phar";
const DEFAULT_PATH = 'bin/composer.phar';
/**
* Returns the location of composer.
@ -20,12 +20,12 @@ class Composer
*/
public static function getComposerLocation()
{
if (!function_exists('shell_exec') || strtolower(substr(PHP_OS, 0, 3)) === 'win') {
if (!\function_exists('shell_exec') || stripos(PHP_OS, 'win') === 0) {
return self::DEFAULT_PATH;
}
// check for global composer install
$path = trim(shell_exec("command -v composer"));
$path = trim(shell_exec('command -v composer'));
// fall back to grav bundled composer
if (!$path || !preg_match('/(composer|composer\.phar)$/', $path)) {

View File

@ -9,7 +9,13 @@
namespace Grav\Common;
use DebugBar\DataCollector\ConfigCollector;
use DebugBar\DataCollector\ExceptionsCollector;
use DebugBar\DataCollector\MemoryCollector;
use DebugBar\DataCollector\MessagesCollector;
use DebugBar\DataCollector\PhpInfoCollector;
use DebugBar\DataCollector\RequestDataCollector;
use DebugBar\DataCollector\TimeDataCollector;
use DebugBar\DebugBar;
use DebugBar\JavascriptRenderer;
use DebugBar\StandardDebugBar;
use Grav\Common\Config\Config;
@ -28,13 +34,16 @@ class Debugger
/** @var StandardDebugBar $debugbar */
protected $debugbar;
/** @var bool */
protected $enabled;
/** @var array */
protected $timers = [];
/** @var string[] $deprecations */
protected $deprecations = [];
/** @var callable */
protected $errorHandler;
/**
@ -42,11 +51,26 @@ class Debugger
*/
public function __construct()
{
$currentTime = microtime(true);
if (!\defined('GRAV_REQUEST_TIME')) {
\define('GRAV_REQUEST_TIME', $currentTime);
}
// Enable debugger until $this->init() gets called.
$this->enabled = true;
$this->debugbar = new StandardDebugBar();
$this->debugbar['time']->addMeasure('Loading', $this->debugbar['time']->getRequestStartTime(), microtime(true));
$debugbar = new DebugBar();
$debugbar->addCollector(new PhpInfoCollector());
$debugbar->addCollector(new MessagesCollector());
$debugbar->addCollector(new RequestDataCollector());
$debugbar->addCollector(new TimeDataCollector($_SERVER['REQUEST_TIME_FLOAT'] ?? GRAV_REQUEST_TIME));
$debugbar['time']->addMeasure('Server', $debugbar['time']->getRequestStartTime(), GRAV_REQUEST_TIME);
$debugbar['time']->addMeasure('Loading', GRAV_REQUEST_TIME, $currentTime);
$debugbar['time']->addMeasure('Debugger', $currentTime, microtime(true));
$this->debugbar = $debugbar;
// Set deprecation collector.
$this->setErrorHandler();
@ -72,9 +96,11 @@ class Debugger
ksort($plugins_config);
$this->debugbar->addCollector(new ConfigCollector((array)$this->config->get('system'), 'Config'));
$this->debugbar->addCollector(new ConfigCollector($plugins_config, 'Plugins'));
$debugbar = $this->debugbar;
$debugbar->addCollector(new MemoryCollector());
$debugbar->addCollector(new ExceptionsCollector());
$debugbar->addCollector(new ConfigCollector((array)$this->config->get('system'), 'Config'));
$debugbar->addCollector(new ConfigCollector($plugins_config, 'Plugins'));
$this->addMessage('Grav v' . GRAV_VERSION);
}
@ -229,7 +255,7 @@ class Debugger
/**
* Start a timer with an associated name and description
*
* @param $name
* @param string $name
* @param string|null $description
*
* @return $this
@ -253,7 +279,7 @@ class Debugger
*/
public function stopTimer($name)
{
if (in_array($name, $this->timers, true) && ($name[0] === '_' || $this->enabled())) {
if (\in_array($name, $this->timers, true) && ($name[0] === '_' || $this->enabled())) {
$this->debugbar['time']->stopMeasure($name);
}
@ -411,8 +437,8 @@ class Debugger
$trace = [];
foreach ($deprecated['trace'] as $current) {
$class = isset($current['class']) ? $current['class'] : '';
$type = isset($current['type']) ? $current['type'] : '';
$class = $current['class'] ?? '';
$type = $current['type'] ?? '';
$function = $this->getFunction($current);
if (isset($current['file'])) {
$current['file'] = str_replace(GRAV_ROOT . '/', '', $current['file']);