diff options
Diffstat (limited to 'scripts/lib/render-hotspots.awk')
| -rw-r--r-- | scripts/lib/render-hotspots.awk | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/lib/render-hotspots.awk b/scripts/lib/render-hotspots.awk new file mode 100644 index 0000000..0eb2b6d --- /dev/null +++ b/scripts/lib/render-hotspots.awk @@ -0,0 +1,56 @@ +# scripts/lib/render-hotspots.awk +# Render a per-line hotspot HTML report from sorted TSV rows. +# Input TSV (sorted slowest-first): "<total_ms>\t<hits>\t<file>\t<line>". +# Variables: +# -v TITLE="..." +# -v SRC=<path> source file for the primary target, used to show line text. + +function esc(s) { + gsub(/&/, "\\&", s); gsub(/</, "\\<", s); gsub(/>/, "\\>", s) + return s +} + +BEGIN { + FS = "\t"; n = 0 + # Load source lines for text display (best effort). + if (SRC != "") { + i = 0 + while ((getline ln < SRC) > 0) { i++; srctext[i] = ln } + close(SRC) + srcbase = SRC; sub(/.*\//, "", srcbase); sub(/.*\\/, "", srcbase) + } +} + +{ + n++ + ms[n] = $1 + 0 + hits[n] = $2 + 0 + file[n] = $3 + line[n] = $4 + 0 + if (n == 1) maxv = $1 + 0 +} + +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 "code{font:12px/1.4 monospace;white-space:pre}" + print ".bar{height:.7em;background:#e8703a;border-radius:2px}" + print "</style></head><body>" + print "<h1>" esc(TITLE) "</h1>" + print "<div class=\"meta\">cumulative self-time per source line, slowest first</div>" + print "<table><thead><tr><th>#</th><th>ms</th><th>hits</th><th>file:line</th><th>source</th><th></th></tr></thead><tbody>" + for (i = 1; i <= n; i++) { + w = (maxv > 0 ? (ms[i] * 100.0 / maxv) : 0) + txt = "" + if (file[i] == srcbase && (line[i] in srctext)) txt = srctext[line[i]] + printf "<tr><td class=\"num\">%d</td><td class=\"num\">%.1f</td><td class=\"num\">%d</td>", i, ms[i], hits[i] + printf "<td>%s:%d</td><td><code>%s</code></td>", esc(file[i]), line[i], esc(txt) + printf "<td><div class=\"bar\" style=\"width:%.1f%%\"></div></td></tr>\n", w + } + print "</tbody></table></body></html>" +} |
