Browse Source

Calculate the total render time in the profiler.

Franz Liedke 12 years ago
parent
commit
59397eb726
1 changed files with 16 additions and 0 deletions
  1. 16 0
      laravel/profiling/profiler.php

+ 16 - 0
laravel/profiling/profiler.php

@@ -14,6 +14,15 @@ class Profiler {
 	 * @var array
 	 * @var array
 	 */
 	 */
 	protected static $data = array('queries' => array(), 'logs' => 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.
 	 * Get the rendered contents of the Profiler.
@@ -28,6 +37,10 @@ class Profiler {
 		// type applications, so we will not send anything in those scenarios.
 		// type applications, so we will not send anything in those scenarios.
 		if ( ! Request::ajax())
 		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);
 			return render('path: '.__DIR__.'/template'.BLADE_EXT, static::$data);
 		}
 		}
 	}
 	}
@@ -67,6 +80,9 @@ class Profiler {
 	 */
 	 */
 	public static function attach()
 	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
 		// 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,
 		// all of the SQL queries and log messages that come through Laravel,
 		// and we will pass them onto the Profiler for simple storage.
 		// and we will pass them onto the Profiler for simple storage.