Merge pull request #19786 from MauricioFauth/Innodb_getPageBufferpool… · phpmyadmin/phpmyadmin@e5acf85
11<?php
2-/**
3- * The InnoDB storage engine
4- */
5263declare(strict_types=1);
7485namespace PhpMyAdmin\Engines;
96107use PhpMyAdmin\Dbal\DatabaseInterface;
8+use PhpMyAdmin\Engines\Innodb\BufferPool;
119use PhpMyAdmin\StorageEngine;
12-use PhpMyAdmin\Util;
10+use PhpMyAdmin\Template;
13111412use function __;
1513use function htmlspecialchars;
16-use function implode;
17141815/**
1916 * The InnoDB storage engine
@@ -110,141 +107,11 @@ public function getInfoPages(): array
110107 *
111108 * @return string html table with stats
112109 */
113-public function getPageBufferpool(): string
110+public function getPageBufferPool(): string
114111 {
115-// The following query is only possible because we know
116-// that we are on MySQL 5 here (checked above)!
117-// side note: I love MySQL 5 for this. :-)
118-$sql = 'SHOW STATUS'
119- . ' WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\''
120- . ' OR Variable_name = \'Innodb_page_size\';';
121-$status = DatabaseInterface::getInstance()->fetchResult($sql, 0, 1);
122-123-/** @var string[] $bytes */
124-$bytes = Util::formatByteDown($status['Innodb_buffer_pool_pages_total'] * $status['Innodb_page_size']);
125-126-$output = '<table class="table table-striped table-hover w-auto float-start caption-top">' . "\n"
127- . ' <caption>' . "\n"
128- . ' ' . __('Buffer Pool Usage') . "\n"
129- . ' </caption>' . "\n"
130- . ' <tfoot>' . "\n"
131- . ' <tr>' . "\n"
132- . ' <th colspan="2">' . "\n"
133- . ' ' . __('Total:') . ' '
134- . Util::formatNumber($status['Innodb_buffer_pool_pages_total'], 0)
135- . ' ' . __('pages')
136- . ' / '
137- . implode(' ', $bytes) . "\n"
138- . ' </th>' . "\n"
139- . ' </tr>' . "\n"
140- . ' </tfoot>' . "\n"
141- . ' <tbody>' . "\n"
142- . ' <tr>' . "\n"
143- . ' <th scope="row">' . __('Free pages') . '</th>' . "\n"
144- . ' <td class="font-monospace text-end">'
145- . Util::formatNumber($status['Innodb_buffer_pool_pages_free'], 0)
146- . '</td>' . "\n"
147- . ' </tr>' . "\n"
148- . ' <tr>' . "\n"
149- . ' <th scope="row">' . __('Dirty pages') . '</th>' . "\n"
150- . ' <td class="font-monospace text-end">'
151- . Util::formatNumber($status['Innodb_buffer_pool_pages_dirty'], 0)
152- . '</td>' . "\n"
153- . ' </tr>' . "\n"
154- . ' <tr>' . "\n"
155- . ' <th scope="row">' . __('Pages containing data') . '</th>' . "\n"
156- . ' <td class="font-monospace text-end">'
157- . Util::formatNumber($status['Innodb_buffer_pool_pages_data'], 0) . "\n"
158- . '</td>' . "\n"
159- . ' </tr>' . "\n"
160- . ' <tr>' . "\n"
161- . ' <th scope="row">' . __('Pages to be flushed') . '</th>' . "\n"
162- . ' <td class="font-monospace text-end">'
163- . Util::formatNumber($status['Innodb_buffer_pool_pages_flushed'], 0) . "\n"
164- . '</td>' . "\n"
165- . ' </tr>' . "\n"
166- . ' <tr>' . "\n"
167- . ' <th scope="row">' . __('Busy pages') . '</th>' . "\n"
168- . ' <td class="font-monospace text-end">'
169- . Util::formatNumber($status['Innodb_buffer_pool_pages_misc'], 0) . "\n"
170- . '</td>' . "\n"
171- . ' </tr>';
172-173-// not present at least since MySQL 5.1.40
174-if (isset($status['Innodb_buffer_pool_pages_latched'])) {
175-$output .= ' <tr>'
176- . ' <th scope="row">' . __('Latched pages') . '</th>'
177- . ' <td class="font-monospace text-end">'
178- . Util::formatNumber($status['Innodb_buffer_pool_pages_latched'], 0)
179- . '</td>'
180- . ' </tr>';
181- }
182-183-$output .= ' </tbody>' . "\n"
184- . '</table>' . "\n\n"
185- . '<table class="table table-striped table-hover w-auto ms-4 float-start caption-top">' . "\n"
186- . ' <caption>' . "\n"
187- . ' ' . __('Buffer Pool Activity') . "\n"
188- . ' </caption>' . "\n"
189- . ' <tbody>' . "\n"
190- . ' <tr>' . "\n"
191- . ' <th scope="row">' . __('Read requests') . '</th>' . "\n"
192- . ' <td class="font-monospace text-end">'
193- . Util::formatNumber($status['Innodb_buffer_pool_read_requests'], 0) . "\n"
194- . '</td>' . "\n"
195- . ' </tr>' . "\n"
196- . ' <tr>' . "\n"
197- . ' <th scope="row">' . __('Write requests') . '</th>' . "\n"
198- . ' <td class="font-monospace text-end">'
199- . Util::formatNumber($status['Innodb_buffer_pool_write_requests'], 0) . "\n"
200- . '</td>' . "\n"
201- . ' </tr>' . "\n"
202- . ' <tr>' . "\n"
203- . ' <th scope="row">' . __('Read misses') . '</th>' . "\n"
204- . ' <td class="font-monospace text-end">'
205- . Util::formatNumber($status['Innodb_buffer_pool_reads'], 0) . "\n"
206- . '</td>' . "\n"
207- . ' </tr>' . "\n"
208- . ' <tr>' . "\n"
209- . ' <th scope="row">' . __('Write waits') . '</th>' . "\n"
210- . ' <td class="font-monospace text-end">'
211- . Util::formatNumber($status['Innodb_buffer_pool_wait_free'], 0) . "\n"
212- . '</td>' . "\n"
213- . ' </tr>' . "\n"
214- . ' <tr>' . "\n"
215- . ' <th scope="row">' . __('Read misses in %') . '</th>' . "\n"
216- . ' <td class="font-monospace text-end">'
217- . ($status['Innodb_buffer_pool_read_requests'] == 0
218- ? '---'
219- : htmlspecialchars(
220- Util::formatNumber(
221-$status['Innodb_buffer_pool_reads'] * 100
222- / $status['Innodb_buffer_pool_read_requests'],
223-3,
224-2,
225- ),
226- ) . ' %') . "\n"
227- . '</td>' . "\n"
228- . ' </tr>' . "\n"
229- . ' <tr>' . "\n"
230- . ' <th scope="row">' . __('Write waits in %') . '</th>' . "\n"
231- . ' <td class="font-monospace text-end">'
232- . ($status['Innodb_buffer_pool_write_requests'] == 0
233- ? '---'
234- : htmlspecialchars(
235- Util::formatNumber(
236-$status['Innodb_buffer_pool_wait_free'] * 100
237- / $status['Innodb_buffer_pool_write_requests'],
238-3,
239-2,
240- ),
241- ) . ' %') . "\n"
242- . '</td>' . "\n"
243- . ' </tr>' . "\n"
244- . ' </tbody>' . "\n"
245- . '</table>' . "\n";
246-247-return $output;
112+return (new Template())->render('server/engines/_innodb_buffer_pool', [
113+'buffer_pool' => $this->getBufferPoolStatus(),
114+ ]);
248115 }
249116250117/**
@@ -313,4 +180,14 @@ public function supportsFilePerTable(): bool
313180314181return $dbi->fetchValue("SHOW GLOBAL VARIABLES LIKE 'innodb_file_per_table';", 1) === 'ON';
315182 }
183+184+private function getBufferPoolStatus(): BufferPool
185+ {
186+$result = DatabaseInterface::getInstance()->tryQuery(
187+"SHOW STATUS WHERE Variable_name LIKE 'Innodb\\_buffer\\_pool\\_%' OR Variable_name = 'Innodb_page_size';",
188+ cacheAffectedRows: false,
189+ );
190+191+return BufferPool::fromResult($result !== false ? $result->fetchAllKeyPair() : []);
192+ }
316193}