Added real memory and thread usage

This commit is contained in:
Shoghi Cervantes 2015-03-16 11:56:00 +01:00
parent 4383e272eb
commit 4ec584d800
4 changed files with 69 additions and 27 deletions

View File

@ -2186,22 +2186,55 @@ class Server{
$this->scheduler->scheduleAsyncTask($this->lastSendUsage);
}
public function getNetwork(){
return $this->mainInterface;
}
private function titleTick(){
if(!Terminal::hasFormattingCodes()){
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() . " " .
$this->getPocketMineVersion() .
" | Online " . count($this->players) . "/" . $this->getMaxPlayers() .
" | RAM " . round((memory_get_usage() / 1024) / 1024, 2) .
"/" . round((memory_get_usage(true) / 1024) / 1024, 2) .
" MB | U " . round($this->mainInterface->getUploadUsage() / 1024, 2) .
" | RAM " . $usage .
" | U " . round($this->mainInterface->getUploadUsage() / 1024, 2) .
" D " . round($this->mainInterface->getDownloadUsage() / 1024, 2) .
" kB/s | TPS " . $this->getTicksPerSecond() .
" | 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;
}
/**

View File

@ -23,6 +23,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
use pocketmine\ThreadManager;
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::GOLD . "TPS: " . TextFormat::WHITE . $server->getTicksPerSecond());
$sender->sendMessage(TextFormat::GOLD . "TPS Load: " . TextFormat::WHITE . $server->getTickUsage() . "%");
//TODO: implement network speed
//$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()->getDownloadSpeed() / 1024, 2) . " kB/s");
$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 . "Upload: " . TextFormat::WHITE . round($server->getNetwork()->getUploadUsage() / 1024, 2) . " kB/s");
$sender->sendMessage(TextFormat::GOLD . "Download: " . TextFormat::WHITE . round($server->getNetwork()->getDownloadUsage() / 1024, 2) . " kB/s");
$sender->sendMessage(TextFormat::GOLD . "Memory: " . TextFormat::WHITE . round(($server->getMemoryUsage() / 1024) / 1024, 2) . " MB");
$sender->sendMessage(TextFormat::GOLD . "Threads: " . TextFormat::WHITE . $server->getThreadCount());
return true;
}

View File

@ -77,7 +77,10 @@ class Effect{
* @return $this
*/
public static function getEffect($id){
return clone self::$effects[(int) $id];
if(isset(self::$effects[$id])){
return clone self::$effects[(int) $id];
}
return null;
}
public static function getEffectByName($name){
@ -184,4 +187,4 @@ class Effect{
break;
}
}
}
}

View File

@ -30,6 +30,7 @@ namespace pocketmine\utils;
class Utils{
public static $online = true;
public static $ip = false;
public static $os;
/**
* Generates an unique identifier to a callable
@ -149,27 +150,31 @@ class Utils{
*
* @return string
*/
public static function getOS(){
$uname = php_uname("s");
if(stripos($uname, "Darwin") !== false){
if(strpos(php_uname("m"), "iP") === 0){
return "ios";
public static function getOS($recalculate = false){
if(self::$os === null or $recalculate){
$uname = php_uname("s");
if(stripos($uname, "Darwin") !== false){
if(strpos(php_uname("m"), "iP") === 0){
self::$os = "ios";
}else{
self::$os = "mac";
}
}elseif(stripos($uname, "Win") !== false or $uname === "Msys"){
self::$os = "win";
}elseif(stripos($uname, "Linux") !== false){
if(@file_exists("/system/build.prop")){
self::$os = "android";
}else{
self::$os = "linux";
}
}elseif(stripos($uname, "BSD") !== false or $uname === "DragonFly"){
self::$os = "bsd";
}else{
return "mac";
self::$os = "other";
}
}elseif(stripos($uname, "Win") !== false or $uname === "Msys"){
return "win";
}elseif(stripos($uname, "Linux") !== false){
if(@file_exists("/system/build.prop")){
return "android";
}else{
return "linux";
}
}elseif(stripos($uname, "BSD") !== false or $uname === "DragonFly"){
return "bsd";
}else{
return "other";
}
return self::$os;
}
/**