interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / argus / r8_offcpu.awk

12 lines · 1128 bytes Raw Blame History
1# Main-thread off-CPU time by blocking site (speed2). Input: `perf script --show-switch-events
2# -F tid,time,event,ip,sym` of `perf record --no-inherit -e context-switches -c 1 -g --switch-events`
3# runs, concatenated with a blank line between. Vars: cfg (label), R (runs). Output: cfg, us/run, waits/run, key.
4# Off-CPU time of one thread: context-switches sample (callchain) -> next PERF_RECORD_SWITCH IN.
5# Key: the first two non-libc user frames. Output: per key total us / R runs, count / R.
6function libc(s) { return s ~ /^(_|lll_|futex|pthread|\[unknown\]|syscall|nanosleep|clock_nanosleep|waitpid|wait4|posix_spawn|read|write|fread|fopen|fclose|open|close|__)/ }
7/PERF_RECORD_SWITCH IN/ { t = $2 + 0; if (pend != "") { d[pend] += t - ts; c[pend]++; pend = "" } next }
8/PERF_RECORD_SWITCH OUT/ { next }
9/context-switches:/ { ts = $2 + 0; inb = 1; k = ""; nk = 0; next }
10inb && /^\t/ { if ($1 !~ /^ffff/) { s = $2; if (!libc(s) && nk < 2) { k = k (nk ? " <- " : "") s; nk++ } } next }
11inb && /^$/ { inb = 0; pend = (k == "" ? "?" : k) }
12END { for (x in d) printf "%s\t%.1f\t%.1f\t%s\n", cfg, d[x] * 1e6 / R, c[x] / R, x }