38 public const GROUP_MINECRAFT =
"Minecraft";
39 public const GROUP_BREAKDOWN =
"Minecraft - Breakdown";
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 = [];
125 private static array $asyncTaskProgressUpdate = [];
127 private static array $asyncTaskCompletion = [];
129 private static array $asyncTaskError = [];
131 public static function init() :
void{
132 if(self::$initialized){
135 self::$initialized =
true;
138 self::$serverTick =
new TimingsHandler(
"Server Tick Update Cycle", self::$fullTick);
139 self::$serverInterrupts =
new TimingsHandler(
"Server Mid-Tick Processing", self::$fullTick);
141 self::$garbageCollector =
new TimingsHandler(
"Garbage Collector", self::$memoryManager);
146 self::$playerNetworkSend =
new TimingsHandler(
"Player Network Send", self::$connection);
147 self::$playerNetworkSendCompress =
new TimingsHandler(
"Player Network Send - Compression", self::$playerNetworkSend);
148 self::$playerNetworkSendCompressBroadcast =
new TimingsHandler(
"Player Network Send - Compression (Broadcast)", self::$playerNetworkSendCompress);
149 self::$playerNetworkSendCompressSessionBuffer =
new TimingsHandler(
"Player Network Send - Compression (Session Buffer)", self::$playerNetworkSendCompress);
150 self::$playerNetworkSendEncrypt =
new TimingsHandler(
"Player Network Send - Encryption", self::$playerNetworkSend);
151 self::$playerNetworkSendInventorySync =
new TimingsHandler(
"Player Network Send - Inventory Sync", self::$playerNetworkSend);
152 self::$playerNetworkSendPreSpawnGameData =
new TimingsHandler(
"Player Network Send - Pre-Spawn Game Data", self::$playerNetworkSend);
154 self::$playerNetworkReceive =
new TimingsHandler(
"Player Network Receive", self::$connection);
155 self::$playerNetworkReceiveDecompress =
new TimingsHandler(
"Player Network Receive - Decompression", self::$playerNetworkReceive);
156 self::$playerNetworkReceiveDecrypt =
new TimingsHandler(
"Player Network Receive - Decryption", self::$playerNetworkReceive);
158 self::$broadcastPackets =
new TimingsHandler(
"Broadcast Packets", self::$playerNetworkSend);
161 self::$playerChunkOrder =
new TimingsHandler(
"Player Order Chunks");
162 self::$playerChunkSend =
new TimingsHandler(
"Player Network Send - Chunks", self::$playerNetworkSend);
165 self::$permissibleCalculation =
new TimingsHandler(
"Permissible Calculation");
166 self::$permissibleCalculationDiff =
new TimingsHandler(
"Permissible Calculation - Diff", self::$permissibleCalculation);
167 self::$permissibleCalculationCallback =
new TimingsHandler(
"Permissible Calculation - Callbacks", self::$permissibleCalculation);
169 self::$syncPlayerDataLoad =
new TimingsHandler(
"Player Data Load");
170 self::$syncPlayerDataSave =
new TimingsHandler(
"Player Data Save");
173 self::$entityMoveCollision =
new TimingsHandler(
"Entity Movement - Collision Checks", self::$entityMove);
175 self::$projectileMove =
new TimingsHandler(
"Projectile Movement", self::$entityMove);
176 self::$projectileMoveRayTrace =
new TimingsHandler(
"Projectile Movement - Ray Tracing", self::$projectileMove);
178 self::$playerCheckNearEntities =
new TimingsHandler(
"checkNearEntities");
180 self::$livingEntityBaseTick =
new TimingsHandler(
"Entity Base Tick - Living");
181 self::$itemEntityBaseTick =
new TimingsHandler(
"Entity Base Tick - ItemEntity");
183 self::$schedulerSync =
new TimingsHandler(
"Scheduler - Sync Tasks");
185 self::$schedulerAsync =
new TimingsHandler(
"Scheduler - Async Tasks");
186 self::$asyncTaskProgressUpdateParent =
new TimingsHandler(
"Async Tasks - Progress Updates", self::$schedulerAsync);
187 self::$asyncTaskCompletionParent =
new TimingsHandler(
"Async Tasks - Completion Handlers", self::$schedulerAsync);
188 self::$asyncTaskErrorParent =
new TimingsHandler(
"Async Tasks - Error Handlers", self::$schedulerAsync);
191 self::$craftingDataCacheRebuild =
new TimingsHandler(
"Build CraftingDataPacket Cache");
197 $name =
"Task: " . $task->getTaskName();
200 $name .=
"(interval:" . $period .
")";
205 if(!isset(self::$pluginTaskTimingMap[$name])){
206 self::$pluginTaskTimingMap[$name] =
new TimingsHandler($name, self::$schedulerSync, $task->getOwnerName());
209 return self::$pluginTaskTimingMap[$name];
215 private static function shortenCoreClassName(
string $class,
string $prefix) :
string{
216 if(str_starts_with($class, $prefix)){
217 return (
new \ReflectionClass($class))->getShortName();
224 if(!isset(self::$entityTypeTimingMap[$entity::class])){
225 if($entity instanceof
Player){
228 $displayName = $entity::class !== Player::class ?
"Player (" . $entity::class .
")" :
"Player";
230 $displayName = self::shortenCoreClassName($entity::class,
"pocketmine\\entity\\");
232 self::$entityTypeTimingMap[$entity::class] =
new TimingsHandler(
"Entity Tick - " . $displayName);
235 return self::$entityTypeTimingMap[$entity::class];
240 if(!isset(self::$tileEntityTypeTimingMap[$tile::class])){
241 self::$tileEntityTypeTimingMap[$tile::class] =
new TimingsHandler(
242 "Block Entity Tick - " . self::shortenCoreClassName($tile::class,
"pocketmine\\block\\tile\\")
246 return self::$tileEntityTypeTimingMap[$tile::class];
251 if(!isset(self::$packetReceiveTimingMap[$pk::class])){
252 self::$packetReceiveTimingMap[$pk::class] =
new TimingsHandler(
"Receive - " . $pk->getName(), self::$playerNetworkReceive);
255 return self::$packetReceiveTimingMap[$pk::class];
259 return self::$packetDecodeTimingMap[$pk::class] ??=
new TimingsHandler(
260 "Decode - " . $pk->getName(),
261 self::getReceiveDataPacketTimings($pk)
266 return self::$packetHandleTimingMap[$pk::class] ??=
new TimingsHandler(
267 "Handler - " . $pk->getName(),
268 self::getReceiveDataPacketTimings($pk)
273 return self::$packetEncodeTimingMap[$pk::class] ??=
new TimingsHandler(
274 "Encode - " . $pk->getName(),
275 self::getSendDataPacketTimings($pk)
281 if(!isset(self::$packetSendTimingMap[$pk::class])){
282 self::$packetSendTimingMap[$pk::class] =
new TimingsHandler(
"Send - " . $pk->getName(), self::$playerNetworkSend);
285 return self::$packetSendTimingMap[$pk::class];
288 public static function getCommandDispatchTimings(
string $commandName) :
TimingsHandler{
291 return self::$commandTimingMap[$commandName] ??=
new TimingsHandler(
"Command - " . $commandName);
295 $eventClass = get_class($event);
296 if(!isset(self::$events[$eventClass])){
297 self::$events[$eventClass] =
new TimingsHandler(self::shortenCoreClassName($eventClass,
"pocketmine\\event\\"), group:
"Events");
300 return self::$events[$eventClass];
307 if(!isset(self::$eventHandlers[$event][$handlerName])){
308 self::$eventHandlers[$event][$handlerName] =
new TimingsHandler($handlerName .
"(" . self::shortenCoreClassName($event,
"pocketmine\\event\\") .
")", group: $group);
311 return self::$eventHandlers[$event][$handlerName];
314 public static function getAsyncTaskProgressUpdateTimings(AsyncTask $task,
string $group = self::GROUP_MINECRAFT) :
TimingsHandler{
315 $taskClass = $task::class;
316 if(!isset(self::$asyncTaskProgressUpdate[$taskClass])){
319 "AsyncTask - " . self::shortenCoreClassName($taskClass,
"pocketmine\\") .
" - Progress Updates",
320 self::$asyncTaskProgressUpdateParent,
325 return self::$asyncTaskProgressUpdate[$taskClass];
328 public static function getAsyncTaskCompletionTimings(AsyncTask $task,
string $group = self::GROUP_MINECRAFT) : TimingsHandler{
329 $taskClass = $task::class;
330 if(!isset(self::$asyncTaskCompletion[$taskClass])){
332 self::$asyncTaskCompletion[$taskClass] =
new TimingsHandler(
333 "AsyncTask - " . self::shortenCoreClassName($taskClass,
"pocketmine\\") .
" - Completion Handler",
334 self::$asyncTaskCompletionParent,
339 return self::$asyncTaskCompletion[$taskClass];
342 public static function getAsyncTaskErrorTimings(AsyncTask $task,
string $group = self::GROUP_MINECRAFT) : TimingsHandler{
343 $taskClass = $task::class;
344 if(!isset(self::$asyncTaskError[$taskClass])){
346 self::$asyncTaskError[$taskClass] =
new TimingsHandler(
347 "AsyncTask - " . self::shortenCoreClassName($taskClass,
"pocketmine\\") .
" - Error Handler",
348 self::$asyncTaskErrorParent,
353 return self::$asyncTaskError[$taskClass];