56 $reserved = memory_get_usage();
60 $status = @file_get_contents(
"/proc/self/status");
61 if($status ===
false)
throw new AssumptionFailedError(
"/proc/self/status should always be accessible");
64 if(preg_match(
"/VmRSS:[ \t]+([0-9]+) kB/", $status, $matches) > 0){
65 $VmRSS = ((int) $matches[1]) * 1024;
68 if(preg_match(
"/VmSize:[ \t]+([0-9]+) kB/", $status, $matches) > 0){
69 $VmSize = ((int) $matches[1]) * 1024;
76 $VmRSS = memory_get_usage();
80 $VmSize = memory_get_usage(
true);
83 return [$reserved, $VmRSS, $VmSize];
98 $mappings = @file(
"/proc/self/maps");
99 if($mappings ===
false)
throw new AssumptionFailedError(
"/proc/self/maps should always be accessible");
100 foreach($mappings as $line){
101 if(preg_match(
"#([a-z0-9]+)\\-([a-z0-9]+) [rwxp\\-]{4} [a-z0-9]+ [^\\[]*\\[([a-zA-z0-9]+)\\]#", trim($line), $matches) > 0){
102 if(str_starts_with($matches[3],
"heap")){
103 $heap += (int) hexdec($matches[2]) - (int) hexdec($matches[1]);
104 }elseif(str_starts_with($matches[3],
"stack")){
105 $stack += (int) hexdec($matches[2]) - (int) hexdec($matches[1]);
111 return [$heap, $stack];