From 22c8114fcc96105d35a6a2cb9ead5dc0184280b5 Mon Sep 17 00:00:00 2001 From: Natan Felles Date: Sun, 8 Dec 2024 00:13:29 -0300 Subject: [PATCH] Improves information about preloading --- src/Debug/AutoloadCollector.php | 59 +++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/src/Debug/AutoloadCollector.php b/src/Debug/AutoloadCollector.php index 75d89d1..45a1687 100644 --- a/src/Debug/AutoloadCollector.php +++ b/src/Debug/AutoloadCollector.php @@ -12,6 +12,7 @@ use Framework\Autoload\Autoloader; use Framework\Autoload\Preloader; use Framework\Debug\Collector; +use Framework\Debug\Debugger; use UnitEnum; /** @@ -81,8 +82,14 @@ public function getContents() : string renderPreload() ?>

Declarations

-

Total of declarations.

+ $declarations = Preloader::getAllDeclarations(); + $classes = $this->getPreloadStatistics()['classes'] ?? []; + ?> +

Total of declarations. + + are preloaded. + +

@@ -94,6 +101,9 @@ public function getContents() : string + $declaration): ?> getDataByDeclaration($declaration); ?> @@ -101,7 +111,14 @@ public function getContents() : string : '' ?>> - + > + +
getDeclarationType($declaration) ?>User: ' . \htmlentities($conf['directives']['opcache.preload_user']) . '

'; } + $result .= $this->renderPreloadStatistics(); return $result; } return '

Preload file has not been set.

'; @@ -249,6 +267,41 @@ protected function getOpcacheConfiguration() : ?array : null; } + protected function renderPreloadStatistics() : string + { + $result = ''; + $statistics = $this->getPreloadStatistics(); + if ($statistics) { + $memory = Debugger::convertSize($statistics['memory_consumption']); + $classes = $statistics['classes']; + $result .= '

Memory: ' . $memory . '

'; + $result .= '

Classes: ' . \count($classes) . '

'; + } + return $result; + } + + /** + * @return array + */ + protected function getPreloadStatistics() : array + { + $statistics = []; + if (\function_exists('opcache_get_status')) { + $status = (array) \opcache_get_status(); + $statistics = $status['preload_statistics'] ?? []; + } + if (empty($statistics) && \defined('IS_TESTING') && IS_TESTING) { + $statistics = [ + 'memory_consumption' => 500000, + 'classes' => [ + 'Foo', + 'Bar', + ], + ]; + } + return $statistics; + } + protected function getDeclarationType(string $declaration) : string { if (\in_array($declaration, \get_declared_classes(), true)) {