Commit c034bb48 authored by yurys@chromium.org's avatar yurys@chromium.org

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
parent 9bc60527
...@@ -141,13 +141,11 @@ class V8_EXPORT CpuProfile { ...@@ -141,13 +141,11 @@ class V8_EXPORT CpuProfile {
class V8_EXPORT CpuProfiler { class V8_EXPORT CpuProfiler {
public: public:
/** /**
* A note on security tokens usage. As scripts from different * Changes default CPU profiler sampling interval to the specified number
* origins can run inside a single V8 instance, it is possible to * of microseconds. Default interval is 1000us. This method must be called
* have functions from different security contexts intermixed in a * when there are no profiles being recorded.
* single CPU profile. To avoid exposing function names belonging to
* other contexts, filtering by security token is performed while
* obtaining profiling results.
*/ */
void SetSamplingInterval(int us);
/** /**
* Returns the number of profiles collected (doesn't include * Returns the number of profiles collected (doesn't include
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#endif #endif
#include "parser.h" #include "parser.h"
#include "platform.h" #include "platform.h"
#include "platform/time.h"
#include "profile-generator-inl.h" #include "profile-generator-inl.h"
#include "property-details.h" #include "property-details.h"
#include "property.h" #include "property.h"
...@@ -7348,6 +7349,13 @@ int CpuProfiler::GetProfileCount() { ...@@ -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) { const CpuProfile* CpuProfiler::GetCpuProfile(int index) {
return reinterpret_cast<const CpuProfile*>( return reinterpret_cast<const CpuProfile*>(
reinterpret_cast<i::CpuProfiler*>(this)->GetProfile(index)); reinterpret_cast<i::CpuProfiler*>(this)->GetProfile(index));
......
...@@ -363,6 +363,8 @@ void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) { ...@@ -363,6 +363,8 @@ void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) {
CpuProfiler::CpuProfiler(Isolate* isolate) CpuProfiler::CpuProfiler(Isolate* isolate)
: isolate_(isolate), : isolate_(isolate),
sampling_interval_(TimeDelta::FromMicroseconds(
FLAG_cpu_profiler_sampling_interval)),
profiles_(new CpuProfilesCollection()), profiles_(new CpuProfilesCollection()),
next_profile_uid_(1), next_profile_uid_(1),
generator_(NULL), generator_(NULL),
...@@ -376,6 +378,8 @@ CpuProfiler::CpuProfiler(Isolate* isolate, ...@@ -376,6 +378,8 @@ CpuProfiler::CpuProfiler(Isolate* isolate,
ProfileGenerator* test_generator, ProfileGenerator* test_generator,
ProfilerEventsProcessor* test_processor) ProfilerEventsProcessor* test_processor)
: isolate_(isolate), : isolate_(isolate),
sampling_interval_(TimeDelta::FromMicroseconds(
FLAG_cpu_profiler_sampling_interval)),
profiles_(test_profiles), profiles_(test_profiles),
next_profile_uid_(1), next_profile_uid_(1),
generator_(test_generator), generator_(test_generator),
...@@ -390,6 +394,12 @@ CpuProfiler::~CpuProfiler() { ...@@ -390,6 +394,12 @@ CpuProfiler::~CpuProfiler() {
} }
void CpuProfiler::set_sampling_interval(TimeDelta value) {
ASSERT(!is_profiling_);
sampling_interval_ = value;
}
void CpuProfiler::ResetProfiles() { void CpuProfiler::ResetProfiles() {
delete profiles_; delete profiles_;
profiles_ = new CpuProfilesCollection(); profiles_ = new CpuProfilesCollection();
...@@ -418,8 +428,7 @@ void CpuProfiler::StartProcessorIfNotStarted() { ...@@ -418,8 +428,7 @@ void CpuProfiler::StartProcessorIfNotStarted() {
generator_ = new ProfileGenerator(profiles_); generator_ = new ProfileGenerator(profiles_);
Sampler* sampler = logger->sampler(); Sampler* sampler = logger->sampler();
processor_ = new ProfilerEventsProcessor( processor_ = new ProfilerEventsProcessor(
generator_, sampler, generator_, sampler, sampling_interval_);
TimeDelta::FromMicroseconds(FLAG_cpu_profiler_sampling_interval));
is_profiling_ = true; is_profiling_ = true;
// Enumerate stuff we already have in the heap. // Enumerate stuff we already have in the heap.
ASSERT(isolate_->heap()->HasBeenSetUp()); ASSERT(isolate_->heap()->HasBeenSetUp());
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "allocation.h" #include "allocation.h"
#include "atomicops.h" #include "atomicops.h"
#include "circular-queue.h" #include "circular-queue.h"
#include "platform/time.h"
#include "sampler.h" #include "sampler.h"
#include "unbound-queue.h" #include "unbound-queue.h"
...@@ -203,6 +204,7 @@ class CpuProfiler : public CodeEventListener { ...@@ -203,6 +204,7 @@ class CpuProfiler : public CodeEventListener {
virtual ~CpuProfiler(); virtual ~CpuProfiler();
void set_sampling_interval(TimeDelta value);
void StartProfiling(const char* title, bool record_samples = false); void StartProfiling(const char* title, bool record_samples = false);
void StartProfiling(String* title, bool record_samples); void StartProfiling(String* title, bool record_samples);
CpuProfile* StopProfiling(const char* title); CpuProfile* StopProfiling(const char* title);
...@@ -260,6 +262,7 @@ class CpuProfiler : public CodeEventListener { ...@@ -260,6 +262,7 @@ class CpuProfiler : public CodeEventListener {
void LogBuiltins(); void LogBuiltins();
Isolate* isolate_; Isolate* isolate_;
TimeDelta sampling_interval_;
CpuProfilesCollection* profiles_; CpuProfilesCollection* profiles_;
unsigned next_profile_uid_; unsigned next_profile_uid_;
ProfileGenerator* generator_; ProfileGenerator* generator_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment