Ejemplo n.º 1
0
 public function stopTiming()
 {
     if (PluginManager::$useTimings) {
         if (--$this->timingDepth !== 0 or $this->start === 0) {
             return;
         }
         $diff = microtime(true) - $this->start;
         $this->totalTime += $diff;
         $this->curTickTotal += $diff;
         $this->count++;
         $this->start = 0;
         if ($this->parent instanceof TimingsHandler) {
             $this->parent->stopTiming();
         }
     }
 }
Ejemplo n.º 2
0
 public function stopTiming()
 {
     if (PluginManager::$useTimings) {
         if (--$this->timingDepth !== 0 or $this->start === 0) {
             return;
         }
         $diff = \microtime(\true) - $this->start;
         $this->totalTime += $diff;
         $this->curTickTotal += $diff;
         ++$this->curCount;
         ++$this->count;
         $this->start = 0;
         if ($this->parent !== \null) {
             $this->parent->stopTiming();
         }
     }
 }
Ejemplo n.º 3
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $tickDiff = max(1, $currentTick - $this->lastUpdate);
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = $this->entityBaseTick($tickDiff);
     $this->updateMovement();
     $this->timings->stopTiming();
     //if($this->isStatic())
     return $hasUpdate;
     //return !($this instanceof Player);
 }
Ejemplo n.º 4
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) !== 1) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return true;
     }
     $mode = strtolower($args[0]);
     if ($mode === "on") {
         $sender->getServer()->getPluginManager()->setUseTimings(true);
         TimingsHandler::reload();
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.enable"));
         return true;
     } elseif ($mode === "off") {
         $sender->getServer()->getPluginManager()->setUseTimings(false);
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.disable"));
         return true;
     }
     if (!$sender->getServer()->getPluginManager()->useTimings()) {
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsDisabled"));
         return true;
     }
     $paste = $mode === "paste";
     if ($mode === "reset") {
         TimingsHandler::reload();
         $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.reset"));
     } elseif ($mode === "merged" or $mode === "report" or $paste) {
         $sampleTime = microtime(true) - self::$timingStart;
         $index = 0;
         $timingFolder = $sender->getServer()->getDataPath() . "timings/";
         if (!file_exists($timingFolder)) {
             mkdir($timingFolder, 0777);
         }
         $timings = $timingFolder . "timings.txt";
         while (file_exists($timings)) {
             $timings = $timingFolder . "timings" . ++$index . ".txt";
         }
         $fileTimings = $paste ? fopen("php://temp", "r+b") : fopen($timings, "a+b");
         TimingsHandler::printTimings($fileTimings);
         fwrite($fileTimings, "Sample time " . round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . PHP_EOL);
         if ($paste) {
             fseek($fileTimings, 0);
             $data = ["syntax" => "text", "poster" => $sender->getServer()->getName(), "content" => stream_get_contents($fileTimings)];
             $ch = curl_init("http://paste.ubuntu.com/");
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
             curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
             curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             curl_setopt($ch, CURLOPT_AUTOREFERER, false);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
             curl_setopt($ch, CURLOPT_HEADER, true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, ["User-Agent: " . $this->getName() . " " . $sender->getServer()->getPocketMineVersion()]);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             $data = curl_exec($ch);
             curl_close($ch);
             if (preg_match('#^Location: http://paste\\.ubuntu\\.com/([0-9]{1,})/#m', $data, $matches) == 0) {
                 $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.pasteError"));
                 return true;
             }
             $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsUpload", ["http://paste.ubuntu.com/" . $matches[1] . "/"]));
             $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsRead", ["http://timings.aikar.co/?url=" . $matches[1]]));
             fclose($fileTimings);
         } else {
             fclose($fileTimings);
             $sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsWrite", [$timings]));
         }
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Tries to execute a server tick
  */
 private function tick()
 {
     $tickTime = microtime(true);
     if ($tickTime - $this->nextTick < -0.025) {
         //Allow half a tick of diff
         return false;
     }
     Timings::$serverTickTimer->startTiming();
     ++$this->tickCounter;
     $this->checkConsole();
     Timings::$connectionTimer->startTiming();
     $this->network->processInterfaces();
     if ($this->rcon !== null) {
         $this->rcon->check();
     }
     Timings::$connectionTimer->stopTiming();
     Timings::$schedulerTimer->startTiming();
     $this->scheduler->mainThreadHeartbeat($this->tickCounter);
     Timings::$schedulerTimer->stopTiming();
     $this->checkTickUpdates($this->tickCounter, $tickTime);
     foreach ($this->players as $player) {
         $player->checkNetwork();
     }
     if (($this->tickCounter & 0b1111) === 0) {
         $this->titleTick();
         $this->maxTick = 20;
         $this->maxUse = 0;
         if (($this->tickCounter & 0b111111111) === 0) {
             try {
                 $this->getPluginManager()->callEvent($this->queryRegenerateTask = new QueryRegenerateEvent($this, 5));
                 if ($this->queryHandler !== null) {
                     $this->queryHandler->regenerateInfo();
                 }
             } catch (\Exception $e) {
                 if ($this->logger instanceof MainLogger) {
                     $this->logger->logException($e);
                 }
             }
         }
         $this->getNetwork()->updateName();
     }
     if ($this->autoSave and ++$this->autoSaveTicker >= $this->autoSaveTicks) {
         $this->autoSaveTicker = 0;
         $this->doAutoSave();
     }
     if ($this->sendUsageTicker > 0 and --$this->sendUsageTicker === 0) {
         $this->sendUsageTicker = 6000;
         $this->sendUsage(SendUsageTask::TYPE_STATUS);
     }
     if ($this->tickCounter % 100 === 0) {
         foreach ($this->levels as $level) {
             $level->clearCache();
         }
         if ($this->getTicksPerSecondAverage() < 12) {
             $this->logger->warning($this->getLanguage()->translateString("pocketmine.server.tickOverload"));
         }
     }
     if ($this->dispatchSignals and $this->tickCounter % 5 === 0) {
         pcntl_signal_dispatch();
     }
     $this->getMemoryManager()->check();
     Timings::$serverTickTimer->stopTiming();
     $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;
     }
     if ($this->maxUse < $use) {
         $this->maxUse = $use;
     }
     array_shift($this->tickAverage);
     $this->tickAverage[] = $tick;
     array_shift($this->useAverage);
     $this->useAverage[] = $use;
     if ($this->nextTick - $tickTime < -1) {
         $this->nextTick = $tickTime;
     } else {
         $this->nextTick += 0.05;
     }
     return true;
 }
