 Chromium Code Reviews
 Chromium Code Reviews Issue 1625753002:
  Allocation sampling for paged/lo spaces  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 1625753002:
  Allocation sampling for paged/lo spaces  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | 5 #ifndef V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | 
| 6 #define V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | 6 #define V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | 
| 7 | 7 | 
| 8 #include <deque> | 8 #include <deque> | 
| 9 #include <map> | 9 #include <map> | 
| 10 #include <set> | 10 #include <set> | 
| 11 #include "include/v8-profiler.h" | 11 #include "include/v8-profiler.h" | 
| 12 #include "src/heap/heap.h" | 12 #include "src/heap/heap.h" | 
| 13 #include "src/profiler/strings-storage.h" | 13 #include "src/profiler/strings-storage.h" | 
| 14 | 14 | 
| 15 namespace v8 { | 15 namespace v8 { | 
| 16 | 16 | 
| 17 namespace base { | 17 namespace base { | 
| 18 class RandomNumberGenerator; | 18 class RandomNumberGenerator; | 
| 19 } | 19 } | 
| 20 | 20 | 
| 21 namespace internal { | 21 namespace internal { | 
| 22 | 22 | 
| 23 class SamplingAllocationObserver; | |
| 23 | 24 | 
| 24 class AllocationProfile : public v8::AllocationProfile { | 25 class AllocationProfile : public v8::AllocationProfile { | 
| 25 public: | 26 public: | 
| 26 AllocationProfile() : nodes_() {} | 27 AllocationProfile() : nodes_() {} | 
| 27 | 28 | 
| 28 Node* GetRootNode() override { | 29 Node* GetRootNode() override { | 
| 29 return nodes_.size() == 0 ? nullptr : &nodes_.front(); | 30 return nodes_.size() == 0 ? nullptr : &nodes_.front(); | 
| 30 } | 31 } | 
| 31 | 32 | 
| 32 std::deque<Node>& nodes() { return nodes_; } | 33 std::deque<Node>& nodes() { return nodes_; } | 
| 33 | 34 | 
| 34 private: | 35 private: | 
| 35 std::deque<Node> nodes_; | 36 std::deque<Node> nodes_; | 
| 36 | 37 | 
| 37 DISALLOW_COPY_AND_ASSIGN(AllocationProfile); | 38 DISALLOW_COPY_AND_ASSIGN(AllocationProfile); | 
| 38 }; | 39 }; | 
| 39 | 40 | 
| 40 class SamplingHeapProfiler : public InlineAllocationObserver { | 41 class SamplingHeapProfiler { | 
| 41 public: | 42 public: | 
| 42 SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate, | 43 SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate, | 
| 43 int stack_depth); | 44 int stack_depth); | 
| 44 ~SamplingHeapProfiler(); | 45 ~SamplingHeapProfiler(); | 
| 45 | 46 | 
| 46 v8::AllocationProfile* GetAllocationProfile(); | 47 v8::AllocationProfile* GetAllocationProfile(); | 
| 47 | 48 | 
| 48 void Step(int bytes_allocated, Address soon_object, size_t size) override; | |
| 49 intptr_t GetNextStepSize() override { | |
| 50 return GetNextSampleInterval(random_, rate_); | |
| 51 } | |
| 52 | |
| 53 StringsStorage* names() const { return names_; } | 49 StringsStorage* names() const { return names_; } | 
| 54 | 50 | 
| 55 class FunctionInfo { | 51 class FunctionInfo { | 
| 56 public: | 52 public: | 
| 57 FunctionInfo(SharedFunctionInfo* shared, StringsStorage* names); | 53 FunctionInfo(SharedFunctionInfo* shared, StringsStorage* names); | 
| 58 explicit FunctionInfo(const char* name) | 54 explicit FunctionInfo(const char* name) | 
| 59 : name_(name), | 55 : name_(name), | 
| 60 script_name_(""), | 56 script_name_(""), | 
| 61 script_id_(v8::UnboundScript::kNoScriptId), | 57 script_id_(v8::UnboundScript::kNoScriptId), | 
| 62 start_position_(0) {} | 58 start_position_(0) {} | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 92 | 88 | 
| 93 SamplingHeapProfiler* const sampling_heap_profiler_; | 89 SamplingHeapProfiler* const sampling_heap_profiler_; | 
| 94 Global<Value> global_; | 90 Global<Value> global_; | 
| 95 std::vector<FunctionInfo*> stack_; | 91 std::vector<FunctionInfo*> stack_; | 
| 96 const size_t size_; | 92 const size_t size_; | 
| 97 | 93 | 
| 98 DISALLOW_COPY_AND_ASSIGN(SampledAllocation); | 94 DISALLOW_COPY_AND_ASSIGN(SampledAllocation); | 
| 99 }; | 95 }; | 
| 100 | 96 | 
| 101 private: | 97 private: | 
| 98 friend class SamplingAllocationObserver; | |
| 
Hannes Payer (out of office)
2016/02/08 10:13:48
Style guide: friends come after variables.
 
mattloring
2016/02/09 20:20:05
Done.
 | |
| 102 using Node = v8::AllocationProfile::Node; | 99 using Node = v8::AllocationProfile::Node; | 
| 
Hannes Payer (out of office)
2016/02/08 10:13:48
Style guide: Do not use using-directives.
 
mattloring
2016/02/09 20:20:05
Done.
 | |
| 103 | 100 | 
| 104 Heap* heap() const { return heap_; } | 101 Heap* heap() const { return heap_; } | 
| 105 | 102 | 
| 106 void SampleObject(Address soon_object, size_t size); | 103 void SampleObject(Address soon_object, size_t size); | 
| 107 | 104 | 
| 108 static intptr_t GetNextSampleInterval(base::RandomNumberGenerator* random, | |
| 109 uint64_t rate); | |
| 110 | |
| 111 // Methods that construct v8::AllocationProfile. | 105 // Methods that construct v8::AllocationProfile. | 
| 112 Node* AddStack(AllocationProfile* profile, | 106 Node* AddStack(AllocationProfile* profile, | 
| 113 const std::map<int, Script*>& scripts, | 107 const std::map<int, Script*>& scripts, | 
| 114 const std::vector<FunctionInfo*>& stack); | 108 const std::vector<FunctionInfo*>& stack); | 
| 115 Node* FindOrAddChildNode(AllocationProfile* profile, | 109 Node* FindOrAddChildNode(AllocationProfile* profile, | 
| 116 const std::map<int, Script*>& scripts, Node* parent, | 110 const std::map<int, Script*>& scripts, Node* parent, | 
| 117 FunctionInfo* function_info); | 111 FunctionInfo* function_info); | 
| 118 Node* AllocateNode(AllocationProfile* profile, | 112 Node* AllocateNode(AllocationProfile* profile, | 
| 119 const std::map<int, Script*>& scripts, | 113 const std::map<int, Script*>& scripts, | 
| 120 FunctionInfo* function_info); | 114 FunctionInfo* function_info); | 
| 121 | 115 | 
| 122 Isolate* const isolate_; | 116 Isolate* const isolate_; | 
| 123 Heap* const heap_; | 117 Heap* const heap_; | 
| 124 base::RandomNumberGenerator* const random_; | 118 SamplingAllocationObserver* new_space_observer_; | 
| 119 SamplingAllocationObserver* other_spaces_observer_; | |
| 125 StringsStorage* const names_; | 120 StringsStorage* const names_; | 
| 126 std::set<SampledAllocation*> samples_; | 121 std::set<SampledAllocation*> samples_; | 
| 127 const uint64_t rate_; | |
| 128 const int stack_depth_; | 122 const int stack_depth_; | 
| 129 }; | 123 }; | 
| 130 | 124 | 
| 125 class SamplingAllocationObserver : public AllocationObserver { | |
| 126 public: | |
| 127 explicit SamplingAllocationObserver(Heap* heap, intptr_t step_size, | |
| 128 uint64_t rate, | |
| 129 SamplingHeapProfiler* profiler, | |
| 130 base::RandomNumberGenerator* random) | |
| 131 : AllocationObserver(step_size), | |
| 132 profiler_(profiler), | |
| 133 heap_(heap), | |
| 134 random_(random), | |
| 135 rate_(rate) {} | |
| 136 virtual ~SamplingAllocationObserver() {} | |
| 137 | |
| 138 protected: | |
| 139 void Step(int bytes_allocated, Address soon_object, size_t size) override { | |
| 140 DCHECK(heap_->gc_state() == Heap::NOT_IN_GC); | |
| 141 DCHECK(soon_object); | |
| 142 profiler_->SampleObject(soon_object, size); | |
| 143 } | |
| 144 | |
| 145 intptr_t GetNextStepSize() override { | |
| 146 return GetNextSampleInterval(random_, rate_); | |
| 147 } | |
| 148 | |
| 149 private: | |
| 150 SamplingHeapProfiler* const profiler_; | |
| 151 Heap* const heap_; | |
| 152 base::RandomNumberGenerator* const random_; | |
| 153 uint64_t const rate_; | |
| 154 | |
| 155 intptr_t GetNextSampleInterval(base::RandomNumberGenerator* random, | |
| 
Hannes Payer (out of office)
2016/02/08 10:13:48
Style guide: methods go before variables.
 
mattloring
2016/02/09 20:20:05
Done.
 | |
| 156 uint64_t rate); | |
| 157 }; | |
| 131 | 158 | 
| 132 } // namespace internal | 159 } // namespace internal | 
| 133 } // namespace v8 | 160 } // namespace v8 | 
| 134 | 161 | 
| 135 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | 162 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | 
| OLD | NEW |