mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
MemoryManager: parameterize an abstract \Logger to remove dependency on MainLogger
This commit is contained in:
@ -27,7 +27,6 @@ use pocketmine\event\server\LowMemoryEvent;
|
|||||||
use pocketmine\scheduler\DumpWorkerMemoryTask;
|
use pocketmine\scheduler\DumpWorkerMemoryTask;
|
||||||
use pocketmine\scheduler\GarbageCollectionTask;
|
use pocketmine\scheduler\GarbageCollectionTask;
|
||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
use pocketmine\utils\MainLogger;
|
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
|
|
||||||
class MemoryManager{
|
class MemoryManager{
|
||||||
@ -264,8 +263,8 @@ class MemoryManager{
|
|||||||
* @param int $maxStringSize
|
* @param int $maxStringSize
|
||||||
*/
|
*/
|
||||||
public function dumpServerMemory(string $outputFolder, int $maxNesting, int $maxStringSize){
|
public function dumpServerMemory(string $outputFolder, int $maxNesting, int $maxStringSize){
|
||||||
MainLogger::getLogger()->notice("[Dump] After the memory dump is done, the server might crash");
|
$this->server->getLogger()->notice("[Dump] After the memory dump is done, the server might crash");
|
||||||
self::dumpMemory($this->server, $outputFolder, $maxNesting, $maxStringSize);
|
self::dumpMemory($this->server, $outputFolder, $maxNesting, $maxStringSize, $this->server->getLogger());
|
||||||
|
|
||||||
if($this->dumpWorkers){
|
if($this->dumpWorkers){
|
||||||
$pool = $this->server->getAsyncPool();
|
$pool = $this->server->getAsyncPool();
|
||||||
@ -278,14 +277,15 @@ class MemoryManager{
|
|||||||
/**
|
/**
|
||||||
* Static memory dumper accessible from any thread.
|
* Static memory dumper accessible from any thread.
|
||||||
*
|
*
|
||||||
* @param mixed $startingObject
|
* @param mixed $startingObject
|
||||||
* @param string $outputFolder
|
* @param string $outputFolder
|
||||||
* @param int $maxNesting
|
* @param int $maxNesting
|
||||||
* @param int $maxStringSize
|
* @param int $maxStringSize
|
||||||
|
* @param \Logger $logger
|
||||||
*
|
*
|
||||||
* @throws \ReflectionException
|
* @throws \ReflectionException
|
||||||
*/
|
*/
|
||||||
public static function dumpMemory($startingObject, string $outputFolder, int $maxNesting, int $maxStringSize){
|
public static function dumpMemory($startingObject, string $outputFolder, int $maxNesting, int $maxStringSize, \Logger $logger){
|
||||||
$hardLimit = ini_get('memory_limit');
|
$hardLimit = ini_get('memory_limit');
|
||||||
ini_set('memory_limit', '-1');
|
ini_set('memory_limit', '-1');
|
||||||
gc_disable();
|
gc_disable();
|
||||||
@ -329,7 +329,7 @@ class MemoryManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents($outputFolder . "/staticProperties.js", json_encode($staticProperties, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
file_put_contents($outputFolder . "/staticProperties.js", json_encode($staticProperties, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||||
MainLogger::getLogger()->info("[Dump] Wrote $staticCount static properties");
|
$logger->info("[Dump] Wrote $staticCount static properties");
|
||||||
|
|
||||||
if(isset($GLOBALS)){ //This might be null if we're on a different thread
|
if(isset($GLOBALS)){ //This might be null if we're on a different thread
|
||||||
$globalVariables = [];
|
$globalVariables = [];
|
||||||
@ -357,7 +357,7 @@ class MemoryManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents($outputFolder . "/globalVariables.js", json_encode($globalVariables, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
file_put_contents($outputFolder . "/globalVariables.js", json_encode($globalVariables, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||||
MainLogger::getLogger()->info("[Dump] Wrote $globalCount global variables");
|
$logger->info("[Dump] Wrote $globalCount global variables");
|
||||||
}
|
}
|
||||||
|
|
||||||
self::continueDump($startingObject, $data, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
self::continueDump($startingObject, $data, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
||||||
@ -411,7 +411,7 @@ class MemoryManager{
|
|||||||
|
|
||||||
}while($continue);
|
}while($continue);
|
||||||
|
|
||||||
MainLogger::getLogger()->info("[Dump] Wrote " . count($objects) . " objects");
|
$logger->info("[Dump] Wrote " . count($objects) . " objects");
|
||||||
|
|
||||||
fclose($obData);
|
fclose($obData);
|
||||||
|
|
||||||
@ -421,7 +421,7 @@ class MemoryManager{
|
|||||||
arsort($instanceCounts, SORT_NUMERIC);
|
arsort($instanceCounts, SORT_NUMERIC);
|
||||||
file_put_contents($outputFolder . "/instanceCounts.js", json_encode($instanceCounts, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
file_put_contents($outputFolder . "/instanceCounts.js", json_encode($instanceCounts, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
MainLogger::getLogger()->info("[Dump] Finished!");
|
$logger->info("[Dump] Finished!");
|
||||||
|
|
||||||
ini_set('memory_limit', $hardLimit);
|
ini_set('memory_limit', $hardLimit);
|
||||||
gc_enable();
|
gc_enable();
|
||||||
|
@ -54,7 +54,8 @@ class DumpWorkerMemoryTask extends AsyncTask{
|
|||||||
["worker" => $this->worker, "store" => $store],
|
["worker" => $this->worker, "store" => $store],
|
||||||
$this->outputFolder . DIRECTORY_SEPARATOR . "AsyncWorker#" . $this->worker->getAsyncWorkerId(),
|
$this->outputFolder . DIRECTORY_SEPARATOR . "AsyncWorker#" . $this->worker->getAsyncWorkerId(),
|
||||||
$this->maxNesting,
|
$this->maxNesting,
|
||||||
$this->maxStringSize
|
$this->maxStringSize,
|
||||||
|
$this->worker->getLogger()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user