mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
Added timings for calling events
this gives a somewhat better overview of events, particularly if many plugins are subscribed to the same costly event (e.g. PlayerMoveEvent). In addition, it allows us to see the frequency that events are occurring.
This commit is contained in:
parent
4c60e82110
commit
b49a9ae81d
@ -26,6 +26,7 @@ declare(strict_types=1);
|
||||
*/
|
||||
namespace pocketmine\event;
|
||||
|
||||
use pocketmine\timings\Timings;
|
||||
use function get_class;
|
||||
|
||||
abstract class Event{
|
||||
@ -51,6 +52,9 @@ abstract class Event{
|
||||
throw new \RuntimeException("Recursive event call detected (reached max depth of " . self::MAX_EVENT_CALL_DEPTH . " calls)");
|
||||
}
|
||||
|
||||
$timings = Timings::getEventTimings($this);
|
||||
$timings->startTiming();
|
||||
|
||||
$handlerList = HandlerListManager::global()->getListFor(get_class($this));
|
||||
|
||||
++self::$eventCallDepth;
|
||||
@ -67,6 +71,7 @@ abstract class Event{
|
||||
}
|
||||
}finally{
|
||||
--self::$eventCallDepth;
|
||||
$timings->stopTiming();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ use pocketmine\entity\Entity;
|
||||
use pocketmine\network\mcpe\protocol\ClientboundPacket;
|
||||
use pocketmine\network\mcpe\protocol\ServerboundPacket;
|
||||
use pocketmine\scheduler\TaskHandler;
|
||||
use function get_class;
|
||||
use function str_starts_with;
|
||||
|
||||
abstract class Timings{
|
||||
public const INCLUDED_BY_OTHER_TIMINGS_PREFIX = "** ";
|
||||
@ -153,6 +155,9 @@ abstract class Timings{
|
||||
|
||||
public static TimingsHandler $playerMove;
|
||||
|
||||
/** @var TimingsHandler[] */
|
||||
private static array $events = [];
|
||||
|
||||
public static function init() : void{
|
||||
if(self::$initialized){
|
||||
return;
|
||||
@ -294,4 +299,18 @@ abstract class Timings{
|
||||
|
||||
return self::$packetSendTimingMap[$pid];
|
||||
}
|
||||
|
||||
public static function getEventTimings(Event $event) : TimingsHandler{
|
||||
$eventClass = get_class($event);
|
||||
if(!isset(self::$events[$eventClass])){
|
||||
if(str_starts_with($eventClass, "pocketmine\\event\\")){
|
||||
$name = (new \ReflectionClass($event))->getShortName();
|
||||
}else{
|
||||
$name = $eventClass;
|
||||
}
|
||||
self::$events[$eventClass] = new TimingsHandler($name, group: "Events");
|
||||
}
|
||||
|
||||
return self::$events[$eventClass];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user