39 public const GROUP_MINECRAFT =
"Minecraft";
41 private static bool $initialized =
false;
52 public static TimingsHandler $playerNetworkSendCompressSessionBuffer;
86 public static array $entityTypeTimingMap = [];
88 public static array $tileEntityTypeTimingMap = [];
90 public static array $packetReceiveTimingMap = [];
93 private static array $packetDecodeTimingMap = [];
95 private static array $packetHandleTimingMap = [];
98 private static array $packetEncodeTimingMap = [];
101 public static array $packetSendTimingMap = [];
103 public static array $pluginTaskTimingMap = [];
109 private static array $commandTimingMap = [];
116 private static array $events = [];
118 private static array $eventHandlers = [];
122 private static array $asyncTaskCompletion = [];
126 private static array $asyncTaskRun = [];
128 public static function init() :
void{
129 if(self::$initialized){
132 self::$initialized =
true;
135 self::$serverTick =
new TimingsHandler(
"Server Tick Update Cycle", self::$fullTick);
136 self::$serverInterrupts =
new TimingsHandler(
"Server Mid-Tick Processing", self::$fullTick);
138 self::$garbageCollector =
new TimingsHandler(
"Garbage Collector", self::$memoryManager);
143 self::$playerNetworkSend =
new TimingsHandler(
"Player Network Send", self::$connection);
144 self::$playerNetworkSendCompress =
new TimingsHandler(
"Player Network Send - Compression", self::$playerNetworkSend);
145 self::$playerNetworkSendCompressBroadcast =
new TimingsHandler(
"Player Network Send - Compression (Broadcast)", self::$playerNetworkSendCompress);
146 self::$playerNetworkSendCompressSessionBuffer =
new TimingsHandler(
"Player Network Send - Compression (Session Buffer)", self::$playerNetworkSendCompress);
147 self::$playerNetworkSendEncrypt =
new TimingsHandler(
"Player Network Send - Encryption", self::$playerNetworkSend);
148 self::$playerNetworkSendInventorySync =
new TimingsHandler(
"Player Network Send - Inventory Sync", self::$playerNetworkSend);
149 self::$playerNetworkSendPreSpawnGameData =
new TimingsHandler(
"Player Network Send - Pre-Spawn Game Data", self::$playerNetworkSend);
151 self::$playerNetworkReceive =
new TimingsHandler(
"Player Network Receive", self::$connection);
152 self::$playerNetworkReceiveDecompress =
new TimingsHandler(
"Player Network Receive - Decompression", self::$playerNetworkReceive);
153 self::$playerNetworkReceiveDecrypt =
new TimingsHandler(
"Player Network Receive - Decryption", self::$playerNetworkReceive);
155 self::$broadcastPackets =
new TimingsHandler(
"Broadcast Packets", self::$playerNetworkSend);
158 self::$playerChunkOrder =
new TimingsHandler(
"Player Order Chunks");
159 self::$playerChunkSend =
new TimingsHandler(
"Player Network Send - Chunks", self::$playerNetworkSend);
162 self::$permissibleCalculation =
new TimingsHandler(
"Permissible Calculation");
163 self::$permissibleCalculationDiff =
new TimingsHandler(
"Permissible Calculation - Diff", self::$permissibleCalculation);
164 self::$permissibleCalculationCallback =
new TimingsHandler(
"Permissible Calculation - Callbacks", self::$permissibleCalculation);
166 self::$syncPlayerDataLoad =
new TimingsHandler(
"Player Data Load");
167 self::$syncPlayerDataSave =
new TimingsHandler(
"Player Data Save");
170 self::$entityMoveCollision =
new TimingsHandler(
"Entity Movement - Collision Checks", self::$entityMove);
172 self::$projectileMove =
new TimingsHandler(
"Projectile Movement", self::$entityMove);
173 self::$projectileMoveRayTrace =
new TimingsHandler(
"Projectile Movement - Ray Tracing", self::$projectileMove);
175 self::$playerCheckNearEntities =
new TimingsHandler(
"checkNearEntities");
177 self::$livingEntityBaseTick =
new TimingsHandler(
"Entity Base Tick - Living");
178 self::$itemEntityBaseTick =
new TimingsHandler(
"Entity Base Tick - ItemEntity");
180 self::$schedulerSync =
new TimingsHandler(
"Scheduler - Sync Tasks");
182 self::$schedulerAsync =
new TimingsHandler(
"Scheduler - Async Tasks");
183 self::$asyncTaskCompletionParent =
new TimingsHandler(
"Async Tasks - Completion Handlers", self::$schedulerAsync);
185 self::$asyncTaskWorkers =
new TimingsHandler(
"Async Task Workers");
188 self::$craftingDataCacheRebuild =
new TimingsHandler(
"Build CraftingDataPacket Cache");
198 $name =
"Task: " . $task->getTaskName();
201 $name .=
"(interval:" . $period .
")";
206 if(!isset(self::$pluginTaskTimingMap[$name])){
207 self::$pluginTaskTimingMap[$name] =
new TimingsHandler($name, self::$schedulerSync, $task->getOwnerName());
210 return self::$pluginTaskTimingMap[$name];
216 private static function shortenCoreClassName(
string $class,
string $prefix) : string{
217 if(str_starts_with($class, $prefix)){
218 return (
new \ReflectionClass($class))->getShortName();
223 public static function getEntityTimings(Entity $entity) : TimingsHandler{
225 if(!isset(self::$entityTypeTimingMap[$entity::class])){
226 if($entity instanceof Player){
229 $displayName = $entity::class !== Player::class ?
"Player (" . $entity::class .
")" :
"Player";
231 $displayName = self::shortenCoreClassName($entity::class,
"pocketmine\\entity\\");
233 self::$entityTypeTimingMap[$entity::class] =
new TimingsHandler(
"Entity Tick - " . $displayName);
236 return self::$entityTypeTimingMap[$entity::class];
239 public static function getTileEntityTimings(Tile $tile) : TimingsHandler{
241 if(!isset(self::$tileEntityTypeTimingMap[$tile::class])){
242 self::$tileEntityTypeTimingMap[$tile::class] =
new TimingsHandler(
243 "Block Entity Tick - " . self::shortenCoreClassName($tile::class,
"pocketmine\\block\\tile\\")
247 return self::$tileEntityTypeTimingMap[$tile::class];
250 public static function getReceiveDataPacketTimings(ServerboundPacket $pk) : TimingsHandler{
252 if(!isset(self::$packetReceiveTimingMap[$pk::class])){
253 self::$packetReceiveTimingMap[$pk::class] =
new TimingsHandler(
"Receive - " . $pk->getName(), self::$playerNetworkReceive);
256 return self::$packetReceiveTimingMap[$pk::class];
259 public static function getDecodeDataPacketTimings(ServerboundPacket $pk) : TimingsHandler{
260 return self::$packetDecodeTimingMap[$pk::class] ??= new TimingsHandler(
261 "Decode - " . $pk->getName(),
262 self::getReceiveDataPacketTimings($pk)
266 public static function getHandleDataPacketTimings(ServerboundPacket $pk) : TimingsHandler{
267 return self::$packetHandleTimingMap[$pk::class] ??= new TimingsHandler(
268 "Handler - " . $pk->getName(),
269 self::getReceiveDataPacketTimings($pk)
273 public static function getEncodeDataPacketTimings(ClientboundPacket $pk) : TimingsHandler{
274 return self::$packetEncodeTimingMap[$pk::class] ??= new TimingsHandler(
275 "Encode - " . $pk->getName(),
276 self::getSendDataPacketTimings($pk)
280 public static function getSendDataPacketTimings(ClientboundPacket $pk) : TimingsHandler{
282 if(!isset(self::$packetSendTimingMap[$pk::class])){
283 self::$packetSendTimingMap[$pk::class] =
new TimingsHandler(
"Send - " . $pk->getName(), self::$playerNetworkSend);
286 return self::$packetSendTimingMap[$pk::class];
289 public static function getCommandDispatchTimings(
string $commandName) : TimingsHandler{
292 return self::$commandTimingMap[$commandName] ??=
new TimingsHandler(
"Command - " . $commandName);
295 public static function getEventTimings(Event $event) : TimingsHandler{
296 $eventClass = get_class($event);
297 if(!isset(self::$events[$eventClass])){
298 self::$events[$eventClass] =
new TimingsHandler(self::shortenCoreClassName($eventClass,
"pocketmine\\event\\"), group:
"Events");
301 return self::$events[$eventClass];
308 if(!isset(self::$eventHandlers[$event][$handlerName])){
309 self::$eventHandlers[$event][$handlerName] =
new TimingsHandler($handlerName .
"(" . self::shortenCoreClassName($event,
"pocketmine\\event\\") .
")", group: $group);
312 return self::$eventHandlers[$event][$handlerName];
315 public static function getAsyncTaskCompletionTimings(AsyncTask $task,
string $group = self::GROUP_MINECRAFT) :
TimingsHandler{
316 $taskClass = $task::class;
317 if(!isset(self::$asyncTaskCompletion[$taskClass])){
320 "AsyncTask - " . self::shortenCoreClassName($taskClass,
"pocketmine\\") .
" - Completion Handler",
321 self::$asyncTaskCompletionParent,
326 return self::$asyncTaskCompletion[$taskClass];
329 public static function getAsyncTaskRunTimings(AsyncTask $task,
string $group = self::GROUP_MINECRAFT) : TimingsHandler{
330 $taskClass = $task::class;
331 if(!isset(self::$asyncTaskRun[$taskClass])){
333 self::$asyncTaskRun[$taskClass] =
new TimingsHandler(
334 "AsyncTask - " . self::shortenCoreClassName($taskClass,
"pocketmine\\") .
" - Run",
335 self::$asyncTaskWorkers,
340 return self::$asyncTaskRun[$taskClass];