mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
MemoryManager: Analyze contents of function/method static variables
it's possible for stuff to hide inside these things that would cause leaks.
This commit is contained in:
parent
b8e1bdbed4
commit
e192c75019
@ -43,6 +43,7 @@ use function gc_enable;
|
|||||||
use function gc_mem_caches;
|
use function gc_mem_caches;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use function get_declared_classes;
|
use function get_declared_classes;
|
||||||
|
use function get_defined_functions;
|
||||||
use function ini_get;
|
use function ini_get;
|
||||||
use function ini_set;
|
use function ini_set;
|
||||||
use function is_array;
|
use function is_array;
|
||||||
@ -328,6 +329,9 @@ class MemoryManager{
|
|||||||
$staticProperties = [];
|
$staticProperties = [];
|
||||||
$staticCount = 0;
|
$staticCount = 0;
|
||||||
|
|
||||||
|
$functionStaticVars = [];
|
||||||
|
$functionStaticVarsCount = 0;
|
||||||
|
|
||||||
foreach(get_declared_classes() as $className){
|
foreach(get_declared_classes() as $className){
|
||||||
$reflection = new \ReflectionClass($className);
|
$reflection = new \ReflectionClass($className);
|
||||||
$staticProperties[$className] = [];
|
$staticProperties[$className] = [];
|
||||||
@ -347,6 +351,20 @@ class MemoryManager{
|
|||||||
if(count($staticProperties[$className]) === 0){
|
if(count($staticProperties[$className]) === 0){
|
||||||
unset($staticProperties[$className]);
|
unset($staticProperties[$className]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach($reflection->getMethods() as $method){
|
||||||
|
if($method->getDeclaringClass()->getName() !== $reflection->getName()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$methodStatics = [];
|
||||||
|
foreach($method->getStaticVariables() as $name => $variable){
|
||||||
|
$methodStatics[$name] = self::continueDump($variable, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
||||||
|
}
|
||||||
|
if(count($methodStatics) > 0){
|
||||||
|
$functionStaticVars[$className . "::" . $method->getName()] = $methodStatics;
|
||||||
|
$functionStaticVarsCount += count($functionStaticVars);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
||||||
@ -381,6 +399,21 @@ class MemoryManager{
|
|||||||
$logger->info("Wrote $globalCount global variables");
|
$logger->info("Wrote $globalCount global variables");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach(get_defined_functions()["user"] as $function){
|
||||||
|
$reflect = new \ReflectionFunction($function);
|
||||||
|
|
||||||
|
$vars = [];
|
||||||
|
foreach($reflect->getStaticVariables() as $varName => $variable){
|
||||||
|
$vars[$varName] = self::continueDump($variable, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
||||||
|
}
|
||||||
|
if(count($vars) > 0){
|
||||||
|
$functionStaticVars[$function] = $vars;
|
||||||
|
$functionStaticVarsCount += count($vars);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_put_contents($outputFolder . '/functionStaticVars.js', json_encode($functionStaticVars, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
|
||||||
|
$logger->info("Wrote $functionStaticVarsCount function static variables");
|
||||||
|
|
||||||
$data = self::continueDump($startingObject, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
$data = self::continueDump($startingObject, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
||||||
|
|
||||||
do{
|
do{
|
||||||
@ -410,7 +443,6 @@ class MemoryManager{
|
|||||||
$info["this"] = self::continueDump($closureThis, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
$info["this"] = self::continueDump($closureThis, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: scan non-closures for statics as well
|
|
||||||
foreach($reflect->getStaticVariables() as $name => $variable){
|
foreach($reflect->getStaticVariables() as $name => $variable){
|
||||||
$info["referencedVars"][$name] = self::continueDump($variable, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
$info["referencedVars"][$name] = self::continueDump($variable, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user