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 = {
81 kqueue_state_strings = {
90 ['PROCESSING'] = 0x100,
95 ['TURNSTILE'] = 0x2000,
98 knote_state_strings = {
101 ['DISABLED'] = 0x0004,
102 ['DROPPING'] = 0x0008,
104 ['POSTING'] = 0x0020,
105 ['STAYACTIVE'] = 0x0040,
106 ['DEFERDELETE'] = 0x0080,
107 ['MERGE_QOS'] = 0x0100,
108 ['REQVANISH'] = 0x0200,
109 ['VANISHED'] = 0x0400,
110 ['SUPPRESSED'] = 0x0800,
113 kevent_flags_strings = {
117 ['DISABLE'] = 0x0008,
118 ['ONESHOT'] = 0x0010,
120 ['RECEIPT'] = 0x0040,
121 ['DISPATCH'] = 0x0080,
122 ['UDATA_SPECIFIC'] = 0x0100,
123 ['VANISHED'] = 0x0200,
130 function kevent_filter_string(filt)
133 elseif filt == -2 then
135 elseif filt == -3 then
137 elseif filt == -4 then
139 elseif filt == -5 then
141 elseif filt == -6 then
143 elseif filt == -7 then
145 elseif filt == -8 then
147 elseif filt == -9 then
149 elseif filt == -10 then
152 elseif filt == -12 then
154 elseif filt == -13 then
156 elseif filt == -14 then
157 return 'MEMORYSTATUS'
158 elseif filt == -15 then
160 elseif filt == -16 then
162 elseif filt == -17 then
165 elseif filt == 17 then
167 elseif filt == 18 then
169 elseif filt == 19 then
171 elseif filt == 20 then
173 elseif filt == 21 then
175 elseif filt == 22 then
177 elseif filt == 23 then
179 elseif filt == 24 then
181 elseif filt == 25 then
183 elseif filt == 26 then
185 elseif filt == 27 then
187 elseif filt == 28 then
189 elseif filt == 29 then
190 return 'SKYWALK_CHANNEL_W'
191 elseif filt == 30 then
192 return 'SKYWALK_CHANNEL_R'
193 elseif filt == 31 then
194 return 'SKYWALK_CHANNEL_E'
195 elseif filt == 32 then
197 elseif filt == 33 then
199 elseif filt == 34 then
201 elseif filt == 35 then
203 elseif filt == 36 then
206 return string.format('[%d]', filt)
212 function processing_begin(workq)
214 local prefix = event_prefix_string(buf, workq)
215 if trace.debugid_is_start(buf.debugid) then
222 printf("%s QoS = %s\n", prefix, qos_string(qos))
224 printf("%s request thread = 0x%x, kqrequest state = %s\n", prefix,
225 buf.arg1, state_string(kqrequest_state_strings, buf.arg2))
230 trace_eventname("KEVENT_kq_processing_begin", processing_begin(false))
231 trace_eventname("KEVENT_kqwq_processing_begin", processing_begin(true))
232 trace_eventname("KEVENT_kqwl_processing_begin", processing_begin(false))
234 function processing_end(workq)
242 printf("%s QoS = %s\n", event_prefix_string(buf, workq), qos_string(qos))
246 trace_eventname("KEVENT_kq_processing_end", processing_end(false))
247 trace_eventname("KEVENT_kqwq_processing_end", processing_end(true))
248 trace_eventname("KEVENT_kqwl_processing_end", processing_end(false))
250 trace_eventname("KEVENT_kqwq_bind", function(buf)
251 printf("%s thread = 0x%x, QoS = %s, kqrequest state = %s\n",
252 event_prefix_string(buf, true), buf.arg1, qos_string(buf.arg3),
253 state_string(kqrequest_state_strings, buf.arg4))
256 trace_eventname("KEVENT_kqwq_unbind", function(buf)
257 printf("%s thread = 0x%x, QoS = %s\n", event_prefix_string(buf, true),
258 buf.arg1, qos_string(buf.arg3))
261 trace_eventname("KEVENT_kqwl_bind", function(buf)
262 qos = buf.arg3 & 0xff
263 duplicate = buf.arg3 & (1 << 8)
264 kqr_override_qos_delta = buf.arg4 >> 8
265 kqr_state = buf.arg4 & 0xff
267 printf("%s thread = 0x%x, QoS = %s, override QoS delta = %d, kqrequest state = %s%s\n",
268 event_prefix_string(buf, false), buf.arg2, qos_string(qos),
269 kqr_override_qos_delta,
270 state_string(kqrequest_state_strings, kqr_state),
271 duplicate and ", duplicate" or "")
274 trace_eventname("KEVENT_kqwl_unbind", function(buf)
278 printf("%s thread = 0x%x, QoS = %s, flags = 0x%x\n", event_prefix_string(buf, false),
279 buf.arg2, qos_string(qos), flags)
282 function thread_request(workq)
284 printf("%s QoS = %s, kqrequest state = %s, override QoS delta = %d\n",
285 event_prefix_string(buf, workq), qos_string(buf.arg2),
286 state_string(kqrequest_state_strings, buf.arg3), buf.arg3 >> 8)
290 function thread_adjust(buf)
292 kqr_qos = buf.arg3 >> 8
293 new_qos = buf.arg3 & 0xff
294 kqr_qos_override = buf.arg4 >> 8
295 kqr_state = buf.arg4 & 0xff
297 printf("%s thread = 0x%x, old/new QoS = %s/%s, old/new override QoS delta = %d/%d, kqrequest state = %s\n",
298 event_prefix_string(buf, false),
304 state_string(kqrequest_state_strings, kqr_state))
307 trace_eventname("KEVENT_kqwq_thread_request", thread_request(true))
308 trace_eventname("KEVENT_kqwl_thread_request", thread_request(false))
309 trace_eventname("KEVENT_kqwl_thread_adjust", thread_adjust)
311 function kevent_register(workq)
313 printf("%s kevent udata = 0x%x, kevent filter = %s, kevent flags = %s\n",
314 event_prefix_string(buf, workq), buf.arg2,
315 kevent_filter_string(buf.arg4),
316 state_string(kevent_flags_strings, buf.arg3))
320 trace_eventname("KEVENT_kq_register", kevent_register(false))
321 trace_eventname("KEVENT_kqwq_register", kevent_register(true))
322 trace_eventname("KEVENT_kqwl_register", kevent_register(false))
324 function kevent_process(workq)
326 printf("%s kevent ident = 0x%x, udata = 0x%x, kevent filter = %s, knote status = %s\n",
327 event_prefix_string(buf, workq), buf.arg3 >> 32, buf.arg2,
328 kevent_filter_string(buf.arg4),
329 state_string(knote_state_strings, buf.arg3 & 0xffffffff))
333 trace_eventname("KEVENT_kq_process", kevent_process(false))
334 trace_eventname("KEVENT_kqwq_process", kevent_process(true))
335 trace_eventname("KEVENT_kqwl_process", kevent_process(false))