diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-04-04 13:56:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-04 13:56:37 +0300 |
commit | 135bdb3d5830672214149fa0b75fadd29b20b844 (patch) | |
tree | f2c1bc68c733829c90090f71d712f78efbc77083 /apps/dav | |
parent | 498d3aea060ed496e2b5351108718e198b021d00 (diff) | |
parent | 7d272c54d013538746d6731097ec37f360effb5d (diff) |
Merge pull request #30823 from nextcloud/work/profiler
Built-in profiler
This adds the required API for collecting information about requests. This information
can then be displayed with the new 'profiler' app.
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | apps/dav/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | apps/dav/lib/Profiler/ProfilerPlugin.php | 47 | ||||
-rw-r--r-- | apps/dav/lib/Server.php | 31 |
4 files changed, 70 insertions, 10 deletions
diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index cf02a3221fb..b1043fcbbec 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -272,6 +272,7 @@ return array( 'OCA\\DAV\\Migration\\Version1016Date20201109085907' => $baseDir . '/../lib/Migration/Version1016Date20201109085907.php', 'OCA\\DAV\\Migration\\Version1017Date20210216083742' => $baseDir . '/../lib/Migration/Version1017Date20210216083742.php', 'OCA\\DAV\\Migration\\Version1018Date20210312100735' => $baseDir . '/../lib/Migration/Version1018Date20210312100735.php', + 'OCA\\DAV\\Profiler\\ProfilerPlugin' => $baseDir . '/../lib/Profiler/ProfilerPlugin.php', 'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningNode.php', 'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => $baseDir . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php', 'OCA\\DAV\\RootCollection' => $baseDir . '/../lib/RootCollection.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index d164ab2b1ce..b94e383cb0e 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -287,6 +287,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Migration\\Version1016Date20201109085907' => __DIR__ . '/..' . '/../lib/Migration/Version1016Date20201109085907.php', 'OCA\\DAV\\Migration\\Version1017Date20210216083742' => __DIR__ . '/..' . '/../lib/Migration/Version1017Date20210216083742.php', 'OCA\\DAV\\Migration\\Version1018Date20210312100735' => __DIR__ . '/..' . '/../lib/Migration/Version1018Date20210312100735.php', + 'OCA\\DAV\\Profiler\\ProfilerPlugin' => __DIR__ . '/..' . '/../lib/Profiler/ProfilerPlugin.php', 'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningNode' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningNode.php', 'OCA\\DAV\\Provisioning\\Apple\\AppleProvisioningPlugin' => __DIR__ . '/..' . '/../lib/Provisioning/Apple/AppleProvisioningPlugin.php', 'OCA\\DAV\\RootCollection' => __DIR__ . '/..' . '/../lib/RootCollection.php', diff --git a/apps/dav/lib/Profiler/ProfilerPlugin.php b/apps/dav/lib/Profiler/ProfilerPlugin.php new file mode 100644 index 00000000000..672ca4010b7 --- /dev/null +++ b/apps/dav/lib/Profiler/ProfilerPlugin.php @@ -0,0 +1,47 @@ +<?php declare(strict_types = 1); +/** + * @copyright 2021 Carl Schwan <carl@carlschwan.eu> + * + * @author Carl Schwan <carl@carlschwan.eu> + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\DAV\Profiler; + +use OCP\IRequest; +use Sabre\DAV\Server; +use Sabre\HTTP\RequestInterface; +use Sabre\HTTP\ResponseInterface; + +class ProfilerPlugin extends \Sabre\DAV\ServerPlugin { + private IRequest $request; + + public function __construct(IRequest $request) { + $this->request = $request; + } + + /** @return void */ + public function initialize(Server $server) { + $server->on('afterMethod:*', [$this, 'afterMethod']); + } + + /** @return void */ + public function afterMethod(RequestInterface $request, ResponseInterface $response) { + $response->addHeader('X-Debug-Token', $this->request->getId()); + } +} diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index 759d39c0233..ff64da2a238 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -36,6 +36,9 @@ namespace OCA\DAV; use OCA\DAV\Connector\Sabre\RequestIdHeaderPlugin; use OCP\Diagnostics\IEventLogger; +use OCP\Profiler\IProfiler; +use OCA\DAV\Profiler\ProfilerPlugin; +use OCP\AppFramework\Http\Response; use Psr\Log\LoggerInterface; use OCA\DAV\AppInfo\PluginManager; use OCA\DAV\CalDAV\BirthdayService; @@ -78,17 +81,19 @@ use Sabre\DAV\UUIDUtil; use SearchDAV\DAV\SearchPlugin; class Server { + private IRequest $request; + private string $baseUri; + public Connector\Sabre\Server $server; + private IProfiler $profiler; + + public function __construct(IRequest $request, string $baseUri) { + $this->profiler = \OC::$server->get(IProfiler::class); + if ($this->profiler->isEnabled()) { + /** @var IEventLogger $eventLogger */ + $eventLogger = \OC::$server->get(IEventLogger::class); + $eventLogger->start('runtime', 'DAV Runtime'); + } - /** @var IRequest */ - private $request; - - /** @var string */ - private $baseUri; - - /** @var Connector\Sabre\Server */ - public $server; - - public function __construct(IRequest $request, $baseUri) { $this->request = $request; $this->baseUri = $baseUri; $logger = \OC::$server->getLogger(); @@ -115,6 +120,7 @@ class Server { $this->server->httpRequest->setUrl($this->request->getRequestUri()); $this->server->setBaseUri($this->baseUri); + $this->server->addPlugin(new ProfilerPlugin($this->request)); $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); $this->server->addPlugin(new AnonymousOptionsPlugin()); $authPlugin = new Plugin(); @@ -343,6 +349,11 @@ class Server { $eventLogger->start('dav_server_exec', ''); $this->server->exec(); $eventLogger->end('dav_server_exec'); + if ($this->profiler->isEnabled()) { + $eventLogger->end('runtime'); + $profile = $this->profiler->collect(\OC::$server->get(IRequest::class), new Response()); + $this->profiler->saveProfile($profile); + } } private function requestIsForSubtree(array $subTrees): bool { |