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
|
|
|
|
2016-04-09 00:00:38 +02:00
|
|
|
$view = id(new PHUITwoColumnView())
|
|
|
|
->setNavigation($nav)
|
|
|
|
->setMainColumn(array(
|
2015-04-07 23:38:03 +02:00
|
|
|
$code_box,
|
|
|
|
$data_box,
|
2016-04-09 00:00:38 +02:00
|
|
|
));
|
2015-04-07 23:28:20 +02:00
|
|
|
|
2016-04-03 02:27:39 +02:00
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
2016-04-09 00:00:38 +02:00
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild($view);
|
2015-04-07 23:28:20 +02:00
|
|
|
}
|
|
|
|
|
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-09-10 23:18:52 +02:00
|
|
|
$purge_button = id(new PHUIButtonView())
|
|
|
|
->setText(pht('Purge Caches'))
|
|
|
|
->setHref('/config/cache/purge/')
|
|
|
|
->setTag('a')
|
|
|
|
->setWorkflow(true)
|
2016-01-28 05:38:01 +01:00
|
|
|
->setIcon('fa-exclamation-triangle');
|
2015-09-10 23:18:52 +02:00
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('Opcode Cache'))
|
|
|
|
->addActionLink($purge_button);
|
|
|
|
|
2015-04-07 23:38:03 +02:00
|
|
|
return id(new PHUIObjectBoxView())
|
2015-09-10 23:18:52 +02:00
|
|
|
->setHeader($header)
|
2016-08-22 19:36:23 +02:00
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
2015-04-07 23:38:03 +02:00
|
|
|
->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)
|
2016-08-22 19:36:23 +02:00
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
[Redesign] Add Table, Collapse support to ObjectBox
Summary: Converts most all tables to be directly set via `setTable` to an ObjectBox. I think this path is more flexible design wise, as we can change the box based on children, and not just CSS. We also already do this with PropertyList, Forms, ObjectList, and Header. `setCollapsed` is added to ObjectBox to all children objects to bleed to the edges (like diffs).
Test Plan: I did a grep of `appendChild($table)` as well as searches for `PHUIObjectBoxView`, also with manual opening of hundreds of files. I'm sure I missed 5-8 places. If you just appendChild($table) nothing breaks, it just looks a little funny.
Reviewers: epriestley, btrahan
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D12955
2015-05-20 21:43:34 +02:00
|
|
|
->setTable($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(
|
2016-01-28 05:38:01 +01:00
|
|
|
id(new PHUIIconView())->setIcon('fa-check', 'green'),
|
2015-04-07 23:28:20 +02:00
|
|
|
' ',
|
|
|
|
$info,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderNo($info) {
|
|
|
|
return array(
|
2016-01-28 05:38:01 +01:00
|
|
|
id(new PHUIIconView())->setIcon('fa-times-circle', 'red'),
|
2015-04-07 23:28:20 +02:00
|
|
|
' ',
|
|
|
|
$info,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderInfo($info) {
|
|
|
|
return array(
|
2016-01-28 05:38:01 +01:00
|
|
|
id(new PHUIIconView())->setIcon('fa-info-circle', 'grey'),
|
2015-04-07 23:28:20 +02:00
|
|
|
' ',
|
|
|
|
$info,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|