mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Merge remote-tracking branch 'origin/minor-next' into major-next
This commit is contained in:
commit
04197d6b80
@ -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);
|
||||
|
@ -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));
|
||||
|
@ -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; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user