pocketmine\utils\Utils::getMemoryUsage PHP Method

getMemoryUsage() public static method

public static getMemoryUsage ( $advanced = false )
    public static function getMemoryUsage($advanced = false)
    {
        $reserved = memory_get_usage();
        $VmSize = null;
        $VmRSS = null;
        if (Utils::getOS() === "linux" or Utils::getOS() === "android") {
            $status = file_get_contents("/proc/self/status");
            if (preg_match("/VmRSS:[ \t]+([0-9]+) kB/", $status, $matches) > 0) {
                $VmRSS = $matches[1] * 1024;
            }
            if (preg_match("/VmSize:[ \t]+([0-9]+) kB/", $status, $matches) > 0) {
                $VmSize = $matches[1] * 1024;
            }
        }
        //TODO: more OS
        if ($VmRSS === null) {
            $VmRSS = memory_get_usage();
        }
        if (!$advanced) {
            return $VmRSS;
        }
        if ($VmSize === null) {
            $VmSize = memory_get_usage(true);
        }
        return [$reserved, $VmRSS, $VmSize];
    }

Usage Example

Example #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::getMemoryUsage