xref: /plan9-contrib/sys/src/cmd/ptrace/guide (revision af198995f3f1f1d87a386835b2bcd15ca90a6fed)
1Example from T.txt (mk all)
2trace for pid 195
3>awk '$2 == 195'
4
5number of page faults
6>awk '$2 == 195 && $6 == "pfault"' | wc -l
7500
8
9number of sleeps
10>awk '$2 == 195 && $5 == "Sleep"' | wc -l
11197
12
13number of core switches
14awk 'BEGIN{nsw = 0; last = -3;}
15	$2 == 195 {if($3 != last) nsw++; last=$3}
16	END{print nsw}' <T.txt
17217
18
19number of acpi domain switches
20awk 'BEGIN{nsw = 0; last = -3;}
21	$2 == 195 {if($3%8 != last%8) nsw++; last=$3}
22	END{print nsw}' <T.txt
23188
24
25times from ready to run
26awk 'BEGIN{nsw = 0; last = -3;}
27	$2 != 195 {next}
28	$6 == "Ready" {stime = $0; ln = NR}
29	$6 == "Run" {if(stime) print $0 - stime, ln, NR; stime = 0} ' <ptrace.out |
30 sort -nr
3169695 T.txt:918 930
3243670 15110 15111
3338796 324 325
3436930 2172 2173
35
36which gives
37  0s 287m 326µ 512n     195 00 mk   Ready  Ready     	4 287326512 0x0
38  0s 287m 370µ 182n     195 21 mk   Run    Run       	3 287370182 0x0
39as the top.
40i.e. core 0 makes it ready, and core 21 picks it 69.695µs laters.
41
42times for sleeps, and line numbers in the trace for the sleep and wakeup
43sorted
44awk 'BEGIN{nsw = 0; last = -3;}
45	$2 != 195 {next}
46	$5 == "Sleep" {stime = $0; ln = NR}
47	$5 == "Ready" {print $0 - stime, ln, NR} ' <T.txt | sort -nr
48
49This gives:
50381601037 15175 19811
51140216350 10518 15064
5258225471 6569 9619
53...
54
55which is
56  0s 288m 716µ 164n     195 03 mk   Sleep      await    ...
57  0s 288m 717µ 848n     195 03 mk   Sleep      Wakeme pc 0xfffffff017e1ac ...
58
59Thus most of the time it's waiting for children, as expected.
60