Merge commit '3907a2b6ba58fa49022e3e7c8256731dfa2e0d00'

This commit is contained in:
Dylan K. Taylor 2020-03-14 13:32:35 +00:00
commit 7b3c2a3703
6 changed files with 13 additions and 11 deletions

View File

@ -230,7 +230,7 @@ class MemoryManager{
if(($this->memoryLimit > 0 or $this->globalMemoryLimit > 0) and ++$this->checkTicker >= $this->checkRate){ if(($this->memoryLimit > 0 or $this->globalMemoryLimit > 0) and ++$this->checkTicker >= $this->checkRate){
$this->checkTicker = 0; $this->checkTicker = 0;
$memory = Process::getMemoryUsage(true); $memory = Process::getAdvancedMemoryUsage();
$trigger = false; $trigger = false;
if($this->memoryLimit > 0 and $memory[0] > $this->memoryLimit){ if($this->memoryLimit > 0 and $memory[0] > $this->memoryLimit){
$trigger = 0; $trigger = 0;

View File

@ -1618,7 +1618,7 @@ class Server{
Timings::$titleTickTimer->startTiming(); Timings::$titleTickTimer->startTiming();
$d = Process::getRealMemoryUsage(); $d = Process::getRealMemoryUsage();
$u = Process::getMemoryUsage(true); $u = Process::getAdvancedMemoryUsage();
$usage = sprintf("%g/%g/%g/%g MB @ %d threads", round(($u[0] / 1024) / 1024, 2), round(($d[0] / 1024) / 1024, 2), round(($u[1] / 1024) / 1024, 2), round(($u[2] / 1024) / 1024, 2), Process::getThreadCount()); $usage = sprintf("%g/%g/%g/%g MB @ %d threads", round(($u[0] / 1024) / 1024, 2), round(($d[0] / 1024) / 1024, 2), round(($u[1] / 1024) / 1024, 2), round(($u[2] / 1024) / 1024, 2), Process::getThreadCount());
$online = count($this->playerList); $online = count($this->playerList);

View File

@ -49,7 +49,7 @@ class StatusCommand extends VanillaCommand{
} }
$rUsage = Process::getRealMemoryUsage(); $rUsage = Process::getRealMemoryUsage();
$mUsage = Process::getMemoryUsage(true); $mUsage = Process::getAdvancedMemoryUsage();
$server = $sender->getServer(); $server = $sender->getServer();
$sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "Server status" . TextFormat::GREEN . " ----"); $sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "Server status" . TextFormat::GREEN . " ----");

View File

@ -75,6 +75,7 @@ class LowMemoryEvent extends ServerEvent{
* Amount of memory already freed * Amount of memory already freed
*/ */
public function getMemoryFreed() : int{ public function getMemoryFreed() : int{
return $this->getMemory() - ($this->isGlobal() ? Process::getMemoryUsage(true)[1] : Process::getMemoryUsage(true)[0]); $usage = Process::getAdvancedMemoryUsage();
return $this->getMemory() - ($this->isGlobal() ? $usage[1] : $usage[0]);
} }
} }

View File

@ -133,7 +133,7 @@ class SendUsageTask extends AsyncTask{
"historyList" => array_values($playerList) "historyList" => array_values($playerList)
]; ];
$info = Process::getMemoryUsage(true); $info = Process::getAdvancedMemoryUsage();
$data["system"] = [ $data["system"] = [
"mainMemory" => $info[0], "mainMemory" => $info[0],
"totalMemory" => $info[1], "totalMemory" => $info[1],

View File

@ -47,9 +47,10 @@ final class Process{
} }
/** /**
* @return int[]|int * @return int[]
* @phpstan-return array{int,int,int}
*/ */
public static function getMemoryUsage(bool $advanced = false){ public static function getAdvancedMemoryUsage(){
$reserved = memory_get_usage(); $reserved = memory_get_usage();
$VmSize = null; $VmSize = null;
$VmRSS = null; $VmRSS = null;
@ -70,10 +71,6 @@ final class Process{
$VmRSS = memory_get_usage(); $VmRSS = memory_get_usage();
} }
if(!$advanced){
return $VmRSS;
}
if($VmSize === null){ if($VmSize === null){
$VmSize = memory_get_usage(true); $VmSize = memory_get_usage(true);
} }
@ -81,6 +78,10 @@ final class Process{
return [$reserved, $VmRSS, $VmSize]; return [$reserved, $VmRSS, $VmSize];
} }
public static function getMemoryUsage() : int{
return self::getAdvancedMemoryUsage()[1];
}
/** /**
* @return int[] * @return int[]
*/ */