]>
Commit | Line | Data |
---|---|---|
bd6521f0 A |
1 | // |
2 | // MessagePrinting.cpp | |
3 | // msa | |
4 | // | |
5 | // Created by James McIlree on 2/5/14. | |
6 | // Copyright (c) 2014 Apple. All rights reserved. | |
7 | // | |
8 | ||
9 | #include "global.h" | |
10 | ||
11 | const char* qos_to_string(uint32_t qos) { | |
12 | static_assert(THREAD_QOS_LAST == 7, "QOS tiers need updating"); | |
13 | ||
14 | switch (qos) { | |
15 | case THREAD_QOS_UNSPECIFIED: | |
16 | return "unspecified"; | |
17 | ||
18 | case THREAD_QOS_MAINTENANCE: | |
19 | return "maintenance"; | |
20 | ||
21 | case THREAD_QOS_BACKGROUND: | |
22 | return "background"; | |
23 | ||
24 | case THREAD_QOS_UTILITY: | |
25 | return "utility"; | |
26 | ||
27 | case THREAD_QOS_LEGACY: | |
28 | return "legacy"; | |
29 | ||
30 | case THREAD_QOS_USER_INITIATED: | |
31 | return "user-initiated"; | |
32 | ||
33 | case THREAD_QOS_USER_INTERACTIVE: | |
34 | return "user-interactive"; | |
35 | ||
36 | default: | |
37 | ASSERT(false, "Unhandled QoS"); | |
38 | return "QOS_???"; | |
39 | } | |
40 | } | |
41 | ||
42 | const char* qos_to_short_string(uint32_t qos) { | |
43 | static_assert(THREAD_QOS_LAST == 7, "QOS tiers need updating"); | |
44 | ||
45 | switch (qos) { | |
46 | case THREAD_QOS_UNSPECIFIED: | |
47 | return "Unspec"; | |
48 | ||
49 | case THREAD_QOS_MAINTENANCE: | |
50 | return "Maint"; | |
51 | ||
52 | case THREAD_QOS_BACKGROUND: | |
53 | return "BG"; | |
54 | ||
55 | case THREAD_QOS_UTILITY: | |
56 | return "Util"; | |
57 | ||
58 | case THREAD_QOS_LEGACY: | |
59 | return "Legacy"; | |
60 | ||
61 | case THREAD_QOS_USER_INITIATED: | |
62 | return "UInit"; | |
63 | ||
64 | case THREAD_QOS_USER_INTERACTIVE: | |
65 | return "UI"; | |
66 | ||
67 | default: | |
68 | ASSERT(false, "Unhandled QoS"); | |
69 | return "???"; | |
70 | } | |
71 | } | |
72 | ||
73 | const char* role_to_short_string(uint32_t role) { | |
74 | switch (role) { | |
75 | // This is seen when apps are terminating | |
76 | case TASK_UNSPECIFIED: | |
77 | return "unspec"; | |
78 | ||
79 | case TASK_FOREGROUND_APPLICATION: | |
80 | return "fg"; | |
81 | ||
82 | case TASK_BACKGROUND_APPLICATION: | |
83 | return "bg"; | |
84 | ||
85 | case TASK_CONTROL_APPLICATION: | |
86 | case TASK_GRAPHICS_SERVER: | |
87 | case TASK_THROTTLE_APPLICATION: | |
88 | case TASK_NONUI_APPLICATION: | |
89 | ASSERT(false, "These should be obsolete"); | |
90 | return "obsolete"; | |
91 | ||
92 | case TASK_DEFAULT_APPLICATION: | |
93 | // Is this obsolete too? | |
94 | return "defapp"; | |
95 | ||
96 | default: | |
97 | ASSERT(false, "Unexpected app role"); | |
98 | return "???"; | |
99 | } | |
100 | } | |
101 | ||
102 | const char* role_to_string(uint32_t role) { | |
103 | switch (role) { | |
104 | // This is seen when apps are terminating | |
105 | case TASK_UNSPECIFIED: | |
106 | return "unspecified"; | |
107 | ||
108 | case TASK_FOREGROUND_APPLICATION: | |
109 | return "foreground"; | |
110 | ||
111 | case TASK_BACKGROUND_APPLICATION: | |
112 | return "background"; | |
113 | ||
114 | case TASK_CONTROL_APPLICATION: | |
115 | return "control-application"; | |
116 | ||
117 | case TASK_GRAPHICS_SERVER: | |
118 | return "graphics-server"; | |
119 | ||
120 | case TASK_THROTTLE_APPLICATION: | |
121 | return "throttle-app"; | |
122 | ||
123 | case TASK_NONUI_APPLICATION: | |
124 | return "nonui-app"; | |
125 | ||
126 | case TASK_DEFAULT_APPLICATION: | |
127 | // Is this obsolete too? | |
128 | return "default-app"; | |
129 | ||
130 | default: | |
131 | ASSERT(false, "Unexpected app role"); | |
132 | return "???"; | |
133 | } | |
134 | } | |
135 | ||
136 | void print_base_empty(PrintBuffer& buffer, | |
137 | const Globals& globals, | |
138 | uintptr_t event_index, | |
139 | const char* type, | |
140 | bool should_newline) | |
141 | { | |
142 | // Base Header is... (32) | |
143 | // | |
144 | // Time(µS) Type Thread ThreadVoucher AppType Process ;; | |
145 | // 123456789abcdef0 1234567890123456789012 1234567890 123456789abcdef0 12345678901234567 123456789012345678901234 12 | |
146 | // 14.11 mach_msg_send 18FB voucher-133 AdaptiveDaemon TextEdit (231) ;; | |
147 | // 18.11 mach_msg_recv 18FB 0 InteractiveDaemon configd (19981) ;; | |
148 | ||
149 | // Base Header is... (64) | |
150 | // | |
151 | // Time(µS) Type Thread ThreadVoucher AppType Process ;; | |
152 | // 123456789abcdef0 1234567890123456789012 1234567890 123456789abcdef0 12345678901234567 123456789012345678901234 12 | |
153 | // 14.11 mach_msg_send 18FB voucher-133 AdaptiveDaemon TextEdit (231) ;; | |
154 | // 18.11 mach_msg_recv 18FB 0 InteractiveDaemon configd (19981) ;; | |
155 | ||
156 | // | |
157 | // [Index] | |
158 | // | |
159 | if (globals.should_print_event_index()) { | |
160 | buffer.printf("%8llu ", (uint64_t)event_index); | |
161 | } | |
162 | ||
163 | // | |
164 | // Time Type Code Thread ThreadVoucher AppType Process | |
165 | // | |
166 | // This assert doesn't handle utf8... | |
167 | ASSERT(strlen(type) <= 22, "Sanity"); | |
168 | ||
169 | buffer.printf("%16s %3s %22s %10s %16s %17s %24s ;;", "-", "-", type, "-", "-", "-", "- (-)"); | |
170 | ||
171 | // | |
172 | // Process | |
173 | // | |
174 | if (should_newline) | |
175 | buffer.printf("\n"); | |
176 | else | |
177 | buffer.printf(" "); | |
178 | } | |
179 | ||
180 | static char* print_base_header(char* buf, char* buf_end, const Globals& globals) { | |
181 | // Base Header is... (32) | |
182 | // | |
183 | // Time(µS) Type Thread ThrVoucher Process ;; | |
184 | // 123456789abcdef0 1234567890123456789012 1234567890 123456789a 123456789012345678901234 12 | |
185 | // 14.11 mach_msg_send 18FB FFFF8E44 TextEdit (231) ;; | |
186 | // 18.11 mach_msg_recv 18FB 0 configd (19981) ;; | |
187 | ||
188 | // Base Header is... (64) | |
189 | // | |
190 | // Time(µS) Type Thread ThreadVoucher Process ;; | |
191 | // 123456789abcdef0 1234567890123456789012 1234567890 123456789abcdef0 123456789012345678901234 12 | |
192 | // 14.11 mach_msg_send 18FB BBBBAAEE55778234 TextEdit (231) ;; | |
193 | // 18.11 mach_msg_recv 18FB 0 configd (19981) ;; | |
194 | ||
195 | // | |
196 | // If we cannot print successfully, we return the orignal pointer. | |
197 | // | |
198 | char* orig_buf = buf; | |
199 | ||
200 | if (globals.should_print_event_index()) | |
201 | buf += snprintf(buf, buf_end - buf,"%8s ", "Event#"); | |
202 | ||
203 | if (buf >= buf_end) | |
204 | return orig_buf; | |
205 | ||
206 | // The character counting for "Time(µS)" is OBO, it treats the µ as two characters. | |
207 | // This means the %16s misaligns. We force it by making the input string 16 printable chars long, | |
208 | // which overflows the %16s to the correct actual output length. | |
209 | const char* time = globals.should_print_mach_absolute_timestamps() ? "Time(mach-abs)" : " Time(µS)"; | |
210 | ||
211 | if (globals.kernel_size() == KernelSize::k32) | |
212 | buf += snprintf(buf, buf_end - buf, "%s %22s %10s %10s %24s ;; ", time, "Type", "Thread", "ThrVoucher", "Process"); | |
213 | else | |
214 | buf += snprintf(buf, buf_end - buf, "%s %22s %10s %16s %24s ;; ", time, "Type", "Thread", "ThreadVoucher", "Process"); | |
215 | ||
216 | return (buf >= buf_end) ? orig_buf : buf; | |
217 | } | |
218 | ||
219 | char* print_mach_msg_header(char* buf, char* buf_end, const Globals& globals) { | |
220 | ||
221 | // MachMsg Header is... (32) | |
222 | // | |
223 | // ;; Message From/To MsgID MsgVoucher DeliveryTime FLAGS | |
224 | // 12 123456789012345678901234567 123456789 123456789a 1234567890123 ... | |
225 | // ;; -> configd (19981) 55 - - ONEWAY, IMP-DONATING | |
226 | // ;; <- TextEdit (231) 55 FFFF8E44 120080 VOUCHER-PROVIDED-BY-KERNEL, VOUCHER-REFUSED | |
227 | ||
228 | // MachMsg Header is... (64) | |
229 | // | |
230 | // ;; Message From/To MsgID MsgVoucher DeliveryTime FLAGS | |
231 | // 12 123456789012345678901234567 123456789 123456789abcdef0 1234567890123 ... | |
232 | // ;; -> configd (19981) 55 - - ONEWAY, IMP-DONATING | |
233 | // ;; <- TextEdit (231) 55 FFFFAAEE55778234 120080 VOUCHER-PROVIDED-BY-KERNEL, VOUCHER-REFUSED | |
234 | ||
235 | char* orig_buf = buf; | |
236 | ||
237 | // | |
238 | // Base Header | |
239 | // | |
240 | buf = print_base_header(buf, buf_end, globals); | |
241 | ||
242 | if (buf == orig_buf) | |
243 | return orig_buf; | |
244 | ||
245 | // | |
246 | // Mach Msg Header | |
247 | // | |
248 | if (globals.kernel_size() == KernelSize::k32) | |
249 | buf += snprintf(buf, buf_end - buf, "%-27s %9s %10s %13s %s\n", "Message-From/To", "MsgID", "MsgVoucher", "DeliveryTime", "FLAGS"); | |
250 | else | |
251 | buf += snprintf(buf, buf_end - buf, "%-27s %9s %16s %13s %s\n", "Message-From/To", "MsgID", "MsgVoucher", "DeliveryTime", "FLAGS"); | |
252 | ||
253 | return (buf >= buf_end) ? orig_buf : buf; | |
254 | } |