Skip to content

Commit

Permalink
Merge pull request #46169 from nextcloud/enh/support-profiler-in-occ
Browse files Browse the repository at this point in the history
Support profiler in occ commands
  • Loading branch information
icewind1991 authored Jul 1, 2024
2 parents 5270ffc + 9a5ab73 commit 55f3e53
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
31 changes: 30 additions & 1 deletion console.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions lib/private/App/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down

0 comments on commit 55f3e53

Please sign in to comment.