Index: src/profiler/sampling-heap-profiler.h |
diff --git a/src/profiler/sampling-heap-profiler.h b/src/profiler/sampling-heap-profiler.h |
index d9b88e9b861bdaa2d135f53b056f301a6f543096..3353589fe34127c875416fb75994c048cee31a23 100644 |
--- a/src/profiler/sampling-heap-profiler.h |
+++ b/src/profiler/sampling-heap-profiler.h |
@@ -20,6 +20,7 @@ class RandomNumberGenerator; |
namespace internal { |
+class SamplingAllocationObserver; |
class AllocationProfile : public v8::AllocationProfile { |
public: |
@@ -37,7 +38,8 @@ class AllocationProfile : public v8::AllocationProfile { |
DISALLOW_COPY_AND_ASSIGN(AllocationProfile); |
}; |
-class SamplingHeapProfiler : public InlineAllocationObserver { |
+ |
+class SamplingHeapProfiler { |
public: |
SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate, |
int stack_depth); |
@@ -45,11 +47,6 @@ class SamplingHeapProfiler : public InlineAllocationObserver { |
v8::AllocationProfile* GetAllocationProfile(); |
- void Step(int bytes_allocated, Address soon_object, size_t size) override; |
- intptr_t GetNextStepSize() override { |
- return GetNextSampleInterval(random_, rate_); |
- } |
- |
StringsStorage* names() const { return names_; } |
class FunctionInfo { |
@@ -99,15 +96,13 @@ class SamplingHeapProfiler : public InlineAllocationObserver { |
}; |
private: |
+ friend class SamplingAllocationObserver; |
using Node = v8::AllocationProfile::Node; |
Heap* heap() const { return heap_; } |
void SampleObject(Address soon_object, size_t size); |
- static intptr_t GetNextSampleInterval(base::RandomNumberGenerator* random, |
- uint64_t rate); |
- |
// Methods that construct v8::AllocationProfile. |
Node* AddStack(AllocationProfile* profile, |
const std::map<int, Script*>& scripts, |
@@ -121,14 +116,49 @@ class SamplingHeapProfiler : public InlineAllocationObserver { |
Isolate* const isolate_; |
Heap* const heap_; |
- base::RandomNumberGenerator* const random_; |
+ SamplingAllocationObserver* new_space_observer_; |
+ SamplingAllocationObserver* other_spaces_observer_; |
StringsStorage* const names_; |
std::set<SampledAllocation*> samples_; |
- const uint64_t rate_; |
const int stack_depth_; |
}; |
+class SamplingAllocationObserver : public AllocationObserver { |
+ public: |
+ explicit SamplingAllocationObserver(Heap* heap, intptr_t step_size, |
+ uint64_t rate, |
+ SamplingHeapProfiler* profiler, |
+ base::RandomNumberGenerator* random) |
+ : AllocationObserver(step_size), |
+ profiler_(profiler), |
+ heap_(heap), |
+ random_(random), |
+ rate_(rate) {} |
+ virtual ~SamplingAllocationObserver() {} |
+ |
+ protected: |
+ void Step(int bytes_allocated, Address soon_object, size_t size) override { |
+ DCHECK(heap_->gc_state() == Heap::NOT_IN_GC); |
+ DCHECK(soon_object); |
+ profiler_->SampleObject(soon_object, size); |
+ } |
+ |
+ intptr_t GetNextStepSize() override { |
+ return GetNextSampleInterval(random_, rate_); |
+ } |
+ |
+ private: |
+ SamplingHeapProfiler* const profiler_; |
+ Heap* const heap_; |
+ base::RandomNumberGenerator* const random_; |
+ uint64_t const rate_; |
+ |
+ intptr_t GetNextSampleInterval(base::RandomNumberGenerator* random, |
+ uint64_t rate); |
+}; |
+ |
+ |
} // namespace internal |
} // namespace v8 |