]> git.saurik.com Git - apple/xnu.git/blob - tools/trace/bridgetime.lua
cba2d522dd6ba28ecc8cc2291f35905e70fc3a1b
[apple/xnu.git] / tools / trace / bridgetime.lua
1 #!/usr/local/bin/luatrace -s
2
3 trace_codename = function(codename, callback)
4 local debugid = trace.debugid(codename)
5 if debugid ~= 0 then
6 trace.single(debugid,callback)
7 else
8 printf("WARNING: Cannot locate debugid for '%s'\n", codename)
9 end
10 end
11
12 initial_timestamp = 0
13 get_prefix = function(buf, char)
14 -- if initial_timestamp == 0 then
15 -- initial_timestamp = buf.timestamp
16 -- end
17 local secs = trace.convert_timestamp_to_nanoseconds(buf.timestamp - initial_timestamp) / 1000000000
18
19 return string.format("%s %6.9f %-30s",
20 char, secs, buf.debugname)
21 end
22
23 initial_arm_timestamp = 0
24 format_timestamp_arm = function(ts)
25 local secs = trace.convert_timestamp_to_nanoseconds(ts - initial_arm_timestamp) / 1000000000
26 return string.format("%6.9f", secs);
27 end
28
29 initial_intel_timestamp = 0
30 format_timestamp_intel = function(ts)
31 local secs = (ts - initial_intel_timestamp) / 1000000000
32 return string.format("%6.9f", secs);
33 end
34
35 format_timestamp_ns = function(ts)
36 local secs = (ts) / 1000000000
37 return string.format("%6.9f", secs);
38 end
39
40 trace_codename("MACH_CLOCK_BRIDGE_RESET_TS", function(buf)
41 local prefix = get_prefix(buf, "X")
42 local reason = "UNKNOWN";
43 if buf[3] == 1 then
44 reason = "RecvSentinel"
45 elseif buf[3] == 2 then
46 reason = "ResetTrue"
47 elseif buf[3] == 3 then
48 reason = "RateZero"
49 end
50 printf("%s %-15s ( %-10s %-10s ) ----------------------------------------\n",
51 prefix, reason, format_timestamp_arm(buf[1]), format_timestamp_intel(buf[2]))
52
53 -- initial_arm_timestamp = buf[1]
54 -- initial_intel_timestamp = buf[2]
55 end)
56
57 trace_codename("MACH_CLOCK_BRIDGE_TS_PARAMS", function(buf)
58 local prefix = get_prefix(buf, ">")
59
60 local rate
61 if darwin.uint64_to_double then
62 rate = darwin.uint64_to_double(buf[3])
63 else
64 rate = math.nan
65 end
66
67 printf("%s %30s( %-10s %-10s ) rate = %f\n",
68 prefix, "", format_timestamp_ns(buf[1]), format_timestamp_intel(buf[2]),
69 rate)
70 end)
71
72 trace_codename("MACH_CLOCK_BRIDGE_REMOTE_TIME", function(buf)
73 local prefix = get_prefix(buf, "-")
74
75 printf("%s ( %-10s %-10s ) @ %-20s\n",
76 prefix, format_timestamp_arm(buf[1]), format_timestamp_intel(buf[2]), format_timestamp_arm(buf[3]))
77 end)
78
79 trace_codename("MACH_CLOCK_BRIDGE_RCV_TS", function(buf)
80 local prefix = get_prefix(buf, "<")
81
82 if buf[2] == 0xfffffffffffffffe then
83 printf("%s ( %-10s Sleep )\n",
84 prefix, format_timestamp_arm(buf[1]), format_timestamp_intel(buf[2]))
85 elseif buf[2] == 0xfffffffffffffffd then
86 printf("%s ( %-10s Wake )\n",
87 prefix, format_timestamp_arm(buf[1]), format_timestamp_intel(buf[2]))
88 elseif buf[2] == 0xfffffffffffffffc then
89 printf("%s ( %-10s Reset )\n",
90 prefix, format_timestamp_arm(buf[1]), format_timestamp_intel(buf[2]))
91 else
92 printf("%s ( %-10s %-10s )\n",
93 prefix, format_timestamp_arm(buf[1]), format_timestamp_intel(buf[2]))
94 end
95
96 end)
97