@@ -137,7 +137,7 @@ + (NSString *)deviceName {
137
137
return [NSString stringWithCString: systemInfo.machine encoding: NSUTF8StringEncoding];
138
138
}
139
139
140
- + ( Thread *) createThread : (thread_t ) threadId
140
+ Thread* createThread (thread_t threadId)
141
141
{
142
142
Thread *thread = new Thread;
143
143
@@ -174,6 +174,16 @@ + (void)recordStackForAllThreads
174
174
thread_count = 1 ;
175
175
}
176
176
177
+ std::map<thread_t , Stack *> stackMap;
178
+ for (mach_msg_type_number_t i = 0 ; i < thread_count; i++) {
179
+ if (threads[i] == sETTraceThread ) {
180
+ continue ;
181
+ }
182
+
183
+ Stack *stack = new Stack;
184
+ stackMap.insert (std::pair<unsigned int , Stack *>(threads[i], stack));
185
+ }
186
+
177
187
// Suspend all threads but ETTrace's
178
188
for (mach_msg_type_number_t i = 0 ; i < thread_count; i++) {
179
189
if (threads[i] != sETTraceThread ) {
@@ -187,36 +197,41 @@ + (void)recordStackForAllThreads
187
197
continue ;
188
198
}
189
199
190
- Stack stack;
191
- stack.time = time;
192
- FIRCLSWriteThreadStack (threads[i], stack.frames , kMaxFramesPerStack , &(stack.frameCount ));
200
+ Stack *stack = stackMap.at (threads[i]);
201
+ stack->time = time;
202
+ FIRCLSWriteThreadStack (threads[i], stack->frames , kMaxFramesPerStack , &(stack->frameCount ));
203
+ }
193
204
194
- std::vector<Stack> *threadStack;
195
- sThreadsLock .lock ();
196
- if (sThreadsMap ->find (threads[i]) == sThreadsMap ->end ()) {
197
- Thread *thread = [self createThread: threads[i]];
205
+ for (mach_msg_type_number_t i = 0 ; i < thread_count; i++) {
206
+ if (threads[i] != sETTraceThread )
207
+ thread_resume (threads[i]);
208
+ }
209
+
210
+ std::vector<Stack> *threadStack;
211
+ std::map<thread_t , Stack *>::iterator it;
212
+ sThreadsLock .lock ();
213
+ for (it = stackMap.begin (); it != stackMap.end (); it++) {
214
+ thread_t t_id = it->first ;
215
+ if (sThreadsMap ->find (t_id) == sThreadsMap ->end ()) {
216
+ Thread *thread = createThread (t_id);
198
217
// Add to hash map
199
- sThreadsMap ->insert (std::pair<unsigned int , Thread *>(threads[i] , thread));
218
+ sThreadsMap ->insert (std::pair<thread_t , Thread *>(t_id , thread));
200
219
201
220
threadStack = thread->stacks ;
202
221
} else {
203
- threadStack = sThreadsMap ->at (threads[i] )->stacks ;
222
+ threadStack = sThreadsMap ->at (t_id )->stacks ;
204
223
}
205
-
224
+ Stack *stack = it-> second ;
206
225
try {
207
- threadStack->emplace_back (stack);
226
+ threadStack->emplace_back (* stack);
208
227
} catch (const std::length_error& le) {
209
228
fflush (stdout);
210
229
fflush (stderr);
211
230
throw le;
212
231
}
213
- sThreadsLock .unlock ();
214
- }
215
-
216
- for (mach_msg_type_number_t i = 0 ; i < thread_count; i++) {
217
- if (threads[i] != sETTraceThread )
218
- thread_resume (threads[i]);
232
+ delete stack;
219
233
}
234
+ sThreadsLock .unlock ();
220
235
}
221
236
222
237
+ (void )setup {
0 commit comments