Bug 713232 - Fix the hang in the built-in profiler on Windows; r=BenWa
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 24 Dec 2011 12:11:26 -0500
changeset 84570 45206fca898d121626f890cb2bdde1ac37a1535f
parent 84569 c93d8c55f67d07b17be78bfefaf77641d0b95d6b
child 84571 1f0062478a1f93231064f24b22c443d544ea3e64
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBenWa
bugs713232
milestone12.0a1
Bug 713232 - Fix the hang in the built-in profiler on Windows; r=BenWa
tools/profiler/sps/TableTicker.cpp
tools/profiler/sps/platform-linux.cc
tools/profiler/sps/platform-macos.cc
tools/profiler/sps/platform-win32.cc
tools/profiler/sps/platform.h
--- a/tools/profiler/sps/TableTicker.cpp
+++ b/tools/profiler/sps/TableTicker.cpp
@@ -326,17 +326,17 @@ void TableTicker::Tick(TickSample* sampl
       }
       mProfile.addTag(ProfileEntry('s', mStack->mStack[i], pc));
     } else {
       mProfile.addTag(ProfileEntry('c', mStack->mStack[i]));
     }
   }
 
   if (!sLastTracerEvent.IsNull()) {
-    TimeDuration delta = TimeStamp::Now() - sLastTracerEvent;
+    TimeDuration delta = sample->timestamp - sLastTracerEvent;
     mProfile.addTag(ProfileEntry('r', delta.ToMilliseconds()));
   }
 }
 
 string ProfileEntry::TagToString(Profile *profile)
 {
   string tag = "";
   if (mTagName == 'r') {
--- a/tools/profiler/sps/platform-linux.cc
+++ b/tools/profiler/sps/platform-linux.cc
@@ -183,16 +183,17 @@ static void ProfilerSignalHandler(int si
     sample->pc = reinterpret_cast<Address>(mcontext.arm_pc);
     sample->sp = reinterpret_cast<Address>(mcontext.arm_sp);
     sample->fp = reinterpret_cast<Address>(mcontext.arm_fp);
 #endif
 #elif V8_HOST_ARCH_MIPS
     // Implement this on MIPS.
     UNIMPLEMENTED();
 #endif
+    sample->timestamp = mozilla::TimeStamp::Now();
   }
 #endif
   sActiveSampler->Tick(sample);
 }
 
 void tgkill(pid_t tgid, pid_t tid, int signalno) {
   syscall(SYS_tgkill, tgid, tid, signalno);
 }
--- a/tools/profiler/sps/platform-macos.cc
+++ b/tools/profiler/sps/platform-macos.cc
@@ -248,16 +248,17 @@ class SamplerThread : public Thread {
     if (thread_get_state(profiled_thread,
                          flavor,
                          reinterpret_cast<natural_t*>(&state),
                          &count) == KERN_SUCCESS) {
       //sample->state = sampler->isolate()->current_vm_state();
       sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip));
       sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp));
       sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp));
+      sample->timestamp = mozilla::TimeStamp::Now();
       sampler->SampleStack(sample);
       sampler->Tick(sample);
     }
     thread_resume(profiled_thread);
   }
 
   const int interval_;
   //RuntimeProfilerRateLimiter rate_limiter_;
--- a/tools/profiler/sps/platform-win32.cc
+++ b/tools/profiler/sps/platform-win32.cc
@@ -72,16 +72,19 @@ class SamplerThread : public Thread {
 
     // Context used for sampling the register state of the profiled thread.
     CONTEXT context;
     memset(&context, 0, sizeof(context));
 
     TickSample sample_obj;
     TickSample* sample = &sample_obj;
 
+    // Grab the timestamp before pausing the thread, to avoid deadlocks.
+    sample->timestamp = mozilla::TimeStamp::Now();
+
     static const DWORD kSuspendFailed = static_cast<DWORD>(-1);
     if (SuspendThread(profiled_thread) == kSuspendFailed)
       return;
 
     context.ContextFlags = CONTEXT_FULL;
     if (GetThreadContext(profiled_thread, &context) != 0) {
 #if V8_HOST_ARCH_X64
       sample->pc = reinterpret_cast<Address>(context.Rip);
--- a/tools/profiler/sps/platform.h
+++ b/tools/profiler/sps/platform.h
@@ -5,16 +5,17 @@
 #ifdef ANDROID
 #include <android/log.h>
 #else
 #define __android_log_print(a, ...)
 #endif
 
 #include "mozilla/Util.h"
 #include "mozilla/unused.h"
+#include "mozilla/TimeStamp.h"
 #include "v8-support.h"
 #include <vector>
 #define ASSERT(a) MOZ_ASSERT(a)
 #ifdef ANDROID
 #define ENABLE_SPS_LEAF_DATA
 #define LOG(text) __android_log_print(ANDROID_LOG_ERROR, "profiler", "%s", text);
 #else
 #define LOG(text) printf("Profiler: %s\n", text)
@@ -226,16 +227,17 @@ class TickSample {
         frames_count(0) {}
   Address pc;  // Instruction pointer.
   Address sp;  // Stack pointer.
   Address fp;  // Frame pointer.
   Address function;  // The last called JS function.
   static const int kMaxFramesCount = 64;
   Address stack[kMaxFramesCount];  // Call stack.
   int frames_count;  // Number of captured frames.
+  mozilla::TimeStamp timestamp;
 };
 
 class Sampler {
  public:
   // Initialize sampler.
   explicit Sampler(int interval, bool profiling);
   virtual ~Sampler();