Skip to content

Commit

Permalink
allow exporting a single profile
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Sep 17, 2023
1 parent 5bcc135 commit 6369023
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
10 changes: 4 additions & 6 deletions apps/dav/lib/Profiler/ProfilerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,26 @@ public function __construct(
$a = 1;
}

/** @return void */
public function initialize(Server $server) {
public function initialize(Server $server): void {
$server->on('beforeMethod:*', [$this, 'beforeMethod'], 1);
$server->on('afterMethod:*', [$this, 'afterMethod'], 9999);
$server->on('afterResponse', [$this, 'afterResponse'], 9999);
$server->on('exception', [$this, 'exception']);
}

public function beforeMethod() {
public function beforeMethod(): void {
$this->eventLogger->start('dav:server:method', 'Processing dav request');
}

/** @return void */
public function afterMethod(RequestInterface $request, ResponseInterface $response) {
public function afterMethod(RequestInterface $request, ResponseInterface $response): void {
$this->eventLogger->end('dav:server:method');
$this->eventLogger->start('dav:server:response', 'Sending dav response');
if ($this->profiler->isEnabled()) {
$response->addHeader('X-Debug-Token', $this->request->getId());
}
}

public function afterResponse(RequestInterface $request, ResponseInterface $response) {
public function afterResponse(RequestInterface $request, ResponseInterface $response): void {
$this->eventLogger->end('dav:server:response');
$this->finalize($response->getStatus());
}
Expand Down
26 changes: 17 additions & 9 deletions core/Command/Profiler/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OC\Core\Command\Profiler;

use _HumbugBox1cb33d1f20f1\LanguageServerProtocol\PackageDescriptor;
use OC\Core\Command\Base;
use OCP\Profiler\IProfiler;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -25,23 +26,30 @@ 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');
->addOption('limit', null, InputOption::VALUE_REQUIRED, 'Maximum number of profiles to export')
->addOption('url', null, InputOption::VALUE_REQUIRED, 'Url to export profiles for')
->addOption('since', null, InputOption::VALUE_REQUIRED, 'Minimum date for exported profiles, as unix timestamp')
->addOption('before', null, InputOption::VALUE_REQUIRED, 'Maximum date for exported profiles, as unix timestamp')
->addOption('token', null, InputOption::VALUE_REQUIRED, 'Export only profile for a single request token');
}

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;
$token = $input->getOption('token') ? $input->getOption('token') : null;
$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);
if ($token) {
$profiles = [$this->profiler->loadProfile($token)];
$profiles = array_filter($profiles);
} else {
$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));

Expand Down
6 changes: 3 additions & 3 deletions lib/private/Profiler/DataCollector/MemoryDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ private function convertToBytes(string $memoryLimit) {

switch (substr($memoryLimit, -1)) {
case 't': $max *= 1024;
// no break
// no break
case 'g': $max *= 1024;
// no break
// no break
case 'm': $max *= 1024;
// no break
// no break
case 'k': $max *= 1024;
}
return $max;
Expand Down
3 changes: 0 additions & 3 deletions lib/private/Profiler/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@

use OC\AppFramework\Http\Request;
use OC\AppFramework\Http\RequestVars;
use OC\Profiler\DataCollector\EventLoggerDataProvider;
use OC\Profiler\DataCollector\HttpDataCollector;
use OC\Profiler\DataCollector\MemoryDataCollector;
use OCP\AppFramework\Http\Response;
use OCP\DataCollector\IDataCollector;
use OCP\Diagnostics\IEventLogger;
use OCP\IRequest;
use OCP\Profiler\IProfiler;
use OCP\Profiler\IProfile;
use OC\SystemConfig;
use Psr\Container\ContainerInterface;

class Profiler implements IProfiler {
/** @var array<string, IDataCollector> */
Expand Down

0 comments on commit 6369023

Please sign in to comment.