getCurrentMemory(), peak: $monitor->getPeakMemory(), limit: $monitor->getMemoryLimit(), usage: $monitor->getMemoryUsagePercentage() ); } public static function current(): self { $monitor = new MemoryMonitor(); return self::fromMemoryMonitor($monitor); } /** * Check if memory usage is critical (>90%) */ public function isCritical(): bool { return $this->usage->greaterThan(Percentage::from(90.0)); } /** * Check if memory usage is high (>80%) */ public function isHigh(): bool { return $this->usage->greaterThan(Percentage::from(80.0)); } /** * Get available memory */ public function getAvailable(): Byte { return $this->limit->subtract($this->current); } /** * Check if we have enough memory for an operation */ public function hasEnoughMemoryFor(Byte $required): bool { return $this->getAvailable()->greaterThan($required); } public function toArray(): array { return [ 'current' => $this->current->toBytes(), 'current_human' => $this->current->toHumanReadable(), 'peak' => $this->peak->toBytes(), 'peak_human' => $this->peak->toHumanReadable(), 'limit' => $this->limit->toBytes(), 'limit_human' => $this->limit->toHumanReadable(), 'usage_percentage' => $this->usage->getValue(), 'is_critical' => $this->isCritical(), 'is_high' => $this->isHigh(), 'available' => $this->getAvailable()->toBytes(), 'available_human' => $this->getAvailable()->toHumanReadable(), ]; } }