1212use Framework \Autoload \Autoloader ;
1313use Framework \Autoload \Preloader ;
1414use Framework \Debug \Collector ;
15+ use Framework \Debug \Debugger ;
1516use UnitEnum ;
1617
1718/**
@@ -81,8 +82,14 @@ public function getContents() : string
8182 <?= $ this ->renderPreload () ?>
8283 <h1>Declarations</h1>
8384 <?php
84- $ declarations = Preloader::getAllDeclarations (); ?>
85- <p>Total of <?= \count ($ declarations ) ?> declarations.</p>
85+ $ declarations = Preloader::getAllDeclarations ();
86+ $ classes = $ this ->getPreloadStatistics ()['classes ' ] ?? [];
87+ ?>
88+ <p>Total of <?= \count ($ declarations ) ?> declarations.
89+ <?php if ($ classes ): ?>
90+ <span style="color: green"><?= \count ($ classes ) ?> are preloaded.</span>
91+ <?php endif ?>
92+ </p>
8693 <table>
8794 <thead>
8895 <tr>
@@ -94,14 +101,24 @@ public function getContents() : string
94101 </tr>
95102 </thead>
96103 <tbody>
104+ <?php
105+ $ count = 0 ;
106+ ?>
97107 <?php foreach ($ declarations as $ index => $ declaration ): ?>
98108 <?php
99109 $ data = $ this ->getDataByDeclaration ($ declaration ); ?>
100110 <tr<?= $ data ? ' class="active" title="Searched with the current Autoloader" '
101111 : '' ?> >
102112 <td><?= $ index + 1 ?> </td>
103113 <td><?= $ this ->getDeclarationType ($ declaration ) ?> </td>
104- <td><?= $ declaration ?> </td>
114+ <td<?= \in_array ($ declaration , $ classes )
115+ ? ' style="color: green" title=" ' . (\MessageFormatter::formatMessage (
116+ 'en ' ,
117+ '{number, ordinal} ' ,
118+ ['number ' => ++$ count ]
119+ )) . ' preloaded" ' : '' ?> >
120+ <?= $ declaration ?>
121+ </td>
105122 <td><?php
106123 if ($ data && isset ($ data ['loaded ' ])) {
107124 echo $ data ['loaded ' ] ? 'Yes ' : 'No ' ;
@@ -234,6 +251,7 @@ protected function renderPreload() : string
234251 $ result .= '<p><strong>User:</strong> '
235252 . \htmlentities ($ conf ['directives ' ]['opcache.preload_user ' ]) . '</p> ' ;
236253 }
254+ $ result .= $ this ->renderPreloadStatistics ();
237255 return $ result ;
238256 }
239257 return '<p>Preload file has not been set.</p> ' ;
@@ -249,6 +267,41 @@ protected function getOpcacheConfiguration() : ?array
249267 : null ;
250268 }
251269
270+ protected function renderPreloadStatistics () : string
271+ {
272+ $ result = '' ;
273+ $ statistics = $ this ->getPreloadStatistics ();
274+ if ($ statistics ) {
275+ $ memory = Debugger::convertSize ($ statistics ['memory_consumption ' ]);
276+ $ classes = $ statistics ['classes ' ];
277+ $ result .= '<p><strong>Memory:</strong> ' . $ memory . '</p> ' ;
278+ $ result .= '<p><strong>Classes:</strong> ' . \count ($ classes ) . '</p> ' ;
279+ }
280+ return $ result ;
281+ }
282+
283+ /**
284+ * @return array<string,mixed>
285+ */
286+ protected function getPreloadStatistics () : array
287+ {
288+ $ statistics = [];
289+ if (\function_exists ('opcache_get_status ' )) {
290+ $ status = (array ) \opcache_get_status ();
291+ $ statistics = $ status ['preload_statistics ' ] ?? [];
292+ }
293+ if (empty ($ statistics ) && \defined ('IS_TESTING ' ) && IS_TESTING ) {
294+ $ statistics = [
295+ 'memory_consumption ' => 500000 ,
296+ 'classes ' => [
297+ 'Foo ' ,
298+ 'Bar ' ,
299+ ],
300+ ];
301+ }
302+ return $ statistics ;
303+ }
304+
252305 protected function getDeclarationType (string $ declaration ) : string
253306 {
254307 if (\in_array ($ declaration , \get_declared_classes (), true )) {
0 commit comments