1 #!/usr/local/bin/luatrace -s
3 trace_codename = function(codename, callback)
4 local debugid = trace.debugid(codename)
6 trace.single(debugid,callback)
8 printf("WARNING: Cannot locate debugid for '%s'\n", codename)
13 get_prefix = function(buf, char)
14 -- if initial_timestamp == 0 then
15 -- initial_timestamp = buf.timestamp
17 local secs = trace.convert_timestamp_to_nanoseconds(buf.timestamp - initial_timestamp) / 1000000000
19 return string.format("%s %6.9f %-30s",
20 char, secs, buf.debugname)
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);
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);
35 format_timestamp_ns = function(ts)
36 local secs = (ts) / 1000000000
37 return string.format("%6.9f", secs);
40 trace_codename("MACH_CLOCK_BRIDGE_RESET_TS", function(buf)
41 local prefix = get_prefix(buf, "X")
42 local reason = "UNKNOWN";
44 reason = "RecvSentinel"
45 elseif buf[3] == 2 then
47 elseif buf[3] == 3 then
50 printf("%s %-15s ( %-10s %-10s ) ----------------------------------------\n",
51 prefix, reason, format_timestamp_arm(buf[1]), format_timestamp_intel(buf[2]))
53 -- initial_arm_timestamp = buf[1]
54 -- initial_intel_timestamp = buf[2]
57 trace_codename("MACH_CLOCK_BRIDGE_TS_PARAMS", function(buf)
58 local prefix = get_prefix(buf, ">")
61 if darwin.uint64_to_double then
62 rate = darwin.uint64_to_double(buf[3])
67 printf("%s %30s( %-10s %-10s ) rate = %f\n",
68 prefix, "", format_timestamp_ns(buf[1]), format_timestamp_intel(buf[2]),
72 trace_codename("MACH_CLOCK_BRIDGE_REMOTE_TIME", function(buf)
73 local prefix = get_prefix(buf, "-")
75 printf("%s ( %-10s %-10s ) @ %-20s\n",
76 prefix, format_timestamp_arm(buf[1]), format_timestamp_intel(buf[2]), format_timestamp_arm(buf[3]))
79 trace_codename("MACH_CLOCK_BRIDGE_RCV_TS", function(buf)
80 local prefix = get_prefix(buf, "<")
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]))
92 printf("%s ( %-10s %-10s )\n",
93 prefix, format_timestamp_arm(buf[1]), format_timestamp_intel(buf[2]))