if (in_array($library, $li3_perf['skip']['library'])) { $skip = true; } } // Check to see if the toolbar should be shown for this controller if (isset($li3_perf['skip']['controller'])) { if (in_array($controller, $li3_perf['skip']['controller'])) { $skip = true; } } // Check to see if the toolbar should be shown for this action if (isset($li3_perf['skip']['action'])) { if (in_array($action, $li3_perf['skip']['action'])) { $skip = true; } } } if ($skip || !isset($result->body[0])) { return $result; } $timers = Data::get('timers') + array('li3_perf_start' => 0, 'li3_perf_end' => 0, 'li3_perf_start_dispatch' => 0, 'li3_perf_has_route' => 0, 'li3_perf_start_call' => 0, 'li3_perf_end_call' => 0, '_filter_for_variables' => 0, '_filter_for_queries' => 0); $View = new View(array('paths' => array('template' => '{:library}/views/elements/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php'))); $toolbar = $View->render('all', array('timers' => $timers += array('dispatch_cycle' => $timers['li3_perf_end'] - $timers['li3_perf_start_dispatch'], 'routing' => $timers['li3_perf_has_route'] - $timers['li3_perf_start_dispatch'], 'call' => isset($timers['li3_perf_end_call']) && isset($timers['li3_perf_start_call']) ? $timers['li3_perf_end_call'] - $timers['li3_perf_start_call'] : 0, 'complete_load_with_li3_perf' => microtime(true) - $timers['li3_perf_start'], 'complete_load' => $timers['li3_perf_end'] - $timers['li3_perf_start'] - $timers['_filter_for_variables'] - $timers['_filter_for_queries']), 'vars' => array('request' => $params['request']->params, 'view' => Data::get('view_vars')), 'queries' => Data::get('queries')), array('library' => 'li3_perf', 'template' => 'toolbar', 'layout' => 'default')); if (preg_match('/<!--\\s*LI3_PERF_TOOLBAR\\s*-->/si', $result->body[0], $match)) { $result->body[0] = str_replace($match[0], $toolbar, $result->body[0]); } else { $result->body[0] = $toolbar . $result->body[0]; } } return $result; });
<?php use lithium\net\http\Media; use li3_perf\extensions\util\Data; // Apply a filter that will gather all the variables available to the view template. Media::applyFilter('render', function ($self, $params, $chain) { $filter_start = microtime(true); $view_vars = array(); foreach ($params['data'] as $k => $v) { if (is_object($v) && method_exists($v, 'data')) { $view_vars[$k] = $v->data(); } else { $view_vars[$k] = $v; } } Data::append('view_vars', $view_vars); Data::append('timers', array('_filter_for_variables' => microtime(true) - $filter_start)); return $chain->next($self, $params, $chain); });
<?php use li3_perf\extensions\util\Data; // Start the timer, note: li3_perf should be added before all other libraries (and after lithium). //$li3_perf_start = microtime(true); Data::set('timers', array('li3_perf_start' => microtime(true))); // Get the queries require __DIR__ . '/bootstrap/queries.php'; // Get the view variables require __DIR__ . '/bootstrap/variables.php'; // li3_perf will apply a filter on the Dispatcher class that renders the toolbar and times things. require __DIR__ . '/bootstrap/dispatcher.php'; // require LITHIUM_APP_PATH . '/libraries/li3_perf/extensions/util/Dump.php';