From 2032fc2d1033a1de1e87874c310adf290d9ba204 Mon Sep 17 00:00:00 2001 From: Pavel Volyntsev Date: Sat, 22 Mar 2014 23:04:53 +0700 Subject: [PATCH 1/7] Added cache panel --- README.markdown | 17 ++ YiiDebugCacheProxy.php | 214 +++++++++++++++++++++ YiiDebugToolbarRoute.php | 1 + messages/ru/yii-debug-toolbar.php | 11 ++ messages/simple/yii-debug-toolbar.php | 11 ++ panels/YiiDebugToolbarPanelCache.php | 256 ++++++++++++++++++++++++++ views/panels/cache.php | 26 +++ views/panels/cache/callstack.php | 25 +++ views/panels/cache/settings.php | 14 ++ views/panels/cache/summary.php | 45 +++++ 10 files changed, 620 insertions(+) create mode 100644 YiiDebugCacheProxy.php create mode 100644 panels/YiiDebugToolbarPanelCache.php create mode 100644 views/panels/cache.php create mode 100644 views/panels/cache/callstack.php create mode 100644 views/panels/cache/settings.php create mode 100644 views/panels/cache/summary.php diff --git a/README.markdown b/README.markdown index 45af592..4d000df 100644 --- a/README.markdown +++ b/README.markdown @@ -14,6 +14,7 @@ Currently, the following panels have been written and are working: * A list of superglobals * Application settings * SQL queries including time to execute and param bindings +* Cache requests including time * Logging output via Yii built-in logging @@ -54,6 +55,22 @@ For use [yii-debug-toolbar](/malyshev/yii-debug-toolbar/) need to specify new `r ), ``` + +* To enable reports about cache usage you need to change application configuration like that +```php +array( + 'class' => 'ext.yii-debug-toolbar.YiiDebugCacheProxy', + 'enableProfiling' => true, + 'cache' => array( + 'class' => 'system.caching.CFileCache', // or other cache class + //... any other valid settings for cache + ), + ), +``` + + ## TODOs and BUGS See: [issues](https://github.com/malyshev/yii-debug-toolbar/issues) diff --git a/YiiDebugCacheProxy.php b/YiiDebugCacheProxy.php new file mode 100644 index 0000000..2fd4c48 --- /dev/null +++ b/YiiDebugCacheProxy.php @@ -0,0 +1,214 @@ + + */ + +Yii::import('system.caching.CCache'); + +/** + * Class YiiDebugCacheProxy + * + * Class to profile cache requests + * + * @author Pavel Volyntsev + * @version $Id$ + * @package + */ +class YiiDebugCacheProxy extends CCache +{ + /** + * @var boolean whether to enable profiling requests to cache. + * Defaults to false. This should be mainly enabled and used during development + * to find out the bottleneck of cache executions. + */ + public $enableProfiling = false; + + /** + * Options to create cache component + * @var array + */ + public $cache; + + /** + * Cache component instance + * @var \CCache + */ + protected $_cacheProxy; + + /** + * Cache usage statistics + * @var array + */ + protected $_stats = array( + 'get' => 0, // read requests quantity + 'get_time' => 0, // read time + 'mget' => 0, + 'mget_time' => 0, + 'set' => 0, // write requests quantity + 'set_time' => 0, // write time + 'delete' => 0, // delete requests quantity + 'delete_time' => 0, // delete time + 'flush' => 0, + 'flush_time' => 0, + 'hit' => 0, // read requests when data found + 'miss' => 0, // read requests when no data found + 'count' => 0, // total requests + 'time' => 0, // total time + ); + + /** + * Key for profiling logs + * @var + */ + private $_logCategory; + + const LOG_CATEGORY = 'system.caching.'; + + public function init() + { + parent::init(); + $this->_logCategory = self::LOG_CATEGORY.get_class($this); + } + + /** + * @return CCache + */ + protected function getCacheProxy() + { + if (is_null($this->_cacheProxy)) + { + $this->_cacheProxy = Yii::createComponent($this->cache); + $this->_cacheProxy->init(); + } + return $this->_cacheProxy; + } + + /** + * @see \CCache::get + * @param string $id + * @return mixed + */ + public function get($id) + { + if ($this->enableProfiling) + { + Yii::beginProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.get'); + } + $value = $this->getCacheProxy()->get($id); + if ($this->enableProfiling) + { + ++$this->_stats['get']; + ++$this->_stats['hit']; + if (false==$value) + ++$this->_stats['miss']; + Yii::endProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.get'); + } + return $value; + } + + /** + * @see \CCache::mget + * @param string[] $ids + * @return array + */ + public function mget($ids) + { + if ($this->enableProfiling) + { + Yii::beginProfile(__METHOD__.'("'.implode('","', $ids).'")', $this->_logCategory.'.mget'); + } + $value = $this->getCacheProxy()->mget($ids); + if ($this->enableProfiling) + { + ++$this->_stats['mget']; + ++$this->_stats['hit']; + if (empty($value)) + { + ++$this->_stats['miss']; + } + Yii::endProfile(__METHOD__.'("'.implode('","', $ids).'")', $this->_logCategory.'.mget'); + } + return $value; + } + + /** + * @see \CCache::set + * @param string $id + * @param mixed $value + * @param int $expire + * @param null $dependency + * @return bool|mixed + */ + public function set($id, $value, $expire = 0, $dependency = null) + { + if ($this->enableProfiling) + { + Yii::beginProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.set'); + } + $returnValue = $this->getCacheProxy()->set($id, $value, $expire, $dependency); + if ($this->enableProfiling) + { + ++$this->_stats['set']; + Yii::endProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.set'); + } + return $returnValue; + } + + /** + * @see \CCache::delete + * @param string $id + * @return bool + */ + public function delete($id) + { + if ($this->profileEnabled) + { + Yii::beginProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.delete'); + } + $value = $this->getCacheProxy()->delete($id); + if ($this->enableProfiling) + { + ++$this->_stats['delete']; + Yii::endProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.delete'); + } + return $value; + } + + /** + * @see \CCache::flush + * @return bool + */ + public function flush() + { + if ($this->profileEnabled) + { + Yii::beginProfile(__METHOD__.'()', $this->_logCategory.'.flush'); + } + $value = $this->getCacheProxy()->flush(); + if ($this->enableProfiling) + { + ++$this->_stats['flush']; + Yii::endProfile(__METHOD__.'()', $this->_logCategory.'.flush'); + } + return $value; + } + + /** + * Returns the statistics about cache usage. + * @return array + */ + public function getStats() + { + $logger = Yii::getLogger(); + $this->_stats['get_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.get')); + $this->_stats['mget_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.mget')); + $this->_stats['set_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.set')); + $this->_stats['delete_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.delete')); + $this->_stats['flush_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.flush')); + $this->_stats['call'] = $this->_stats['get'] + $this->_stats['mget'] + $this->_stats['set'] + $this->_stats['delete'] + $this->_stats['flush']; + $this->_stats['time'] = $this->_stats['get_time'] + $this->_stats['mget_time'] + $this->_stats['set_time'] + $this->_stats['delete_time'] + $this->_stats['flush_time']; + return $this->_stats; + } +} \ No newline at end of file diff --git a/YiiDebugToolbarRoute.php b/YiiDebugToolbarRoute.php index 6d9e4d2..4b78f2d 100644 --- a/YiiDebugToolbarRoute.php +++ b/YiiDebugToolbarRoute.php @@ -25,6 +25,7 @@ class YiiDebugToolbarRoute extends CLogRoute 'YiiDebugToolbarPanelViews', 'YiiDebugToolbarPanelSql', 'YiiDebugToolbarPanelLogging', + 'YiiDebugToolbarPanelCache', ); /** diff --git a/messages/ru/yii-debug-toolbar.php b/messages/ru/yii-debug-toolbar.php index 499dd34..8a2b0e4 100644 --- a/messages/ru/yii-debug-toolbar.php +++ b/messages/ru/yii-debug-toolbar.php @@ -76,6 +76,17 @@ 'Servers' => 'Сервер', 'No SQL queries were recorded during this request or profiling the SQL is DISABLED.' => 'Запросо к базе не было, либо профилирование SQL отключено.', +// Cache + 'Cache' => 'Кэш', + 'Total' => 'Общее количество', + 'Hit' => 'Количество чтений', + 'Miss' => 'Количество промахов', + 'No cache usage' => 'Кэш не используется', + 'Cache requests' => 'Запросы к кэшу', + 'Method' => 'Метод', + 'Cache not configured' => 'Кэш не настроен', + 'No cache request logged or profiling the cache is DISABLED.' => 'Обращений к кэшу нет, либо профилирование кэша отключено', + // logging 'Logging' => 'Логирование', '{n} message|{n} messages' => '{n} сообщение|{n} сообщения|{n} сообщений', diff --git a/messages/simple/yii-debug-toolbar.php b/messages/simple/yii-debug-toolbar.php index 830cac4..186464c 100644 --- a/messages/simple/yii-debug-toolbar.php +++ b/messages/simple/yii-debug-toolbar.php @@ -76,6 +76,17 @@ 'Servers' => '', 'No SQL queries were recorded during this request or profiling the SQL is DISABLED.' => '', +// Cache + 'Cache' => '', + 'Total' => '', + 'Hit' => '', + 'Miss' => '', + 'No cache usage' => '', + 'Cache requests' => '', + 'Method' => '', + 'Cache not configured' => '', + 'No cache request logged or profiling the cache is DISABLED.' => '', + // logging 'Logging' => '', '{n} message|{n} messages' => '', diff --git a/panels/YiiDebugToolbarPanelCache.php b/panels/YiiDebugToolbarPanelCache.php new file mode 100644 index 0000000..323eaf2 --- /dev/null +++ b/panels/YiiDebugToolbarPanelCache.php @@ -0,0 +1,256 @@ + + */ + + +/** + * YiiDebugToolbarPanelCache class. + * + * YiiDebugToolbarPanelCache prepare data to render cache panel: + * * Cache settings + * * Profiling with requests time + * * Summary/Statistics + * + * @author Pavel Volyntsev + * @version $Id$ + * @package + */ +class YiiDebugToolbarPanelCache extends YiiDebugToolbarPanel +{ + public $i = 'i'; + + private $_cache; + + public function __construct($owner = null) + { + parent::__construct($owner); + + try { + $cache = Yii::app()->cache; + if (!($cache instanceof YiiDebugCacheProxy)) + { + $this->_cache = false; + } + } catch (Exception $e) { + $this->_cache = false; + } + } + + /** + * {@inheritdoc} + */ + public function getMenuTitle() + { + return YiiDebug::t('Cache'); + } + + /** + * {@inheritdoc} + */ + public function getMenuSubTitle($f=4) + { + if (false !== $this->_cache) { + /** @var YiiDebugCacheProxy $cache */ + $cache = Yii::app()->cache; + $stats = $cache->getStats(); + return $stats['hit'] . ($stats['hit'] > 0 ? ('/'. vsprintf('%0.'.$f.'F', $stats['time']) . 's') : ''); + } + return YiiDebug::t('No cache usage'); + } + + /** + * {@inheritdoc} + */ + public function getTitle() + { + if (false !== $this->_cache) + { + return YiiDebug::t('Cache requests'); + } + return YiiDebug::t('No cache usage'); + } + + /** + * {@inheritdoc} + */ + public function getSubTitle() + { + return false !== $this->_cache + ? ('(' . self::getMenuSubTitle(6) . ')') + : null; + } + + /** + * Initialize panel + */ + public function init() + { + + } + + /** + * {@inheritdoc} + */ + public function run() + { + if (false === $this->_cache) { + return; + } + + $logs = $this->filterLogs(); + $this->render('cache', array( + 'settings' => $this->getCacheComponents(), + 'summary' => $this->processSummary(), + 'callstack' => $this->processCallstack($logs) + )); + } + + private function duration($secs) + { + $vals = array( + 'w' => (int) ($secs / 86400 / 7), + 'd' => $secs / 86400 % 7, + 'h' => $secs / 3600 % 24, + 'm' => $secs / 60 % 60, + 's' => $secs % 60 + ); + $result = array(); + $added = false; + foreach ($vals as $k => $v) + { + if ($v > 0 || false !== $added) + { + $added = true; + $result[] = $v . $k; + } + } + return implode(' ', $result); + } + + private function getCacheComponents() + { + return Yii::app()->cache; + } + + + /** + * Processing callstack. + * + * @param array $logs Logs. + * @return array + */ + protected function processCallstack(array $logs) + { + if (empty($logs)) + { + return $logs; + } + + $stack = array(); + $results = array(); + $n = 0; + + foreach ($logs as $log) + { + if(CLogger::LEVEL_PROFILE !== $log[1]) + continue; + + $message = $log[0]; + + if (0 === strncasecmp($message,'begin:',6)) + { + $log[0] = substr($message,6); + $log[4] = $n; + $stack[] = $log; + $n++; + } + else if (0 === strncasecmp($message, 'end:', 4)) + { + $token = substr($message,4); + if(null !== ($last = array_pop($stack)) && $last[0] === $token) + { + $delta = $log[3] - $last[3]; + $results[$last[4]] = array($token, $delta, count($stack)); + } + else + throw new CException(Yii::t('yii-debug-toolbar', + 'Mismatching code block "{token}". Make sure the calls to Yii::beginProfile() and Yii::endProfile() be properly nested.', + array('{token}' => $token) + )); + } + } + // remaining entries should be closed here + $now = microtime(true); + while (null !== ($last = array_pop($stack))){ + $results[$last[4]] = array($last[0], $now - $last[3], count($stack)); + } + + ksort($results); + return $results; // array_map(array($this, 'formatLogEntry'), $results); + } + + /** + * Processing summary. + * + * @param array $logs Logs. + * @return array + */ + protected function processSummary() + { + /** @var YiiDebugCacheProxy $cache */ + $cache = Yii::app()->cache; + return $cache->getStats(); + } + + /** + * Aggregates the report result. + * + * @param array $result log result for this code block + * @param float $delta time spent for this code block + * @return array + */ + protected function aggregateResult($result, $delta) + { + list($token, $calls, $min, $max, $total) = $result; + + switch (true) + { + case ($delta < $min): + $min = $delta; + break; + case ($delta > $max): + $max = $delta; + break; + default: + // nothing + break; + } + + $calls++; + $total += $delta; + + return array($token, $calls, $min, $max, $total); + } + + /** + * Get filter logs. + * + * @return array + */ + protected function filterLogs() + { + $logs = array(); + foreach ($this->owner->getLogs() as $entry) + { + if (CLogger::LEVEL_PROFILE === $entry[1] && 0 === strpos($entry[2], YiiDebugCacheProxy::LOG_CATEGORY)) + { + $logs[] = $entry; + } + } + return $logs; + } + +} diff --git a/views/panels/cache.php b/views/panels/cache.php new file mode 100644 index 0000000..921cb60 --- /dev/null +++ b/views/panels/cache.php @@ -0,0 +1,26 @@ +
+
    +
  • +
  • +
  • +
