*/ private static array $handlerTimings = []; public function __construct( private TimingsHandler $timings ){ parent::__construct(); } public function addNotifier(\Closure $handler) : SleeperHandlerEntry{ $name = Utils::getNiceClosureName($handler); $timings = self::$handlerTimings[$name] ??= new TimingsHandler("Snooze Handler: " . $name, $this->timings); return parent::addNotifier(function() use ($timings, $handler) : void{ $timings->startTiming(); $handler(); $timings->stopTiming(); }); } /** * Returns the time in nanoseconds spent processing notifications since the last reset. */ public function getNotificationProcessingTime() : int{ return $this->notificationProcessingTimeNs; } /** * Resets the notification processing time tracker to zero. */ public function resetNotificationProcessingTime() : void{ $this->notificationProcessingTimeNs = 0; } public function processNotifications() : void{ $startTime = hrtime(true); $this->timings->startTiming(); try{ parent::processNotifications(); }finally{ $this->notificationProcessingTimeNs += hrtime(true) - $startTime; $this->timings->stopTiming(); } } }