-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
145 additions
and
4 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
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Buggregator\Trap\Support\Caster; | ||
|
||
use Buggregator\Trap\Support\Tick; | ||
use Symfony\Component\VarDumper\Cloner\Stub; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class TickerCaster | ||
{ | ||
public static function cast(Tick $tick, array $a, Stub $stub, bool $isNested): mixed | ||
{ | ||
$stub->type = $stub::TYPE_REF; | ||
$stub->class = $tick->__toString(); | ||
$stub->attr = $tick->line; | ||
|
||
return []; | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Buggregator\Trap\Support; | ||
|
||
/** | ||
* Data object representing a tick. | ||
* | ||
* @see tr() | ||
* @internal | ||
*/ | ||
final class Tick | ||
{ | ||
/** | ||
* @param int<0, max> $number The tick number. | ||
* @param float $delta The time delta between the current and previous tick. | ||
* @param int $memory The memory usage. | ||
* @param array{ | ||
* function?: string, | ||
* line?: int, | ||
* file?: string, | ||
* class?: class-string, | ||
* type?: string, | ||
* args?: list<mixed> | ||
* } $line The stack trace line. | ||
*/ | ||
public function __construct( | ||
public readonly int $number, | ||
public readonly float $delta, | ||
public readonly int $memory, | ||
public readonly array $line, | ||
) { | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
// Format delta | ||
$delta = $this->delta; | ||
$deltaStr = match (true) { | ||
$delta === 0.0 => '-.---', | ||
$delta < 0.001 => \sprintf('+%.3fms', $delta * 1000), | ||
$delta < 0.01 => \sprintf('+%.2fms', $delta * 1000), | ||
$delta < 1 => \sprintf('+%.1fms', ($delta * 1000)), | ||
$delta < 10 => \sprintf('+%.2fs', $delta), | ||
$delta < 60 => \sprintf('+%.3fs', $delta), | ||
default => \sprintf('+%dm %ds', (int) $delta % 60, (int) $delta % 60), | ||
}; | ||
|
||
return \sprintf( | ||
"Tick #%d %s %sM", | ||
$this->number, | ||
$deltaStr, | ||
\number_format( | ||
$this->memory / 1024 / 1024, | ||
2, | ||
'.', | ||
'_', | ||
), | ||
); | ||
} | ||
} |
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