Skip to content

Commit

Permalink
Add Record to represent profiler recordings
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Nov 17, 2024
1 parent 05dd8ea commit 1cb3b3a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/ConfigProfiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace ICanBoogie;

use ICanBoogie\Config\Builder;
use ICanBoogie\ConfigProfiler\Record;

/**
* Collects timing information about configuration builders.
*/
final class ConfigProfiler
{
/**
* @var array{ 0: float, 1: float, 2: string, 3: string }
* @var Record[]
*/
public static array $entries;
public static array $records;

/**
* @template T of object
Expand All @@ -23,6 +24,6 @@ final class ConfigProfiler
*/
public static function add(float $started_at, string $config_class, string $builder_class): void
{
self::$entries[] = [ $started_at, microtime(true), $config_class, $builder_class ];
self::$records[] = new Record($started_at, microtime(true) - $started_at, $config_class, $builder_class);
}
}
24 changes: 24 additions & 0 deletions lib/ConfigProfiler/Record.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace ICanBoogie\ConfigProfiler;

use ICanBoogie\Config\Builder;

readonly class Record
{
/**
* @template T of object
*
* @param float $timestamp When the configuration started to build.
* @param float $duration The duration of the build.
* @param class-string<T> $config_class
* @param class-string<Builder<T>> $builder_class
*/
public function __construct(
public float $timestamp,
public float $duration,
public string $config_class,
public string $builder_class,
) {
}
}
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# $schema: https://phpstan.olvlvl.com/schema.json
parameters:
level: max
paths:
Expand Down

0 comments on commit 1cb3b3a

Please sign in to comment.