Ejemplo n.º 6
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     if (!$this->isAlive()) {
         ++$this->deadTicks;
         if ($this->deadTicks >= 10) {
             $this->despawnFromAll();
             if (!$this->isPlayer) {
                 $this->close();
             }
         }
         return $this->deadTicks < 10;
     }
     $tickDiff = $currentTick - $this->lastUpdate;
     if ($tickDiff <= 0) {
         return false;
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = $this->entityBaseTick($tickDiff);
     $this->updateMovement();
     $this->timings->stopTiming();
     //if($this->isStatic())
     return $hasUpdate;
     //return !($this instanceof Player);
 }
Ejemplo n.º 7
0
 /**
  * Tries to execute a server tick
  */
 private function tick()
 {
     $tickTime = microtime(true);
     if ($tickTime < $this->nextTick) {
         return false;
     }
     Timings::$serverTickTimer->startTiming();
     ++$this->tickCounter;
     $this->checkConsole();
     Timings::$connectionTimer->startTiming();
     $this->network->processInterfaces();
     Timings::$connectionTimer->stopTiming();
     Timings::$schedulerTimer->startTiming();
     $this->scheduler->mainThreadHeartbeat($this->tickCounter);
     Timings::$schedulerTimer->stopTiming();
     $this->checkTickUpdates($this->tickCounter);
     if (($this->tickCounter & 0b1111) === 0) {
         $this->titleTick();
         if ($this->queryHandler !== null and ($this->tickCounter & 0b111111111) === 0) {
             try {
                 $this->queryHandler->regenerateInfo();
             } catch (\Exception $e) {
                 if ($this->logger instanceof MainLogger) {
                     $this->logger->logException($e);
                 }
             }
         }
     }
     Timings::$generationTimer->startTiming();
     try {
         $this->generationManager->process();
     } catch (\Exception $e) {
         if ($this->logger instanceof MainLogger) {
             $this->logger->logException($e);
         }
     }
     Timings::$generationTimer->stopTiming();
     if ($this->tickCounter % 100 === 0) {
         foreach ($this->levels as $level) {
             $level->clearCache();
         }
     }
     Timings::$serverTickTimer->stopTiming();
     TimingsHandler::tick();
     $now = microtime(true);
     array_shift($this->tickAverage);
     $this->tickAverage[] = min(20, 1 / max(0.001, $now - $tickTime));
     array_shift($this->useAverage);
     $this->useAverage[] = min(1, ($now - $tickTime) / 0.05);
     if ($this->nextTick - $tickTime < -1) {
         $this->nextTick = $tickTime;
     }
     $this->nextTick += 0.05;
     return true;
 }
