2015-04-07 23:28:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorConfigCacheController
|
|
|
|
extends PhabricatorConfigController {
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$nav = $this->buildSideNavView();
|
|
|
|
$nav->selectFilter('cache/');
|
|
|
|
|
|
|
|
$title = pht('Cache Status');
|
|
|
|
|
|
|
|
$crumbs = $this
|
|
|
|
->buildApplicationCrumbs()
|
|
|
|
->addTextCrumb(pht('Cache Status'));
|
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
$code_box = $this->renderCodeBox();
|
|
|
|
$data_box = $this->renderDataBox();
|
2015-04-07 23:28:20 +02:00
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
$nav->appendChild(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$code_box,
|
|
|
|
$data_box,
|
|
|
|
));
|
2015-04-07 23:28:20 +02:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
$nav,
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
private function renderCodeBox() {
|
|
|
|
$cache = PhabricatorOpcodeCacheSpec::getActiveCacheSpec();
|
2015-04-07 23:28:20 +02:00
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
$properties = id(new PHUIPropertyListView());
|
2015-04-07 23:28:20 +02:00
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
$this->renderCommonProperties($properties, $cache);
|
2015-04-07 23:28:20 +02:00
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
return id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('Opcode Cache'))
|
|
|
|
->addPropertyList($properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderDataBox() {
|
|
|
|
$cache = PhabricatorDataCacheSpec::getActiveCacheSpec();
|
|
|
|
|
|
|
|
$properties = id(new PHUIPropertyListView());
|
|
|
|
|
|
|
|
$this->renderCommonProperties($properties, $cache);
|
|
|
|
|
2015-04-08 01:00:18 +02:00
|
|
|
$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',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
return id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('Data Cache'))
|
2015-04-08 01:00:18 +02:00
|
|
|
->addPropertyList($properties)
|
|
|
|
->appendChild($table);
|
2015-04-07 23:38:03 +02:00
|
|
|
}
|
2015-04-07 23:28:20 +02:00
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
private function renderCommonProperties(
|
|
|
|
PHUIPropertyListView $properties,
|
|
|
|
PhabricatorCacheSpec $cache) {
|
|
|
|
|
|
|
|
if ($cache->getName() !== null) {
|
|
|
|
$name = $this->renderYes($cache->getName());
|
2015-04-07 23:28:20 +02:00
|
|
|
} else {
|
2015-04-07 23:38:03 +02:00
|
|
|
$name = $this->renderNo(pht('None'));
|
2015-04-07 23:28:20 +02:00
|
|
|
}
|
2015-04-07 23:38:03 +02:00
|
|
|
$properties->addProperty(pht('Cache'), $name);
|
2015-04-07 23:28:20 +02:00
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
if ($cache->getIsEnabled()) {
|
|
|
|
$enabled = $this->renderYes(pht('Enabled'));
|
2015-04-07 23:28:20 +02:00
|
|
|
} else {
|
2015-04-07 23:38:03 +02:00
|
|
|
$enabled = $this->renderNo(pht('Not Enabled'));
|
2015-04-07 23:28:20 +02:00
|
|
|
}
|
2015-04-07 23:38:03 +02:00
|
|
|
$properties->addProperty(pht('Enabled'), $enabled);
|
2015-04-07 23:28:20 +02:00
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
$version = $cache->getVersion();
|
|
|
|
if ($version) {
|
|
|
|
$properties->addProperty(pht('Version'), $this->renderInfo($version));
|
2015-04-07 23:28:20 +02:00
|
|
|
}
|
2015-04-08 00:08:47 +02:00
|
|
|
|
|
|
|
if ($cache->getName() === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$mem_total = $cache->getTotalMemory();
|
|
|
|
$mem_used = $cache->getUsedMemory();
|
|
|
|
|
|
|
|
if ($mem_total) {
|
|
|
|
$percent = 100 * ($mem_used / $mem_total);
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Memory Usage'),
|
|
|
|
pht(
|
|
|
|
'%s of %s',
|
|
|
|
phutil_tag('strong', array(), sprintf('%.1f%%', $percent)),
|
|
|
|
phutil_format_bytes($mem_total)));
|
|
|
|
}
|
|
|
|
|
|
|
|
$entry_count = $cache->getEntryCount();
|
|
|
|
if ($entry_count !== null) {
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Cache Entries'),
|
|
|
|
pht('%s', new PhutilNumber($entry_count)));
|
|
|
|
}
|
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
}
|
2015-04-07 23:28:20 +02:00
|
|
|
|
|
|
|
private function renderYes($info) {
|
|
|
|
return array(
|
|
|
|
id(new PHUIIconView())->setIconFont('fa-check', 'green'),
|
|
|
|
' ',
|
|
|
|
$info,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderNo($info) {
|
|
|
|
return array(
|
|
|
|
id(new PHUIIconView())->setIconFont('fa-times-circle', 'red'),
|
|
|
|
' ',
|
|
|
|
$info,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderInfo($info) {
|
|
|
|
return array(
|
|
|
|
id(new PHUIIconView())->setIconFont('fa-info-circle', 'grey'),
|
|
|
|
' ',
|
|
|
|
$info,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|