pocketmine\utils\Utils::getRealMemoryUsage PHP Method

getRealMemoryUsage() public static method

public static getRealMemoryUsage ( )
    public static function getRealMemoryUsage()
    {
        $stack = 0;
        $heap = 0;
        if (Utils::getOS() === "linux" or Utils::getOS() === "android") {
            $mappings = file("/proc/self/maps");
            foreach ($mappings as $line) {
                if (preg_match("#([a-z0-9]+)\\-([a-z0-9]+) [rwxp\\-]{4} [a-z0-9]+ [^\\[]*\\[([a-zA-z0-9]+)\\]#", trim($line), $matches) > 0) {
                    if (strpos($matches[3], "heap") === 0) {
                        $heap += hexdec($matches[2]) - hexdec($matches[1]);
                    } elseif (strpos($matches[3], "stack") === 0) {
                        $stack += hexdec($matches[2]) - hexdec($matches[1]);
                    }
                }
            }
        }
        return [$heap, $stack];
    }

Usage Example

Ejemplo n.º 1
0
 public function check()
 {
     $d = Utils::getRealMemoryUsage();
     $u = Utils::getMemoryUsage(true);
     $usage = round($u[0] / 1024 / 1024, 2) . "/" . round($d[0] / 1024 / 1024, 2) . "/" . round($u[1] / 1024 / 1024, 2) . "/" . round($u[2] / 1024 / 1024, 2) . " MB @ " . Utils::getThreadCount() . " threads";
     $serverStatus = serialize(["online" => count($this->server->getOnlinePlayers()), "max" => $this->server->getMaxPlayers(), "upload" => round($this->server->getNetwork()->getUpload() / 1024, 2), "download" => round($this->server->getNetwork()->getDownload() / 1024, 2), "tps" => $this->server->getTicksPerSecondAverage(), "load" => $this->server->getTickUsageAverage(), "usage" => $usage]);
     for ($n = 0; $n < $this->threads; ++$n) {
         if (!$this->workers[$n]->isTerminated()) {
             $this->workers[$n]->serverStatus = $serverStatus;
         }
         if ($this->workers[$n]->isTerminated() === true) {
             $this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
         } elseif ($this->workers[$n]->isWaiting()) {
             if ($this->workers[$n]->response !== "") {
                 $this->server->getLogger()->info($this->workers[$n]->response);
                 $this->workers[$n]->synchronized(function (RCONInstance $thread) {
                     $thread->notify();
                 }, $this->workers[$n]);
             } else {
                 $response = new RemoteConsoleCommandSender();
                 $command = $this->workers[$n]->cmd;
                 $this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command));
                 if (!$ev->isCancelled()) {
                     $this->server->dispatchCommand($ev->getSender(), $ev->getCommand());
                 }
                 $this->workers[$n]->response = $response->getMessage();
                 $this->workers[$n]->synchronized(function (RCONInstance $thread) {
                     $thread->notify();
                 }, $this->workers[$n]);
             }
         }
     }
 }
All Usage Examples Of pocketmine\utils\Utils::getRealMemoryUsage