Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tools/argus/r8_offcpu.awk # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers 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. 6 function 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 } 10 inb && /^\t/ { if ($1 !~ /^ffff/) { s = $2; if (!libc(s) && nk < 2) { k = k (nk ? " <- " : "") s; nk++ } } next } 11 inb && /^$/ { inb = 0; pend = (k == "" ? "?" : k) } 12 END { for (x in d) printf "%s\t%.1f\t%.1f\t%s\n", cfg, d[x] * 1e6 / R, c[x] / R, x }