From 3aae84edd1ce050a0f7013b5ca24323e1af49583 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 23 Feb 2019 01:24:08 +0100 Subject: [PATCH 1/2] [rendertime] Timing problem during addon config read --- src/App.php | 9 +++++++-- src/Util/Profiler.php | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/App.php b/src/App.php index 3df285cb38..571546cbb0 100644 --- a/src/App.php +++ b/src/App.php @@ -358,10 +358,15 @@ class App $this->getMode()->determine($this->basePath); if ($this->getMode()->has(App\Mode::DBAVAILABLE)) { - Core\Hook::loadHooks(); $loader = new ConfigCacheLoader($this->basePath); - Core\Hook::callAll('load_config', $loader); $this->config->getCache()->load($loader->loadCoreConfig('addon'), true); + + $this->profiler->update( + $this->config->get('system', 'profiler', false), + $this->config->get('rendertime', 'callstack', false)); + + Core\Hook::loadHooks(); + Core\Hook::callAll('load_config', $loader); } $this->loadDefaultTimezone(); diff --git a/src/Util/Profiler.php b/src/Util/Profiler.php index c8c5633718..fe72efce40 100644 --- a/src/Util/Profiler.php +++ b/src/Util/Profiler.php @@ -42,6 +42,18 @@ class Profiler implements ContainerInterface return $this->rendertime; } + /** + * Updates the enabling of the current profiler + * + * @param bool $enabled + * @param bool $renderTime + */ + public function update($enabled = false, $renderTime = false) + { + $this->enabled = $enabled; + $this->rendertime = $renderTime; + } + /** * @param bool $enabled True, if the Profiler is enabled * @param bool $renderTime True, if the Profiler should measure the whole rendertime including functions From dddaf8ea1d4c3941107d17dd7781de001d2a5db9 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 23 Feb 2019 01:37:29 +0100 Subject: [PATCH 2/2] improve tests --- tests/src/Util/ProfilerTest.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/src/Util/ProfilerTest.php b/tests/src/Util/ProfilerTest.php index 87796a2f37..449ec5e5ff 100644 --- a/tests/src/Util/ProfilerTest.php +++ b/tests/src/Util/ProfilerTest.php @@ -189,13 +189,29 @@ class ProfilerTest extends MockedTest } /** - * Test if no rendertime is set + * Test different enable and disable states of the profiler */ - public function testNoRenderTime() + public function testEnableDisable() { $profiler = new Profiler(true, false); $this->assertFalse($profiler->isRendertime()); $this->assertEmpty($profiler->getRendertimeString()); + + $profiler->saveTimestamp(time(), 'network', 'test1'); + + $profiler->update(false, false); + + $this->assertFalse($profiler->isRendertime()); + $this->assertEmpty($profiler->getRendertimeString()); + + $profiler->update(true, true); + + $profiler->saveTimestamp(time(), 'database', 'test2'); + + $this->assertTrue($profiler->isRendertime()); + $output = $profiler->getRendertimeString(); + $this->assertRegExp('/test1: \d+/', $output); + $this->assertRegExp('/test2: \d+/', $output); } }