-
Notifications
You must be signed in to change notification settings - Fork 5
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
1 parent
271d035
commit 370a1c3
Showing
4 changed files
with
84 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Patchlevel\EventSourcing\Debug; | ||
|
||
use Symfony\Component\Stopwatch\Stopwatch; | ||
|
||
final class DefaultProfiler implements Profiler | ||
{ | ||
public function __construct( | ||
private readonly ProfileDataHolder $dataHolder, | ||
private readonly Stopwatch|null $stopwatch = null, | ||
) { | ||
} | ||
|
||
/** | ||
* @param \Closure():T $closure | ||
* | ||
* @return T | ||
* | ||
* @template T of mixed | ||
*/ | ||
public function profile(string $name, \Closure $closure, $context = []): mixed | ||
Check failure on line 22 in src/Debug/DefaultProfiler.php GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)MissingParamType
|
||
{ | ||
$data = new ProfileData($name, $context); | ||
Check failure on line 24 in src/Debug/DefaultProfiler.php GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)MixedArgument
|
||
|
||
$this->dataHolder->addData($data); | ||
$event = $this->stopwatch?->start('event_sourcing', $name); | ||
$data->start(); | ||
|
||
try { | ||
return $closure(); | ||
} finally { | ||
$data->stop(); | ||
$event?->stop(); | ||
} | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace Patchlevel\EventSourcing\Debug; | ||
|
||
interface Profiler | ||
{ | ||
/** | ||
* @param \Closure():T $closure | ||
* | ||
* @return T | ||
* | ||
* @template T of mixed | ||
*/ | ||
public function profile(string $name, \Closure $closure, $context = []): mixed; | ||
Check failure on line 14 in src/Debug/Profiler.php GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)MissingParamType
|
||
} |
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