mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Improved memory output, logging, removed locks
This commit is contained in:
parent
d2bf92c3ed
commit
1666602652
@ -1561,6 +1561,8 @@ class Server{
|
||||
$this->logger->warning($this->getName() . " may not work right with less than 128MB of memory");
|
||||
}
|
||||
@ini_set("memory_limit", $memory);
|
||||
$this->logger->notice("The memory limit will only affect the main thread, and it's unreliable.");
|
||||
$this->logger->notice("To control the memory usage, reduce the amount of threads and chunks loaded");
|
||||
}
|
||||
|
||||
if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){
|
||||
@ -1855,6 +1857,8 @@ class Server{
|
||||
$this->logger->warning($this->getName() . " may not work right with less than 256MB of memory", true, true, 0);
|
||||
}
|
||||
@ini_set("memory_limit", $memory);
|
||||
$this->logger->notice("The memory limit will only affect the main thread, and it's unreliable.");
|
||||
$this->logger->notice("To control the memory usage, reduce the amount of threads and chunks loaded");
|
||||
}
|
||||
|
||||
if($this->getConfigBoolean("hardcore", false) === true and $this->getDifficulty() < 3){
|
||||
@ -2192,14 +2196,8 @@ class Server{
|
||||
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";
|
||||
}
|
||||
$u = $this->getMemoryUsage(true);
|
||||
$usage = round(($u[0] / 1024) / 1024, 2) . "/".round(($u[1] / 1024) / 1024, 2)." MB @ " . $this->getThreadCount() . " threads";
|
||||
|
||||
echo "\x1b]0;" . $this->getName() . " " .
|
||||
$this->getPocketMineVersion() .
|
||||
@ -2213,34 +2211,31 @@ class Server{
|
||||
|
||||
public function getMemoryUsage($advanced = false){
|
||||
$VmSize = null;
|
||||
$VmHWM = null;
|
||||
$VmRSS = null;
|
||||
if(Utils::getOS() === "linux" or Utils::getOS() === "bsd"){
|
||||
$status = file_get_contents("/proc/self/status");
|
||||
if(preg_match("/VmHWM:[ \t]+([0-9]+) kB/", $status, $matches) > 0){
|
||||
$VmHWM = $matches[1] * 1024;
|
||||
if(preg_match("/VmRSS:[ \t]+([0-9]+) kB/", $status, $matches) > 0){
|
||||
$VmRSS = $matches[1] * 1024;
|
||||
}
|
||||
|
||||
if(preg_match("/VmData:[ \t]+([0-9]+) kB/", $status, $matches) > 0){
|
||||
$VmData = $matches[1] * 1024;
|
||||
if(preg_match("/VmSize:[ \t]+([0-9]+) kB/", $status, $matches) > 0){
|
||||
$VmSize = $matches[1] * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
if($VmHWM === null){
|
||||
$VmHWM = memory_get_usage();
|
||||
if($VmRSS === null){
|
||||
$VmRSS = memory_get_usage();
|
||||
}
|
||||
|
||||
if(!$advanced){
|
||||
return $VmHWM;
|
||||
return $VmRSS;
|
||||
}
|
||||
|
||||
if($VmSize === null){
|
||||
$VmSize = memory_get_usage(true);
|
||||
}
|
||||
|
||||
return [
|
||||
"hardware" => $VmHWM,
|
||||
"virtual" => $VmSize,
|
||||
];
|
||||
return [$VmRSS, $VmSize];
|
||||
}
|
||||
|
||||
public function getThreadCount(){
|
||||
|
@ -25,10 +25,6 @@
|
||||
namespace pocketmine\utils;
|
||||
use pocketmine\entity\Entity;
|
||||
|
||||
/**
|
||||
* WARNING: This class is available on the PocketMine-MP Zephir project.
|
||||
* If this class is modified, remember to modify the PHP C extension.
|
||||
*/
|
||||
class Binary{
|
||||
const BIG_ENDIAN = 0x00;
|
||||
const LITTLE_ENDIAN = 0x01;
|
||||
|
@ -47,7 +47,7 @@ class MainLogger extends \AttachableThreadedLogger{
|
||||
$this->logFile = $logFile;
|
||||
$this->logDebug = (bool) $logDebug;
|
||||
$this->logStream = "";
|
||||
$this->start(PTHREADS_INHERIT_NONE);
|
||||
$this->start();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,7 +190,11 @@ class MainLogger extends \AttachableThreadedLogger{
|
||||
$this->attachment->call($level, $message);
|
||||
}
|
||||
|
||||
$this->logStream .= date("Y-m-d", $now) . " " . $cleanMessage;
|
||||
$str = date("Y-m-d", $now) . " " . $cleanMessage . "\n";
|
||||
$this->synchronized(function($str){
|
||||
$this->logStream .= $str;
|
||||
$this->notify();
|
||||
}, $str);
|
||||
}
|
||||
|
||||
public function run(){
|
||||
@ -201,15 +205,15 @@ class MainLogger extends \AttachableThreadedLogger{
|
||||
}
|
||||
|
||||
while($this->shutdown === false){
|
||||
$this->synchronized(function(){
|
||||
if(strlen($this->logStream) > 0){
|
||||
$this->lock();
|
||||
$chunk = $this->logStream;
|
||||
$this->logStream = "";
|
||||
$this->unlock();
|
||||
fwrite($this->logResource, $chunk);
|
||||
}else{
|
||||
usleep(250000);
|
||||
$this->wait(250000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(strlen($this->logStream) > 0){
|
||||
|
@ -24,8 +24,6 @@ namespace pocketmine\utils;
|
||||
|
||||
/**
|
||||
* Unsecure Random Number Noise, used for fast seeded values
|
||||
* WARNING: This class is available on the PocketMine-MP Zephir project.
|
||||
* If this class is modified, remember to modify the PHP C extension.
|
||||
*/
|
||||
class Random{
|
||||
|
||||
|
@ -70,9 +70,9 @@ abstract class TextFormat{
|
||||
*/
|
||||
public static function clean($string, $removeFormat = true){
|
||||
if($removeFormat){
|
||||
return preg_replace(["/§[0123456789abcdefklmnor]/", "/\x1b\\[[0-9;]+m/"], "", $string);
|
||||
return preg_replace(["/§[0123456789abcdefklmnor]/", "/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/"], "", $string);
|
||||
}
|
||||
return preg_replace("/\x1b\\[[0-9;]+m/", "", $string);
|
||||
return preg_replace("/\x1b[\\(\\][[0-9;\\[\\(]+[Bm]/", "", $string);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 7c0888f4ad51c4eb9b695c38691b16aa08522493
|
||||
Subproject commit 639108fb3aeb48a113df3b31516af6ac4f5ba402
|
2
src/spl
2
src/spl
@ -1 +1 @@
|
||||
Subproject commit 695451daf403d86e9db11e6119a6c9cef7f85463
|
||||
Subproject commit 5ad5b3535c9519b2e013a61a2d55fccae014e037
|
Loading…
x
Reference in New Issue
Block a user