aboutsummaryrefslogtreecommitdiff
path: root/scripts/lib/trace-phase-extract.awk
blob: 429f8cfcb050d3439a29cbe0d2341e0b88d4f837 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
  }
}