Changeset View
Changeset View
Standalone View
Standalone View
src/applications/cache/spec/PhabricatorDataCacheSpec.php
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | if (version_compare(phpversion(), '5.5', '>=')) { | ||||
->setMessage($message) | ->setMessage($message) | ||||
->addPHPExtension('apcu'); | ->addPHPExtension('apcu'); | ||||
} else { | } else { | ||||
$this->raiseInstallAPCIssue(); | $this->raiseInstallAPCIssue(); | ||||
} | } | ||||
} | } | ||||
private function initAPCCommonSpec() { | private function initAPCCommonSpec() { | ||||
$state = array(); | |||||
if (function_exists('apcu_sma_info')) { | |||||
$mem = apcu_sma_info(); | |||||
$info = apcu_cache_info(); | |||||
} else if (function_exists('apc_sma_info')) { | |||||
$mem = apc_sma_info(); | $mem = apc_sma_info(); | ||||
$info = apc_cache_info('user'); | |||||
} else { | |||||
$mem = null; | |||||
} | |||||
if ($mem) { | |||||
$this->setTotalMemory($mem['num_seg'] * $mem['seg_size']); | $this->setTotalMemory($mem['num_seg'] * $mem['seg_size']); | ||||
$info = apc_cache_info('user'); | |||||
$this->setUsedMemory($info['mem_size']); | $this->setUsedMemory($info['mem_size']); | ||||
$this->setEntryCount(count($info['cache_list'])); | $this->setEntryCount(count($info['cache_list'])); | ||||
$cache = $info['cache_list']; | $cache = $info['cache_list']; | ||||
$state = array(); | $state = array(); | ||||
foreach ($cache as $item) { | foreach ($cache as $item) { | ||||
$info = idx($item, 'info', '<unknown-key>'); | $info = idx($item, 'info', '<unknown-key>'); | ||||
$key = self::getKeyPattern($info); | $key = self::getKeyPattern($info); | ||||
if (empty($state[$key])) { | if (empty($state[$key])) { | ||||
$state[$key] = array( | $state[$key] = array( | ||||
'max' => 0, | 'max' => 0, | ||||
'total' => 0, | 'total' => 0, | ||||
'count' => 0, | 'count' => 0, | ||||
); | ); | ||||
} | } | ||||
$state[$key]['max'] = max($state[$key]['max'], $item['mem_size']); | $state[$key]['max'] = max($state[$key]['max'], $item['mem_size']); | ||||
$state[$key]['total'] += $item['mem_size']; | $state[$key]['total'] += $item['mem_size']; | ||||
$state[$key]['count']++; | $state[$key]['count']++; | ||||
} | } | ||||
} | |||||
$this->setCacheSummary($state); | $this->setCacheSummary($state); | ||||
} | } | ||||
private static function getKeyPattern($key) { | private static function getKeyPattern($key) { | ||||
// If this key isn't in the current cache namespace, don't reveal any | // If this key isn't in the current cache namespace, don't reveal any | ||||
// information about it. | // information about it. | ||||
$namespace = PhabricatorEnv::getEnvConfig('phabricator.cache-namespace'); | $namespace = PhabricatorEnv::getEnvConfig('phabricator.cache-namespace'); | ||||
Show All 15 Lines |