Merge branch 'next-minor'

# Conflicts:
#	resources/vanilla
#	src/plugin/PluginBase.php
#	src/plugin/PluginDescription.php
#	src/pocketmine/Player.php
#	src/pocketmine/network/rcon/RCON.php
#	src/pocketmine/network/rcon/RCONInstance.php
#	src/pocketmine/scheduler/AsyncTask.php
#	src/pocketmine/tile/Spawnable.php
#	src/scheduler/AsyncPool.php
#	src/utils/Config.php
#	src/utils/Timezone.php
#	src/utils/UUID.php
#	src/utils/Utils.php
#	src/world/format/io/region/RegionLoader.php
This commit is contained in:
Dylan K. Taylor
2020-04-19 11:13:41 +01:00
20 changed files with 139 additions and 58 deletions

View File

@ -55,13 +55,16 @@ final class Process{
$VmSize = null;
$VmRSS = null;
if(Utils::getOS() === "linux" or Utils::getOS() === "android"){
$status = file_get_contents("/proc/self/status");
$status = @file_get_contents("/proc/self/status");
if($status === false) throw new AssumptionFailedError("/proc/self/status should always be accessible");
// the numbers found here should never be bigger than PHP_INT_MAX, so we expect them to always be castable to int
if(preg_match("/VmRSS:[ \t]+([0-9]+) kB/", $status, $matches) > 0){
$VmRSS = $matches[1] * 1024;
$VmRSS = ((int) $matches[1]) * 1024;
}
if(preg_match("/VmSize:[ \t]+([0-9]+) kB/", $status, $matches) > 0){
$VmSize = $matches[1] * 1024;
$VmSize = ((int) $matches[1]) * 1024;
}
}
@ -90,13 +93,14 @@ final class Process{
$heap = 0;
if(Utils::getOS() === "linux" or Utils::getOS() === "android"){
$mappings = file("/proc/self/maps");
$mappings = @file("/proc/self/maps");
if($mappings === false) throw new AssumptionFailedError("/proc/self/maps should always be accessible");
foreach($mappings as $line){
if(preg_match("#([a-z0-9]+)\\-([a-z0-9]+) [rwxp\\-]{4} [a-z0-9]+ [^\\[]*\\[([a-zA-z0-9]+)\\]#", trim($line), $matches) > 0){
if(strpos($matches[3], "heap") === 0){
$heap += hexdec($matches[2]) - hexdec($matches[1]);
$heap += (int) hexdec($matches[2]) - (int) hexdec($matches[1]);
}elseif(strpos($matches[3], "stack") === 0){
$stack += hexdec($matches[2]) - hexdec($matches[1]);
$stack += (int) hexdec($matches[2]) - (int) hexdec($matches[1]);
}
}
}
@ -107,7 +111,9 @@ final class Process{
public static function getThreadCount() : int{
if(Utils::getOS() === "linux" or Utils::getOS() === "android"){
if(preg_match("/Threads:[ \t]+([0-9]+)/", file_get_contents("/proc/self/status"), $matches) > 0){
$status = @file_get_contents("/proc/self/status");
if($status === false) throw new AssumptionFailedError("/proc/self/status should always be accessible");
if(preg_match("/Threads:[ \t]+([0-9]+)/", $status, $matches) > 0){
return (int) $matches[1];
}
}