mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 04:20:55 +01:00
Use PhutilConsoleTable in ./bin/storage probe
Summary: Fixes T8477. Use `PhutilConsoleTable` to render the output from `./bin/storage probe`. Test Plan: Ran `./bin/storage probe` and saw tabulated output. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Maniphest Tasks: T8477 Differential Revision: https://secure.phabricator.com/D13339
This commit is contained in:
parent
1851ca2d71
commit
68bb60e52f
1 changed files with 41 additions and 18 deletions
|
@ -45,34 +45,57 @@ final class PhabricatorStorageManagementProbeWorkflow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$console->writeOut("%s\n", pht('APPROXIMATE TABLE SIZES'));
|
|
||||||
asort($totals);
|
asort($totals);
|
||||||
|
|
||||||
|
$table = id(new PhutilConsoleTable())
|
||||||
|
->setShowHeader(false)
|
||||||
|
->setPadding(2)
|
||||||
|
->addColumn('name', array('title' => pht('Database / Table')))
|
||||||
|
->addColumn('size', array('title' => pht('Size')))
|
||||||
|
->addColumn('percentage', array('title' => pht('Percentage')));
|
||||||
|
|
||||||
foreach ($totals as $db => $size) {
|
foreach ($totals as $db => $size) {
|
||||||
$database_size = $this->formatSize($totals[$db], $overall);
|
list($database_size, $database_percentage) = $this->formatSize(
|
||||||
$console->writeOut(
|
$totals[$db],
|
||||||
"**%s**\n",
|
$overall);
|
||||||
sprintf('%-32.32s %18s', $db, $database_size));
|
|
||||||
|
$table->addRow(array(
|
||||||
|
'name' => phutil_console_format('**%s**', $db),
|
||||||
|
'size' => phutil_console_format('**%s**', $database_size),
|
||||||
|
'percentage' => phutil_console_format('**%s**', $database_percentage),
|
||||||
|
));
|
||||||
$data[$db] = isort($data[$db], '_totalSize');
|
$data[$db] = isort($data[$db], '_totalSize');
|
||||||
foreach ($data[$db] as $table => $info) {
|
foreach ($data[$db] as $table_name => $info) {
|
||||||
$table_size = $this->formatSize($info['_totalSize'], $overall);
|
list($table_size, $table_percentage) = $this->formatSize(
|
||||||
$console->writeOut(
|
$info['_totalSize'],
|
||||||
"%s\n",
|
$overall);
|
||||||
sprintf(' %-28.28s %18s', $table, $table_size));
|
|
||||||
|
$table->addRow(array(
|
||||||
|
'name' => ' '.$table_name,
|
||||||
|
'size' => $table_size,
|
||||||
|
'percentage' => $table_percentage,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$overall_size = $this->formatSize($overall, $overall);
|
|
||||||
$console->writeOut(
|
|
||||||
"**%s**\n",
|
|
||||||
sprintf('%-32.32s %18s', pht('TOTAL'), $overall_size));
|
|
||||||
|
|
||||||
|
list($overall_size, $overall_percentage) = $this->formatSize(
|
||||||
|
$overall,
|
||||||
|
$overall);
|
||||||
|
$table->addRow(array(
|
||||||
|
'name' => phutil_console_format('**%s**', pht('TOTAL')),
|
||||||
|
'size' => phutil_console_format('**%s**', $overall_size),
|
||||||
|
'percentage' => phutil_console_format('**%s**', $overall_percentage),
|
||||||
|
));
|
||||||
|
|
||||||
|
$table->draw();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formatSize($n, $o) {
|
private function formatSize($n, $o) {
|
||||||
return sprintf(
|
return array(
|
||||||
'%8.8s MB %5.5s%%',
|
sprintf('%8.8s MB', number_format($n / (1024 * 1024), 1)),
|
||||||
number_format($n / (1024 * 1024), 1),
|
sprintf('%3.1f%%', 100 * ($n / $o)),
|
||||||
sprintf('%3.1f', 100 * ($n / $o)));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue