MemoryManager: parameterize an abstract \Logger to remove dependency on MainLogger

This commit is contained in:
Dylan K. Taylor
2018-06-04 13:30:48 +01:00
parent 1d71f0cf43
commit 35eaf38ca1
2 changed files with 14 additions and 13 deletions

View File

@ -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();

View File

@ -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()
); );
} }
} }