diff options
Diffstat (limited to 'scripts/lib/render-phases.awk')
| -rw-r--r-- | scripts/lib/render-phases.awk | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/scripts/lib/render-phases.awk b/scripts/lib/render-phases.awk new file mode 100644 index 0000000..fcb11ec --- /dev/null +++ b/scripts/lib/render-phases.awk @@ -0,0 +1,41 @@ +# scripts/lib/render-phases.awk +# Render per-phase hotspot HTML from sorted TSV rows. +# Input TSV: "<total_ms>\t<hits>\t<phase>". +# Variables: +# -v TITLE="..." + +function esc(s) { + gsub(/&/, "\\&", s); gsub(/</, "\\<", s); gsub(/>/, "\\>", s) + return s +} + +BEGIN { FS = "\t"; n = 0 } + +{ + n++ + ms[n] = $1 + 0 + hits[n] = $2 + 0 + phase[n] = $3 + if (n == 1) maxv = ms[n] +} + +END { + print "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\">" + print "<title>" esc(TITLE) "</title>" + print "<style>body{font:14px/1.5 sans-serif;margin:0;padding:1.5rem;color:#111}" + print "h1{font-size:18px}.meta{color:#555;margin-bottom:1rem}" + print "table{border-collapse:collapse;width:100%}" + print "th,td{padding:.3rem .5rem;text-align:left;border-bottom:1px solid #eee}" + print "td.num{text-align:right;font-variant-numeric:tabular-nums}" + print ".bar{height:.7em;background:#4cbf8f;border-radius:2px}" + print "</style></head><body>" + print "<h1>" esc(TITLE) "</h1>" + print "<div class=\"meta\">cumulative self-time by pipeline phase, slowest first</div>" + print "<table><thead><tr><th>#</th><th>ms</th><th>hits</th><th>phase</th><th></th></tr></thead><tbody>" + for (i = 1; i <= n; i++) { + w = (maxv > 0 ? (ms[i] * 100.0 / maxv) : 0) + printf "<tr><td class=\"num\">%d</td><td class=\"num\">%.1f</td><td class=\"num\">%d</td><td>%s</td>", i, ms[i], hits[i], esc(phase[i]) + printf "<td><div class=\"bar\" style=\"width:%.1f%%\"></div></td></tr>\n", w + } + print "</tbody></table></body></html>" +} |
