From 87f8e1e3663c76251034b88aa8caaf4b711e75a7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 23 Sep 2020 12:14:01 +0200 Subject: [PATCH 1/2] Log an error if a dashboard widget loads longer than 1 second Signed-off-by: Joas Schilling --- lib/private/Dashboard/Manager.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/private/Dashboard/Manager.php b/lib/private/Dashboard/Manager.php index bc57326dff..94b80a3b4a 100644 --- a/lib/private/Dashboard/Manager.php +++ b/lib/private/Dashboard/Manager.php @@ -95,7 +95,16 @@ class Manager implements IManager { } try { + $startTime = microtime(true); $widget->load(); + $endTime = microtime(true); + $duration = $endTime - $startTime; + if ($duration > 1) { + \OC::$server->getLogger()->error('Dashboard widget {widget} took {duration} seconds to load.', [ + 'widget' => $widget->getId(), + 'duration' => round($duration, 2), + ]); + } } catch (Throwable $e) { \OC::$server->getLogger()->logException($e, [ 'message' => 'Error during dashboard widget loading: ' . $e->getMessage(), From 5475bb4083e767652fe1b7f3a37064bdec697a2c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 23 Sep 2020 12:14:31 +0200 Subject: [PATCH 2/2] Log a warning if a "lazy" initial state loads longer than 1 second Signed-off-by: Joas Schilling --- lib/private/InitialStateService.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/private/InitialStateService.php b/lib/private/InitialStateService.php index 55ce9c4172..c74eb683bd 100644 --- a/lib/private/InitialStateService.php +++ b/lib/private/InitialStateService.php @@ -72,7 +72,17 @@ class InitialStateService implements IInitialStateService { private function invokeLazyStateCallbacks(): void { foreach ($this->lazyStates as $app => $lazyStates) { foreach ($lazyStates as $key => $lazyState) { + $startTime = microtime(true); $this->provideInitialState($app, $key, $lazyState()); + $endTime = microtime(true); + $duration = $endTime - $startTime; + if ($duration > 1) { + $this->logger->warning('Lazy initial state provider for {key} took {duration} seconds.', [ + 'app' => $app, + 'key' => $key, + 'duration' => round($duration, 2), + ]); + } } } $this->lazyStates = [];