diff --git a/src/plugin/PluginManager.php b/src/plugin/PluginManager.php index 46ff52497..475533f7b 100644 --- a/src/plugin/PluginManager.php +++ b/src/plugin/PluginManager.php @@ -63,7 +63,10 @@ use function realpath; use function shuffle; use function sprintf; use function str_contains; +use function str_starts_with; +use function strlen; use function strtolower; +use function substr; /** * Manages all the plugins @@ -651,7 +654,12 @@ class PluginManager{ throw new PluginException("Plugin attempted to register event handler " . $handlerName . "() to event " . $event . " while not enabled"); } - $timings = new TimingsHandler("Plugin: " . $plugin->getDescription()->getFullName() . " Event: " . $handlerName . "(" . (new \ReflectionClass($event))->getShortName() . ")"); + $prefix = $plugin->getDescription()->getSrcNamespacePrefix(); + if(str_starts_with($handlerName, $prefix)){ + $handlerName = substr($handlerName, strlen($prefix) + 1); + } + + $timings = new TimingsHandler($handlerName . "(" . (new \ReflectionClass($event))->getShortName() . ")", group: $plugin->getDescription()->getFullName()); $registeredListener = new RegisteredListener($handler, $priority, $plugin, $handleCancelled, $timings); HandlerListManager::global()->getListFor($event)->register($registeredListener); diff --git a/src/timings/TimingsHandler.php b/src/timings/TimingsHandler.php index a619e3ba8..3cf65c203 100644 --- a/src/timings/TimingsHandler.php +++ b/src/timings/TimingsHandler.php @@ -25,6 +25,7 @@ namespace pocketmine\timings; use pocketmine\entity\Living; use pocketmine\Server; +use pocketmine\utils\Utils; use function count; use function hrtime; @@ -34,7 +35,7 @@ class TimingsHandler{ /** @return string[] */ public static function printTimings() : array{ - $result = ["Minecraft"]; + $groups = []; foreach(TimingsRecord::getAll() as $timings){ $time = $timings->getTotalTime(); @@ -46,7 +47,16 @@ class TimingsHandler{ $avg = $time / $count; - $result[] = " " . $timings->getName() . " Time: $time Count: " . $count . " Avg: $avg Violations: " . $timings->getViolations(); + $group = $timings->getGroup(); + $groups[$group][] = $timings->getName() . " Time: $time Count: " . $count . " Avg: $avg Violations: " . $timings->getViolations(); + } + $result = []; + + foreach(Utils::stringifyKeys($groups) as $groupName => $lines){ + $result[] = $groupName; + foreach($lines as $line){ + $result[] = " $line"; + } } $result[] = "# Version " . Server::getInstance()->getVersion(); @@ -102,11 +112,14 @@ class TimingsHandler{ public function __construct( private string $name, - private ?TimingsHandler $parent = null + private ?TimingsHandler $parent = null, + private string $group = "Minecraft" ){} public function getName() : string{ return $this->name; } + public function getGroup() : string{ return $this->group; } + public function startTiming() : void{ if(self::$enabled){ $this->internalStartTiming(hrtime(true)); diff --git a/src/timings/TimingsRecord.php b/src/timings/TimingsRecord.php index 8ee752ae2..8449a7e8d 100644 --- a/src/timings/TimingsRecord.php +++ b/src/timings/TimingsRecord.php @@ -88,6 +88,8 @@ final class TimingsRecord{ public function getName() : string{ return $this->handler->getName(); } + public function getGroup() : string{ return $this->handler->getGroup(); } + public function getCount() : int{ return $this->count; } public function getCurCount() : int{ return $this->curCount; }