Skip to content

Commit 4783c39

Browse files
author
epriestley
committedApr 7, 2015
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
1 parent ac27b93 commit 4783c39

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed
 

‎src/applications/cache/spec/PhabricatorDataCacheSpec.php

+48
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
final class PhabricatorDataCacheSpec extends PhabricatorCacheSpec {
44

5+
private $cacheSummary;
6+
7+
public function setCacheSummary(array $cache_summary) {
8+
$this->cacheSummary = $cache_summary;
9+
return $this;
10+
}
11+
12+
public function getCacheSummary() {
13+
return $this->cacheSummary;
14+
}
15+
516
public static function getActiveCacheSpec() {
617
$spec = new PhabricatorDataCacheSpec();
718
// NOTE: If APCu is installed, it reports that APC is installed.
@@ -79,6 +90,43 @@ private static function getAPCCommonSpec(PhabricatorDataCacheSpec $spec) {
7990
$info = apc_cache_info('user');
8091
$spec->setUsedMemory($info['mem_size']);
8192
$spec->setEntryCount(count($info['cache_list']));
93+
94+
$cache = $info['cache_list'];
95+
$state = array();
96+
foreach ($cache as $item) {
97+
$key = self::getKeyPattern($item['info']);
98+
if (empty($state[$key])) {
99+
$state[$key] = array(
100+
'max' => 0,
101+
'total' => 0,
102+
'count' => 0,
103+
);
104+
}
105+
$state[$key]['max'] = max($state[$key]['max'], $item['mem_size']);
106+
$state[$key]['total'] += $item['mem_size'];
107+
$state[$key]['count']++;
108+
}
109+
110+
$spec->setCacheSummary($state);
111+
}
112+
113+
private static function getKeyPattern($key) {
114+
// If this key isn't in the current cache namespace, don't reveal any
115+
// information about it.
116+
$namespace = PhabricatorEnv::getEnvConfig('phabricator.cache-namespace');
117+
if (strncmp($key, $namespace.':', strlen($namespace) + 1)) {
118+
return '<other-namespace>';
119+
}
120+
121+
$key = preg_replace('/(?<![a-zA-Z])\d+(?![a-zA-Z])/', 'N', $key);
122+
$key = preg_replace('/PHID-[A-Z]{4}-[a-z0-9]{20}/', 'PHID', $key);
123+
124+
// TODO: We should probably standardize how digests get embedded into cache
125+
// keys to make this rule more generic.
126+
$key = preg_replace('/:celerity:.*$/', ':celerity:X', $key);
127+
$key = preg_replace('/:pkcs8:.*$/', ':pkcs8:X', $key);
128+
129+
return $key;
82130
}
83131

84132
}

‎src/applications/config/controller/PhabricatorConfigCacheController.php

+40-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,48 @@ private function renderDataBox() {
5252

5353
$this->renderCommonProperties($properties, $cache);
5454

55+
$table = null;
56+
if ($cache->getName() !== null) {
57+
$total_memory = $cache->getTotalMemory();
58+
59+
$summary = $cache->getCacheSummary();
60+
$summary = isort($summary, 'total');
61+
$summary = array_reverse($summary, true);
62+
63+
$rows = array();
64+
foreach ($summary as $key => $info) {
65+
$rows[] = array(
66+
$key,
67+
pht('%s', new PhutilNumber($info['count'])),
68+
phutil_format_bytes($info['max']),
69+
phutil_format_bytes($info['total']),
70+
sprintf('%.1f%%', (100 * ($info['total'] / $total_memory))),
71+
);
72+
}
73+
74+
$table = id(new AphrontTableView($rows))
75+
->setHeaders(
76+
array(
77+
pht('Pattern'),
78+
pht('Count'),
79+
pht('Largest'),
80+
pht('Total'),
81+
pht('Usage'),
82+
))
83+
->setColumnClasses(
84+
array(
85+
'wide',
86+
'n',
87+
'n',
88+
'n',
89+
'n',
90+
));
91+
}
92+
5593
return id(new PHUIObjectBoxView())
5694
->setHeaderText(pht('Data Cache'))
57-
->addPropertyList($properties);
95+
->addPropertyList($properties)
96+
->appendChild($table);
5897
}
5998

6099
private function renderCommonProperties(

0 commit comments

Comments
 (0)
Failed to load comments.