Translated using Weblate (Portuguese)
[phpmyadmin.git] / src / Profiling.php
blob6aa20807f9b892c8da372a84acaf1785f1aea290
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin;
7 use PhpMyAdmin\Utils\SessionCache;
9 /**
10 * Statement resource usage.
12 final class Profiling
14 public static function isSupported(DatabaseInterface $dbi): bool
16 if (SessionCache::has('profiling_supported')) {
17 return (bool) SessionCache::get('profiling_supported');
20 /**
21 * 5.0.37 has profiling but for example, 5.1.20 does not
22 * (avoid a trip to the server for MySQL before 5.0.37)
23 * and do not set a constant as we might be switching servers
25 if ($dbi->fetchValue('SELECT @@have_profiling')) {
26 SessionCache::set('profiling_supported', true);
28 return true;
31 SessionCache::set('profiling_supported', false);
33 return false;
36 public static function enable(DatabaseInterface $dbi): void
38 if (! isset($_SESSION['profiling']) || ! self::isSupported($dbi)) {
39 return;
42 $dbi->query('SET PROFILING=1;');
45 /** @psalm-return list<array{Status: non-empty-string, Duration: numeric-string}> */
46 public static function getInformation(DatabaseInterface $dbi): array
48 if (! isset($_SESSION['profiling']) || ! self::isSupported($dbi)) {
49 return [];
52 /** @psalm-var list<array{Status: non-empty-string, Duration: numeric-string}> $profile */
53 $profile = $dbi->fetchResult('SHOW PROFILE;');
55 return $profile;
58 /**
59 * Check if profiling was requested and remember it.
61 public static function check(DatabaseInterface $dbi, ResponseRenderer $response): void
63 if (isset($_REQUEST['profiling']) && self::isSupported($dbi)) {
64 $_SESSION['profiling'] = true;
65 } elseif (isset($_REQUEST['profiling_form'])) {
66 // the checkbox was unchecked
67 unset($_SESSION['profiling']);
70 if (! isset($_SESSION['profiling'])) {
71 return;
74 $scripts = $response->getHeader()->getScripts();
75 $scripts->addFiles([
76 'vendor/chart.umd.js',
77 'vendor/jquery/jquery.tablesorter.js',
78 ]);