Skip to content
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

Add searching for XHProf local files #111

Merged
merged 26 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
591fcbd
Add FilesObserver
roxblnfk Feb 3, 2024
9b093a6
Add Profiler frames
roxblnfk Feb 3, 2024
371adfb
Simplify Plain console renderer
roxblnfk Feb 3, 2024
486b25c
Add parsing and sending of XHProf files into the UI
roxblnfk Feb 18, 2024
cf367ce
Better profile spans sorting; temporary fixes
roxblnfk Feb 27, 2024
a0694c8
Merge branch 'master' into files-observer
roxblnfk Mar 30, 2024
aaed096
Correct buffer size in the HTTP Emitter
roxblnfk Apr 10, 2024
45a5b8a
Merge branch 'refs/heads/master' into files-observer
roxblnfk Apr 14, 2024
2321f16
Refactor Profiler frame
roxblnfk Apr 14, 2024
df472bc
Cleanup
roxblnfk Apr 16, 2024
ab2cc53
Merge branch 'refs/heads/master' into files-observer
roxblnfk Apr 16, 2024
a276d29
Handle FS error when profiler files are read
roxblnfk Apr 16, 2024
a40cab7
Merge branch 'refs/heads/master' into files-observer
roxblnfk May 24, 2024
c9c6aeb
style(php-cs-fixer): lint php files and fix coding standards
May 31, 2024
e7e4307
Merge branch 'refs/heads/master' into files-observer
roxblnfk May 31, 2024
c15e5fe
feat: added configs for profilers with mapping to php.ini; added PhpI…
roxblnfk May 31, 2024
f834bce
style(php-cs-fixer): lint php files and fix coding standards
May 31, 2024
144cf7e
chore: polishing
roxblnfk May 31, 2024
75bfef3
style(php-cs-fixer): lint php files and fix coding standards
May 31, 2024
de2277c
feat: sort profiler edges using Tree abstraction; add envs TRAP_XHPRO…
roxblnfk Jun 1, 2024
aea9261
style(php-cs-fixer): lint php files and fix coding standards
Jun 1, 2024
5939b7d
chore: add short comment for the TRAP_XHPROF_SORT env; update compose…
roxblnfk Jun 1, 2024
3e7ce4c
chore(psalm): fix psalm issues
roxblnfk Jun 1, 2024
41c4a76
chore(psalm): fix psalm issues
roxblnfk Jun 1, 2024
0403cb3
chore(psalm): fix psalm issues
roxblnfk Jun 1, 2024
fd1889c
chore(psalm): fix psalm issues
roxblnfk Jun 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,4 @@
<code><![CDATA[getDescriptorByClassName]]></code>
</MixedMethodCall>
</file>
<file src="src/functions.php">
<MixedArrayAccess>
<code><![CDATA[AbstractCloner::$defaultCasters[EnumValue::class]]]></code>
<code><![CDATA[AbstractCloner::$defaultCasters[MapField::class]]]></code>
<code><![CDATA[AbstractCloner::$defaultCasters[Message::class]]]></code>
<code><![CDATA[AbstractCloner::$defaultCasters[RepeatedField::class]]]></code>
</MixedArrayAccess>
<MixedArrayAssignment>
<code><![CDATA[AbstractCloner::$defaultCasters[EnumValue::class]]]></code>
<code><![CDATA[AbstractCloner::$defaultCasters[MapField::class]]]></code>
<code><![CDATA[AbstractCloner::$defaultCasters[Message::class]]]></code>
<code><![CDATA[AbstractCloner::$defaultCasters[RepeatedField::class]]]></code>
</MixedArrayAssignment>
</file>
</files>
16 changes: 0 additions & 16 deletions resources/templates/plain.php

This file was deleted.

18 changes: 18 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Buggregator\Trap;

use Buggregator\Trap\Config\Server\Files\SPX as SPXFileConfig;
use Buggregator\Trap\Config\Server\Files\XDebug as XDebugFileConfig;
use Buggregator\Trap\Config\Server\Files\XHProf as XHProfFileConfig;
use Buggregator\Trap\Config\Server\Frontend as FrontendConfig;
use Buggregator\Trap\Config\Server\SocketServer;
use Buggregator\Trap\Handler\Http\Handler\Websocket;
Expand All @@ -28,7 +31,7 @@
private array $servers = [];

/** @var \Fiber[] Any tasks in fibers */
private array $fibers = [];

Check failure on line 34 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Property Buggregator\Trap\Application::$fibers with generic class Fiber does not specify its types: TStart, TResume, TReturn, TSuspend

Check failure on line 34 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Property Buggregator\Trap\Application::$fibers with generic class Fiber does not specify its types: TStart, TResume, TReturn, TSuspend

