getUser();
if (($user['role'] ?? null) !== 'admin') {
return '';
}
$time_ms = (microtime(true) - ($_SERVER['REQUEST_TIME_FLOAT'] ?? microtime(true))) * 1000;
$memory = memory_get_peak_usage(true);
$query_count = Profiler::count();
$query_time = Profiler::totalTime();
$rows = '';
foreach (Profiler::entries() as $entry) {
$rows .= '
' .
'| ' . number_format($entry['time_ms'], 2) . ' ms | ' .
'' . htmlspecialchars($entry['sql'], ENT_QUOTES, 'UTF-8') . ' | ' .
'' . htmlspecialchars(json_encode($entry['params'], JSON_UNESCAPED_UNICODE), ENT_QUOTES, 'UTF-8') . ' | ' .
'
';
}
return self::html($time_ms, $memory, $query_count, $query_time, $rows);
}
/**
* @param float $time_ms Время выполнения запроса, мс
* @param int $memory Пиковое потребление памяти, байт
* @param int $query_count Число SQL-запросов
* @param float $query_time Суммарное время SQL-запросов, мс
* @param string $rows Готовые со списком запросов
* @return string
*/
private static function html(float $time_ms, int $memory, int $query_count, float $query_time, string $rows): string
{
$memory_mb = number_format($memory / 1024 / 1024, 2);
$time = number_format($time_ms, 1);
$query_ms = number_format($query_time, 1);
return <<
Profiler
время: {$time} ms
память: {$memory_mb} MB
SQL: {$query_count} ({$query_ms} ms)
| Время |
SQL |
Параметры |
{$rows}
HTML;
}
}