From 63a5269313c1db50094a38f4ad8c8f070a7047ad Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 16 May 2015 16:02:32 +0200 Subject: [PATCH] Added settings.profile-report-trigger to only extract timings on a given tps rate --- src/pocketmine/Server.php | 7 ++++-- src/pocketmine/event/TimingsHandler.php | 29 +++++++++++++++++++------ src/pocketmine/resources/pocketmine.yml | 2 ++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index c97c88398..686ef9c52 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -139,6 +139,8 @@ class Server{ /** @var PluginManager */ private $pluginManager = null; + private $profilingTickRate = 20; + /** @var AutoUpdater */ private $updater = null; @@ -1672,6 +1674,7 @@ class Server{ $this->pluginManager = new PluginManager($this, $this->commandMap); $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender); $this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false)); + $this->profilingTickRate = (float) $this->getProperty("settings.profile-report-trigger", 20); $this->pluginManager->registerInterface(PharPluginLoader::class); set_exception_handler([$this, "exceptionHandler"]); @@ -2456,12 +2459,12 @@ class Server{ Timings::$serverTickTimer->stopTiming(); - TimingsHandler::tick(); - $now = microtime(true); $tick = min(20, 1 / max(0.001, $now - $tickTime)); $use = min(1, ($now - $tickTime) / 0.05); + TimingsHandler::tick($tick <= $this->profilingTickRate); + if($this->maxTick > $tick){ $this->maxTick = $tick; } diff --git a/src/pocketmine/event/TimingsHandler.php b/src/pocketmine/event/TimingsHandler.php index bc41a507d..2444af1aa 100644 --- a/src/pocketmine/event/TimingsHandler.php +++ b/src/pocketmine/event/TimingsHandler.php @@ -36,6 +36,7 @@ class TimingsHandler{ private $parent = null; private $count = 0; + private $curCount = 0; private $start = 0; private $timingDepth = 0; private $totalTime = 0; @@ -97,14 +98,26 @@ class TimingsHandler{ } } - public static function tick(){ + public static function tick($measure = true){ if(PluginManager::$useTimings){ - foreach(self::$HANDLERS as $timings){ - if($timings->curTickTotal > 0.05){ - $timings->violations += round($timings->curTickTotal / 0.05); + if($measure){ + foreach(self::$HANDLERS as $timings){ + if($timings->curTickTotal > 0.05){ + $timings->violations += round($timings->curTickTotal / 0.05); + } + $timings->curTickTotal = 0; + $timings->curCount = 0; + $timings->timingDepth = 0; + } + }else{ + foreach(self::$HANDLERS as $timings){ + $timings->totalTime -= $timings->curTickTotal; + $timings->count -= $timings->curCount; + + $timings->curTickTotal = 0; + $timings->curCount = 0; + $timings->timingDepth = 0; } - $timings->curTickTotal = 0; - $timings->timingDepth = 0; } } } @@ -127,7 +140,8 @@ class TimingsHandler{ $diff = microtime(true) - $this->start; $this->totalTime += $diff; $this->curTickTotal += $diff; - $this->count++; + ++$this->curCount; + ++$this->count; $this->start = 0; if($this->parent instanceof TimingsHandler){ $this->parent->stopTiming(); @@ -137,6 +151,7 @@ class TimingsHandler{ public function reset(){ $this->count = 0; + $this->curCount = 0; $this->violations = 0; $this->curTickTotal = 0; $this->totalTime = 0; diff --git a/src/pocketmine/resources/pocketmine.yml b/src/pocketmine/resources/pocketmine.yml index f7885066d..a7fd73238 100644 --- a/src/pocketmine/resources/pocketmine.yml +++ b/src/pocketmine/resources/pocketmine.yml @@ -16,6 +16,8 @@ settings: deprecated-verbose: true #Enable plugin and core profiling by default enable-profiling: false + #Will only add results when tick measurement is below or equal to given value (default 20) + profile-report-trigger: 20 #Sends anonymous statistics to create usage reports send-usage: true #Number of AsyncTask workers.