| | public function profileReport(): string { |
| | if (empty($this->pStats)) { |
| | - return "\n\n"; |
| | + return "\nNo profiling data collected.\n"; |
| | } |
| | |
| | // Sort by total time descending |
| | - uasort( $this->pStats, fn($a, $b) => $b['time'] <=> $a['time'] ); |
| | + uasort($this->pStats, fn($a, $b) => $b['time'] <=> $a['time']); |
| | |
| | - $out = "\n\n"; |
| | + $out = sprintf("\n%-35s | %6s | %9s | %9s\n", 'Method', 'Calls', 'Total(ms)', 'Avg(ms)'); |
| | + $out .= str_repeat('-', 68) . "\n"; |
| | + |
| | + foreach ($this->pStats as $name => $stat) { |
| | + $totalMs = $stat['time'] * 1000; |
| | + $avgMs = $stat['cnt'] > 0 ? $totalMs / $stat['cnt'] : 0; |
| | + |
| | + // Strip class name for cleaner output |
| | + $cleanName = str_replace(__CLASS__ . '::', '', $name); |
| | + |
| | + $out .= sprintf("%-35s | %6d | %9.2f | %9.2f\n", |
| | + substr($cleanName, 0, 35), |
| | + $stat['cnt'], |
| | + $totalMs, |
| | + $avgMs |
| | + ); |
| | + } |
| | + |
| | return $out; |
| | } |