Chromium Code Reviews| 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..c79b7a4eaab68d076ee41d6edfa2f5e41f84289b 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,47 @@ 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(heap, step_size), |
| + profiler_(profiler), |
| + rate_(rate), |
| + random_(random) {} |
| + 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* profiler_; |
| + uint64_t rate_; |
|
ofrobots
2016/01/23 16:16:31
Weak suggestion: prefer to group member together b
mattloring
2016/01/26 00:42:48
Done.
|
| + base::RandomNumberGenerator* random_; |
|
ofrobots
2016/01/23 16:16:31
Mark the above as const. E.g. SamplingHeapProfiler
mattloring
2016/01/26 00:42:48
Done.
|
| + |
| + intptr_t GetNextSampleInterval(base::RandomNumberGenerator* random, |
| + uint64_t rate); |
|
ofrobots
2016/01/23 16:16:31
Any reason you make this non-static here?
mattloring
2016/01/26 00:42:48
I was having problems with `incomplete type base::
ofrobots
2016/01/26 15:47:15
Move (keep) the function in the .cc file. This can
|
| +}; |
| + |
| + |
| } // namespace internal |
| } // namespace v8 |