Ejemplo n.º 8
0
 public function __destruct()
 {
     $this->timings->remove();
 }
Ejemplo n.º 9
0
 public function remove()
 {
     $this->cancelled = true;
     $this->task->setHandler(null);
     $this->timings->remove();
 }
Ejemplo n.º 10
0
 public function reload()
 {
     $this->logger->info("Saving levels...");
     foreach ($this->levels as $level) {
         $level->save();
     }
     $this->pluginManager->disablePlugins();
     $this->pluginManager->clearPlugins();
     $this->commandMap->clearCommands();
     $this->logger->info("Reloading properties...");
     $this->properties->reload();
     $this->advancedConfig->reload();
     $this->loadAdvancedConfig();
     $this->maxPlayers = $this->getConfigInt("max-players", 20);
     if ($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3) {
         $this->setConfigInt("difficulty", 3);
     }
     $this->banByIP->load();
     $this->banByName->load();
     $this->banByCID->load();
     $this->reloadWhitelist();
     $this->operators->reload();
     $this->memoryManager->doObjectCleanup();
     foreach ($this->getIPBans()->getEntries() as $entry) {
         $this->getNetwork()->blockAddress($entry->getName(), -1);
     }
     $this->pluginManager->registerInterface(PharPluginLoader::class);
     $this->pluginManager->registerInterface(FolderPluginLoader::class);
     $this->pluginManager->registerInterface(ScriptPluginLoader::class);
     $this->pluginManager->loadPlugins($this->pluginPath);
     $this->enablePlugins(PluginLoadOrder::STARTUP);
     $this->enablePlugins(PluginLoadOrder::POSTWORLD);
     TimingsHandler::reload();
 }
Ejemplo n.º 11
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return \true;
     }
     if (\count($args) !== 1) {
         $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
         return \true;
     }
     $mode = \strtolower($args[0]);
     if ($mode === "on") {
         $sender->getServer()->getPluginManager()->setUseTimings(\true);
         TimingsHandler::reload();
         $sender->sendMessage("Enabled Timings & Reset");
         return \true;
     } elseif ($mode === "off") {
         $sender->getServer()->getPluginManager()->setUseTimings(\false);
         $sender->sendMessage("Disabled Timings");
         return \true;
     }
     if (!$sender->getServer()->getPluginManager()->useTimings()) {
         $sender->sendMessage("Please enable timings by typing /timings on");
         return \true;
     }
     $paste = $mode === "paste";
     if ($mode === "reset") {
         TimingsHandler::reload();
         $sender->sendMessage("Timings reset");
     } elseif ($mode === "merged" or $mode === "report" or $paste) {
         $sampleTime = \microtime(\true) - self::$timingStart;
         $index = 0;
         $timingFolder = $sender->getServer()->getDataPath() . "timings/";
         if (!\file_exists($timingFolder)) {
             \mkdir($timingFolder, 0777);
         }
         $timings = $timingFolder . "timings.txt";
         while (\file_exists($timings)) {
             $timings = $timingFolder . "timings" . ++$index . ".txt";
         }
         $fileTimings = $paste ? \fopen("php://temp", "r+b") : \fopen($timings, "a+b");
         TimingsHandler::printTimings($fileTimings);
         \fwrite($fileTimings, "Sample time " . \round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . \PHP_EOL);
         if ($paste) {
             \fseek($fileTimings, 0);
             $data = ["syntax" => "text", "poster" => $sender->getServer()->getName(), "content" => \stream_get_contents($fileTimings)];
             $ch = curl_init("http://paste.ubuntu.com/");
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, \false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
             curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
             curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
             curl_setopt($ch, CURLOPT_AUTOREFERER, \false);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, \false);
             curl_setopt($ch, CURLOPT_HEADER, \true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, ["User-Agent: " . $this->getName() . " " . $sender->getServer()->getPocketMineVersion()]);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, \true);
             $data = curl_exec($ch);
             curl_close($ch);
             if (\preg_match('#^Location: http://paste\\.ubuntu\\.com/([0-9]{1,})/#m', $data, $matches) == 0) {
                 $sender->sendMessage("An error happened while pasting the report");
                 return \true;
             }
             $sender->sendMessage("Timings uploaded to http://paste.ubuntu.com/" . $matches[1] . "/");
             $sender->sendMessage("You can read the results at http://timings.aikar.co/?url=" . $matches[1]);
             \fclose($fileTimings);
         } else {
             \fclose($fileTimings);
             $sender->sendMessage("Timings written to " . $timings);
         }
     }
     return \true;
 }
