Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Adds HTML report

AuthorDave Jarvis <email>
Date2026-02-09 22:23:26 GMT-0800
Commit0f005adf85f2fbf83bb22f11c607873b80f41d1d
Parent3b6e6de
Git.php
public function profileReport(): string {
if (empty($this->pStats)) {
- return "\nNo profiling data collected.\n";
+ return "<p>No profiling data collected.</p>";
}
// Sort by total time descending
uasort($this->pStats, fn($a, $b) => $b['time'] <=> $a['time']);
- $out = sprintf("\n%-35s | %6s | %9s | %9s\n", 'Method', 'Calls', 'Total(ms)', 'Avg(ms)');
- $out .= str_repeat('-', 68) . "\n";
+ $html = '<table border="1" cellspacing="0" cellpadding="5" style="border-collapse: collapse; font-family: monospace; width: 100%;">';
+ $html .= '<thead style="background: #eee;"><tr>';
+ $html .= '<th style="text-align: left;">Method</th>';
+ $html .= '<th style="text-align: right;">Calls</th>';
+ $html .= '<th style="text-align: right;">Total (ms)</th>';
+ $html .= '<th style="text-align: right;">Avg (ms)</th>';
+ $html .= '</tr></thead><tbody>';
foreach ($this->pStats as $name => $stat) {
- $totalMs = $stat['time'] * 1000;
- $avgMs = $stat['cnt'] > 0 ? $totalMs / $stat['cnt'] : 0;
+ $totalMs = $stat['time'] * 1000;
+ $avgMs = $stat['cnt'] > 0 ? $totalMs / $stat['cnt'] : 0;
- // Strip class name for cleaner output
- $cleanName = str_replace(__CLASS__ . '::', '', $name);
+ // Remove namespace/class prefix for cleaner display
+ $cleanName = str_replace(__CLASS__ . '::', '', $name);
- $out .= sprintf("%-35s | %6d | %9.2f | %9.2f\n",
- substr($cleanName, 0, 35),
- $stat['cnt'],
- $totalMs,
- $avgMs
- );
+ $html .= '<tr>';
+ $html .= '<td>' . htmlspecialchars($cleanName) . '</td>';
+ $html .= '<td style="text-align: right;">' . $stat['cnt'] . '</td>';
+ $html .= '<td style="text-align: right;">' . number_format($totalMs, 2) . '</td>';
+ $html .= '<td style="text-align: right;">' . number_format($avgMs, 2) . '</td>';
+ $html .= '</tr>';
}
- return $out;
+ $html .= '</tbody></table>';
+
+ return $html;
}
Delta21 lines added, 14 lines removed, 7-line increase