diff --git a/src/applications/cache/spec/PhabricatorDataCacheSpec.php b/src/applications/cache/spec/PhabricatorDataCacheSpec.php --- a/src/applications/cache/spec/PhabricatorDataCacheSpec.php +++ b/src/applications/cache/spec/PhabricatorDataCacheSpec.php @@ -2,6 +2,17 @@ final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec { + private $cacheSummary; + + public function setCacheSummary(array $cache_summary) { + $this->cacheSummary = $cache_summary; + return $this; + } + + public function getCacheSummary() { + return $this->cacheSummary; + } + public static function getActiveCacheSpec() { $spec = new PhabricatorDataCacheSpec(); // NOTE: If APCu is installed, it reports that APC is installed. @@ -79,6 +90,43 @@ $info = apc_cache_info('user'); $spec->setUsedMemory($info['mem_size']); $spec->setEntryCount(count($info['cache_list'])); + + $cache = $info['cache_list']; + $state = array(); + foreach ($cache as $item) { + $key = self::getKeyPattern($item['info']); + if (empty($state[$key])) { + $state[$key] = array( + 'max' => 0, + 'total' => 0, + 'count' => 0, + ); + } + $state[$key]['max'] = max($state[$key]['max'], $item['mem_size']); + $state[$key]['total'] += $item['mem_size']; + $state[$key]['count']++; + } + + $spec->setCacheSummary($state); + } + + private static function getKeyPattern($key) { + // If this key isn't in the current cache namespace, don't reveal any + // information about it. + $namespace = PhabricatorEnv::getEnvConfig('phabricator.cache-namespace'); + if (strncmp($key, $namespace.':', strlen($namespace) + 1)) { + return ''; + } + + $key = preg_replace('/(?renderCommonProperties($properties, $cache); + $table = null; + if ($cache->getName() !== null) { + $total_memory = $cache->getTotalMemory(); + + $summary = $cache->getCacheSummary(); + $summary = isort($summary, 'total'); + $summary = array_reverse($summary, true); + + $rows = array(); + foreach ($summary as $key => $info) { + $rows[] = array( + $key, + pht('%s', new PhutilNumber($info['count'])), + phutil_format_bytes($info['max']), + phutil_format_bytes($info['total']), + sprintf('%.1f%%', (100 * ($info['total'] / $total_memory))), + ); + } + + $table = id(new AphrontTableView($rows)) + ->setHeaders( + array( + pht('Pattern'), + pht('Count'), + pht('Largest'), + pht('Total'), + pht('Usage'), + )) + ->setColumnClasses( + array( + 'wide', + 'n', + 'n', + 'n', + 'n', + )); + } + return id(new PHUIObjectBoxView()) ->setHeaderText(pht('Data Cache')) - ->addPropertyList($properties); + ->addPropertyList($properties) + ->appendChild($table); } private function renderCommonProperties(