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 = {
79 ['THREQUESTED'] = 0x2,
83 kqueue_state_strings = {
92 ['PROCESSING'] = 0x100,
98 knote_state_strings = {
101 ['DISABLED'] = 0x0004,
102 ['DROPPING'] = 0x0008,
103 ['USEWAIT'] = 0x0010,
104 ['ATTACHING'] = 0x0020,
105 ['STAYACTIVE'] = 0x0040,
106 ['DEFERDELETE'] = 0x0080,
107 ['ATTACHED'] = 0x0100,
108 ['DISPATCH'] = 0x0200,
109 ['UDATA_SPECIFIC'] = 0x0400,
110 ['SUPPRESSED'] = 0x0800,
111 ['STOLENDROP'] = 0x1000,
112 ['REQVANISH'] = 0x2000,
113 ['VANISHED'] = 0x4000,
115 knote_state_strings = {
118 ['DISABLED'] = 0x0004,
119 ['DROPPING'] = 0x0008,
120 ['USEWAIT'] = 0x0010,
121 ['ATTACHING'] = 0x0020,
122 ['STAYACTIVE'] = 0x0040,
123 ['DEFERDELETE'] = 0x0080,
124 ['ATTACHED'] = 0x0100,
125 ['DISPATCH'] = 0x0200,
126 ['UDATA_SPECIFIC'] = 0x0400,
127 ['SUPPRESSED'] = 0x0800,
128 ['STOLENDROP'] = 0x1000,
129 ['REQVANISH'] = 0x2000,
130 ['VANISHED'] = 0x4000,
134 kevent_flags_strings = {
138 ['DISABLE'] = 0x0008,
139 ['ONESHOT'] = 0x0010,
141 ['RECEIPT'] = 0x0040,
142 ['DISPATCH'] = 0x0080,
143 ['UDATA_SPECIFIC'] = 0x0100,
144 ['VANISHED'] = 0x0200,
151 function kevent_filter_string(filt)
154 elseif filt == -2 then
156 elseif filt == -3 then
158 elseif filt == -4 then
160 elseif filt == -5 then
162 elseif filt == -6 then
164 elseif filt == -7 then
166 elseif filt == -8 then
168 elseif filt == -9 then
170 elseif filt == -10 then
173 elseif filt == -12 then
175 elseif filt == -13 then
177 elseif filt == -14 then
178 return 'MEMORYSTATUS'
179 elseif filt == 15 then
181 elseif filt == 16 then
183 elseif filt == 17 then
185 elseif filt == 18 then
187 elseif filt == 19 then
189 elseif filt == 20 then
191 elseif filt == 21 then
193 elseif filt == 22 then
195 elseif filt == 23 then
197 elseif filt == 24 then
198 return 'SKYWALK_CHANNEL_W'
199 elseif filt == 25 then
200 return 'SKYWALK_CHANNEL_R'
201 elseif filt == 26 then
203 elseif filt == 27 then
205 elseif filt == 28 then
206 return 'SKYWALK_CHANNEL_E'
207 elseif filt == 29 then
210 return string.format('[%d]', filt)
216 function processing_begin(workq)
218 local prefix = event_prefix_string(buf, workq)
219 if trace.debugid_is_start(buf.debugid) then
226 printf("%s QoS = %s\n", prefix, qos_string(qos))
228 printf("%s request thread = 0x%x, kqrequest state = %s\n", prefix,
229 buf.arg1, state_string(kqrequest_state_strings, buf.arg2))
234 trace_eventname("KEVENT_kq_processing_begin", processing_begin(false))
235 trace_eventname("KEVENT_kqwq_processing_begin", processing_begin(true))
236 trace_eventname("KEVENT_kqwl_processing_begin", processing_begin(false))
238 function processing_end(workq)
246 printf("%s QoS = %s\n", event_prefix_string(buf, workq), qos_string(qos))
250 trace_eventname("KEVENT_kq_processing_end", processing_end(false))
251 trace_eventname("KEVENT_kqwq_processing_end", processing_end(true))
252 trace_eventname("KEVENT_kqwl_processing_end", processing_end(false))
254 trace_eventname("KEVENT_kqwq_bind", function(buf)
255 printf("%s thread = 0x%x, QoS = %s, kqrequest state = %s\n",
256 event_prefix_string(buf, true), buf.arg1, qos_string(buf.arg3),
257 state_string(kqrequest_state_strings, buf.arg4))
260 trace_eventname("KEVENT_kqwq_unbind", function(buf)
261 printf("%s thread = 0x%x, QoS = %s\n", event_prefix_string(buf, true),
262 buf.arg1, qos_string(buf.arg3))
265 trace_eventname("KEVENT_kqwl_bind", function(buf)
266 qos = buf.arg3 & 0xff
267 duplicate = buf.arg3 & (1 << 8)
268 kqr_override_qos_delta = buf.arg4 >> 8
269 kqr_state = buf.arg4 & 0xff
271 printf("%s thread = 0x%x, QoS = %s, override QoS delta = %d, kqrequest state = %s%s\n",
272 event_prefix_string(buf, false), buf.arg2, qos_string(qos),
273 kqr_override_qos_delta,
274 state_string(kqrequest_state_strings, kqr_state),
275 duplicate ? ", duplicate" : "")
278 trace_eventname("KEVENT_kqwl_unbind", function(buf)
282 printf("%s thread = 0x%x, QoS = %s, flags = 0x%x\n", event_prefix_string(buf, false),
283 buf.arg2, qos_string(qos), flags)
286 function thread_request(workq)
288 printf("%s QoS = %s, kqrequest state = %s, override QoS delta = %d\n",
289 event_prefix_string(buf, workq), qos_string(buf.arg2),
290 state_string(kqrequest_state_strings, buf.arg3), buf.arg3 >> 8)
294 function thread_adjust(buf)
296 kqr_qos = buf.arg3 >> 8
297 new_qos = buf.arg3 & 0xff
298 kqr_qos_override = buf.arg4 >> 8
299 kqr_state = buf.arg4 & 0xff
301 printf("%s thread = 0x%x, old/new QoS = %s/%s, old/new override QoS delta = %d/%d, kqrequest state = %s\n",
302 event_prefix_string(buf, false),
308 state_string(kqrequest_state_strings, kqr_state))
311 trace_eventname("KEVENT_kqwq_thread_request", thread_request(true))
312 trace_eventname("KEVENT_kqwl_thread_request", thread_request(false))
313 trace_eventname("KEVENT_kqwl_thread_adjust", thread_adjust)
315 function kevent_register(workq)
317 printf("%s kevent udata = 0x%x, kevent filter = %s, kevent flags = %s\n",
318 event_prefix_string(buf, workq), buf.arg2,
319 kevent_filter_string(buf.arg4),
320 state_string(kevent_flags_strings, buf.arg3))
324 trace_eventname("KEVENT_kq_register", kevent_register(false))
325 trace_eventname("KEVENT_kqwq_register", kevent_register(true))
326 trace_eventname("KEVENT_kqwl_register", kevent_register(false))
328 function kevent_process(workq)
330 printf("%s kevent ident = 0x%x, udata = 0x%x, kevent filter = %s, knote status = %s\n",
331 event_prefix_string(buf, workq), buf.arg3 >> 32, buf.arg2,
332 kevent_filter_string(buf.arg4),
333 state_string(knote_state_strings, buf.arg3 & 0xffffffff))
337 trace_eventname("KEVENT_kq_process", kevent_process(false))
338 trace_eventname("KEVENT_kqwq_process", kevent_process(true))
339 trace_eventname("KEVENT_kqwl_process", kevent_process(false))