| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Profiler; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class ProfilingContext { |
| 13 |
private string $entryPoint = 'unknown'; |
| 14 |
private string $handler = 'unknown'; |
| 15 |
|
| 16 |
private bool $initialized = false; |
| 17 |
|
| 18 |
private static ?ProfilingContext $instance = null; |
| 19 |
|
| 20 |
public static function singleton(): ProfilingContext { |
| 21 |
self::$instance ??= new self(); |
| 22 |
|
| 23 |
return self::$instance; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function init( string $entryPoint, string $handler ) { |
| 33 |
|
| 34 |
if ( !$this->initialized ) { |
| 35 |
$this->initialized = true; |
| 36 |
$this->entryPoint = $entryPoint; |
| 37 |
$this->handler = $handler; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public function isInitialized() { |
| 45 |
return $this->initialized; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function getEntryPoint(): string { |
| 52 |
return $this->entryPoint; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function getHandler(): string { |
| 59 |
return $this->handler; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public function getHandlerMetricPrefix(): string { |
| 66 |
|
| 67 |
return $this->entryPoint . '_' . strtr( |
| 68 |
$this->handler, |
| 69 |
[ '{' => '', '}' => '', ':' => '_', '/' => '_', '.' => '_' ] |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public static function destroySingleton() { |
| 77 |
self::$instance = null; |
| 78 |
} |
| 79 |
} |