]>
Commit | Line | Data |
---|---|---|
a0619f9c A |
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 | workqueue_ptr_map = {}; | |
14 | get_prefix = function(buf) | |
15 | if initial_timestamp == 0 then | |
16 | initial_timestamp = buf.timestamp | |
17 | end | |
18 | local secs = trace.convert_timestamp_to_nanoseconds(buf.timestamp - initial_timestamp) / 1000000000 | |
19 | ||
20 | local prefix | |
21 | if trace.debugid_is_start(buf.debugid) then | |
22 | prefix = "→" | |
23 | elseif trace.debugid_is_end(buf.debugid) then | |
24 | prefix = "←" | |
25 | else | |
26 | prefix = "↔" | |
27 | end | |
28 | ||
29 | local proc | |
30 | if buf.command ~= "kernel_task" then | |
31 | proc = buf.command | |
32 | workqueue_ptr_map[buf[1]] = buf.command | |
33 | elseif workqueue_ptr_map[buf[1]] ~= nil then | |
34 | proc = workqueue_ptr_map[buf[1]] | |
35 | else | |
36 | proc = "UNKNOWN" | |
37 | end | |
38 | ||
39 | return string.format("%s %6.9f %-17s [%05d.%06x] %-24s", | |
40 | prefix, secs, proc, buf.pid, buf.threadid, buf.debugname) | |
41 | end | |
42 | ||
43 | trace_codename("pthread_thread_create", function(buf) | |
44 | local prefix = get_prefix(buf) | |
45 | if trace.debugid_is_start(buf.debugid) then | |
46 | printf("%s\tthread creation request: 0x%x\n", prefix, buf[1]) | |
47 | elseif trace.debugid_is_end(buf.debugid) then | |
48 | printf("%s\t thread creation complete: pthread 0x%x (error: %d)\n", prefix, buf[2], buf[1]) | |
49 | elseif buf[4] == 2 then | |
50 | printf("%s\t thread stack created: 0x%x + 0x%x\n", prefix, buf[2], buf[1]) | |
51 | elseif buf[4] == 3 then | |
52 | printf("%s\t thread using custom stack") | |
53 | end | |
54 | end) | |
55 | ||
56 | trace_codename("pthread_thread_terminate", function(buf) | |
57 | local prefix = get_prefix(buf) | |
58 | if trace.debugid_is_start(buf.debugid) then | |
59 | printf("%s\tthread terminate: stack 0x%x + 0x%x, kthport 0x%x\n", prefix, buf[1], buf[2], buf[3]) | |
60 | elseif trace.debugid_is_end(buf.debugid) then | |
61 | printf("%s\t thread terminate: ret %d\n", prefix, buf[1]) | |
62 | end | |
63 | end) | |
64 | ||
65 | -- The trace codes we need aren't enabled by default | |
66 | darwin.sysctlbyname("kern.pthread_debug_tracing", 1) | |
67 | completion_handler = function() | |
68 | darwin.sysctlbyname("kern.pthread_debug_tracing", 0) | |
69 | end | |
70 | trace.set_completion_handler(completion_handler) |