mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Report CPU and tick usage accurately using averages (#195)
This commit is contained in:
parent
669af6f7b3
commit
8bdfe0d297
@ -165,8 +165,8 @@ class Server{
|
||||
private $nextTick = 0;
|
||||
private $tickAverage = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20];
|
||||
private $useAverage = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
private $maxTick = 20;
|
||||
private $maxUse = 0;
|
||||
private $currentTPS = 20;
|
||||
private $currentUse = 0;
|
||||
|
||||
private $sendUsageTicker = 0;
|
||||
|
||||
@ -614,7 +614,7 @@ class Server{
|
||||
* @return float
|
||||
*/
|
||||
public function getTicksPerSecond(){
|
||||
return round($this->maxTick, 2);
|
||||
return round($this->currentTPS, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -632,7 +632,7 @@ class Server{
|
||||
* @return float
|
||||
*/
|
||||
public function getTickUsage(){
|
||||
return round($this->maxUse * 100, 2);
|
||||
return round($this->currentUse * 100, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2290,8 +2290,8 @@ class Server{
|
||||
" | Memory " . $usage .
|
||||
" | U " . round($this->network->getUpload() / 1024, 2) .
|
||||
" D " . round($this->network->getDownload() / 1024, 2) .
|
||||
" kB/s | TPS " . $this->getTicksPerSecond() .
|
||||
" | Load " . $this->getTickUsage() . "%\x07";
|
||||
" kB/s | TPS " . $this->getTicksPerSecondAverage() .
|
||||
" | Load " . $this->getTickUsageAverage() . "%\x07";
|
||||
|
||||
$this->network->resetStatistics();
|
||||
}
|
||||
@ -2355,8 +2355,8 @@ class Server{
|
||||
|
||||
if(($this->tickCounter & 0b1111) === 0){
|
||||
$this->titleTick();
|
||||
$this->maxTick = 20;
|
||||
$this->maxUse = 0;
|
||||
$this->currentTPS = 20;
|
||||
$this->currentUse = 0;
|
||||
|
||||
if(($this->tickCounter & 0b111111111) === 0){
|
||||
try{
|
||||
@ -2401,23 +2401,15 @@ class Server{
|
||||
Timings::$serverTickTimer->stopTiming();
|
||||
|
||||
$now = microtime(true);
|
||||
$tick = min(20, 1 / max(0.001, $now - $tickTime));
|
||||
$use = min(1, ($now - $tickTime) / 0.05);
|
||||
$this->currentTPS = min(20, 1 / max(0.001, $now - $tickTime));
|
||||
$this->currentUse = 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;
|
||||
}
|
||||
TimingsHandler::tick($this->currentTPS <= $this->profilingTickRate);
|
||||
|
||||
array_shift($this->tickAverage);
|
||||
$this->tickAverage[] = $tick;
|
||||
$this->tickAverage[] = $this->currentTPS;
|
||||
array_shift($this->useAverage);
|
||||
$this->useAverage[] = $use;
|
||||
$this->useAverage[] = $this->currentUse;
|
||||
|
||||
if(($this->nextTick - $tickTime) < -1){
|
||||
$this->nextTick = $tickTime;
|
||||
|
@ -82,6 +82,7 @@ class StatusCommand extends VanillaCommand{
|
||||
}
|
||||
|
||||
$sender->sendMessage(TextFormat::GOLD . "Current TPS: {$tpsColor}{$server->getTicksPerSecond()} ({$server->getTickUsage()}%)");
|
||||
$sender->sendMessage(TextFormat::GOLD . "Average TPS: {$tpsColor}{$server->getTicksPerSecondAverage()} ({$server->getTickUsageAverage()}%)");
|
||||
|
||||
$sender->sendMessage(TextFormat::GOLD . "Network upload: " . TextFormat::RED . round($server->getNetwork()->getUpload() / 1024, 2) . " kB/s");
|
||||
$sender->sendMessage(TextFormat::GOLD . "Network download: " . TextFormat::RED . round($server->getNetwork()->getDownload() / 1024, 2) . " kB/s");
|
||||
|
Loading…
x
Reference in New Issue
Block a user