From c034bb48b504192a35b07762a8b5bebc0b3973c7 Mon Sep 17 00:00:00 2001 From: "yurys@chromium.org" Date: Wed, 4 Sep 2013 11:55:28 +0000 Subject: [PATCH] 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 R=bmeurer@chromium.org, loislo@chromium.org Review URL: https://codereview.chromium.org/23902004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16525 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8-profiler.h | 10 ++++------ src/api.cc | 8 ++++++++ src/cpu-profiler.cc | 13 +++++++++++-- src/cpu-profiler.h | 3 +++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/v8-profiler.h b/include/v8-profiler.h index 1932fb8..65a2f9a 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 diff --git a/src/api.cc b/src/api.cc index 1a422fb..5901e45 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(this)->set_sampling_interval( + i::TimeDelta::FromMicroseconds(us)); +} + + const CpuProfile* CpuProfiler::GetCpuProfile(int index) { return reinterpret_cast( reinterpret_cast(this)->GetProfile(index)); diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc index 34bebb8..35fe788 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()); diff --git a/src/cpu-profiler.h b/src/cpu-profiler.h index a6eccff..e36c301 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_; -- 2.7.4