From 59397eb726840d640873bc3c668ccc5e1912b3c6 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sun, 24 Jun 2012 21:17:32 +0300 Subject: [PATCH 1/8] Calculate the total render time in the profiler. --- laravel/profiling/profiler.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/laravel/profiling/profiler.php b/laravel/profiling/profiler.php index 9b6edfef..0dc837c3 100644 --- a/laravel/profiling/profiler.php +++ b/laravel/profiling/profiler.php @@ -14,6 +14,15 @@ class Profiler { * @var array */ protected static $data = array('queries' => array(), 'logs' => array()); + + /** + * The time when the profiler was setup. + * + * This is used for generating the total page rendering time. + * + * @var float + */ + protected static $start_time; /** * Get the rendered contents of the Profiler. @@ -28,6 +37,10 @@ public static function render($response) // type applications, so we will not send anything in those scenarios. if ( ! Request::ajax()) { + if ($this->start_time) + { + static::$data['time'] = number_format((microtime(true) - $this->start_time) * 1000, 2); + } return render('path: '.__DIR__.'/template'.BLADE_EXT, static::$data); } } @@ -67,6 +80,9 @@ public static function query($sql, $bindings, $time) */ public static function attach() { + // Record when the profiler was setup (as a rough measure for render time) + $this->start_time = microtime(true); + // First we'll attach to the query and log events. These allow us to catch // all of the SQL queries and log messages that come through Laravel, // and we will pass them onto the Profiler for simple storage. From c74123098beb026de713efa139a532f9ba3aa9cd Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sun, 24 Jun 2012 21:27:57 +0300 Subject: [PATCH 2/8] Render page generation time on anbu profiler console. --- laravel/profiling/template.blade.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/laravel/profiling/template.blade.php b/laravel/profiling/template.blade.php index 0b0ffef8..a06f7957 100755 --- a/laravel/profiling/template.blade.php +++ b/laravel/profiling/template.blade.php @@ -61,6 +61,9 @@ @endif + @if (isset($time)) +
  • Time {{ $time }}ms
  • + @endif
  • ×
  • From 52f98b7cf6fff813698a3e7220104bf1f5c81e77 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Mon, 25 Jun 2012 01:12:31 +0300 Subject: [PATCH 3/8] Use start_time attribute like a static attribute (as it is). --- laravel/profiling/profiler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/laravel/profiling/profiler.php b/laravel/profiling/profiler.php index 0dc837c3..d39f8bd9 100644 --- a/laravel/profiling/profiler.php +++ b/laravel/profiling/profiler.php @@ -37,9 +37,9 @@ public static function render($response) // type applications, so we will not send anything in those scenarios. if ( ! Request::ajax()) { - if ($this->start_time) + if (static::$start_time) { - static::$data['time'] = number_format((microtime(true) - $this->start_time) * 1000, 2); + static::$data['time'] = number_format((microtime(true) - static::$start_time) * 1000, 2); } return render('path: '.__DIR__.'/template'.BLADE_EXT, static::$data); } @@ -81,7 +81,7 @@ public static function query($sql, $bindings, $time) public static function attach() { // Record when the profiler was setup (as a rough measure for render time) - $this->start_time = microtime(true); + static::$start_time = microtime(true); // First we'll attach to the query and log events. These allow us to catch // all of the SQL queries and log messages that come through Laravel, From 204a64f006992894b57811596e2e66e91c912216 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Mon, 25 Jun 2012 14:56:04 +0300 Subject: [PATCH 4/8] Simply use the LARAVEL_START constant for calculation page generation time in profiler. --- laravel/profiling/profiler.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/laravel/profiling/profiler.php b/laravel/profiling/profiler.php index d39f8bd9..4fd9c183 100644 --- a/laravel/profiling/profiler.php +++ b/laravel/profiling/profiler.php @@ -15,15 +15,6 @@ class Profiler { */ protected static $data = array('queries' => array(), 'logs' => array()); - /** - * The time when the profiler was setup. - * - * This is used for generating the total page rendering time. - * - * @var float - */ - protected static $start_time; - /** * Get the rendered contents of the Profiler. * @@ -37,10 +28,7 @@ public static function render($response) // type applications, so we will not send anything in those scenarios. if ( ! Request::ajax()) { - if (static::$start_time) - { - static::$data['time'] = number_format((microtime(true) - static::$start_time) * 1000, 2); - } + static::$data['time'] = number_format((microtime(true) - LARAVEL_START) * 1000, 2); return render('path: '.__DIR__.'/template'.BLADE_EXT, static::$data); } } @@ -80,9 +68,6 @@ public static function query($sql, $bindings, $time) */ public static function attach() { - // Record when the profiler was setup (as a rough measure for render time) - static::$start_time = microtime(true); - // First we'll attach to the query and log events. These allow us to catch // all of the SQL queries and log messages that come through Laravel, // and we will pass them onto the Profiler for simple storage. From bcd63ab5affaa29e187baf75452a74ee5a5772c3 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Mon, 25 Jun 2012 14:56:42 +0300 Subject: [PATCH 5/8] We can be fairly sure the $time variable is set in the profiler view. --- laravel/profiling/template.blade.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/laravel/profiling/template.blade.php b/laravel/profiling/template.blade.php index a06f7957..d87b19d5 100755 --- a/laravel/profiling/template.blade.php +++ b/laravel/profiling/template.blade.php @@ -61,9 +61,7 @@ @endif - @if (isset($time))
  • Time {{ $time }}ms
  • - @endif
  • ×
  • From 98b92185e314d8866ab7dae8d35fa8c8cec5c87f Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Mon, 2 Jul 2012 03:38:58 +0300 Subject: [PATCH 6/8] Calculate memory and peak memory usage in profiler, too. --- laravel/profiling/profiler.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/laravel/profiling/profiler.php b/laravel/profiling/profiler.php index 4fd9c183..b2a8635f 100644 --- a/laravel/profiling/profiler.php +++ b/laravel/profiling/profiler.php @@ -28,10 +28,24 @@ public static function render($response) // type applications, so we will not send anything in those scenarios. if ( ! Request::ajax()) { + static::$data['memory'] = static::get_file_size(memory_get_usage(true)); + static::$data['memory_peak'] = static::get_file_size(memory_get_peak_usage(true)); static::$data['time'] = number_format((microtime(true) - LARAVEL_START) * 1000, 2); return render('path: '.__DIR__.'/template'.BLADE_EXT, static::$data); } } + + /** + * Calculate the human-readable file size (with proper units). + * + * @param int $size + * @return string + */ + private static function get_file_size($size) + { + $units = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'); + return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2).' '.$units[$i]; + } /** * Add a log entry to the log entries array. From 94e9106b760eb1b50eb81ac83b23f400b6a3e829 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Mon, 2 Jul 2012 03:42:43 +0300 Subject: [PATCH 7/8] Display memory usage (and peak usage) in the profiler bar, too. --- laravel/profiling/template.blade.php | 1 + 1 file changed, 1 insertion(+) diff --git a/laravel/profiling/template.blade.php b/laravel/profiling/template.blade.php index d87b19d5..32c430a6 100755 --- a/laravel/profiling/template.blade.php +++ b/laravel/profiling/template.blade.php @@ -62,6 +62,7 @@
  • Time {{ $time }}ms
  • +
  • Memory {{ $memory }} ({{ $memory_peak }})
  • ×
  • From 6b5cccc15f015a531099ae27455c02b0f869a043 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 7 Jul 2012 02:13:44 +0200 Subject: [PATCH 8/8] Move get_file_size() helper function to helpers.php. --- laravel/helpers.php | 12 ++++++++++++ laravel/profiling/profiler.php | 16 ++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/laravel/helpers.php b/laravel/helpers.php index 07f9940a..b45fd9d2 100644 --- a/laravel/helpers.php +++ b/laravel/helpers.php @@ -580,4 +580,16 @@ function get_cli_option($option, $default = null) } return value($default); +} + +/** + * Calculate the human-readable file size (with proper units). + * + * @param int $size + * @return string + */ +function get_file_size($size) +{ + $units = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'); + return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2).' '.$units[$i]; } \ No newline at end of file diff --git a/laravel/profiling/profiler.php b/laravel/profiling/profiler.php index b2a8635f..c8f069ae 100644 --- a/laravel/profiling/profiler.php +++ b/laravel/profiling/profiler.php @@ -28,24 +28,12 @@ public static function render($response) // type applications, so we will not send anything in those scenarios. if ( ! Request::ajax()) { - static::$data['memory'] = static::get_file_size(memory_get_usage(true)); - static::$data['memory_peak'] = static::get_file_size(memory_get_peak_usage(true)); + static::$data['memory'] = get_file_size(memory_get_usage(true)); + static::$data['memory_peak'] = get_file_size(memory_get_peak_usage(true)); static::$data['time'] = number_format((microtime(true) - LARAVEL_START) * 1000, 2); return render('path: '.__DIR__.'/template'.BLADE_EXT, static::$data); } } - - /** - * Calculate the human-readable file size (with proper units). - * - * @param int $size - * @return string - */ - private static function get_file_size($size) - { - $units = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'); - return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2).' '.$units[$i]; - } /** * Add a log entry to the log entries array.