Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: src/profiler/sampling-heap-profiler.cc

Issue 1625753002: Allocation sampling for paged/lo spaces (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8aa92e61f119d040e7247086ba7ab5c872716ba4 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()->AddInlineAllocationObserver(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()->RemoveInlineAllocationObserver(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();

Powered by Google App Engine
This is Rietveld 408576698