5 // Created by James McIlree on 2/5/14.
6 // Copyright (c) 2014 Apple. All rights reserved.
11 const char* qos_to_string(uint32_t qos
) {
12 static_assert(THREAD_QOS_LAST
== 7, "QOS tiers need updating");
15 case THREAD_QOS_UNSPECIFIED
:
18 case THREAD_QOS_MAINTENANCE
:
21 case THREAD_QOS_BACKGROUND
:
24 case THREAD_QOS_UTILITY
:
27 case THREAD_QOS_LEGACY
:
30 case THREAD_QOS_USER_INITIATED
:
31 return "user-initiated";
33 case THREAD_QOS_USER_INTERACTIVE
:
34 return "user-interactive";
37 ASSERT(false, "Unhandled QoS");
42 const char* qos_to_short_string(uint32_t qos
) {
43 static_assert(THREAD_QOS_LAST
== 7, "QOS tiers need updating");
46 case THREAD_QOS_UNSPECIFIED
:
49 case THREAD_QOS_MAINTENANCE
:
52 case THREAD_QOS_BACKGROUND
:
55 case THREAD_QOS_UTILITY
:
58 case THREAD_QOS_LEGACY
:
61 case THREAD_QOS_USER_INITIATED
:
64 case THREAD_QOS_USER_INTERACTIVE
:
68 ASSERT(false, "Unhandled QoS");
73 const char* role_to_short_string(uint32_t role
) {
75 // This is seen when apps are terminating
76 case TASK_UNSPECIFIED
:
79 case TASK_FOREGROUND_APPLICATION
:
82 case TASK_BACKGROUND_APPLICATION
:
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");
92 case TASK_DEFAULT_APPLICATION
:
93 // Is this obsolete too?
97 ASSERT(false, "Unexpected app role");
102 const char* role_to_string(uint32_t role
) {
104 // This is seen when apps are terminating
105 case TASK_UNSPECIFIED
:
106 return "unspecified";
108 case TASK_FOREGROUND_APPLICATION
:
111 case TASK_BACKGROUND_APPLICATION
:
114 case TASK_CONTROL_APPLICATION
:
115 return "control-application";
117 case TASK_GRAPHICS_SERVER
:
118 return "graphics-server";
120 case TASK_THROTTLE_APPLICATION
:
121 return "throttle-app";
123 case TASK_NONUI_APPLICATION
:
126 case TASK_DEFAULT_APPLICATION
:
127 // Is this obsolete too?
128 return "default-app";
131 ASSERT(false, "Unexpected app role");
136 void print_base_empty(PrintBuffer
& buffer
,
137 const Globals
& globals
,
138 uintptr_t event_index
,
142 // Base Header is... (32)
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) ;;
149 // Base Header is... (64)
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) ;;
159 if (globals
.should_print_event_index()) {
160 buffer
.printf("%8llu ", (uint64_t)event_index
);
164 // Time Type Code Thread ThreadVoucher AppType Process
166 // This assert doesn't handle utf8...
167 ASSERT(strlen(type
) <= 22, "Sanity");
169 buffer
.printf("%16s %3s %22s %10s %16s %17s %24s ;;", "-", "-", type
, "-", "-", "-", "- (-)");
180 static char* print_base_header(char* buf
, char* buf_end
, const Globals
& globals
) {
181 // Base Header is... (32)
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) ;;
188 // Base Header is... (64)
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) ;;
196 // If we cannot print successfully, we return the orignal pointer.
198 char* orig_buf
= buf
;
200 if (globals
.should_print_event_index())
201 buf
+= snprintf(buf
, buf_end
- buf
,"%8s ", "Event#");
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)";
211 if (globals
.kernel_size() == KernelSize::k32
)
212 buf
+= snprintf(buf
, buf_end
- buf
, "%s %22s %10s %10s %24s ;; ", time
, "Type", "Thread", "ThrVoucher", "Process");
214 buf
+= snprintf(buf
, buf_end
- buf
, "%s %22s %10s %16s %24s ;; ", time
, "Type", "Thread", "ThreadVoucher", "Process");
216 return (buf
>= buf_end
) ? orig_buf
: buf
;
219 char* print_mach_msg_header(char* buf
, char* buf_end
, const Globals
& globals
) {
221 // MachMsg Header is... (32)
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
228 // MachMsg Header is... (64)
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
235 char* orig_buf
= buf
;
240 buf
= print_base_header(buf
, buf_end
, globals
);
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");
251 buf
+= snprintf(buf
, buf_end
- buf
, "%-27s %9s %16s %13s %s\n", "Message-From/To", "MsgID", "MsgVoucher", "DeliveryTime", "FLAGS");
253 return (buf
>= buf_end
) ? orig_buf
: buf
;