mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-29 00:34:05 +02:00
cli/config: add profiler
This commit is contained in:
parent
0a33e4f1ed
commit
247ff40459
@ -17,6 +17,11 @@ class ConfigCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function renderAction()
|
public function renderAction()
|
||||||
{
|
{
|
||||||
|
$profile = $this->params->shift('profile');
|
||||||
|
if ($profile) {
|
||||||
|
$this->enableDbProfiler();
|
||||||
|
}
|
||||||
|
|
||||||
$config = new IcingaConfig($this->db());
|
$config = new IcingaConfig($this->db());
|
||||||
Benchmark::measure('Rendering config');
|
Benchmark::measure('Rendering config');
|
||||||
if ($config->hasBeenModified()) {
|
if ($config->hasBeenModified()) {
|
||||||
@ -35,6 +40,44 @@ class ConfigCommand extends Command
|
|||||||
$checksum
|
$checksum
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($profile) {
|
||||||
|
$this->dumpDbProfile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function dumpDbProfile()
|
||||||
|
{
|
||||||
|
$profiler = $this->getDbProfiler();
|
||||||
|
|
||||||
|
$totalTime = $profiler->getTotalElapsedSecs();
|
||||||
|
$queryCount = $profiler->getTotalNumQueries();
|
||||||
|
$longestTime = 0;
|
||||||
|
$longestQuery = null;
|
||||||
|
|
||||||
|
foreach ($profiler->getQueryProfiles() as $query) {
|
||||||
|
echo $query->getQuery() . "\n";
|
||||||
|
if ($query->getElapsedSecs() > $longestTime) {
|
||||||
|
$longestTime = $query->getElapsedSecs();
|
||||||
|
$longestQuery = $query->getQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo 'Executed ' . $queryCount . ' queries in ' . $totalTime . ' seconds' . "\n";
|
||||||
|
echo 'Average query length: ' . $totalTime / $queryCount . ' seconds' . "\n";
|
||||||
|
echo 'Queries per second: ' . $queryCount / $totalTime . "\n";
|
||||||
|
echo 'Longest query length: ' . $longestTime . "\n";
|
||||||
|
echo "Longest query: \n" . $longestQuery . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getDbProfiler()
|
||||||
|
{
|
||||||
|
return $this->db()->getDbAdapter()->getProfiler();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function enableDbProfiler()
|
||||||
|
{
|
||||||
|
return $this->getDbProfiler()->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user