mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 04:20:55 +01:00
Summarize data cache usage and allocation information
Summary: Ref T5501. Group cache data by key pattern. Test Plan: {F362994} Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5501 Differential Revision: https://secure.phabricator.com/D12317
This commit is contained in:
parent
ac27b93c9f
commit
4783c3940d
2 changed files with 88 additions and 1 deletions
|
@ -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 @@ final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec {
|
|||
$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 '<other-namespace>';
|
||||
}
|
||||
|
||||
$key = preg_replace('/(?<![a-zA-Z])\d+(?![a-zA-Z])/', 'N', $key);
|
||||
$key = preg_replace('/PHID-[A-Z]{4}-[a-z0-9]{20}/', 'PHID', $key);
|
||||
|
||||
// TODO: We should probably standardize how digests get embedded into cache
|
||||
// keys to make this rule more generic.
|
||||
$key = preg_replace('/:celerity:.*$/', ':celerity:X', $key);
|
||||
$key = preg_replace('/:pkcs8:.*$/', ':pkcs8:X', $key);
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,9 +52,48 @@ final class PhabricatorConfigCacheController
|
|||
|
||||
$this->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(
|
||||
|
|
Loading…
Reference in a new issue