Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Side by Side Diff: runtime/vm/thread_interrupter_macos.cc

Issue 109803002: Profiler Take 2 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "platform/globals.h"
6 #if defined(TARGET_OS_MACOS)
7
8 #include "vm/signal_handler.h"
9 #include "vm/thread_interrupter.h"
10
11 namespace dart {
12
13 DECLARE_FLAG(bool, thread_interrupter);
14 DECLARE_FLAG(bool, trace_thread_interrupter);
15
16 class ThreadInterrupterMacOS : public AllStatic {
17 public:
18 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info,
19 void* context_) {
20 if (signal != SIGPROF) {
21 return;
22 }
23 ThreadInterrupter::ThreadState* state =
24 ThreadInterrupter::CurrentThreadState();
25 if ((state == NULL) || (state->callback == NULL)) {
26 // No interrupter state or callback.
27 return;
28 }
29 ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId()));
30
31 // Extract thread state.
32 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_);
33 mcontext_t mcontext = context->uc_mcontext;
34 InterruptedThreadState its;
35 its.tid = state->id;
36 its.pc = SignalHandler::GetProgramCounter(mcontext);
37 its.fp = SignalHandler::GetFramePointer(mcontext);
38 its.sp = SignalHandler::GetStackPointer(mcontext);
39 state->callback(its, state->data);
40 }
41 };
42
43
44 void ThreadInterrupter::InterruptThreads(int64_t current_time) {
45 for (intptr_t i = 0; i < threads_size_; i++) {
46 ThreadState* state = threads_[i];
47 ASSERT(state->id != Thread::kInvalidThreadId);
48 if (FLAG_trace_thread_interrupter) {
49 OS::Print("ThreadInterrupter interrupting %p\n", state->id);
50 }
51 pthread_kill(state->id, SIGPROF);
52 }
53 }
54
55
56 void ThreadInterrupter::InstallSignalHandler() {
57 SignalHandler::Install(ThreadInterrupterMacOS::ThreadInterruptSignalHandler);
58 }
59
60
61 } // namespace dart
62
63 #endif // defined(TARGET_OS_MACOS)
64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698