Ejemplo n.º 12
0
 private function pasteTimings()
 {
     $sampleTime = microtime(true) - TimingsCommand::$timingStart;
     $ft = fopen("php://temp", "r+b");
     TimingsHandler::printTimings($ft);
     fwrite($ft, "Sample time " . round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . PHP_EOL);
     fseek($ft, 0);
     $data = ["syntax" => "text", "poster" => "LegionPE", "content" => stream_get_contents($ft)];
     $ch = curl_init("http://paste.ubuntu.com/");
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_AUTOREFERER, false);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
     curl_setopt($ch, CURLOPT_HEADER, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, ["User-Agent: LegionPE " . $this->getDescription()->getVersion()]);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $data = curl_exec($ch);
     curl_close($ch);
     if (preg_match('#^Location: http://paste\\.ubuntu\\.com/([0-9]{1,})/#m', $data, $matches) == 0) {
         return "about:blank";
     }
     fclose($ft);
     return "http://timings.aikar.co/?url={$matches['1']}";
 }
Ejemplo n.º 13
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) !== 1) {
         $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
         return true;
     }
     $mode = strtolower($args[0]);
     if ($mode === "on") {
         $sender->getServer()->getPluginManager()->setUseTimings(true);
         TimingsHandler::reload();
         $sender->sendMessage("Enabled Timings & Reset");
         return true;
     } elseif ($mode === "off") {
         $sender->getServer()->getPluginManager()->setUseTimings(false);
         $sender->sendMessage("Disabled Timings");
     }
     if (!$sender->getServer()->getPluginManager()->useTimings()) {
         $sender->sendMessage("Please enable timings by typing /timings on");
         return true;
     }
     $paste = $mode === "paste";
     if ($mode === "reset") {
         TimingsHandler::reload();
         $sender->sendMessage("Timings reset");
     } elseif ($mode === "merged" or $mode === "report" or $paste) {
         $sampleTime = microtime(true) - self::$timingStart;
         $index = 0;
         $timingFolder = $sender->getServer()->getDataPath() . "timings/";
         @mkdir($timingFolder, 0777);
         $timings = $timingFolder . "timings.txt";
         while (file_exists($timings)) {
             $timings = $timingFolder . "timings" . ++$index . ".txt";
         }
         $fileTimings = $paste ? fopen("php://temp", "r+b") : fopen($timings, "a+b");
         TimingsHandler::printTimings($fileTimings);
         fwrite($fileTimings, "Sample time " . round($sampleTime * 1000000000) . " (" . $sampleTime . "s)" . PHP_EOL);
         if ($paste) {
             fseek($fileTimings, 0);
             $data = ["public" => false, "description" => $sender->getServer()->getName() . " Timings", "files" => ["timings.txt" => ["content" => stream_get_contents($fileTimings)]]];
             $ch = curl_init("https://api.github.com/gists");
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
             curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
             curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_SLASHES));
             curl_setopt($ch, CURLOPT_AUTOREFERER, true);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json", "User-Agent: " . $this->getName() . " " . $sender->getServer()->getPocketMineVersion()]);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             $ret = curl_exec($ch);
             $data = json_decode($ret);
             curl_close($ch);
             if ($data === false or $data === null or !isset($data->html_url)) {
                 $sender->sendMessage("An error happened while pasting the report");
                 return true;
             }
             $timings = $data->html_url;
         }
         fclose($fileTimings);
         $sender->sendMessage("Timings written to " . $timings);
         $sender->sendMessage("Paste contents of file into form at http://aikar.co/timings.php to read results.");
     }
     return true;
 }