本文整理汇总了PHP中Profiler::start方法的典型用法代码示例。如果您正苦于以下问题:PHP Profiler::start方法的具体用法?PHP Profiler::start怎么用?PHP Profiler::start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Profiler
的用法示例。
在下文中一共展示了Profiler::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
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);
}
if (!empty($this->_config['connection']['persistent']) and $this->_config['connection']['database'] !== Database_MySQL::$_current_databases[$this->_connection_id]) {
$this->_select_db($this->_config['connection']['database']);
}
if (($result = mysql_query($sql, $this->_connection)) === FALSE) {
if (isset($benchmark)) {
Profiler::delete($benchmark);
}
throw new Database_Exception(':error [ :query ]', array(':error' => mysql_error($this->_connection), ':query' => $sql), mysql_errno($this->_connection));
}
if (isset($benchmark)) {
Profiler::stop($benchmark);
}
$this->last_query = $sql;
if ($type === Database::SELECT) {
return new Database_MySQL_Result($result, $sql, $as_object, $params);
} elseif ($type === Database::INSERT) {
return array(mysql_insert_id($this->_connection), mysql_affected_rows($this->_connection));
} else {
return mysql_affected_rows($this->_connection);
}
}
示例2: start
public static function start($nodeName)
{
if (defined('PROFILER_SWITCH') && PROFILER_SWITCH == 1) {
Profiler::enable();
}
return Profiler::start($nodeName);
}
示例3: get_smarty
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;
}
示例4: execute
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;
}
示例5: start_zend_profiler
/**
* Start Zend Profiler
*/
function start_zend_profiler()
{
include APPPATH . 'config' . DIRECTORY_SEPARATOR . 'database.php';
if ($db[$active_group]['Zend_Db_Profiler_Firebug']) {
Profiler::start($db[$active_group], Zend_Db_Table_Abstract::getDefaultAdapter());
}
}
示例6: __construct
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;
}
示例7: __construct
public function __construct($id = NULL)
{
Kohana::$profiling === TRUE && ($bm = Profiler::start('ORM', __FUNCTION__));
parent::__construct($id);
$this->after_initialize();
isset($bm) && Profiler::stop($bm);
}
示例8: run
/**
* 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();
}
}
示例9: run
/**
*
* @param Model_Job $job
* @return void
*/
public function run(Model_Job $job)
{
if (Kohana::$profiling === TRUE) {
$benchmark = Profiler::start('Rub job', $job->name);
}
$this->values(array('job_id' => $job->id))->create();
$this->set_status(Model_Job::STATUS_RUNNING);
try {
$job = $job->job;
$minion_task = Minion_Task::convert_task_to_class_name($job);
if (is_array($job)) {
$passed = call_user_func($job);
} elseif (class_exists($minion_task)) {
Minion_Task::factory(array($job))->execute();
$passed = TRUE;
} elseif (strpos($job, '::') === FALSE) {
$function = new ReflectionFunction($job);
$passed = $function->invoke();
} else {
list($class, $method) = explode('::', $job, 2);
$method = new ReflectionMethod($class, $method);
$passed = $method->invoke(NULL);
}
} catch (Exception $e) {
$this->failed();
return;
}
$this->complete();
if (isset($benchmark)) {
Profiler::stop($benchmark);
}
}
示例10: delete
/**
* 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);
}
示例11: set_filename
public function set_filename($file)
{
Kohana::$profiling === TRUE && ($bm = Profiler::start('View', __FUNCTION__));
$this->_import_options($file);
if ($this->_viewfile) {
if (($path = Kohana::find_file('views', $this->_viewfile, $this->_format . '.haml')) === FALSE) {
if (($path = Kohana::find_file('views', $this->_viewfile, $this->_format . '.php')) !== FALSE) {
$this->_file = $path;
} else {
if (is_string($file) && ($path = Kohana::find_file('views', $file)) !== FALSE) {
$this->_file = $path;
}
}
isset($bm) && Profiler::stop($bm);
return $this;
}
$this->_file = $this->_get_compiled_haml($path);
isset($bm) && Profiler::stop($bm);
return $this;
}
if ($this->_is_inline) {
$this->_file = $this->_get_compiled_inline_haml($this->_inline_haml);
}
isset($bm) && Profiler::stop($bm);
return $this;
}
示例12: measure_runtime
/**
* @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;
}
示例13: __construct
/**
* Create new Core object and initialize our own settings
*
* @param string $text Text string to filter html
* @param integer $format Format id [Optional]
* @param array $filter Array of allowed tags [Optional]
*
* @used Config::load
* @used Config::get
* @used Profiler::start
*/
public function __construct($text, $format = 1, array $filter = NULL)
{
// Be sure to only profile if it's enabled
if (Gleez::$profiling) {
// Start a new benchmark
$this->benchmark = Profiler::start('Gleez Filter', __FUNCTION__);
}
// Load the configuration for this type
$config = Config::load('inputfilter');
if ($config->allowed_protocols and is_array($config->allowed_protocols)) {
$this->allowed_protocols = $config->allowed_protocols;
}
if ($config->allowed_tags and is_array($config->allowed_tags)) {
$this->allowed_tags = $config->allowed_tags;
}
if (!array_key_exists($format, $config->formats)) {
// make sure a valid format id exists, if not set default format id
$format = (int) $config->get('default_format', 1);
}
if (isset($filter['settings']['allowed_html'])) {
$this->allowed_tags = preg_split('/\\s+|<|>/', $filter['settings']['allowed_html'], -1, PREG_SPLIT_NO_EMPTY);
}
$this->_text = (string) $text;
$this->_config = $config;
if (Kohana::PRODUCTION !== Kohana::$environment) {
Log::debug('HTML Filter Library initialized');
}
}
示例14: query
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();
}
}
示例15: load
/**
* 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;
}