+
+
+
+ render('cache/settings', array( + 'settings'=>$settings + )) ?> +
+
+ render('cache/summary', array( + 'summary'=>$summary + )) ?> +
+
+ render('cache/callstack', array( + 'callstack'=>$callstack + )) ?> +
+
+
+
diff --git a/views/panels/cache/callstack.php b/views/panels/cache/callstack.php new file mode 100644 index 0000000..764f999 --- /dev/null +++ b/views/panels/cache/callstack.php @@ -0,0 +1,25 @@ + + + + + + + + + + + + $entry):?> + + + + + + + +
#
+ +

+ +

+ \ No newline at end of file diff --git a/views/panels/cache/settings.php b/views/panels/cache/settings.php new file mode 100644 index 0000000..936bbda --- /dev/null +++ b/views/panels/cache/settings.php @@ -0,0 +1,14 @@ + + + + $value) : ?> + + + + + + +
dump($value); ?>
+ + + \ No newline at end of file diff --git a/views/panels/cache/summary.php b/views/panels/cache/summary.php new file mode 100644 index 0000000..815d6d7 --- /dev/null +++ b/views/panels/cache/summary.php @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
s
/ / %
get s
multy get s
set s
delete s
flush s
+ +

+ +

+ From 17af568323d62d7c47a2f5f5c7ec45b69d198632 Mon Sep 17 00:00:00 2001 From: Pavel Volyntsev Date: Mon, 24 Mar 2014 23:32:04 +0700 Subject: [PATCH 2/7] misprint --- YiiDebugCacheProxy.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/YiiDebugCacheProxy.php b/YiiDebugCacheProxy.php index 2fd4c48..8a7f8e8 100644 --- a/YiiDebugCacheProxy.php +++ b/YiiDebugCacheProxy.php @@ -163,7 +163,7 @@ public function set($id, $value, $expire = 0, $dependency = null) */ public function delete($id) { - if ($this->profileEnabled) + if ($this->enableProfiling) { Yii::beginProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.delete'); } @@ -182,7 +182,7 @@ public function delete($id) */ public function flush() { - if ($this->profileEnabled) + if ($this->enableProfiling) { Yii::beginProfile(__METHOD__.'()', $this->_logCategory.'.flush'); } From 79df7bdd51bda019720e23c565be7baecdd4a6c6 Mon Sep 17 00:00:00 2001 From: Pavel Volyntsev Date: Tue, 25 Mar 2014 01:06:13 +0700 Subject: [PATCH 3/7] fixed wrong "miss" counter --- YiiDebugCacheProxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YiiDebugCacheProxy.php b/YiiDebugCacheProxy.php index 8a7f8e8..4d80fe5 100644 --- a/YiiDebugCacheProxy.php +++ b/YiiDebugCacheProxy.php @@ -101,7 +101,7 @@ public function get($id) { ++$this->_stats['get']; ++$this->_stats['hit']; - if (false==$value) + if (false===$value) ++$this->_stats['miss']; Yii::endProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.get'); } From 1b6104705bc478457f06326646ce4e5f4f275770 Mon Sep 17 00:00:00 2001 From: Pavel Volyntsev Date: Sun, 28 Sep 2014 22:39:40 +0700 Subject: [PATCH 4/7] Added 'add' method to cache proxy class --- YiiDebugCacheProxy.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/YiiDebugCacheProxy.php b/YiiDebugCacheProxy.php index 4d80fe5..b87f508 100644 --- a/YiiDebugCacheProxy.php +++ b/YiiDebugCacheProxy.php @@ -48,6 +48,8 @@ class YiiDebugCacheProxy extends CCache 'mget_time' => 0, 'set' => 0, // write requests quantity 'set_time' => 0, // write time + 'add' => 0, // add requests quantity + 'add_time' => 0, 'delete' => 0, // delete requests quantity 'delete_time' => 0, // delete time 'flush' => 0, @@ -156,6 +158,31 @@ public function set($id, $value, $expire = 0, $dependency = null) return $returnValue; } + /** + * @see \CCache::add + * @param string $id the key identifying the value to be cached + * @param mixed $value the value to be cached + * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire. + * @param ICacheDependency $dependency dependency of the cached item. If the dependency changes, the item is labeled invalid. + * @return boolean true if the value is successfully stored into cache, false otherwise + */ + public function add($id,$value,$expire=0,$dependency=null) + { + if ($this->enableProfiling) + { + Yii::beginProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.add'); + } + + $returnValue = $this->getCacheProxy()->add($id, $value, $expire, $dependency); + + if ($this->enableProfiling) + { + ++$this->_stats['add']; + Yii::endProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.add'); + } + return $returnValue; + } + /** * @see \CCache::delete * @param string $id @@ -205,10 +232,11 @@ public function getStats() $this->_stats['get_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.get')); $this->_stats['mget_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.mget')); $this->_stats['set_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.set')); + $this->_stats['add_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.add')); $this->_stats['delete_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.delete')); $this->_stats['flush_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.flush')); $this->_stats['call'] = $this->_stats['get'] + $this->_stats['mget'] + $this->_stats['set'] + $this->_stats['delete'] + $this->_stats['flush']; - $this->_stats['time'] = $this->_stats['get_time'] + $this->_stats['mget_time'] + $this->_stats['set_time'] + $this->_stats['delete_time'] + $this->_stats['flush_time']; + $this->_stats['time'] = $this->_stats['get_time'] + $this->_stats['mget_time'] + $this->_stats['set_time'] + $this->_stats['add_time'] + $this->_stats['delete_time'] + $this->_stats['flush_time']; return $this->_stats; } } \ No newline at end of file From 0670f3f998e241b3b618183f078344e64b9c2b1f Mon Sep 17 00:00:00 2001 From: Pavel Volyntsev Date: Sun, 28 Sep 2014 22:45:02 +0700 Subject: [PATCH 5/7] Calculate cache usage counters even if profiling is disabled --- YiiDebugCacheProxy.php | 47 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/YiiDebugCacheProxy.php b/YiiDebugCacheProxy.php index b87f508..0700bc3 100644 --- a/YiiDebugCacheProxy.php +++ b/YiiDebugCacheProxy.php @@ -99,12 +99,12 @@ public function get($id) Yii::beginProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.get'); } $value = $this->getCacheProxy()->get($id); + ++$this->_stats['get']; + ++$this->_stats['hit']; + if (false===$value) + ++$this->_stats['miss']; if ($this->enableProfiling) { - ++$this->_stats['get']; - ++$this->_stats['hit']; - if (false===$value) - ++$this->_stats['miss']; Yii::endProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.get'); } return $value; @@ -122,14 +122,14 @@ public function mget($ids) Yii::beginProfile(__METHOD__.'("'.implode('","', $ids).'")', $this->_logCategory.'.mget'); } $value = $this->getCacheProxy()->mget($ids); + ++$this->_stats['mget']; + ++$this->_stats['hit']; + if (empty($value)) + { + ++$this->_stats['miss']; + } if ($this->enableProfiling) { - ++$this->_stats['mget']; - ++$this->_stats['hit']; - if (empty($value)) - { - ++$this->_stats['miss']; - } Yii::endProfile(__METHOD__.'("'.implode('","', $ids).'")', $this->_logCategory.'.mget'); } return $value; @@ -150,9 +150,9 @@ public function set($id, $value, $expire = 0, $dependency = null) Yii::beginProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.set'); } $returnValue = $this->getCacheProxy()->set($id, $value, $expire, $dependency); + ++$this->_stats['set']; if ($this->enableProfiling) { - ++$this->_stats['set']; Yii::endProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.set'); } return $returnValue; @@ -195,9 +195,9 @@ public function delete($id) Yii::beginProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.delete'); } $value = $this->getCacheProxy()->delete($id); + ++$this->_stats['delete']; if ($this->enableProfiling) { - ++$this->_stats['delete']; Yii::endProfile(__METHOD__.'("'.$id.'")', $this->_logCategory.'.delete'); } return $value; @@ -214,9 +214,9 @@ public function flush() Yii::beginProfile(__METHOD__.'()', $this->_logCategory.'.flush'); } $value = $this->getCacheProxy()->flush(); + ++$this->_stats['flush']; if ($this->enableProfiling) { - ++$this->_stats['flush']; Yii::endProfile(__METHOD__.'()', $this->_logCategory.'.flush'); } return $value; @@ -228,15 +228,18 @@ public function flush() */ public function getStats() { - $logger = Yii::getLogger(); - $this->_stats['get_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.get')); - $this->_stats['mget_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.mget')); - $this->_stats['set_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.set')); - $this->_stats['add_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.add')); - $this->_stats['delete_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.delete')); - $this->_stats['flush_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.flush')); - $this->_stats['call'] = $this->_stats['get'] + $this->_stats['mget'] + $this->_stats['set'] + $this->_stats['delete'] + $this->_stats['flush']; - $this->_stats['time'] = $this->_stats['get_time'] + $this->_stats['mget_time'] + $this->_stats['set_time'] + $this->_stats['add_time'] + $this->_stats['delete_time'] + $this->_stats['flush_time']; + $this->_stats['call'] = $this->_stats['get'] + $this->_stats['mget'] + $this->_stats['set'] + $this->_stats['add'] + $this->_stats['delete'] + $this->_stats['flush']; + if ($this->enableProfiling) + { + $logger = Yii::getLogger(); + $this->_stats['get_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.get')); + $this->_stats['mget_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.mget')); + $this->_stats['set_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.set')); + $this->_stats['add_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.add')); + $this->_stats['delete_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.delete')); + $this->_stats['flush_time'] = array_sum($logger->getProfilingResults(null, $this->_logCategory.'.flush')); + $this->_stats['time'] = $this->_stats['get_time'] + $this->_stats['mget_time'] + $this->_stats['set_time'] + $this->_stats['delete_time'] + $this->_stats['flush_time']; + } return $this->_stats; } } \ No newline at end of file From 3e0c24bb00dcfba44dafdd55e668a52a147ad840 Mon Sep 17 00:00:00 2001 From: Pavel Volyntsev Date: Sun, 28 Sep 2014 23:08:51 +0700 Subject: [PATCH 6/7] Missprint in cache proxy stats --- YiiDebugCacheProxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YiiDebugCacheProxy.php b/YiiDebugCacheProxy.php index 0700bc3..a1fb62c 100644 --- a/YiiDebugCacheProxy.php +++ b/YiiDebugCacheProxy.php @@ -228,7 +228,7 @@ public function flush() */ public function getStats() { - $this->_stats['call'] = $this->_stats['get'] + $this->_stats['mget'] + $this->_stats['set'] + $this->_stats['add'] + $this->_stats['delete'] + $this->_stats['flush']; + $this->_stats['count'] = $this->_stats['get'] + $this->_stats['mget'] + $this->_stats['set'] + $this->_stats['add'] + $this->_stats['delete'] + $this->_stats['flush']; if ($this->enableProfiling) { $logger = Yii::getLogger(); From 2bc51a466b4e7280edc5cd267447c1d5ae194a77 Mon Sep 17 00:00:00 2001 From: Pavel Volyntsev Date: Tue, 15 Nov 2016 14:12:30 +0700 Subject: [PATCH 7/7] Update composer.json --- composer.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 380bcdd..a4238df 100644 --- a/composer.json +++ b/composer.json @@ -9,5 +9,12 @@ "email": "malyshev.php@gmail.com", "homepage": "http://www.yiiframework.com/extension/yii-debug-toolbar/" } - ] + ], + "autoload": { + "classmap": [ + ".", + "widgets/", + "panels/" + ] + } }