OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ |
| 6 #define V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ |
| 7 |
| 8 #include <set> |
| 9 #include "src/base/utils/random-number-generator.h" |
| 10 #include "src/profiler/allocation-tracker.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 |
| 15 class SamplingHeapProfiler : public InlineAllocationObserver { |
| 16 public: |
| 17 SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate, |
| 18 int stack_depth); |
| 19 ~SamplingHeapProfiler(); |
| 20 |
| 21 void GetHeapSample(OutputStream* stream); |
| 22 |
| 23 void Step(int bytes_allocated, Address soon_object, size_t size) override; |
| 24 intptr_t GetNextStepSize() override { |
| 25 return GetNextSampleInterval(random_, rate_); |
| 26 } |
| 27 |
| 28 StringsStorage* names() const { return names_; } |
| 29 |
| 30 struct FunctionInfo { |
| 31 FunctionInfo(SharedFunctionInfo* shared, StringsStorage* names); |
| 32 |
| 33 const char* const name; |
| 34 const char* script_name; |
| 35 int script_id; |
| 36 int start_position; |
| 37 }; |
| 38 |
| 39 class SampledAllocation { |
| 40 public: |
| 41 SampledAllocation(SamplingHeapProfiler* shp, Isolate* isolate, |
| 42 Local<Value> local, size_t size, int max_frames); |
| 43 ~SampledAllocation() { |
| 44 stack_.Iterate(&DeleteFunctionInfo); |
| 45 global_.Reset(); // drop the reference. |
| 46 } |
| 47 size_t get_size() const { return size_; } |
| 48 List<FunctionInfo*>& get_stack() { return stack_; } |
| 49 |
| 50 private: |
| 51 static void OnWeakCallback(const WeakCallbackInfo<SampledAllocation>& data); |
| 52 static void DeleteFunctionInfo(FunctionInfo** infop) { delete *infop; } |
| 53 |
| 54 SamplingHeapProfiler* const shp_; |
| 55 Global<Value> global_; |
| 56 List<FunctionInfo*> stack_; |
| 57 const size_t size_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(SampledAllocation); |
| 60 }; |
| 61 |
| 62 private: |
| 63 Heap* heap() const { return heap_; } |
| 64 |
| 65 void SampleObject(Address soon_object, size_t size); |
| 66 |
| 67 static intptr_t GetNextSampleInterval(base::RandomNumberGenerator* random, |
| 68 uint64_t rate); |
| 69 |
| 70 Isolate* const isolate_; |
| 71 Heap* const heap_; |
| 72 base::RandomNumberGenerator* const random_; |
| 73 StringsStorage* const names_; |
| 74 std::set<SampledAllocation*> samples_; |
| 75 const uint64_t rate_; |
| 76 const int stack_depth_; |
| 77 }; |
| 78 |
| 79 } // namespace internal |
| 80 } // namespace v8 |
| 81 |
| 82 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ |
OLD | NEW |