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

Unified Diff: runtime/vm/thread_interrupter_linux.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/thread_interrupter_android.cc ('k') | runtime/vm/thread_interrupter_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/thread_interrupter_linux.cc
diff --git a/runtime/vm/thread_interrupter_linux.cc b/runtime/vm/thread_interrupter_linux.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ee6b4a7569ea7f6f57d416a2f8194b069ed590fa
--- /dev/null
+++ b/runtime/vm/thread_interrupter_linux.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "platform/globals.h"
+#if defined(TARGET_OS_LINUX)
+
+#include "vm/signal_handler.h"
+#include "vm/thread_interrupter.h"
+
+namespace dart {
+
+DECLARE_FLAG(bool, thread_interrupter);
+DECLARE_FLAG(bool, trace_thread_interrupter);
+
+class ThreadInterrupterLinux : public AllStatic {
+ public:
+ static void ThreadInterruptSignalHandler(int signal, siginfo_t* info,
+ void* context_) {
+ if (signal != SIGPROF) {
+ return;
+ }
+ ThreadInterrupter::ThreadState* state =
+ ThreadInterrupter::CurrentThreadState();
+ if ((state == NULL) || (state->callback == NULL)) {
+ // No interrupter state or callback.
+ return;
+ }
+ ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId()));
+ // Extract thread state.
+ ucontext_t* context = reinterpret_cast<ucontext_t*>(context_);
+ mcontext_t mcontext = context->uc_mcontext;
+ InterruptedThreadState its;
+ its.tid = state->id;
+ its.pc = SignalHandler::GetProgramCounter(mcontext);
+ its.fp = SignalHandler::GetFramePointer(mcontext);
+ its.sp = SignalHandler::GetStackPointer(mcontext);
+ state->callback(its, state->data);
+ }
+};
+
+
+void ThreadInterrupter::InterruptThreads(int64_t current_time) {
+ for (intptr_t i = 0; i < threads_size_; i++) {
+ ThreadState* state = threads_[i];
+ ASSERT(state->id != Thread::kInvalidThreadId);
+ if (FLAG_trace_thread_interrupter) {
+ OS::Print("ThreadInterrupter interrupting %p\n",
+ reinterpret_cast<void*>(state->id));
+ }
+ pthread_kill(state->id, SIGPROF);
+ }
+}
+
+
+void ThreadInterrupter::InstallSignalHandler() {
+ SignalHandler::Install(ThreadInterrupterLinux::ThreadInterruptSignalHandler);
+}
+
+
+} // namespace dart
+
+#endif // defined(TARGET_OS_LINUX)
« no previous file with comments | « runtime/vm/thread_interrupter_android.cc ('k') | runtime/vm/thread_interrupter_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698