pthreads seem to be fully supported on Linux and Android which allows to remove many...
authoryurys@chromium.org <yurys@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 16 Apr 2013 12:06:43 +0000 (12:06 +0000)
committeryurys@chromium.org <yurys@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 16 Apr 2013 12:06:43 +0000 (12:06 +0000)
Also OS::Sleep(interval_) is used to pause sampling thread on all platforms. It makes no sense to send signal once 900mks to compensate 100mks delay on signal delivery as the signals would be delivered once 900mks.

BUG=None

Review URL: https://codereview.chromium.org/14238007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14278 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/cpu-profiler.h
src/log.h
src/platform.h
src/sampler.cc

index 89d9c81..6e2b0e0 100644 (file)
@@ -31,6 +31,7 @@
 #include "allocation.h"
 #include "atomicops.h"
 #include "circular-queue.h"
+#include "sampler.h"
 #include "unbound-queue.h"
 
 namespace v8 {
index 29bc8e8..21f387e 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -74,6 +74,7 @@ namespace internal {
 class LogMessageBuilder;
 class Profiler;
 class Semaphore;
+struct TickSample;
 class Ticker;
 class Isolate;
 class PositionsRecorder;
index 8551616..266c13a 100644 (file)
@@ -99,7 +99,6 @@ int random();
 #include "atomicops.h"
 #include "lazy-instance.h"
 #include "platform-tls.h"
-#include "sampler.h"
 #include "utils.h"
 #include "v8globals.h"
 
index 55b943c..2774629 100644 (file)
@@ -69,8 +69,7 @@ namespace v8 {
 namespace internal {
 
 
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) \
-    || defined(__NetBSD__) || defined(__sun) || defined(__ANDROID__)
+#if defined(USE_SIGNALS)
 
 #if defined(__ANDROID__) && !defined(__BIONIC_HAVE_UCONTEXT_T)
 
@@ -147,34 +146,17 @@ enum { REG_EBP = 6, REG_ESP = 7, REG_EIP = 14 };
 #endif  // __ANDROID__ && !defined(__BIONIC_HAVE_UCONTEXT_T)
 
 
-static pthread_t GetThreadID() {
-#if defined(__ANDROID__)
-  // Android's C library provides gettid(2).
-  return gettid();
-#elif defined(__linux__)
-  // Glibc doesn't provide a wrapper for gettid(2).
-  return syscall(SYS_gettid);
-#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
-    || defined(__sun)
-  return pthread_self();
-#endif
-}
-
-
 class Sampler::PlatformData : public Malloced {
  public:
   PlatformData()
-      : vm_tid_(GetThreadID()),
-        vm_tgid_(getpid()),
+      : vm_tid_(pthread_self()),
         profiled_thread_id_(ThreadId::Current()) {}
 
   pthread_t vm_tid() const { return vm_tid_; }
-  int vm_tgid() const { return vm_tgid_; }
   ThreadId profiled_thread_id() { return profiled_thread_id_; }
 
  private:
   pthread_t vm_tid_;
-  const int vm_tgid_;
   ThreadId profiled_thread_id_;
 };
 
@@ -440,7 +422,7 @@ class SamplerThread : public Thread {
         if (signal_handler_installed_) RestoreSignalHandler();
 #endif
       }
-      Sleep();  // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
+      OS::Sleep(interval_);
     }
   }
 
@@ -452,42 +434,13 @@ class SamplerThread : public Thread {
   }
 
 #if defined(USE_SIGNALS)
+
   void SampleContext(Sampler* sampler) {
     if (!signal_handler_installed_) return;
-    Sampler::PlatformData* platform_data = sampler->platform_data();
-    int tid = platform_data->vm_tid();
-    // Glibc doesn't provide a wrapper for tgkill(2).
-#if defined(ANDROID)
-    syscall(__NR_tgkill, platform_data->vm_tgid(), tid, SIGPROF);
-#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
-    || defined(__sun)
-    pthread_kill(tid, SIGPROF);
-#else
-    int result = syscall(SYS_tgkill, platform_data->vm_tgid(), tid, SIGPROF);
+    pthread_t tid = sampler->platform_data()->vm_tid();
+    int result = pthread_kill(tid, SIGPROF);
     USE(result);
     ASSERT(result == 0);
-#endif
-  }
-
-  void Sleep() {
-    // Convert ms to us and subtract 100 us to compensate delays
-    // occuring during signal delivery.
-    useconds_t interval = interval_ * 1000 - 100;
-#if defined(ANDROID)
-    usleep(interval);
-#else
-    int result = usleep(interval);
-#ifdef DEBUG
-    if (result != 0 && errno != EINTR) {
-      fprintf(stderr,
-              "SamplerThread usleep error; interval = %u, errno = %d\n",
-              interval,
-              errno);
-      ASSERT(result == 0 || errno == EINTR);
-    }
-#endif  // DEBUG
-    USE(result);
-#endif  // ANDROID
   }
 
 #elif defined(__MACH__)
@@ -561,10 +514,6 @@ class SamplerThread : public Thread {
     thread_resume(profiled_thread);
   }
 
-  void Sleep() {
-    OS::Sleep(interval_);
-  }
-
 #elif defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
 
   void SampleContext(Sampler* sampler) {
@@ -624,10 +573,6 @@ class SamplerThread : public Thread {
     ResumeThread(profiled_thread);
   }
 
-  void Sleep() {
-    OS::Sleep(interval_);
-  }
-
 #endif  // USE_SIGNALS
 
   const int interval_;