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 {
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
......
......@@ -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));
......
......@@ -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());
......
......@@ -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_;
......
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