1 #!/usr/local/bin/luatrace -s
3 trace_eventname = function(codename, callback)
4 local debugid = trace.debugid(codename)
6 trace.single(debugid,callback)
8 printf("WARNING: Cannot locate debugid for '%s'\n", codename)
14 function event_prefix_string(buf, workq)
15 if initial_timestamp == 0 then
16 initial_timestamp = buf.timestamp
18 local secs = trace.convert_timestamp_to_nanoseconds(buf.timestamp - initial_timestamp) / 1000000000
21 if trace.debugid_is_start(buf.debugid) then
23 elseif trace.debugid_is_end(buf.debugid) then
31 local prefix = string.format("%s %6.9f %-17s [%05d.%06x] %-28s\t",
32 type, secs, proc, buf.pid, buf.threadid, buf.debugname)
34 prefix = prefix .. string.format(" 0x%16x", buf.arg1)
40 function qos_string(qos)
58 return string.format("??[0x%x]", qos)
62 function state_string(strings, state)
65 for name, bit in pairs(strings) do
66 if (state & bit) == bit then
77 kqrequest_state_strings = {
78 ['THREQUESTED'] = 0x02,
84 kqueue_state_strings = {
93 ['PROCESSING'] = 0x100,
99 knote_state_strings = {
102 ['DISABLED'] = 0x0004,
103 ['DROPPING'] = 0x0008,
105 ['ATTACHING'] = 0x0020,
106 ['STAYACTIVE'] = 0x0040,
107 ['DEFERDELETE'] = 0x0080,
108 ['ATTACHED'] = 0x0100,
109 ['DISPATCH'] = 0x0200,
110 ['UDATA_SPECIFIC'] = 0x0400,
111 ['SUPPRESSED'] = 0x0800,
112 ['MERGE_QOS'] = 0x1000,
113 ['REQVANISH'] = 0x2000,
114 ['VANISHED'] = 0x4000,
117 kevent_flags_strings = {
121 ['DISABLE'] = 0x0008,
122 ['ONESHOT'] = 0x0010,
124 ['RECEIPT'] = 0x0040,
125 ['DISPATCH'] = 0x0080,
126 ['UDATA_SPECIFIC'] = 0x0100,
127 ['VANISHED'] = 0x0200,
134 function kevent_filter_string(filt)
137 elseif filt == -2 then
139 elseif filt == -3 then
141 elseif filt == -4 then
143 elseif filt == -5 then
145 elseif filt == -6 then
147 elseif filt == -7 then
149 elseif filt == -8 then
151 elseif filt == -9 then
153 elseif filt == -10 then
156 elseif filt == -12 then
158 elseif filt == -13 then
160 elseif filt == -14 then
161 return 'MEMORYSTATUS'
162 elseif filt == 15 then
164 elseif filt == 16 then
166 elseif filt == 17 then
168 elseif filt == 18 then
170 elseif filt == 19 then
172 elseif filt == 20 then
174 elseif filt == 21 then
176 elseif filt == 22 then
178 elseif filt == 23 then
180 elseif filt == 24 then
181 return 'SKYWALK_CHANNEL_W'
182 elseif filt == 25 then
183 return 'SKYWALK_CHANNEL_R'
184 elseif filt == 26 then
186 elseif filt == 27 then
188 elseif filt == 28 then
189 return 'SKYWALK_CHANNEL_E'
190 elseif filt == 29 then
193 return string.format('[%d]', filt)
199 function processing_begin(workq)
201 local prefix = event_prefix_string(buf, workq)
202 if trace.debugid_is_start(buf.debugid) then
209 printf("%s QoS = %s\n", prefix, qos_string(qos))
211 printf("%s request thread = 0x%x, kqrequest state = %s\n", prefix,
212 buf.arg1, state_string(kqrequest_state_strings, buf.arg2))
217 trace_eventname("KEVENT_kq_processing_begin", processing_begin(false))
218 trace_eventname("KEVENT_kqwq_processing_begin", processing_begin(true))
219 trace_eventname("KEVENT_kqwl_processing_begin", processing_begin(false))
221 function processing_end(workq)
229 printf("%s QoS = %s\n", event_prefix_string(buf, workq), qos_string(qos))
233 trace_eventname("KEVENT_kq_processing_end", processing_end(false))
234 trace_eventname("KEVENT_kqwq_processing_end", processing_end(true))
235 trace_eventname("KEVENT_kqwl_processing_end", processing_end(false))
237 trace_eventname("KEVENT_kqwq_bind", function(buf)
238 printf("%s thread = 0x%x, QoS = %s, kqrequest state = %s\n",
239 event_prefix_string(buf, true), buf.arg1, qos_string(buf.arg3),
240 state_string(kqrequest_state_strings, buf.arg4))
243 trace_eventname("KEVENT_kqwq_unbind", function(buf)
244 printf("%s thread = 0x%x, QoS = %s\n", event_prefix_string(buf, true),
245 buf.arg1, qos_string(buf.arg3))
248 trace_eventname("KEVENT_kqwl_bind", function(buf)
249 qos = buf.arg3 & 0xff
250 duplicate = buf.arg3 & (1 << 8)
251 kqr_override_qos_delta = buf.arg4 >> 8
252 kqr_state = buf.arg4 & 0xff
254 printf("%s thread = 0x%x, QoS = %s, override QoS delta = %d, kqrequest state = %s%s\n",
255 event_prefix_string(buf, false), buf.arg2, qos_string(qos),
256 kqr_override_qos_delta,
257 state_string(kqrequest_state_strings, kqr_state),
258 duplicate and ", duplicate" or "")
261 trace_eventname("KEVENT_kqwl_unbind", function(buf)
265 printf("%s thread = 0x%x, QoS = %s, flags = 0x%x\n", event_prefix_string(buf, false),
266 buf.arg2, qos_string(qos), flags)
269 function thread_request(workq)
271 printf("%s QoS = %s, kqrequest state = %s, override QoS delta = %d\n",
272 event_prefix_string(buf, workq), qos_string(buf.arg2),
273 state_string(kqrequest_state_strings, buf.arg3), buf.arg3 >> 8)
277 function thread_adjust(buf)
279 kqr_qos = buf.arg3 >> 8
280 new_qos = buf.arg3 & 0xff
281 kqr_qos_override = buf.arg4 >> 8
282 kqr_state = buf.arg4 & 0xff
284 printf("%s thread = 0x%x, old/new QoS = %s/%s, old/new override QoS delta = %d/%d, kqrequest state = %s\n",
285 event_prefix_string(buf, false),
291 state_string(kqrequest_state_strings, kqr_state))
294 trace_eventname("KEVENT_kqwq_thread_request", thread_request(true))
295 trace_eventname("KEVENT_kqwl_thread_request", thread_request(false))
296 trace_eventname("KEVENT_kqwl_thread_adjust", thread_adjust)
298 function kevent_register(workq)
300 printf("%s kevent udata = 0x%x, kevent filter = %s, kevent flags = %s\n",
301 event_prefix_string(buf, workq), buf.arg2,
302 kevent_filter_string(buf.arg4),
303 state_string(kevent_flags_strings, buf.arg3))
307 trace_eventname("KEVENT_kq_register", kevent_register(false))
308 trace_eventname("KEVENT_kqwq_register", kevent_register(true))
309 trace_eventname("KEVENT_kqwl_register", kevent_register(false))
311 function kevent_process(workq)
313 printf("%s kevent ident = 0x%x, udata = 0x%x, kevent filter = %s, knote status = %s\n",
314 event_prefix_string(buf, workq), buf.arg3 >> 32, buf.arg2,
315 kevent_filter_string(buf.arg4),
316 state_string(knote_state_strings, buf.arg3 & 0xffffffff))
320 trace_eventname("KEVENT_kq_process", kevent_process(false))
321 trace_eventname("KEVENT_kqwq_process", kevent_process(true))
322 trace_eventname("KEVENT_kqwl_process", kevent_process(false))