Index: src/platform-linux.cc |
diff --git a/src/platform-linux.cc b/src/platform-linux.cc |
index 398e9545688c0726e9946eeb0e4eff02b0658902..af47d05b88b8aff7d7eb8687e95a58bfd0200f82 100644 |
--- a/src/platform-linux.cc |
+++ b/src/platform-linux.cc |
@@ -68,6 +68,7 @@ |
#include "platform-posix.h" |
#include "platform.h" |
+#include "simulator.h" |
#include "v8threads.h" |
#include "vm-state-inl.h" |
@@ -1076,6 +1077,21 @@ static int GetThreadID() { |
} |
+class Sampler::PlatformData : public Malloced { |
+ public: |
+ PlatformData() |
+ : vm_tid_(GetThreadID()), |
+ profiled_thread_id_(ThreadId::Current()) {} |
+ |
+ pthread_t vm_tid() const { return vm_tid_; } |
+ ThreadId profiled_thread_id() { return profiled_thread_id_; } |
+ |
+ private: |
+ pthread_t vm_tid_; |
+ ThreadId profiled_thread_id_; |
+}; |
+ |
+ |
static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { |
#if defined(__native_client__) |
// As Native Client does not support signal handling, profiling |
@@ -1097,10 +1113,33 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { |
Sampler* sampler = isolate->logger()->sampler(); |
if (sampler == NULL || !sampler->IsActive()) return; |
+#if defined(USE_SIMULATOR) |
+#if V8_TARGET_ARCH_ARM || V8_TARGET_ARCH_MIPS |
+ ThreadId thread_id = sampler->platform_data()->profiled_thread_id(); |
+ Isolate::PerIsolateThreadData* per_thread_data = isolate-> |
+ FindPerThreadDataForThread(thread_id); |
+ if (!per_thread_data) return; |
+ Simulator* sim = per_thread_data->simulator(); |
+ // Check if there is active simulator before allocating TickSample. |
+ if (!sim) return; |
+#endif |
+#endif // USE_SIMULATOR |
+ |
TickSample sample_obj; |
TickSample* sample = isolate->cpu_profiler()->TickSampleEvent(); |
if (sample == NULL) sample = &sample_obj; |
+#if defined(USE_SIMULATOR) |
+#if V8_TARGET_ARCH_ARM |
+ sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
+ sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
+ sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::r11)); |
+#elif V8_TARGET_ARCH_MIPS |
+ sample->pc = reinterpret_cast<Address>(sim->get_register(Simulator::pc)); |
+ sample->sp = reinterpret_cast<Address>(sim->get_register(Simulator::sp)); |
+ sample->fp = reinterpret_cast<Address>(sim->get_register(Simulator::fp)); |
+#endif |
+#else |
// Extracting the sample from the context is extremely machine dependent. |
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context); |
mcontext_t& mcontext = ucontext->uc_mcontext; |
@@ -1132,23 +1171,13 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { |
sample->sp = reinterpret_cast<Address>(mcontext.gregs[29]); |
sample->fp = reinterpret_cast<Address>(mcontext.gregs[30]); |
#endif // V8_HOST_ARCH_* |
+#endif // USE_SIMULATOR |
sampler->SampleStack(sample); |
sampler->Tick(sample); |
#endif // __native_client__ |
} |
-class Sampler::PlatformData : public Malloced { |
- public: |
- PlatformData() : vm_tid_(GetThreadID()) {} |
- |
- int vm_tid() const { return vm_tid_; } |
- |
- private: |
- const int vm_tid_; |
-}; |
- |
- |
class SignalSender : public Thread { |
public: |
static const int kSignalSenderStackSize = 64 * KB; |