Reviewers: loislo, Benedikt Meurer, Sven Panne,

Description:
Allow configuring CPU profiler sampling interval using public API

The only way to change it at the moment is using a command line flag. We are
going to add a setting to Chrome DevTools which would allow chaning default
interval and that requires proper v8 API.

BUG=v8:2814

Please review this at https://codereview.chromium.org/23902004/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M include/v8-profiler.h
  M src/api.cc
  M src/cpu-profiler.h
  M src/cpu-profiler.cc


Index: include/v8-profiler.h
diff --git a/include/v8-profiler.h b/include/v8-profiler.h
index 1932fb8cd767b16cbcb3faaf693283605be11381..65a2f9ab673596af3f6e1d12418e99b0a7570fb1 100644
--- a/include/v8-profiler.h
+++ b/include/v8-profiler.h
@@ -141,13 +141,11 @@ class V8_EXPORT CpuProfile {
 class V8_EXPORT CpuProfiler {
  public:
   /**
-   * A note on security tokens usage. As scripts from different
-   * origins can run inside a single V8 instance, it is possible to
-   * have functions from different security contexts intermixed in a
-   * single CPU profile. To avoid exposing function names belonging to
-   * other contexts, filtering by security token is performed while
-   * obtaining profiling results.
+   * Changes default CPU profiler sampling interval to the specified number
+ * of microseconds. Default interval is 1000us. This method must be called
+   * when there are no profiles being recorded.
    */
+  void SetSamplingInterval(int us);

   /**
    * Returns the number of profiles collected (doesn't include
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 1a422fb73861a319e5d66a3c2603116767378f09..5901e450dfe8948fc1cc353b99cf96a7c97dc81c 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -53,6 +53,7 @@
 #endif
 #include "parser.h"
 #include "platform.h"
+#include "platform/time.h"
 #include "profile-generator-inl.h"
 #include "property-details.h"
 #include "property.h"
@@ -7348,6 +7349,13 @@ int CpuProfiler::GetProfileCount() {
 }


+void CpuProfiler::SetSamplingInterval(int us) {
+  ASSERT(us >= 0);
+  return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval(
+      i::TimeDelta::FromMicroseconds(us));
+}
+
+
 const CpuProfile* CpuProfiler::GetCpuProfile(int index) {
   return reinterpret_cast<const CpuProfile*>(
       reinterpret_cast<i::CpuProfiler*>(this)->GetProfile(index));
Index: src/cpu-profiler.cc
diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc
index 34bebb8eca1bfe8cd220240ff297fa972d8430f4..35fe7888646c0e37adcc5944947d3f15feaeabf4 100644
--- a/src/cpu-profiler.cc
+++ b/src/cpu-profiler.cc
@@ -363,6 +363,8 @@ void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) {

 CpuProfiler::CpuProfiler(Isolate* isolate)
     : isolate_(isolate),
+      sampling_interval_(TimeDelta::FromMicroseconds(
+          FLAG_cpu_profiler_sampling_interval)),
       profiles_(new CpuProfilesCollection()),
       next_profile_uid_(1),
       generator_(NULL),
@@ -376,6 +378,8 @@ CpuProfiler::CpuProfiler(Isolate* isolate,
                          ProfileGenerator* test_generator,
                          ProfilerEventsProcessor* test_processor)
     : isolate_(isolate),
+      sampling_interval_(TimeDelta::FromMicroseconds(
+          FLAG_cpu_profiler_sampling_interval)),
       profiles_(test_profiles),
       next_profile_uid_(1),
       generator_(test_generator),
@@ -390,6 +394,12 @@ CpuProfiler::~CpuProfiler() {
 }


+void CpuProfiler::set_sampling_interval(TimeDelta value) {
+  ASSERT(!is_profiling_);
+  sampling_interval_ = value;
+}
+
+
 void CpuProfiler::ResetProfiles() {
   delete profiles_;
   profiles_ = new CpuProfilesCollection();
@@ -418,8 +428,7 @@ void CpuProfiler::StartProcessorIfNotStarted() {
     generator_ = new ProfileGenerator(profiles_);
     Sampler* sampler = logger->sampler();
     processor_ = new ProfilerEventsProcessor(
-        generator_, sampler,
-        TimeDelta::FromMicroseconds(FLAG_cpu_profiler_sampling_interval));
+        generator_, sampler, sampling_interval_);
     is_profiling_ = true;
     // Enumerate stuff we already have in the heap.
     ASSERT(isolate_->heap()->HasBeenSetUp());
Index: src/cpu-profiler.h
diff --git a/src/cpu-profiler.h b/src/cpu-profiler.h
index a6eccffb6bc6f025ca73833e66cf61a0c23fb527..e36c3016bed163e1737d0650e48b36b048c44b10 100644
--- a/src/cpu-profiler.h
+++ b/src/cpu-profiler.h
@@ -31,6 +31,7 @@
 #include "allocation.h"
 #include "atomicops.h"
 #include "circular-queue.h"
+#include "platform/time.h"
 #include "sampler.h"
 #include "unbound-queue.h"

@@ -203,6 +204,7 @@ class CpuProfiler : public CodeEventListener {

   virtual ~CpuProfiler();

+  void set_sampling_interval(TimeDelta value);
   void StartProfiling(const char* title, bool record_samples = false);
   void StartProfiling(String* title, bool record_samples);
   CpuProfile* StopProfiling(const char* title);
@@ -260,6 +262,7 @@ class CpuProfiler : public CodeEventListener {
   void LogBuiltins();

   Isolate* isolate_;
+  TimeDelta sampling_interval_;
   CpuProfilesCollection* profiles_;
   unsigned next_profile_uid_;
   ProfileGenerator* generator_;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to