PocketMine-MP
5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
TimeTrackingSleeperHandler.php
1
<?php
2
3
/*
4
*
5
* ____ _ _ __ __ _ __ __ ____
6
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10
*
11
* This program is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU Lesser General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
15
*
16
* @author PocketMine Team
17
* @link http://www.pocketmine.net/
18
*
19
*
20
*/
21
22
declare(strict_types=1);
23
24
namespace
pocketmine
;
25
26
use
pocketmine\snooze\SleeperHandler
;
27
use
pocketmine\snooze\SleeperHandlerEntry
;
28
use
pocketmine\timings\TimingsHandler
;
29
use
pocketmine\utils\Utils
;
30
use
function
hrtime;
31
36
final
class
TimeTrackingSleeperHandler
extends
SleeperHandler
{
37
38
private
int
$notificationProcessingTimeNs = 0;
39
44
private
static
array $handlerTimings = [];
45
46
public
function
__construct(
47
private
TimingsHandler
$timings
48
){
49
parent::__construct();
50
}
51
52
public
function
addNotifier
(\Closure $handler) :
SleeperHandlerEntry
{
53
$name =
Utils
::getNiceClosureName($handler);
54
$timings = self::$handlerTimings[$name] ??=
new
TimingsHandler
(
"Snooze Handler: "
. $name, $this->timings);
55
56
return
parent::addNotifier(
function
() use ($timings, $handler) :
void
{
57
$timings->startTiming();
58
$handler();
59
$timings->stopTiming();
60
});
61
}
62
66
public
function
getNotificationProcessingTime
() : int{ return $this->notificationProcessingTimeNs; }
67
71
public
function
resetNotificationProcessingTime
() : void{ $this->notificationProcessingTimeNs = 0; }
72
73
public
function
processNotifications
() : void{
74
$startTime = hrtime(true);
75
$this->timings->startTiming();
76
try
{
77
parent::processNotifications();
78
}
finally
{
79
$this->notificationProcessingTimeNs += hrtime(
true
) - $startTime;
80
$this->timings->stopTiming();
81
}
82
}
83
}
pocketmine\TimeTrackingSleeperHandler
Definition
TimeTrackingSleeperHandler.php:36
pocketmine\TimeTrackingSleeperHandler\addNotifier
addNotifier(\Closure $handler)
Definition
TimeTrackingSleeperHandler.php:52
pocketmine\TimeTrackingSleeperHandler\resetNotificationProcessingTime
resetNotificationProcessingTime()
Definition
TimeTrackingSleeperHandler.php:71
pocketmine\TimeTrackingSleeperHandler\getNotificationProcessingTime
getNotificationProcessingTime()
Definition
TimeTrackingSleeperHandler.php:66
pocketmine\TimeTrackingSleeperHandler\processNotifications
processNotifications()
Definition
TimeTrackingSleeperHandler.php:73
pocketmine\snooze\SleeperHandlerEntry
Definition
SleeperHandlerEntry.php:33
pocketmine\snooze\SleeperHandler
Definition
SleeperHandler.php:25
pocketmine\timings\TimingsHandler
Definition
TimingsHandler.php:32
pocketmine\utils\Utils
Definition
Utils.php:103
pocketmine
src
TimeTrackingSleeperHandler.php
Generated by
1.12.0