| Index: src/profiler/sampling-heap-profiler.cc
|
| diff --git a/src/profiler/sampling-heap-profiler.cc b/src/profiler/sampling-heap-profiler.cc
|
| index 0e68338230fd311a0719d4d0a18278950a75173b..077b4466730fa746a26fe677809b3de2baa4fdba 100644
|
| --- a/src/profiler/sampling-heap-profiler.cc
|
| +++ b/src/profiler/sampling-heap-profiler.cc
|
| @@ -16,23 +16,51 @@
|
| namespace v8 {
|
| namespace internal {
|
|
|
| +
|
| +// We sample with a Poisson process, with constant average sampling interval.
|
| +// This follows the exponential probability distribution with parameter
|
| +// λ = 1/rate where rate is the average number of bytes between samples.
|
| +//
|
| +// Let u be a uniformly distributed random number between 0 and 1, then
|
| +// next_sample = (- ln u) / λ
|
| +intptr_t SamplingAllocationObserver::GetNextSampleInterval(
|
| + base::RandomNumberGenerator* random, uint64_t rate) {
|
| + if (FLAG_sampling_heap_profiler_suppress_randomness) {
|
| + return rate;
|
| + }
|
| + double u = random->NextDouble();
|
| + double next = (-std::log(u)) * rate;
|
| + return next < kPointerSize
|
| + ? kPointerSize
|
| + : (next > INT_MAX ? INT_MAX : static_cast<intptr_t>(next));
|
| +}
|
| +
|
| +
|
| SamplingHeapProfiler::SamplingHeapProfiler(Heap* heap, StringsStorage* names,
|
| uint64_t rate, int stack_depth)
|
| - : InlineAllocationObserver(GetNextSampleInterval(
|
| - heap->isolate()->random_number_generator(), rate)),
|
| - isolate_(heap->isolate()),
|
| + : isolate_(heap->isolate()),
|
| heap_(heap),
|
| - random_(isolate_->random_number_generator()),
|
| names_(names),
|
| samples_(),
|
| - rate_(rate),
|
| stack_depth_(stack_depth) {
|
| - heap->new_space()->AddInlineAllocationObserver(this);
|
| + new_space_observer_ = new SamplingAllocationObserver(
|
| + heap_, rate, rate, this, heap->isolate()->random_number_generator());
|
| + heap->new_space()->AddAllocationObserver(new_space_observer_);
|
| + other_spaces_observer_ = new SamplingAllocationObserver(
|
| + heap_, rate, rate, this, heap->isolate()->random_number_generator());
|
| + heap->old_space()->AddAllocationObserver(other_spaces_observer_);
|
| + heap->code_space()->AddAllocationObserver(other_spaces_observer_);
|
| + heap->map_space()->AddAllocationObserver(other_spaces_observer_);
|
| + heap->lo_space()->AddAllocationObserver(other_spaces_observer_);
|
| }
|
|
|
|
|
| SamplingHeapProfiler::~SamplingHeapProfiler() {
|
| - heap_->new_space()->RemoveInlineAllocationObserver(this);
|
| + heap_->new_space()->RemoveAllocationObserver(new_space_observer_);
|
| + heap_->old_space()->RemoveAllocationObserver(other_spaces_observer_);
|
| + heap_->code_space()->RemoveAllocationObserver(other_spaces_observer_);
|
| + heap_->map_space()->RemoveAllocationObserver(other_spaces_observer_);
|
| + heap_->lo_space()->RemoveAllocationObserver(other_spaces_observer_);
|
|
|
| // Clear samples and drop all the weak references we are keeping.
|
| std::set<SampledAllocation*>::iterator it;
|
| @@ -43,13 +71,6 @@ SamplingHeapProfiler::~SamplingHeapProfiler() {
|
| samples_.swap(empty);
|
| }
|
|
|
| -void SamplingHeapProfiler::Step(int bytes_allocated, Address soon_object,
|
| - size_t size) {
|
| - DCHECK(heap_->gc_state() == Heap::NOT_IN_GC);
|
| - DCHECK(soon_object);
|
| - SampleObject(soon_object, size);
|
| -}
|
| -
|
|
|
| void SamplingHeapProfiler::SampleObject(Address soon_object, size_t size) {
|
| DisallowHeapAllocation no_allocation;
|
| @@ -70,25 +91,6 @@ void SamplingHeapProfiler::SampleObject(Address soon_object, size_t size) {
|
| }
|
|
|
|
|
| -// We sample with a Poisson process, with constant average sampling interval.
|
| -// This follows the exponential probability distribution with parameter
|
| -// λ = 1/rate where rate is the average number of bytes between samples.
|
| -//
|
| -// Let u be a uniformly distributed random number between 0 and 1, then
|
| -// next_sample = (- ln u) / λ
|
| -intptr_t SamplingHeapProfiler::GetNextSampleInterval(
|
| - base::RandomNumberGenerator* random, uint64_t rate) {
|
| - if (FLAG_sampling_heap_profiler_suppress_randomness) {
|
| - return rate;
|
| - }
|
| - double u = random->NextDouble();
|
| - double next = (-std::log(u)) * rate;
|
| - return next < kPointerSize
|
| - ? kPointerSize
|
| - : (next > INT_MAX ? INT_MAX : static_cast<intptr_t>(next));
|
| -}
|
| -
|
| -
|
| void SamplingHeapProfiler::SampledAllocation::OnWeakCallback(
|
| const WeakCallbackInfo<SampledAllocation>& data) {
|
| SampledAllocation* sample = data.GetParameter();
|
|
|