private readonly Buffer $buffer;

Expand Down Expand Up @@ -67,7 +70,8 @@
]);
$this->processors[] = $inspector;

$withFrontend and $this->configureFrontend(8000);

Check failure on line 73 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Only booleans are allowed in &&, null given on the right side.

Check failure on line 73 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Only booleans are allowed in &&, null given on the right side.
$this->configureFileObserver();

Check warning on line 74 in src/Application.php

View check run for this annotation

Codecov / codecov/patch

src/Application.php#L74

Added line #L74 was not covered by tests

foreach ($map as $config) {
$this->prepareServerFiber($config, $inspector, $this->logger);
Expand All @@ -80,13 +84,13 @@
public function run(int $sleep = 50): void
{
foreach ($this->senders as $sender) {
\assert($sender instanceof Sender);

Check failure on line 87 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Call to function assert() with true will always evaluate to true.

Check failure on line 87 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Instanceof between Buggregator\Trap\Sender and Buggregator\Trap\Sender will always evaluate to true.

Check failure on line 87 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Call to function assert() with true will always evaluate to true.

Check failure on line 87 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Instanceof between Buggregator\Trap\Sender and Buggregator\Trap\Sender will always evaluate to true.
if ($sender instanceof Processable) {
$this->processors[] = $sender;
}
}

while (true) {

Check failure on line 93 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

While loop condition is always true.

Check failure on line 93 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

While loop condition is always true.
$this->process($this->senders);
\usleep($sleep);
}
Expand Down Expand Up @@ -143,6 +147,11 @@
}
},
);
foreach ($this->processors as $processor) {
if ($processor instanceof Cancellable) {
$processor->cancel();

Check warning on line 152 in src/Application.php

View check run for this annotation

Codecov / codecov/patch

src/Application.php#L150-L152

Added lines #L150 - L152 were not covered by tests
}
}
}

/**
Expand All @@ -150,7 +159,7 @@
* @param Inspector $inspector
* @return \Fiber
*/
public function prepareServerFiber(SocketServer $config, Inspector $inspector, Logger $logger): \Fiber

Check failure on line 162 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Method Buggregator\Trap\Application::prepareServerFiber() return type with generic class Fiber does not specify its types: TStart, TResume, TReturn, TSuspend

