styles(); } // Load the profiler view $data = array ( 'profiles' => Profiler::$profiles, 'styles' => $styles, 'execution_time' => microtime(TRUE) - $start ); $view = new View('profiler/profiler', $data); // Return rendered view if $return is TRUE if ($return === TRUE) return $view->render(); // Add profiler data to the output if (stripos(Kohana::$output, '') !== FALSE) { // Closing body tag was found, insert the profiler data before it Kohana::$output = str_ireplace('', $view->render().'', Kohana::$output); } else { // Append the profiler data to the output Kohana::$output .= $view->render(); } } /** * Benchmark times and memory usage from the Benchmark library. * * @return void */ public static function benchmarks() { if ( ! Profiler::show('benchmarks')) return; $table = new Profiler_Table(); $table->add_column(); $table->add_column('kp-column kp-data'); $table->add_column('kp-column kp-data'); $table->add_column('kp-column kp-data'); $table->add_row(array(__('Benchmarks'), __('Count'), __('Time'), __('Memory')), 'kp-title', 'background-color: #FFE0E0'); $benchmarks = Benchmark::get(TRUE); // Moves the first benchmark (total execution time) to the end of the array $benchmarks = array_slice($benchmarks, 1) + array_slice($benchmarks, 0, 1); text::alternate(); foreach ($benchmarks as $name => $benchmark) { // Clean unique id from system benchmark names $name = ucwords(str_replace(array('_', '-'), ' ', str_replace(SYSTEM_BENCHMARK.'_', '', $name))); $data = array(__($name), $benchmark['count'], number_format($benchmark['time'], Kohana::config('profiler.time_decimals')), number_format($benchmark['memory'] / 1024 / 1024, Kohana::config('profiler.memory_decimals')).'MB'); $class = text::alternate('', 'kp-altrow'); if ($name == 'Total Execution') { // Clear the count column $data[1] = ''; $class = 'kp-totalrow'; } $table->add_row($data, $class); } Profiler::add($table); } /** * Database query benchmarks. * * @return void */ public static function database() { if ( ! Profiler::show('database')) return; $queries = Database::$benchmarks; // Don't show if there are no queries if (empty($queries)) return; $table = new Profiler_Table(); $table->add_column(); $table->add_column('kp-column kp-data'); $table->add_column('kp-column kp-data'); $table->add_row(array(__('Queries'), __('Time'), __('Rows')), 'kp-title', 'background-color: #E0FFE0'); text::alternate(); $total_time = $total_rows = 0; foreach ($queries as $query) { $data = array($query['query'], number_format($query['time'], Kohana::config('profiler.time_decimals')), $query['rows']); $class = text::alternate('', 'kp-altrow'); $table->add_row($data, $class); $total_time += $query['time']; $total_rows += $query['rows']; } $data = array(__('Total: ') . count($queries), number_format($total_time, Kohana::config('profiler.time_decimals')), $total_rows); $table->add_row($data, 'kp-totalrow'); Profiler::add($table); } /** * Session data. * * @return void */ public static function session() { if (empty($_SESSION)) return; if ( ! Profiler::show('session')) return; $table = new Profiler_Table(); $table->add_column('kp-name'); $table->add_column(); $table->add_row(array(__('Session'), __('Value')), 'kp-title', 'background-color: #CCE8FB'); text::alternate(); foreach($_SESSION as $name => $value) { if (is_object($value)) { $value = get_class($value).' [object]'; } $data = array($name, $value); $class = text::alternate('', 'kp-altrow'); $table->add_row($data, $class); } Profiler::add($table); } /** * POST data. * * @return void */ public static function post() { if (empty($_POST)) return; if ( ! Profiler::show('post')) return; $table = new Profiler_Table(); $table->add_column('kp-name'); $table->add_column(); $table->add_row(array(__('POST'), __('Value')), 'kp-title', 'background-color: #E0E0FF'); text::alternate(); foreach($_POST as $name => $value) { $data = array($name, $value); $class = text::alternate('', 'kp-altrow'); $table->add_row($data, $class); } Profiler::add($table); } /** * Cookie data. * * @return void */ public static function cookies() { if (empty($_COOKIE)) return; if ( ! Profiler::show('cookies')) return; $table = new Profiler_Table(); $table->add_column('kp-name'); $table->add_column(); $table->add_row(array(__('Cookies'), __('Value')), 'kp-title', 'background-color: #FFF4D7'); text::alternate(); foreach($_COOKIE as $name => $value) { $data = array($name, $value); $class = text::alternate('', 'kp-altrow'); $table->add_row($data, $class); } Profiler::add($table); } }