Optimise plugin timings report entries

this format is already supported by the timings host, so no changes are required to support this.
This commit is contained in:
Dylan K. Taylor 2023-03-27 01:15:42 +01:00
parent acc8ae87fb
commit cebdb95265
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 18 additions and 4 deletions

View File

@ -651,7 +651,7 @@ 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() . ")");
$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);

View File

@ -34,7 +34,7 @@ class TimingsHandler{
/** @return string[] */
public static function printTimings() : array{
$result = ["Minecraft"];
$groups = [];
foreach(TimingsRecord::getAll() as $timings){
$time = $timings->getTotalTime();
@ -46,7 +46,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($groups as $groupName => $lines){
$result[] = $groupName;
foreach($lines as $line){
$result[] = " $line";
}
}
$result[] = "# Version " . Server::getInstance()->getVersion();
@ -102,11 +111,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));

View File

@ -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; }