-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Kanti/feature/sentry-profiling
- Loading branch information
Showing
37 changed files
with
945 additions
and
356 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.phpunit.cache | ||
composer.lock | ||
public/ | ||
vendor/ | ||
.phpunit.result.cache | ||
var | ||
Resources/Public/test-result |
This file contains 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,12 @@ | ||
watch: | ||
directories: | ||
- Classes/ | ||
- Tests/ | ||
fileMask: '*.php' | ||
notifications: | ||
passingTests: false | ||
failingTests: false | ||
phpunit: | ||
binaryPath: vendor/bin/phpunit | ||
arguments: '--stop-on-failure' | ||
timeout: 180 |
This file contains 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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kanti\ServerTiming\Dto; | ||
|
||
use Kanti\ServerTiming\Utility\TimingUtility; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use TYPO3\CMS\Core\Http\ServerRequestFactory; | ||
|
||
final class ScriptResult | ||
{ | ||
private function __construct(public readonly ?ServerRequestInterface $request, public readonly ?ResponseInterface $response, public readonly ?int $cliExitCode) | ||
{ | ||
} | ||
|
||
public static function fromRequest(ServerRequestInterface $request, ?ResponseInterface $response = null): ScriptResult | ||
{ | ||
return new ScriptResult($request, $response, null); | ||
} | ||
|
||
public static function fromCli(?int $cliExitCode = null): ScriptResult | ||
{ | ||
return new ScriptResult(null, null, $cliExitCode); | ||
} | ||
|
||
public static function fromShutdown(): ScriptResult | ||
{ | ||
if (TimingUtility::IS_CLI) { | ||
return self::fromCli(); | ||
} | ||
|
||
return self::fromRequest($GLOBALS['TYPO3_REQUEST'] ?? ServerRequestFactory::fromGlobals()); | ||
} | ||
|
||
public function isCli(): bool | ||
{ | ||
return !$this->request; | ||
} | ||
} |
This file contains 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
This file contains 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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kanti\ServerTiming\EventListener; | ||
|
||
use Kanti\ServerTiming\Dto\ScriptResult; | ||
use Kanti\ServerTiming\Utility\TimingUtility; | ||
use Symfony\Component\Console\Event\ConsoleCommandEvent; | ||
use Symfony\Component\Console\Event\ConsoleTerminateEvent; | ||
|
||
final class ConsoleCommandEventListener | ||
{ | ||
public function start(ConsoleCommandEvent $event): void | ||
{ | ||
TimingUtility::start('cli', (string)$event->getCommand()?->getName()); | ||
} | ||
|
||
public function stop(ConsoleTerminateEvent $event): void | ||
{ | ||
TimingUtility::end('cli'); | ||
TimingUtility::getInstance()->shutdown(ScriptResult::fromCli($event->getExitCode())); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kanti\ServerTiming\Service; | ||
|
||
use Kanti\ServerTiming\Utility\TimingUtility; | ||
|
||
final class ConfigService | ||
{ | ||
/** @var int */ | ||
private const DEFAULT_STOP_WATCH_LIMIT = 100_000; | ||
|
||
public function stopWatchLimit(): int | ||
{ | ||
return (int)($this->getConfig('stop_watch_limit') ?: self::DEFAULT_STOP_WATCH_LIMIT); | ||
} | ||
|
||
public function tracesSampleRate(): ?float | ||
{ | ||
$tracesSampleRate = $this->getConfig(TimingUtility::IS_CLI ? 'sentry_cli_sample_rate' : 'sentry_sample_rate'); | ||
return $tracesSampleRate === '' ? null : (float)$tracesSampleRate; | ||
} | ||
|
||
public function enableTracing(): ?bool | ||
{ | ||
$tracesSampleRate = $this->tracesSampleRate(); | ||
return $tracesSampleRate === null ? null : (bool)$tracesSampleRate; | ||
} | ||
|
||
private function getConfig(string $path): string | ||
{ | ||
return (string)($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['server_timing'][$path] ?? ''); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Classes/Service/RegisterShutdownFunction/RegisterShutdownFunction.php
This file contains 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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kanti\ServerTiming\Service\RegisterShutdownFunction; | ||
|
||
final class RegisterShutdownFunction implements RegisterShutdownFunctionInterface | ||
{ | ||
public function register(callable $callback): void | ||
{ | ||
register_shutdown_function($callback); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Classes/Service/RegisterShutdownFunction/RegisterShutdownFunctionInterface.php
This file contains 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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kanti\ServerTiming\Service\RegisterShutdownFunction; | ||
|
||
interface RegisterShutdownFunctionInterface | ||
{ | ||
public function register(callable $callback): void; | ||
} |
15 changes: 15 additions & 0 deletions
15
Classes/Service/RegisterShutdownFunction/RegisterShutdownFunctionNoop.php
This file contains 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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kanti\ServerTiming\Service\RegisterShutdownFunction; | ||
|
||
final class RegisterShutdownFunctionNoop implements RegisterShutdownFunctionInterface | ||
{ | ||
public int $callCount = 0; | ||
|
||
public function register(callable $callback): void | ||
{ | ||
$this->callCount++; | ||
} | ||
} |
Oops, something went wrong.