Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
89
src/Framework/Filesystem/ValueObjects/ScannerMemoryUsage.php
Normal file
89
src/Framework/Filesystem/ValueObjects/ScannerMemoryUsage.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Filesystem\ValueObjects;
|
||||
|
||||
use App\Framework\Core\ValueObjects\Byte;
|
||||
use App\Framework\Core\ValueObjects\Percentage;
|
||||
use App\Framework\Performance\MemoryMonitor;
|
||||
|
||||
/**
|
||||
* Represents memory usage statistics for the scanner
|
||||
*/
|
||||
final readonly class ScannerMemoryUsage
|
||||
{
|
||||
public function __construct(
|
||||
public Byte $current,
|
||||
public Byte $peak,
|
||||
public Byte $limit,
|
||||
public Percentage $usage
|
||||
) {
|
||||
}
|
||||
|
||||
public static function fromMemoryMonitor(MemoryMonitor $monitor): self
|
||||
{
|
||||
return new self(
|
||||
current: $monitor->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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user