PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Timings.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 namespace pocketmine\event;
23 
24 
30 
31 abstract class Timings{
32 
34  public static $serverTickTimer;
36  public static $playerListTimer;
38  public static $connectionTimer;
40  public static $tickablesTimer;
42  public static $schedulerTimer;
44  public static $chunkIOTickTimer;
46  public static $timeUpdateTimer;
48  public static $serverCommandTimer;
50  public static $worldSaveTimer;
52  public static $generationTimer;
54  public static $permissibleCalculationTimer;
56  public static $permissionDefaultTimer;
57 
59  public static $entityMoveTimer;
61  public static $tickEntityTimer;
63  public static $activatedEntityTimer;
65  public static $tickTileEntityTimer;
66 
68  public static $timerEntityBaseTick;
70  public static $timerEntityAI;
72  public static $timerEntityAICollision;
74  public static $timerEntityAIMove;
76  public static $timerEntityTickRest;
77 
79  public static $processQueueTimer;
81  public static $schedulerSyncTimer;
82 
84  public static $playerCommandTimer;
85 
87  public static $entityTypeTimingMap = [];
89  public static $tileEntityTypeTimingMap = [];
91  public static $pluginTaskTimingMap = [];
92 
93  public static function init(){
94  if(self::$serverTickTimer instanceof TimingsHandler){
95  return;
96  }
97 
98  self::$serverTickTimer = new TimingsHandler("** Full Server Tick");
99  self::$playerListTimer = new TimingsHandler("Player List");
100  self::$connectionTimer = new TimingsHandler("Connection Handler");
101  self::$tickablesTimer = new TimingsHandler("Tickables");
102  self::$schedulerTimer = new TimingsHandler("Scheduler");
103  self::$chunkIOTickTimer = new TimingsHandler("ChunkIOTick");
104  self::$timeUpdateTimer = new TimingsHandler("Time Update");
105  self::$serverCommandTimer = new TimingsHandler("Server Command");
106  self::$worldSaveTimer = new TimingsHandler("World Save");
107  self::$generationTimer = new TimingsHandler("World Generation");
108  self::$permissibleCalculationTimer = new TimingsHandler("Permissible Calculation");
109  self::$permissionDefaultTimer = new TimingsHandler("Default Permission Calculation");
110 
111  self::$entityMoveTimer = new TimingsHandler("** entityMove");
112  self::$tickEntityTimer = new TimingsHandler("** tickEntity");
113  self::$activatedEntityTimer = new TimingsHandler("** activatedTickEntity");
114  self::$tickTileEntityTimer = new TimingsHandler("** tickTileEntity");
115 
116  self::$timerEntityBaseTick = new TimingsHandler("** livingEntityBaseTick");
117  self::$timerEntityAI = new TimingsHandler("** livingEntityAI");
118  self::$timerEntityAICollision = new TimingsHandler("** livingEntityAICollision");
119  self::$timerEntityAIMove = new TimingsHandler("** livingEntityAIMove");
120  self::$timerEntityTickRest = new TimingsHandler("** livingEntityTickRest");
121 
122  self::$processQueueTimer = new TimingsHandler("processQueue");
123  self::$schedulerSyncTimer = new TimingsHandler("** Scheduler - Sync Tasks", PluginManager::$pluginParentTimer);
124 
125  self::$playerCommandTimer = new TimingsHandler("** playerCommand");
126 
127  }
128 
135  public static function getPluginTaskTimings(TaskHandler $task, $period){
136  $ftask = $task->getTask();
137  if($ftask instanceof PluginTask and $ftask->getOwner() !== null){
138  $plugin = $ftask->getOwner()->getDescription()->getFullName();
139  }elseif($task->timingName !== null){
140  $plugin = "Scheduler";
141  }else{
142  $plugin = "Unknown";
143  }
144 
145  $taskname = $task->getTaskName();
146 
147  $name = "Task: " . $plugin . " Runnable: " . $taskname;
148 
149  if($period > 0){
150  $name .= "(interval:" . $period . ")";
151  }else{
152  $name .= "(Single)";
153  }
154 
155  if(!isset(self::$pluginTaskTimingMap[$name])){
156  self::$pluginTaskTimingMap[$name] = new TimingsHandler($name, self::$schedulerSyncTimer);
157  }
158 
159  return self::$pluginTaskTimingMap[$name];
160  }
161 
167  public static function getEntityTimings(Entity $entity){
168  $entityType = (new \ReflectionClass($entity))->getShortName();
169  if(!isset(self::$entityTypeTimingMap[$entityType])){
170  self::$entityTypeTimingMap[$entityType] = new TimingsHandler("** tickEntity - " . $entityType, self::$activatedEntityTimer);
171  }
172 
173  return self::$entityTypeTimingMap[$entityType];
174  }
175 
181  public static function getTileEntityTimings(Tile $tile){
182  $tileType = (new \ReflectionClass($tile))->getShortName();
183  if(!isset(self::$tileEntityTypeTimingMap[$tileType])){
184  self::$tileEntityTypeTimingMap[$tileType] = new TimingsHandler("** tickTileEntity - " . $tileType, self::$tickTileEntityTimer);
185  }
186 
187  return self::$tileEntityTypeTimingMap[$tileType];
188  }
189 
190 }
static getTileEntityTimings(Tile $tile)
Definition: Timings.php:181
static getPluginTaskTimings(TaskHandler $task, $period)
Definition: Timings.php:135
static getEntityTimings(Entity $entity)
Definition: Timings.php:167