diff --git a/README.org b/README.org index aca66fa..9365444 100755 --- a/README.org +++ b/README.org @@ -5,9 +5,12 @@ [[file:README_cn.org][中文说明]] * Dependency -- laravel 5 (5.0 - 5.5) +- laravel 5-10 (for version 5 and higher laravel 10) - [[https://github.com/barryvdh/laravel-debugbar][barryvdh/laravel-debugbar]] (laravel-debugbar itself dosen't display debug messages in console) * Introduction + +=composer require biohazard/laravel-console-debug= + This package can show laravel-debugbar's debug messages and SQL queries in *console*. For example, there have a =test= command @@ -41,6 +44,14 @@ For example, there have a =test= command +-------------------------------+----------+ | select * from `users` limit 1 | 9.77ms | +-------------------------------+----------+ + + +-------------+---------+ + | Name | Memory | + +-------------+---------+ + | Booting | 17.47MB | + | Application | 8.77MB | + +-------------+---------+ + #+END_SRC =Test= command's example (this example require laravel 5.4+ to run, you need put these code in =routes/console.php=, for laravel 5.3 and below you can use =Command= class) diff --git a/composer.json b/composer.json index 66c8663..1f867ce 100755 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "frostrain/laravel-console-debug", + "name": "biohazard/laravel-console-debug", "description": "Show debug informations in console", "keywords": ["laravel", "debug"], "type": "library", @@ -11,7 +11,8 @@ } ], "require": { - "barryvdh/laravel-debugbar": "2.*|3.*" + "barryvdh/laravel-debugbar": "2.*|3.*", + "biohazard/laravel-debugbar-memory": "dev-master" }, "autoload": { "psr-4": { diff --git a/src/ConsoleOutputDebugCommand.php b/src/ConsoleOutputDebugCommand.php index b8706e6..07d9fda 100755 --- a/src/ConsoleOutputDebugCommand.php +++ b/src/ConsoleOutputDebugCommand.php @@ -4,6 +4,7 @@ use Illuminate\Console\Command; use Symfony\Component\Console\Helper\TableSeparator; +use Illuminate\Support\Arr; class ConsoleOutputDebugCommand extends Command { @@ -59,7 +60,7 @@ public function handle() if (!$this->output->isVerbose()) { return; } - $this->debugbar = $this->laravel->make('debugbar'); + $this->debugbar = app()->make('debugbar'); $this->columnLengthLimit = config('console_debug.column_length_limit'); $this->debugMessageStyles = config('console_debug.debug_message_styles'); @@ -70,6 +71,30 @@ public function handle() $this->outputMessages(); $this->outputSqls(); + $this->outputMemory(); + } + + protected function outputMemory() + { + + if (!$this->debugbar->hasCollector('memory_details')) { + return; + } + + $memories = $this->debugbar + ->getCollector('memory_details') + ->collect(); + + $memories = $memories['measures']; + + $memories = Arr::map($memories, function (string $value, string $key) { + return [$key, $value]; + }); + + $this->table( + ['Name', 'Memory'], + $memories + ); } protected function outputMessages() @@ -102,7 +127,7 @@ protected function outputMessages() $this->info(''); // table 方法传入的 $header 和 $data 最好是 元素数目相等, 并且顺序对应... // 否则结果会比较怪异 - $header = ['level', 'debug message']; + $header = ['Level', 'Debug message']; // table 方法无法设置 verbosity ... $this->table($header, $rows); } @@ -158,7 +183,7 @@ protected function outputSqls() $this->line(''); // table 方法传入的 $header 和 $data 最好是 元素数目相等, 并且顺序对应... // 否则结果会比较怪异 - $header = ['sql', 'duration']; + $header = ['SQL', 'Duration']; // table 方法无法设置 verbosity ... $this->table($header, $rows); }