aboutsummaryrefslogtreecommitdiff
path: root/scripts/lib/trace-phase-extract.awk
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/trace-phase-extract.awk')
-rw-r--r--scripts/lib/trace-phase-extract.awk75
1 files changed, 75 insertions, 0 deletions
diff --git a/scripts/lib/trace-phase-extract.awk b/scripts/lib/trace-phase-extract.awk
new file mode 100644
index 0000000..429f8cf
--- /dev/null
+++ b/scripts/lib/trace-phase-extract.awk
@@ -0,0 +1,75 @@
+# scripts/lib/trace-phase-extract.awk
+# Aggregate xtrace timing markers into coarse trbldoc pipeline phases.
+#
+# Input: trace.*.log files emitted by scripts/lib/trace-init.sh in time mode.
+# Output rows: "<total_ms>\t<hits>\t<phase>" at END.
+#
+# Required -v vars:
+# SRC_BASE
+# L_DISCOVER_END
+# L_EXTRACT_END
+# L_ORDER_END
+# L_RENDER_END
+# L_NAV_END
+# L_REFS_END
+# L_TOC_END
+# L_ASSEMBLE_END
+
+function basename(p) {
+ sub(/.*\//, "", p)
+ sub(/.*\\/, "", p)
+ return p
+}
+
+function parse(line, s, n, f, loc) {
+ if (line !~ /@+TBL@@ /) return 0
+ s = line
+ sub(/^.*TBL@@ /, "", s)
+ n = split(s, f, " ")
+ if (n < 2) return 0
+ loc = f[1]
+ if (!match(loc, /:[0-9]+$/)) return 0
+ g_line = substr(loc, RSTART + 1) + 0
+ g_base = basename(substr(loc, 1, RSTART - 1))
+ g_epoch = f[2]
+ return 1
+}
+
+function phase_for(line) {
+ if (line <= L_DISCOVER_END) return "discover_sources"
+ if (line <= L_EXTRACT_END) return "extract_chunks"
+ if (line <= L_ORDER_END) return "build_render_order"
+ if (line <= L_RENDER_END) return "render_chunks"
+ if (line <= L_NAV_END) return "build_nav"
+ if (line <= L_REFS_END) return "resolve_refs"
+ if (line <= L_TOC_END) return "apply_toc"
+ if (line <= L_ASSEMBLE_END) return "assemble_site"
+ return "other"
+}
+
+BEGIN {
+ if (SRC_BASE == "") SRC_BASE = "trbldoc.sh"
+}
+
+FNR == 1 { have_prev = 0 }
+
+{
+ if (!parse($0)) next
+ if (g_base != SRC_BASE) next
+ if (have_prev && g_epoch != "" && prev_epoch != "") {
+ d = g_epoch - prev_epoch
+ if (d < 0) d = 0
+ ph = phase_for(prev_line)
+ ms[ph] += d * 1000.0
+ hits[ph] += 1
+ }
+ prev_line = g_line
+ prev_epoch = g_epoch
+ have_prev = 1
+}
+
+END {
+ for (ph in ms) {
+ printf "%.3f\t%d\t%s\n", ms[ph], hits[ph], ph
+ }
+}