-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Profiler.php
35 lines (29 loc) · 1.05 KB
/
Profiler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace PetrKnap\Profiler;
/* final */class Profiler implements ProfilerInterface
{
public function __construct(
private readonly bool $takeSnapshotOnTick = Profile::DO_NOT_TAKE_SNAPSHOT_ON_TICK,
/**
* @deprecated backward compatibility with old named argument calls
*
* @todo remove it
*/
private readonly bool $listenToTicks = Profile::DO_NOT_TAKE_SNAPSHOT_ON_TICK,
) {
}
public function profile(callable $callable): ProcessableProfileInterface & ProfileWithOutputInterface
{
$profiling = Profiling::start($this->takeSnapshotOnTick, $this->listenToTicks);
$output = $callable(Profiling::createNestedProfiler($profiling));
/** @var Profile<mixed> $profile */
$profile = $profiling->finish();
$profile->setOutput($output);
return $profile; // @phpstan-ignore return.type
}
public function takeSnapshot(): void
{
throw new Exception\ProfilerCouldNotTakeSnapshotOutsideParentProfile();
}
}