/** * Overload Sprig::delete() to update child articles * to become children of the uncategorized subcategory */ public function delete(Database_Query_Builder_Delete $query = NULL) { Kohana::$log->add(Kohana::DEBUG, 'Beginning subcategory deletion for subcategory_id='.$this->id); if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start('blog', 'delete subcategory'); } $uncategorized = Sprig::factory('subcategory', array('name'=>'uncategorized'))->load(); // Modify category IDs for all child articles try { DB::update('articles')->value('subcategory_id', $uncategorized->id) ->where('subcategory_id', '=', $this->id)->execute(); } catch (Database_Exception $e) { Kohana::$log->add(Kohana::ERROR, 'Exception occured while modifying deleted subcategory\'s articles. '.$e->getMessage()); return $this; } if (isset($benchmark)) { Profiler::stop($benchmark); } return parent::delete($query); }
public function render() { $token = Profiler::start(__CLASS__, __FUNCTION__); $r = parent::render(); Profiler::stop($token); return $r; }
/** * @param string $function * @param mixed $parameters .... */ public function measure_runtime() { $arr = func_get_args(); $fn = array_shift($arr); if (is_array($fn)) { $cl_name = get_class($fn[0]); $fn_name = $fn[1]; } elseif (0 === strpos(strtolower($fn), 'self::')) { $fn_name = explode('::', $fn); $cl_name = get_class(); $fn_name = $fn_name[1]; } elseif (0 === strpos(strtolower($fn), 'parent::')) { $fn_name = explode('::', $fn); $cl_name = get_parent_class(get_class()); $fn_name = $fn_name[1]; } else { $fn_name = explode('::', $fn); $cl_name = $fn_name[0]; $fn_name = $fn_name[1]; } $time = microtime(true); if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start($cl_name, $fn_name); } $response = call_user_func_array($fn, $arr); $time = (microtime(true) - $time) * 1000; if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } ORM::factory('Rest_Metric')->millisec($cl_name . '/' . $fn_name, ceil($time)); return $response; }
/** * Returns the translation table for a given language. * * // Get all defined Spanish messages * $messages = I18n::load('es-es'); * * После генерации таблицы происходит создание Javascript файла с таблицей * перевода для загружаемого языка. * * @param string $lang language to load * @return array */ public static function load($lang) { $table = parent::load($lang); $filename = Kohana::$cache_dir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('i18n', NULL)) . $lang . '.js'; if (!file_exists($filename) or file_exists($filename) and time() - filemtime($filename) > Date::DAY) { if (Kohana::$profiling === TRUE and class_exists('Profiler', FALSE)) { // Start a new benchmark $benchmark = Profiler::start('i18n', 'Generate file for lang - ' . $lang); } try { // Create the log file file_put_contents($filename, '// Auto generated i18n lang file for lang ' . $lang . ". Created on " . date('Y-m-d H:i:s') . "\n"); file_put_contents($filename, 'cms.addTranslation(' . json_encode($table) . ');', FILE_APPEND); // Allow anyone to write to log files chmod($filename, 0777); } catch (Exception $e) { // do something } if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } } return $table; }
public function __construct($id = NULL) { Kohana::$profiling === TRUE && ($bm = Profiler::start('ORM', __FUNCTION__)); parent::__construct($id); $this->after_initialize(); isset($bm) && Profiler::stop($bm); }
public function query($type, $sql, $as_object = FALSE, array $params = NULL) { $this->_connection or $this->connect(); if (JsonApiApplication::$profiling) { $benchmark = Profiler::start("Database ({$this->_instance})", $sql); } try { $result = $this->_connection->query($sql); } catch (Exception $e) { if (isset($benchmark)) { Profiler::delete($benchmark); } throw new Database_Exception(':error [ :query ]', array(':error' => $e->getMessage(), ':query' => $sql), $e->getCode()); } if (isset($benchmark)) { Profiler::stop($benchmark); } $this->last_query = $sql; if ($type === Database::SELECT) { if ($as_object === FALSE) { $result->setFetchMode(PDO::FETCH_ASSOC); } elseif (is_string($as_object)) { $result->setFetchMode(PDO::FETCH_CLASS, $as_object, $params); } else { $result->setFetchMode(PDO::FETCH_CLASS, 'stdClass'); } $result = $result->fetchAll(); return new Database_Result_Cached($result, $sql, $as_object, $params); } elseif ($type === Database::INSERT) { return array($this->_connection->lastInsertId(), $result->rowCount()); } else { return $result->rowCount(); } }
public static function get_smarty() { if (isset(self::$smarty)) { return self::$smarty; } $token = Kohana::$profiling ? Profiler::start('smarty', 'load smarty') : false; $config = Kohana::config('smarty'); try { include $config->smarty_class_file; } catch (Exception $e) { throw new Kohana_Exception('Could not load Smarty class file'); } $smarty = new Smarty(); // deal with initial config $smarty->php_handling = constant($config->php_handling); // deal with main config foreach ($config->smarty_config as $key => $value) { $smarty->{$key} = $value; } // check we can write to the compiled templates directory if (!is_writeable($smarty->compile_dir)) { self::create_dir($smarty->compile_dir, 'Smarty compiled template'); } // if smarty caching is enabled, check we can write to the cache directory if ($smarty->caching && !is_writeable($smarty->cache_dir)) { self::create_dir($smarty->cache_dir, 'Smarty cache'); } self::$smarty = $smarty; $token ? Profiler::stop($token) : null; return $smarty; }
public function stopQuery() { if ($this->benchmark) { \Profiler::stop($this->benchmark); $this->benchmark = null; } }
/** * Stop Zend Profiler */ function stop_zend_profiler() { include APPPATH . 'config' . DIRECTORY_SEPARATOR . 'database.php'; if ($db[$active_group]['Zend_Db_Profiler_Firebug']) { Profiler::stop(); } }
public function execute($db = 'default') { if (!is_object($db)) { // Get the database instance $db = Database::instance($db); } // Import the SQL locally $sql = $this->_sql; if (!empty($this->_values)) { // Quote all of the values $values = array_map(array($db, 'quote'), $this->_values); // Replace the values in the SQL $sql = strtr($sql, $values); } if ($this->profile === TRUE) { // Start profiling this query $token = Profiler::start('database (' . (string) $db . ')', $sql); } // Load the result $result = $db->query($this->_type, $sql); if (isset($token)) { // Stop profiling Profiler::stop($token); } return $result; }
public function __construct($file = null, array $data = null) { $token = Kohana::$profiling ? Profiler::start('renderer', 'new kohana view') : false; $this->_config = Kohana::config('render'); parent::__construct($file, $data); $token ? Profiler::stop($token) : null; }
/** * Run script * */ public function run() { try { $content = $this->_factory->getModel('crawlerModel')->crawl($this->_args); //array of data to render $result = array(); $sortArr = array(); foreach ($content as $key => $data) { $time = $data['time']; Profiler::start($key); $renderData = TagCounterHelper::count($data['content'], 'img'); Profiler::stop($key); $time += Profiler::fetch($key); array_push($result, array($key, (int) $renderData['img'], $time)); array_push($sortArr, $renderData['img']); } array_multisort($sortArr, SORT_DESC, $result); if (!empty($result)) { array_unshift($result, $this->_tableHeaders); } ViewHelper::getRenderer()->process(array('grid' => $result)); } catch (Exception $e) { echo $e->getMessage(); } }
/** * Processes the request, executing the controller. Before the routed action * is run, the before() method will be called, which allows the controller * to overload the action based on the request parameters. After the action * is run, the after() method will be called, for post-processing. * * By default, the output from the controller is captured and returned, and * no headers are sent. * * @return $this */ public function execute() { // Create the class prefix $prefix = 'controller_'; if (!empty($this->directory)) { // Add the directory name to the class prefix $prefix .= str_replace(array('\\', '/'), '_', trim($this->directory, '/')) . '_'; } if (Kohana::$profiling === TRUE) { // Start benchmarking $benchmark = Profiler::start('Requests', $this->uri); } try { // Load the controller using reflection $class = new ReflectionClass($prefix . $this->controller); if ($class->isAbstract()) { throw new Kohana_Exception('Cannot create instances of abstract :controller', array(':controller' => $prefix . $this->controller)); } // Create a new instance of the controller $controller = $class->newInstance($this); // Execute the "before action" method $class->getMethod('before')->invoke($controller); // Determine the action to use $action = empty($this->action) ? Route::$default_action : $this->action; // Ensure the action exists, and use __call() if it doesn't if ($class->hasMethod('action_' . $action)) { // Execute the main action with the parameters $class->getMethod('action_' . $action)->invokeArgs($controller, $this->_params); } else { $class->getMethod('__call')->invokeArgs($controller, array($action, $this->_params)); } // Execute the "after action" method $class->getMethod('after')->invoke($controller); } catch (Exception $e) { if (isset($benchmark)) { // Delete the benchmark, it is invalid Profiler::delete($benchmark); } if ($e instanceof ReflectionException) { // Reflection will throw exceptions for missing classes or actions $this->status = 404; } else { // All other exceptions are PHP/server errors $this->status = 500; } // Re-throw the exception throw $e; } if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } return $this; }
public function testServerDataFromProfilerToProfile() { $serverData = array('foo' => 'bar'); // Currently, $_SERVER data is hardcoded empty array, @see Profiler::stop:r256 $profiler = new Profiler(); $profiler->start(); $profile = $profiler->stop(); // Override $_SERVER for tests $profile->setServerData($serverData); $this->assertEquals($serverData, $profile->getServerData()); }
public function friends() { if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start('Kohana_Facebook', 'facebook->api(/me/friends)'); } $result = $this->_facebook->api('/me/friends'); if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } return $result['data']; }
public function render(array $params = array()) { if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start('Widget render', $this->name); } $this->_fetch_template(); $this->set_params($params); return $this->_fetch_render(); if (isset($benchmark)) { Profiler::stop($benchmark); } }
private function _execute_request($url) { if (Kohana::$profiling) { $benchmark = Profiler::start("Helper ({$this})", $this->_url); } $request = Request::factory($url); $response = $request->execute(); if (isset($benchmark)) { Profiler::stop($benchmark); } return $response->body(); }
/** * Dispatches an event to observer's callback * * @param Event $event * @return Observer */ public function dispatch(Event $event) { if (!$this->isValidFor($event)) { return $this; } $callback = $this->getCallback(); $this->setEvent($event); $_profilerKey = 'OBSERVER: ' . (is_object($callback[0]) ? get_class($callback[0]) : (string) $callback[0]) . ' -> ' . $callback[1]; Profiler::start($_profilerKey); call_user_func($callback, $this); Profiler::stop($_profilerKey); return $this; }
/** * Wrap requested view inside module and render * * @return string */ public function render($file = null) { // Start benchmark if (Kohana::$profiling === true and class_exists('Profiler', false)) { $benchmark = Profiler::start('View', __METHOD__ . '(' . $this->_name . ')'); } $module = (string) View::factory('generic/mod', array('class' => 'mod ' . Arr::get_once($this->_data, 'mod_class', strtr(basename($this->_file, '.php'), '_', '-')), 'id' => Arr::get_once($this->_data, 'mod_id'), 'actions' => isset($this->_data['mod_actions']) ? (string) View::factory('generic/actions', array('actions' => Arr::get_once($this->_data, 'mod_actions'))) : null, 'actions2' => isset($this->_data['mod_actions2']) ? (string) View::factory('generic/actions', array('actions' => Arr::get_once($this->_data, 'mod_actions2'))) : null, 'title' => Arr::get_once($this->_data, 'mod_title'), 'subtitle' => Arr::get_once($this->_data, 'mod_subtitle'), 'pagination' => Arr::get_once($this->_data, 'pagination'), 'content' => parent::render($file))); // Stop benchmark if (isset($benchmark)) { Profiler::stop($benchmark); } return $module; }
/** * Получение карты сайта * * @param boolean $include_hidden Включить скрытые страницы * @return Model_Page_Sitemap */ public static function get($include_hidden = FALSE) { if (Kohana::$profiling) { $benchmark = Profiler::start('Sitemap', __METHOD__); } $status = (bool) $include_hidden ? 1 : 0; if (!array_key_exists($status, Model_Page_Sitemap::$_sitemap)) { $pages = ORM::factory('page')->order_by('parent_id', 'asc')->order_by('position', 'asc'); if ((bool) $include_hidden === FALSE) { $pages->where('status_id', 'in', array(Model_Page::STATUS_PASSWORD_PROTECTED, Model_Page::STATUS_PUBLISHED)); } $res_pages = $pages->find_all(); $_pages = array(); foreach ($res_pages as $page) { $_pages[$page->id] = $page->as_array(); $_pages[$page->id]['uri'] = ''; $_pages[$page->id]['url'] = ''; $_pages[$page->id]['slug'] = $page->slug; $_pages[$page->id]['level'] = 0; $_pages[$page->id]['is_active'] = TRUE; } $pages = array(); foreach ($_pages as &$page) { $pages[$page['parent_id']][] =& $page; } foreach ($_pages as &$page) { if (isset($pages[$page['id']])) { foreach ($pages[$page['id']] as &$_page) { $_page['level'] = $page['level'] + 1; $_page['parent'] = $page; $_page['uri'] = $page['uri'] . '/' . $_page['slug']; $_page['url'] = URL::frontend($_page['uri']); $_page['is_active'] = URL::match($_page['uri']); if (empty($_page['layout_file'])) { $_page['layout_file'] = $page['layout_file']; } if ($_page['is_active']) { $page['is_active'] = TRUE; } } $page['childs'] = $pages[$page['id']]; } } Model_Page_Sitemap::$_sitemap[$status] = new Sitemap(reset($pages)); } if (isset($benchmark)) { Profiler::stop($benchmark); } return clone Model_Page_Sitemap::$_sitemap[$status]; }
/** * Retrieve the news feed items. First try from cache, otherwise load it from the website. * @return array */ private function _get_news_feed() { $benchmark = Profiler::start('Admin Dashboard', __FUNCTION__); $cache = Cache::instance(); // Attempt to load feed from cache otherwise get it from the website. if (!($feed = $cache->get('admin.dashboard.news_feed', FALSE))) { try { $feed = Feed::parse($this->_news_feed_url); $cache->set('admin.dashboard.news_feed', $feed, 360); } catch (Exception $e) { Hint::error($e); } } Profiler::stop($benchmark); return $feed; }
/** * * @return boolean */ public static function is_mobile() { if (self::$is_mobile !== NULL) { return self::$is_mobile; } if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start('Kohana', 'detect mobile'); } $agent = strtolower(Request::$user_agent); $mobile_browser = 0; if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', $agent)) { $mobile_browser++; } if (isset($_SERVER['HTTP_ACCEPT']) and strpos(strtolower($_SERVER['HTTP_ACCEPT']), 'application/vnd.wap.xhtml+xml') !== false) { $mobile_browser++; } if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) { $mobile_browser++; } if (isset($_SERVER['HTTP_PROFILE'])) { $mobile_browser++; } $mobile_ua = substr($agent, 0, 4); $mobile_agents = array('w3c ', 'acs-', 'alav', 'alca', 'amoi', 'audi', 'avan', 'benq', 'bird', 'blac', 'blaz', 'brew', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eric', 'hipt', 'inno', 'ipaq', 'java', 'jigs', 'kddi', 'keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-', 'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'nec-', 'newt', 'noki', 'oper', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox', 'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar', 'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-', 'tosh', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'wapp', 'wapr', 'webc', 'winw', 'xda', 'xda-'); if (in_array($mobile_ua, $mobile_agents)) { $mobile_browser++; } if (isset($_SERVER['ALL_HTTP']) and strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== FALSE) { $mobile_browser++; } // Pre-final check to reset everything if the user is on Windows if (strpos($agent, 'windows') !== FALSE) { $mobile_browser = 0; } // But WP7 is also Windows, with a slightly different characteristic if (strpos($agent, 'windows phone') !== FALSE) { $mobile_browser++; } if (isset($benchmark)) { Profiler::stop($benchmark); } if ($mobile_browser > 0) { self::$is_mobile = TRUE; } self::$is_mobile = FALSE; return self::$is_mobile; }
public function render() { // Ensure the layout is loaded if (!$this->loaded()) { return "Layout Failed to render because it wasn't loaded."; } if (Kohana::$profiling === TRUE) { // Start a new benchmark $benchmark = Profiler::start('Kohanut', 'Render Layout'); } $out = Kohanut_Twig::render($this->code); if (isset($benchmark)) { // Stop the benchmark Profiler::stop($benchmark); } return $out; }
/** * * @param string $keyword * @param boolean $only_title * @param string $modules * @param integer $limit * @param integer $offset * @return array */ public function find_by_keyword($keyword, $only_title = FALSE, $modules = NULL, $limit = 50, $offset = 0) { if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start('Search', __FUNCTION__); } $query = DB::select('id', 'module', 'title', 'annotation', 'params')->from('search_index'); $result = $this->_get_query($query, $keyword, $only_title, $modules, $limit, $offset)->execute()->as_array(); $ids = array(); foreach ($result as $row) { $row['params'] = Kohana::unserialize($row['params']); $ids[$row['module']][$row['id']] = $row; } if (isset($benchmark)) { Profiler::stop($benchmark); } return $ids; }
/** * Overload Sprig::delete() to remove * file from the upload dir */ public function delete(Database_Query_Builder_Delete $query = NULL) { Kohana::$log->add(Kohana::DEBUG, 'Beginning photo deletion'); if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start('photo', 'delete photo'); } if(file_exists($this->path)) unlink($this->path); if (isset($benchmark)) { Profiler::stop($benchmark); } return parent::delete($query); }
/** * Overload Sprig::delete() to remove tags * from the article-tag pivot table */ public function delete(Database_Query_Builder_Delete $query = NULL) { Kohana::$log->add(Kohana::DEBUG, 'Beginning article deletion for article_id=' . $this->id); if (Kohana::$profiling === TRUE) { $benchmark = Profiler::start('blog', 'delete article'); } try { DB::delete('articles_tags')->where('article_id', '=', $this->id)->execute(); } catch (Database_Exception $e) { Kohana::$log->add(Kohana::ERROR, 'Exception occured while modifying deleted article\'s tags. ' . $e->getMessage()); return $this; } if (isset($benchmark)) { Profiler::stop($benchmark); } return parent::delete($query); }
public function execute_request(Request $request, Response $response) { $prefix = "Controller_"; $directory = $request->directory(); $controller = $request->controller(); if ($directory) { $prefix .= str_replace(array("\\", "/"), "_", trim($directory, "/")) . "_"; } if (JsonApiApplication::$profiling) { $benchmark = "'" . $request->uri() . "'"; if ($request !== Request::$initial and Request::$current) { $benchmark .= " « '" . Request::$current->uri() . "'"; } $benchmark = Profiler::start("Requests", $benchmark); } $previous = Request::$current; Request::$current = $request; $initial_request = $request === Request::$initial; try { if (!class_exists($prefix . $controller)) { throw HTTP_Exception::factory(404, "The requested URL :uri was not found on this server.", array(":uri" => $request->uri()))->request($request); } $class = new ReflectionClass($prefix . $controller); if ($class->isAbstract()) { throw new JsonApiApplication_Exception("Cannot create instances of abstract :controller", array(":controller" => $prefix . $controller)); } $controller = $class->newInstance($request, $response); $response = $class->getMethod("execute")->invoke($controller); if (!$response instanceof Response) { throw new JsonApiApplication_Exception("Controller failed to return a Response"); } } catch (HTTP_Exception $e) { if ($e->request() === NULL) { $e->request($request); } $response = $e->get_response(); } catch (Exception $e) { $response = JsonApiApplication_Exception::_handler($e); } Request::$current = $previous; if (isset($benchmark)) { Profiler::stop($benchmark); } return $response; }
/** * Note: $type is ignored. Reason being, $type is unnecessary for returning correct results, * and in some cases results will not correspond with $type - examples: * "select * into outfile..." * "insert into...on duplicate key update" * Also, for insert queries on tables without an autoincrement id, only rows affected * need be returned. * * @param string $type ignored * @param string $sql * @param boolean $as_object * @return object PDO result */ public function query($type, $sql, $as_object) { // Make sure the database is connected $this->_connection or $this->connect(); if (!empty($this->_config['profiling'])) { // Benchmark this query for the current instance $benchmark = Profiler::start("Database ({$this->_instance})", $sql); } try { $result = $this->_connection->query($sql); } catch (Exception $e) { if (isset($benchmark)) { // This benchmark is worthless Profiler::delete($benchmark); } // Rethrow the exception throw $e; } if (isset($benchmark)) { Profiler::stop($benchmark); } // Set the last query $this->last_query = $sql; if ($result->columnCount() > 0) { // Convert the result into an array, as PDOStatement::rowCount is not reliable if ($as_object === FALSE) { $result->setFetchMode(PDO::FETCH_ASSOC); } elseif (is_string($as_object)) { $result->setFetchMode(PDO::FETCH_CLASS, $as_object); } else { $result->setFetchMode(PDO::FETCH_CLASS, 'stdClass'); } $result = $result->fetchAll(); // Return an iterator of results return new Database_Result_Cached($result, $sql, $as_object); } else { $insert_id = $this->_connection->lastInsertId(); if ($insert_id > 0) { return array($insert_id, $result->rowCount()); } else { // Return the number of rows affected return $result->rowCount(); } } }
/** * Check permission for object * * @static * @param Permission_Interface $model Object implemeneting permission interface * @param string $permission * @param mixed $user Defaults to session user * @return boolean */ public static function has(Permission_Interface $model, $permission = Permission_Interface::PERMISSION_READ, $user = false) { if (Kohana::$profiling === true && class_exists('Profiler', false)) { $benchmark = Profiler::start('Anqh', __METHOD__ . '(' . get_class($model) . ')'); } // Make sure we have a valid user, if any $user = Model_User::find_user($user); // Create unique permission id for caching $permission_id = sprintf('%s:%d:%s:%d', get_class($model), $model->id(), $permission, $user && $user->loaded() ? $user->id : 0); // If permission check not found from cache ask the model if (!isset(self::$_permissions[$permission_id])) { self::$_permissions[$permission_id] = $model->has_permission($permission, $user); } if (isset($benchmark)) { Profiler::stop($benchmark); } return self::$_permissions[$permission_id]; }
/** * Smarty {report}{/report} block plugin * * Banded Report Generator Framework * * This is the main block for this framework and it acts as a container for the * rest of the {report_*} block types and handles the looping requirements of * the given dataset. * * @type block * @name report * @version 0.1.6 * @see http://www.phpinsider.com/smarty-forum/viewtopic.php?t=4125 * * @author boots < jayboots @at@ yahoo com > * @copyright brainpower, boots, 2004-2005 * @license LGPL * * @thanks messju mohr, sophistry * * @param recordset REQUIRED * @param record REQUIRED * @param groups default: null * @param resort default: false */ function smarty_block_Kohana_profiler($params, $content, &$smarty, &$repeat) { static $stack = array(); static $profiles = array(); static $firsttime = true; if ($firsttime) { $smarty->assign_by_ref('Kohana_profiles', $profiles); $firsttime = false; } if ($repeat) { // opening tag if (Kohana::$profiling) { $name = isset($params['name']) ? $params['name'] : 'other'; $token = Profiler::start('Smarty_rendering', $name); } else { $token = $name = ''; } // always need to do this in case the status of Kohana::$profiling is changed before closing tag array_push($stack, array($token, $name)); } else { // closing tag list($token, $name) = array_pop($stack); if (Kohana::$profiling) { Profiler::stop($token); // array (time, mem, size) $total = Profiler::total($token); $total[2] = strlen($content); $total[3] = microtime(true) - KOHANA_START_TIME; $total[4] = memory_get_usage(); $smarty->assign('Kohana_profiler', $total); if (isset($profiles[$name])) { $profiles[$name][0] += $total[0]; $profiles[$name][1] += $total[1]; $profiles[$name][2] += $total[2]; } else { $profiles[$name] = $total; } } else { $total = array(0, 0, strlen($content), microtime(true) - KOHANA_START_TIME, memory_get_usage()); $smarty->assign('Kohana_profiler', $total); } return $content; } }