-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Allow using the profiler to selectively profile production instances #39399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3908ff2
make FileProfilerStorage more lazy
icewind1991 d8cb835
add a more limited version of IRequest to prevent injection loops
icewind1991 af4e9c5
allow enable the profiler per-request by setting a shared secret
icewind1991 453c921
fix app loading event id
icewind1991 ce79d43
move more dav profiler logic to the ProfilerPlugin and also enable it…
icewind1991 e7f1e15
fix clearing profiles
icewind1991 b39a3c1
move profiler data collectors to core
icewind1991 5bcc135
move some profiler commands to core
icewind1991 6369023
allow exporting a single profile
icewind1991 a3c4777
minor fixes
icewind1991 2d48849
update autoloader
icewind1991 1f32b18
fix tests
icewind1991 f0f1425
fix error page handling
icewind1991 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
move some profiler commands to core
Signed-off-by: Robin Appelman <[email protected]>
- Loading branch information
commit 5bcc1356167eb28560fa1204d5578bc976e6b97b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| // SPDX-FileCopyrightText: 2022 Robin Appelman <[email protected]> | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| namespace OC\Core\Command\Profiler; | ||
|
|
||
| use OC\Core\Command\Base; | ||
| use OCP\Profiler\IProfiler; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class Clear extends Base { | ||
| private IProfiler $profiler; | ||
|
|
||
| public function __construct(IProfiler $profiler) { | ||
| parent::__construct(); | ||
| $this->profiler = $profiler; | ||
| } | ||
|
|
||
| protected function configure() { | ||
| $this | ||
| ->setName('profiler:clear') | ||
| ->setDescription('Remove all saved profiles'); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int { | ||
| $this->profiler->clear(); | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| // SPDX-FileCopyrightText: 2022 Robin Appelman <[email protected]> | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| namespace OC\Core\Command\Profiler; | ||
|
|
||
| use OCP\IConfig; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class Disable extends Command { | ||
| private IConfig $config; | ||
|
|
||
| public function __construct(IConfig $config) { | ||
| parent::__construct(); | ||
| $this->config = $config; | ||
| } | ||
|
|
||
| protected function configure() { | ||
|
||
| $this | ||
| ->setName('profiler:disable') | ||
| ->setDescription('Disable profiling'); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int { | ||
| $this->config->setSystemValue('profiler', false); | ||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| // SPDX-FileCopyrightText: 2022 Robin Appelman <[email protected]> | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| namespace OC\Core\Command\Profiler; | ||
|
|
||
| use OCP\IConfig; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class Enable extends Command { | ||
| private IConfig $config; | ||
|
|
||
| public function __construct(IConfig $config) { | ||
| parent::__construct(); | ||
| $this->config = $config; | ||
| } | ||
|
|
||
| protected function configure() { | ||
|
||
| $this | ||
| ->setName('profiler:enable') | ||
| ->setDescription('Enable profiling'); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int { | ||
| $this->config->setSystemValue('profiler', true); | ||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| // SPDX-FileCopyrightText: 2022 Robin Appelman <[email protected]> | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| namespace OC\Core\Command\Profiler; | ||
|
|
||
| use OC\Core\Command\Base; | ||
| use OCP\Profiler\IProfiler; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class Export extends Base { | ||
| private IProfiler $profiler; | ||
|
|
||
| public function __construct(IProfiler $profiler) { | ||
| parent::__construct(); | ||
| $this->profiler = $profiler; | ||
| } | ||
|
|
||
| protected function configure() { | ||
|
||
| $this | ||
| ->setName('profiler:export') | ||
| ->setDescription('Export captured profiles as json') | ||
| ->addOption('limit', null, InputOption::VALUE_REQUIRED, 'Maximum number of profiles to return') | ||
| ->addOption('url', null, InputOption::VALUE_REQUIRED, 'Url to list profiles for') | ||
| ->addOption('since', null, InputOption::VALUE_REQUIRED, 'Minimum date for listed profiles, as unix timestamp') | ||
| ->addOption('before', null, InputOption::VALUE_REQUIRED, 'Maximum date for listed profiles, as unix timestamp'); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int { | ||
| $since = $input->getOption('since') ? (int)$input->getOption('since') : null; | ||
| $before = $input->getOption('before') ? (int)$input->getOption('before') : null; | ||
| $limit = $input->getOption('limit') ? (int)$input->getOption('limit') : 1000; | ||
| $url = $input->getOption('url'); | ||
|
|
||
| $profiles = $this->profiler->find($url, $limit, null, $since, $before); | ||
| $profiles = array_reverse($profiles); | ||
| $profiles = array_map(function (array $profile) { | ||
| return $this->profiler->loadProfile($profile['token']); | ||
| }, $profiles); | ||
|
|
||
| $output->writeln(json_encode($profiles)); | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| // SPDX-FileCopyrightText: 2022 Robin Appelman <[email protected]> | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| namespace OC\Core\Command\Profiler; | ||
|
|
||
| use OC\Core\Command\Base; | ||
| use OC\Profiler\DataCollector\DbDataCollector; | ||
| use OC\Profiler\DataCollector\MemoryDataCollector; | ||
| use OCP\Profiler\IProfiler; | ||
| use Symfony\Component\Console\Helper\Table; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class ListCommand extends Base { | ||
| private IProfiler $profiler; | ||
|
|
||
| public function __construct(IProfiler $profiler) { | ||
| parent::__construct(); | ||
| $this->profiler = $profiler; | ||
| } | ||
|
|
||
| protected function configure() { | ||
|
||
| parent::configure(); | ||
| $this | ||
| ->setName('profiler:list') | ||
| ->setDescription('List captured profiles') | ||
| ->addOption('limit', null, InputOption::VALUE_REQUIRED, 'Maximum number of profiles to return') | ||
| ->addOption('url', null, InputOption::VALUE_REQUIRED, 'Url to list profiles for') | ||
| ->addOption('since', null, InputOption::VALUE_REQUIRED, 'Minimum date for listed profiles, as unix timestamp') | ||
| ->addOption('before', null, InputOption::VALUE_REQUIRED, 'Maximum date for listed profiles, as unix timestamp'); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int { | ||
| $since = $input->getOption('since') ? (int)$input->getOption('since') : null; | ||
| $before = $input->getOption('before') ? (int)$input->getOption('before') : null; | ||
| $limit = $input->getOption('limit') ? (int)$input->getOption('limit') : 1000; | ||
| $url = $input->getOption('url'); | ||
|
|
||
| $profiles = $this->profiler->find($url, $limit, null, $since, $before); | ||
| $profiles = array_reverse($profiles); | ||
| foreach ($profiles as &$profile) { | ||
| $info = $this->profiler->loadProfile($profile['token']); | ||
|
|
||
| /** @var DbDataCollector $dbCollector */ | ||
| $dbCollector = $info->getCollector('db'); | ||
|
||
| /** @var MemoryDataCollector $memoryCollector */ | ||
| $memoryCollector = $info->getCollector('memory'); | ||
|
|
||
| if ($dbCollector) { | ||
|
||
| $profile['queries'] = count($dbCollector->getQueries()); | ||
| } else { | ||
| $profile['queries'] = '--'; | ||
| } | ||
| if ($memoryCollector) { | ||
|
||
| $profile['memory'] = $memoryCollector->getMemory(); | ||
| } else { | ||
| $profile['memory'] = '--'; | ||
| } | ||
| } | ||
|
|
||
| $outputType = $input->getOption('output'); | ||
|
|
||
| if ($profiles) { | ||
| if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { | ||
| $this->writeArrayInOutputFormat($input, $output, $profiles); | ||
| } else { | ||
| $table = new Table($output); | ||
| $table->setHeaders(array_keys($profiles[0])); | ||
| $table->setRows($profiles); | ||
| $table->render(); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.