Check failure on line 162 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Method Buggregator\Trap\Application::prepareServerFiber() return type with generic class Fiber does not specify its types: TStart, TResume, TReturn, TSuspend
{
return $this->fibers[] = new \Fiber(function () use ($config, $inspector, $logger): void {
do {
Expand Down Expand Up @@ -216,8 +225,17 @@
return Server::init(
$config->port,
payloadSize: 524_288,
clientInflector: $clientInflector,

Check failure on line 228 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Parameter $clientInflector of static method Buggregator\Trap\Socket\Server::init() expects (Closure(Buggregator\Trap\Socket\Client, int): void)|null, Closure(Buggregator\Trap\Socket\Client, int): Buggregator\Trap\Socket\Client given.

Check failure on line 228 in src/Application.php

View workflow job for this annotation

GitHub Actions / static-analysis (ubuntu-latest, 8.2, locked)

Parameter $clientInflector of static method Buggregator\Trap\Socket\Server::init() expects (Closure(Buggregator\Trap\Socket\Client, int): void)|null, Closure(Buggregator\Trap\Socket\Client, int): Buggregator\Trap\Socket\Client given.
logger: $this->logger,
);
}

private function configureFileObserver(): void

Check warning on line 233 in src/Application.php

View check run for this annotation

Codecov / codecov/patch

src/Application.php#L233

Added line #L233 was not covered by tests
{
$this->processors[] = $this->container->make(Service\FilesObserver::class, [
$this->container->get(XHProfFileConfig::class),
$this->container->get(XDebugFileConfig::class),
$this->container->get(SPXFileConfig::class),
]);

Check warning on line 239 in src/Application.php

View check run for this annotation

Codecov / codecov/patch

src/Application.php#L235-L239

Added lines #L235 - L239 were not covered by tests
}
}
1 change: 1 addition & 0 deletions src/Client/TrapHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static function fromArray(array $array): self
*
* @param int<0, max> $number The tick number.
* @param float $delta The time delta between the current and previous tick.
* @param int<0, max> $memory The memory usage.
*
* @internal
*/
Expand Down
18 changes: 13 additions & 5 deletions src/Client/TrapHandle/StackTrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,19 @@ public static function stackTrace(string $baseDir = '', bool $provideObjects = f
$cwdLen = \strlen($dir);
$stack = [];
$internal = false;
foreach (
\debug_backtrace(
($provideObjects ? \DEBUG_BACKTRACE_PROVIDE_OBJECT : 0) | \DEBUG_BACKTRACE_IGNORE_ARGS,
) as $frame
) {

/** @var array{
* function: non-empty-string,
* line?: int,
* file?: string,
* class?: class-string,
* type?: string,
* object?: object,
* args?: list<mixed>
* } $frame */
foreach (\debug_backtrace(
($provideObjects ? \DEBUG_BACKTRACE_PROVIDE_OBJECT : 0) | \DEBUG_BACKTRACE_IGNORE_ARGS,
) as $frame) {
$class = $frame['class'] ?? '';
if (\str_starts_with($class, 'Buggregator\\Trap\\Client\\')) {
$internal = true;
Expand Down
2 changes: 2 additions & 0 deletions src/Command/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public function createRegistry(OutputInterface $output): Sender\SenderRegistry
public function getSubscribedSignals(): array
{
$result = [];
/** @psalm-suppress MixedAssignment */
\defined('SIGINT') and $result[] = \SIGINT;
/** @psalm-suppress MixedAssignment */
\defined('SIGTERM') and $result[] = \SIGTERM;

return $result;
Expand Down
33 changes: 33 additions & 0 deletions src/Config/Server/Files/ObserverConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Buggregator\Trap\Config\Server\Files;

use Buggregator\Trap\Service\FilesObserver\FrameConverter;

/**
* @internal
*/
abstract class ObserverConfig
{
/** @var non-empty-string|null */
public ?string $path = null;

/** @var class-string<FrameConverter>|null */
public ?string $converterClass = null;

/** @var float Scan interval in seconds */
public float $scanInterval = 5.0;

/**
* @psalm-assert-if-true non-empty-string $this->path
* @psalm-assert-if-true class-string<FrameConverter> $this->converterClass
*/
public function isValid(): bool

Check warning on line 27 in src/Config/Server/Files/ObserverConfig.php

View check run for this annotation

Codecov / codecov/patch

src/Config/Server/Files/ObserverConfig.php#L27

Added line #L27 was not covered by tests
{
/** @psalm-suppress RedundantCondition */
return $this->path !== null && $this->converterClass !== null && $this->path !== ''
&& \is_a($this->converterClass, FrameConverter::class, true) && $this->scanInterval > 0.0;

Check warning on line 31 in src/Config/Server/Files/ObserverConfig.php

View check run for this annotation

Codecov / codecov/patch

src/Config/Server/Files/ObserverConfig.php#L30-L31

Added lines #L30 - L31 were not covered by tests
}
}
17 changes: 17 additions & 0 deletions src/Config/Server/Files/SPX.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Buggregator\Trap\Config\Server\Files;

use Buggregator\Trap\Service\Config\PhpIni;

/**
* @internal
*/
final class SPX extends ObserverConfig
{
/** @var non-empty-string|null Path to SPX files */
#[PhpIni('spx.data_dir')]
public ?string $path = null;
}
17 changes: 17 additions & 0 deletions src/Config/Server/Files/XDebug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Buggregator\Trap\Config\Server\Files;

use Buggregator\Trap\Service\Config\PhpIni;

/**
* @internal
*/
final class XDebug extends ObserverConfig
{
/** @var non-empty-string|null Path to XDebug files */
#[PhpIni('xdebug.output_dir')]
public ?string $path = null;
}
35 changes: 35 additions & 0 deletions src/Config/Server/Files/XHProf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Buggregator\Trap\Config\Server\Files;

use Buggregator\Trap\Service\Config\Env;
use Buggregator\Trap\Service\Config\PhpIni;
use Buggregator\Trap\Service\FilesObserver\Converter\XHProf as Converter;
use Buggregator\Trap\Service\FilesObserver\FrameConverter;

/**
* @internal
*/
final class XHProf extends ObserverConfig
{
/**
* @var int<0, 3> Edges sorting algorithm
* Where:
* 0 - Deep-first
* 1 - Deep-first with sorting by WT
* 2 - Level-by-level
* 3 - Level-by-level with sorting by WT
*/
#[Env('TRAP_XHPROF_SORT')]
public int $algorithm = 3;

/** @var non-empty-string|null Path to XHProf files */
#[Env('TRAP_XHPROF_PATH')]
#[PhpIni('xhprof.output_dir')]
public ?string $path = null;

/** @var class-string<FrameConverter>|null */
public ?string $converterClass = Converter::class;
}
2 changes: 1 addition & 1 deletion src/Processable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Buggregator\Trap;

/**
* Must be processed in a main loop.
* Must be processed in a main loop outside a Fiber
*
* @internal
*/
Expand Down
Loading
Loading