Skip to content

Commit

Permalink
Merge pull request #111: Add searching for XHProf local files
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jun 1, 2024
2 parents 3aedbe7 + fd1889c commit a90a651
Show file tree
Hide file tree
Showing 37 changed files with 1,225 additions and 89 deletions.
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 Down Expand Up @@ -68,6 +71,7 @@ public function __construct(
$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.
$this->configureFileObserver();

foreach ($map as $config) {
$this->prepareServerFiber($config, $inspector, $this->logger);
Expand Down Expand Up @@ -143,6 +147,11 @@ function (): void {
}
},
);
foreach ($this->processors as $processor) {
if ($processor instanceof Cancellable) {
$processor->cancel();
}
}
}

/**
Expand Down Expand Up @@ -220,4 +229,13 @@ private function createServer(SocketServer $config, Inspector $inspector): Serve
logger: $this->logger,
);
}

private function configureFileObserver(): void
{
$this->processors[] = $this->container->make(Service\FilesObserver::class, [
$this->container->get(XHProfFileConfig::class),
$this->container->get(XDebugFileConfig::class),
$this->container->get(SPXFileConfig::class),
]);
}
}
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
{
/** @psalm-suppress RedundantCondition */
return $this->path !== null && $this->converterClass !== null && $this->path !== ''
&& \is_a($this->converterClass, FrameConverter::class, true) && $this->scanInterval > 0.0;
}
}
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

0 comments on commit a90a651

Please sign in to comment.