From 01dbb8fca2d6e0af48847e39048a529cc2e9fcb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 27 Jun 2024 12:25:20 +0200 Subject: [PATCH 1/2] fix(profiler): Remove bogus profiler event start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes profiler event graph by removing an event start which had no matching end() call. Signed-off-by: Côme Chilliet --- lib/private/App/AppManager.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 0786fbded20fd..52a88a724ffb1 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -388,8 +388,8 @@ public function loadApp(string $app): void { if ($appPath === false) { return; } - $eventLogger = \OC::$server->get(\OCP\Diagnostics\IEventLogger::class); - $eventLogger->start("bootstrap:load_app:$app", "Load $app"); + $eventLogger = \OC::$server->get(IEventLogger::class); + $eventLogger->start("bootstrap:load_app:$app", "Load app: $app"); // in case someone calls loadApp() directly \OC_App::registerAutoloading($app, $appPath); @@ -400,8 +400,6 @@ public function loadApp(string $app): void { $hasAppPhpFile = is_file($appPath . '/appinfo/app.php'); - $eventLogger = \OC::$server->get(IEventLogger::class); - $eventLogger->start('bootstrap:load_app_' . $app, 'Load app: ' . $app); if ($isBootable && $hasAppPhpFile) { $this->logger->error('/appinfo/app.php is not loaded when \OCP\AppFramework\Bootstrap\IBootstrap on the application class is used. Migrate everything from app.php to the Application class.', [ 'app' => $app, From 9a5ab7330a5c83f84f596690e8b22693686ebdd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 27 Jun 2024 12:26:53 +0200 Subject: [PATCH 2/2] feat(profiler): Add support for profiler in occ commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commands will appear in available profiles after the command ran. Method is set to "occ" and URL to the command line with parameters. Signed-off-by: Côme Chilliet --- console.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/console.php b/console.php index 693a2618a8886..7b067a84a3523 100644 --- a/console.php +++ b/console.php @@ -10,6 +10,10 @@ require_once __DIR__ . '/lib/versioncheck.php'; use OC\Console\Application; +use OCP\AppFramework\Http\Response; +use OCP\Diagnostics\IEventLogger; +use OCP\IRequest; +use OCP\Profiler\IProfiler; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\ConsoleOutput; @@ -67,9 +71,34 @@ function exceptionHandler($exception) { echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini." . PHP_EOL; } + $eventLogger = \OCP\Server::get(IEventLogger::class); + $eventLogger->start('console:build_application', 'Build Application instance and load commands'); + $application = \OCP\Server::get(Application::class); $application->loadCommands(new ArgvInput(), new ConsoleOutput()); - $application->run(); + + $eventLogger->end('console:build_application'); + $eventLogger->start('console:run', 'Run the command'); + + $application->setAutoExit(false); + $exitCode = $application->run(); + + $eventLogger->end('console:run'); + + $profiler = \OCP\Server::get(IProfiler::class); + if ($profiler->isEnabled()) { + $eventLogger->end('runtime'); + $profile = $profiler->collect(\OCP\Server::get(IRequest::class), new Response()); + $profile->setMethod('occ'); + $profile->setUrl(implode(' ', $argv)); + $profiler->saveProfile($profile); + } + + if ($exitCode > 255) { + $exitCode = 255; + } + + exit($exitCode); } catch (Exception $ex) { exceptionHandler($ex); } catch (Error $ex) {