# 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: "\t\t" 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 } }