mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 02:38:54 +00:00
Added real memory and thread usage
This commit is contained in:
parent
4383e272eb
commit
4ec584d800
@ -2187,22 +2187,55 @@ class Server{
|
|||||||
$this->scheduler->scheduleAsyncTask($this->lastSendUsage);
|
$this->scheduler->scheduleAsyncTask($this->lastSendUsage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNetwork(){
|
||||||
|
return $this->mainInterface;
|
||||||
|
}
|
||||||
|
|
||||||
private function titleTick(){
|
private function titleTick(){
|
||||||
if(!Terminal::hasFormattingCodes()){
|
if(!Terminal::hasFormattingCodes()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$usage = $this->getMemoryUsage();
|
||||||
|
if($usage === null){
|
||||||
|
$usage = round((memory_get_usage() / 1024) / 1024, 2) .
|
||||||
|
"/" . round((memory_get_usage(true) / 1024) / 1024, 2) .
|
||||||
|
" MB @ " . $this->getThreadCount() . " threads";
|
||||||
|
}else{
|
||||||
|
$usage = round(($usage / 1024) / 1024, 2) . " MB @ " . $this->getThreadCount() . " threads";
|
||||||
|
}
|
||||||
|
|
||||||
echo "\x1b]0;" . $this->getName() . " " .
|
echo "\x1b]0;" . $this->getName() . " " .
|
||||||
$this->getPocketMineVersion() .
|
$this->getPocketMineVersion() .
|
||||||
" | Online " . count($this->players) . "/" . $this->getMaxPlayers() .
|
" | Online " . count($this->players) . "/" . $this->getMaxPlayers() .
|
||||||
" | RAM " . round((memory_get_usage() / 1024) / 1024, 2) .
|
" | RAM " . $usage .
|
||||||
"/" . round((memory_get_usage(true) / 1024) / 1024, 2) .
|
" | U " . round($this->mainInterface->getUploadUsage() / 1024, 2) .
|
||||||
" MB | U " . round($this->mainInterface->getUploadUsage() / 1024, 2) .
|
|
||||||
" D " . round($this->mainInterface->getDownloadUsage() / 1024, 2) .
|
" D " . round($this->mainInterface->getDownloadUsage() / 1024, 2) .
|
||||||
" kB/s | TPS " . $this->getTicksPerSecond() .
|
" kB/s | TPS " . $this->getTicksPerSecond() .
|
||||||
" | Load " . $this->getTickUsage() . "%\x07";
|
" | Load " . $this->getTickUsage() . "%\x07";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMemoryUsage(){
|
||||||
|
if(Utils::getOS() === "linux" or Utils::getOS() === "bsd"){
|
||||||
|
if(preg_match("/VmSize:[ \t]+([0-9]+) kB/", file_get_contents("/proc/self/status"), $matches) > 0){
|
||||||
|
return $matches[1] * 1024;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return memory_get_usage(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getThreadCount(){
|
||||||
|
if(Utils::getOS() === "linux" or Utils::getOS() === "bsd"){
|
||||||
|
|
||||||
|
if(preg_match("/Threads:[ \t]+([0-9]+)/", file_get_contents("/proc/self/status"), $matches) > 0){
|
||||||
|
return (int) $matches[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count(ThreadManager::getInstance()->getAll()) + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to execute a server tick
|
* Tries to execute a server tick
|
||||||
|
@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
|
|||||||
|
|
||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
use pocketmine\utils\TextFormat;
|
use pocketmine\utils\TextFormat;
|
||||||
|
use pocketmine\ThreadManager;
|
||||||
|
|
||||||
class StatusCommand extends VanillaCommand{
|
class StatusCommand extends VanillaCommand{
|
||||||
|
|
||||||
@ -44,10 +45,10 @@ class StatusCommand extends VanillaCommand{
|
|||||||
$sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "Server status" . TextFormat::GREEN . " ----");
|
$sender->sendMessage(TextFormat::GREEN . "---- " . TextFormat::WHITE . "Server status" . TextFormat::GREEN . " ----");
|
||||||
$sender->sendMessage(TextFormat::GOLD . "TPS: " . TextFormat::WHITE . $server->getTicksPerSecond());
|
$sender->sendMessage(TextFormat::GOLD . "TPS: " . TextFormat::WHITE . $server->getTicksPerSecond());
|
||||||
$sender->sendMessage(TextFormat::GOLD . "TPS Load: " . TextFormat::WHITE . $server->getTickUsage() . "%");
|
$sender->sendMessage(TextFormat::GOLD . "TPS Load: " . TextFormat::WHITE . $server->getTickUsage() . "%");
|
||||||
//TODO: implement network speed
|
$sender->sendMessage(TextFormat::GOLD . "Upload: " . TextFormat::WHITE . round($server->getNetwork()->getUploadUsage() / 1024, 2) . " kB/s");
|
||||||
//$sender->sendMessage(TextFormat::GOLD . "Upload: " . TextFormat::WHITE . round($server->getNetwork()->getUploadSpeed() / 1024, 2) . " kB/s");
|
$sender->sendMessage(TextFormat::GOLD . "Download: " . TextFormat::WHITE . round($server->getNetwork()->getDownloadUsage() / 1024, 2) . " kB/s");
|
||||||
//$sender->sendMessage(TextFormat::GOLD . "Download: " . TextFormat::WHITE . round($server->getNetwork()->getDownloadSpeed() / 1024, 2) . " kB/s");
|
$sender->sendMessage(TextFormat::GOLD . "Memory: " . TextFormat::WHITE . round(($server->getMemoryUsage() / 1024) / 1024, 2) . " MB");
|
||||||
$sender->sendMessage(TextFormat::GOLD . "Memory: " . TextFormat::WHITE . round((memory_get_usage() / 1024) / 1024, 2) . TextFormat::YELLOW . "/" . TextFormat::WHITE . round((memory_get_usage(true) / 1024) / 1024, 2) . " MB");
|
$sender->sendMessage(TextFormat::GOLD . "Threads: " . TextFormat::WHITE . $server->getThreadCount());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -77,8 +77,11 @@ class Effect{
|
|||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public static function getEffect($id){
|
public static function getEffect($id){
|
||||||
|
if(isset(self::$effects[$id])){
|
||||||
return clone self::$effects[(int) $id];
|
return clone self::$effects[(int) $id];
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getEffectByName($name){
|
public static function getEffectByName($name){
|
||||||
if(defined(Effect::class . "::" . strtoupper($name))){
|
if(defined(Effect::class . "::" . strtoupper($name))){
|
||||||
|
@ -30,6 +30,7 @@ namespace pocketmine\utils;
|
|||||||
class Utils{
|
class Utils{
|
||||||
public static $online = true;
|
public static $online = true;
|
||||||
public static $ip = false;
|
public static $ip = false;
|
||||||
|
public static $os;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an unique identifier to a callable
|
* Generates an unique identifier to a callable
|
||||||
@ -149,29 +150,33 @@ class Utils{
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getOS(){
|
public static function getOS($recalculate = false){
|
||||||
|
if(self::$os === null or $recalculate){
|
||||||
$uname = php_uname("s");
|
$uname = php_uname("s");
|
||||||
if(stripos($uname, "Darwin") !== false){
|
if(stripos($uname, "Darwin") !== false){
|
||||||
if(strpos(php_uname("m"), "iP") === 0){
|
if(strpos(php_uname("m"), "iP") === 0){
|
||||||
return "ios";
|
self::$os = "ios";
|
||||||
}else{
|
}else{
|
||||||
return "mac";
|
self::$os = "mac";
|
||||||
}
|
}
|
||||||
}elseif(stripos($uname, "Win") !== false or $uname === "Msys"){
|
}elseif(stripos($uname, "Win") !== false or $uname === "Msys"){
|
||||||
return "win";
|
self::$os = "win";
|
||||||
}elseif(stripos($uname, "Linux") !== false){
|
}elseif(stripos($uname, "Linux") !== false){
|
||||||
if(@file_exists("/system/build.prop")){
|
if(@file_exists("/system/build.prop")){
|
||||||
return "android";
|
self::$os = "android";
|
||||||
}else{
|
}else{
|
||||||
return "linux";
|
self::$os = "linux";
|
||||||
}
|
}
|
||||||
}elseif(stripos($uname, "BSD") !== false or $uname === "DragonFly"){
|
}elseif(stripos($uname, "BSD") !== false or $uname === "DragonFly"){
|
||||||
return "bsd";
|
self::$os = "bsd";
|
||||||
}else{
|
}else{
|
||||||
return "other";
|
self::$os = "other";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return self::$os;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a prettified hexdump
|
* Returns a prettified hexdump
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user