- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
143 lines
5.6 KiB
PHP
143 lines
5.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
use App\Framework\Cache\Driver\InMemoryCache;
|
|
use App\Framework\Cache\GeneralCache;
|
|
use App\Framework\Core\PathProvider;
|
|
use App\Framework\DateTime\SystemClock;
|
|
use App\Framework\DI\DefaultContainer;
|
|
use App\Framework\DI\Initializer;
|
|
use App\Framework\Discovery\Factory\DiscoveryServiceFactory;
|
|
use App\Framework\Discovery\ValueObjects\DiscoveryConfiguration;
|
|
use App\Framework\Serializer\Json\JsonSerializer;
|
|
|
|
echo "=== Comparing Memory-Managed vs Standard Discovery ===\n\n";
|
|
|
|
try {
|
|
$projectRoot = dirname(__DIR__, 2);
|
|
$srcPath = $projectRoot . '/src';
|
|
|
|
$container = new DefaultContainer();
|
|
$pathProvider = new PathProvider($projectRoot);
|
|
$clock = new SystemClock();
|
|
$cacheDriver = new InMemoryCache();
|
|
$serializer = new JsonSerializer();
|
|
$cache = new GeneralCache($cacheDriver, $serializer);
|
|
|
|
$factory = new DiscoveryServiceFactory($container, $pathProvider, $cache, $clock);
|
|
|
|
echo "=== Test 1: Memory Monitoring ENABLED ===\n";
|
|
|
|
// Create configuration with memory monitoring enabled using development config
|
|
$memoryEnabledConfig = DiscoveryConfiguration::development()
|
|
->withPaths([$srcPath]);
|
|
|
|
// Use reflection to create service with custom config
|
|
$reflection = new ReflectionClass($factory);
|
|
$createMethod = $reflection->getMethod('create');
|
|
$createMethod->setAccessible(true);
|
|
|
|
$memoryService = $createMethod->invoke($factory, $memoryEnabledConfig);
|
|
|
|
echo "Starting memory-managed discovery...\n";
|
|
$startTime = microtime(true);
|
|
$memoryRegistry = $memoryService->discover();
|
|
$memoryTime = microtime(true) - $startTime;
|
|
|
|
echo "Memory-managed results:\n";
|
|
echo "- Total items: " . count($memoryRegistry) . "\n";
|
|
echo "- Initializers: " . $memoryRegistry->attributes->getCount(Initializer::class) . "\n";
|
|
echo "- Attribute types: " . count($memoryRegistry->attributes->getAllTypes()) . "\n";
|
|
echo "- Processing time: " . round($memoryTime * 1000, 2) . "ms\n\n";
|
|
|
|
echo "=== Test 2: Memory Monitoring DISABLED ===\n";
|
|
|
|
// Create configuration with memory monitoring disabled
|
|
$standardConfig = new DiscoveryConfiguration(
|
|
paths: [$srcPath],
|
|
useCache: false,
|
|
enableMemoryMonitoring: false,
|
|
maxFilesPerBatch: 200,
|
|
memoryLimitMB: 256
|
|
);
|
|
|
|
$standardService = $createMethod->invoke($factory, $standardConfig);
|
|
|
|
echo "Starting standard discovery...\n";
|
|
$startTime = microtime(true);
|
|
$standardRegistry = $standardService->discover();
|
|
$standardTime = microtime(true) - $startTime;
|
|
|
|
echo "Standard results:\n";
|
|
echo "- Total items: " . count($standardRegistry) . "\n";
|
|
echo "- Initializers: " . $standardRegistry->attributes->getCount(Initializer::class) . "\n";
|
|
echo "- Attribute types: " . count($standardRegistry->attributes->getAllTypes()) . "\n";
|
|
echo "- Processing time: " . round($standardTime * 1000, 2) . "ms\n\n";
|
|
|
|
echo "=== Comparison ===\n";
|
|
echo "Memory vs Standard:\n";
|
|
echo "- Total items: " . count($memoryRegistry) . " vs " . count($standardRegistry) .
|
|
" (diff: " . (count($standardRegistry) - count($memoryRegistry)) . ")\n";
|
|
echo "- Initializers: " . $memoryRegistry->attributes->getCount(Initializer::class) .
|
|
" vs " . $standardRegistry->attributes->getCount(Initializer::class) .
|
|
" (diff: " . ($standardRegistry->attributes->getCount(Initializer::class) - $memoryRegistry->attributes->getCount(Initializer::class)) . ")\n";
|
|
echo "- Processing time: " . round($memoryTime * 1000, 2) . "ms vs " . round($standardTime * 1000, 2) . "ms\n\n";
|
|
|
|
// Check which specific initializers are missing in memory-managed discovery
|
|
echo "=== Missing Initializers Analysis ===\n";
|
|
$memoryInitializers = $memoryRegistry->attributes->get(Initializer::class);
|
|
$standardInitializers = $standardRegistry->attributes->get(Initializer::class);
|
|
|
|
// Create sets for comparison
|
|
$memorySet = [];
|
|
foreach ($memoryInitializers as $mapping) {
|
|
$key = $mapping->class->getFullyQualified() . '::' . ($mapping->method ? $mapping->method->toString() : '(class)');
|
|
$memorySet[$key] = true;
|
|
}
|
|
|
|
$standardSet = [];
|
|
foreach ($standardInitializers as $mapping) {
|
|
$key = $mapping->class->getFullyQualified() . '::' . ($mapping->method ? $mapping->method->toString() : '(class)');
|
|
$standardSet[$key] = true;
|
|
}
|
|
|
|
// Find missing in memory-managed
|
|
$missing = [];
|
|
foreach ($standardSet as $key => $value) {
|
|
if (! isset($memorySet[$key])) {
|
|
$missing[] = $key;
|
|
}
|
|
}
|
|
|
|
if (! empty($missing)) {
|
|
echo "Initializers found ONLY in standard discovery (" . count($missing) . "):\n";
|
|
foreach ($missing as $key) {
|
|
echo "- $key\n";
|
|
}
|
|
} else {
|
|
echo "✅ No missing initializers detected\n";
|
|
}
|
|
|
|
// Find files that might not be processed in memory-managed discovery
|
|
echo "\n=== Attribute Types Comparison ===\n";
|
|
$memoryTypes = $memoryRegistry->attributes->getAllTypes();
|
|
$standardTypes = $standardRegistry->attributes->getAllTypes();
|
|
|
|
foreach ($standardTypes as $type) {
|
|
$memoryCount = $memoryRegistry->attributes->getCount($type);
|
|
$standardCount = $standardRegistry->attributes->getCount($type);
|
|
$shortType = substr(strrchr($type, '\\'), 1) ?: $type;
|
|
|
|
if ($memoryCount !== $standardCount) {
|
|
echo "- $shortType: $memoryCount vs $standardCount (diff: " . ($standardCount - $memoryCount) . ")\n";
|
|
}
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
echo "❌ Error: " . $e->getMessage() . "\n";
|
|
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
|
|
}
|