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

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

Issue 1412733008: Switch profiler from isolates to threads (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include <sys/syscall.h> // NOLINT 8 #include <sys/syscall.h> // NOLINT
9 #include <errno.h> // NOLINT
9 10
10 #include "vm/flags.h" 11 #include "vm/flags.h"
11 #include "vm/os.h" 12 #include "vm/os.h"
13 #include "vm/profiler.h"
12 #include "vm/signal_handler.h" 14 #include "vm/signal_handler.h"
13 #include "vm/thread_interrupter.h" 15 #include "vm/thread_interrupter.h"
14 16
15 namespace dart { 17 namespace dart {
16 18
17 DECLARE_FLAG(bool, thread_interrupter); 19 DECLARE_FLAG(bool, thread_interrupter);
18 DECLARE_FLAG(bool, trace_thread_interrupter); 20 DECLARE_FLAG(bool, trace_thread_interrupter);
19 21
20 class ThreadInterrupterAndroid : public AllStatic { 22 class ThreadInterrupterAndroid : public AllStatic {
21 public: 23 public:
22 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info, 24 static void ThreadInterruptSignalHandler(int signal, siginfo_t* info,
23 void* context_) { 25 void* context_) {
24 if (signal != SIGPROF) { 26 if (signal != SIGPROF) {
25 return; 27 return;
26 } 28 }
27 Thread* thread = Thread::Current(); 29 Thread* thread = Thread::Current();
28 if (thread == NULL) { 30 if (thread == NULL) {
29 return; 31 return;
30 } 32 }
31 ThreadInterruptCallback callback = NULL; 33 ThreadInterruptCallback callback = Profiler::SampleThreadInterruptCallback;
32 void* callback_data = NULL;
33 if (!thread->IsThreadInterrupterEnabled(&callback, &callback_data)) {
34 return;
35 }
36 // Extract thread state. 34 // Extract thread state.
37 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_); 35 ucontext_t* context = reinterpret_cast<ucontext_t*>(context_);
38 mcontext_t mcontext = context->uc_mcontext; 36 mcontext_t mcontext = context->uc_mcontext;
39 InterruptedThreadState its; 37 InterruptedThreadState its;
40 its.tid = thread->id();
41 its.pc = SignalHandler::GetProgramCounter(mcontext); 38 its.pc = SignalHandler::GetProgramCounter(mcontext);
42 its.fp = SignalHandler::GetFramePointer(mcontext); 39 its.fp = SignalHandler::GetFramePointer(mcontext);
43 its.csp = SignalHandler::GetCStackPointer(mcontext); 40 its.csp = SignalHandler::GetCStackPointer(mcontext);
44 its.dsp = SignalHandler::GetDartStackPointer(mcontext); 41 its.dsp = SignalHandler::GetDartStackPointer(mcontext);
45 its.lr = SignalHandler::GetLinkRegister(mcontext); 42 its.lr = SignalHandler::GetLinkRegister(mcontext);
46 callback(its, callback_data); 43 callback(thread, its);
47 } 44 }
48 }; 45 };
49 46
50 47
51 void ThreadInterrupter::InterruptThread(Thread* thread) { 48 void ThreadInterrupter::InterruptThread(Thread* thread) {
52 if (FLAG_trace_thread_interrupter) { 49 if (FLAG_trace_thread_interrupter) {
53 OS::Print("ThreadInterrupter interrupting %p\n", 50 OS::Print("ThreadInterrupter interrupting %p\n",
54 reinterpret_cast<void*>(thread->id())); 51 reinterpret_cast<void*>(thread->id()));
55 } 52 }
56 int result = syscall(__NR_tgkill, getpid(), thread->id(), SIGPROF); 53 int result = syscall(__NR_tgkill, getpid(), thread->id(), SIGPROF);
57 ASSERT(result == 0); 54 ASSERT((result == 0) || (result == ESRCH));
58 } 55 }
59 56
60 57
61 void ThreadInterrupter::InstallSignalHandler() { 58 void ThreadInterrupter::InstallSignalHandler() {
62 SignalHandler::Install( 59 SignalHandler::Install(
63 ThreadInterrupterAndroid::ThreadInterruptSignalHandler); 60 ThreadInterrupterAndroid::ThreadInterruptSignalHandler);
64 } 61 }
65 62
66 63
67 void ThreadInterrupter::RemoveSignalHandler() { 64 void ThreadInterrupter::RemoveSignalHandler() {
68 SignalHandler::Remove(); 65 SignalHandler::Remove();
69 } 66 }
70 67
71 } // namespace dart 68 } // namespace dart
72 69
73 #endif // defined(TARGET_OS_ANDROID) 70 #endif // defined(TARGET_OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698