aboutsummaryrefslogtreecommitdiffstats
path: root/console.php
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-06-27 12:26:53 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-06-27 12:26:53 +0200
commit9a5ab7330a5c83f84f596690e8b22693686ebdd8 (patch)
tree02c6888783063c0e5604cb8fbaf6f8d072afb181 /console.php
parent01dbb8fca2d6e0af48847e39048a529cc2e9fcb0 (diff)
downloadnextcloud-server-9a5ab7330a5c83f84f596690e8b22693686ebdd8.tar.gz
nextcloud-server-9a5ab7330a5c83f84f596690e8b22693686ebdd8.zip
feat(profiler): Add support for profiler in occ commands
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 <come.chilliet@nextcloud.com>
Diffstat (limited to 'console.php')
-rw-r--r--console.php31
1 files changed, 30 insertions, 1 deletions
diff --git a/console.php b/console.php
index 693a2618a88..7b067a84a35 100644
--- a/console.php
+++ b/console.php
@@ -10,6 +10,10 @@ declare(strict_types=1);
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 @@ try {
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) {