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> |
(...skipping 30 matching lines...) Expand all Loading... | |
41 class SamplingHeapProfiler { | 41 class SamplingHeapProfiler { |
42 public: | 42 public: |
43 SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate, | 43 SamplingHeapProfiler(Heap* heap, StringsStorage* names, uint64_t rate, |
44 int stack_depth); | 44 int stack_depth); |
45 ~SamplingHeapProfiler(); | 45 ~SamplingHeapProfiler(); |
46 | 46 |
47 v8::AllocationProfile* GetAllocationProfile(); | 47 v8::AllocationProfile* GetAllocationProfile(); |
48 | 48 |
49 StringsStorage* names() const { return names_; } | 49 StringsStorage* names() const { return names_; } |
50 | 50 |
51 class FunctionInfo { | 51 class AllocationNode; |
52 | |
53 struct Sample { | |
54 size_t size; | |
55 AllocationNode* owner; | |
56 Global<Value> global; | |
57 SamplingHeapProfiler* profiler; | |
ulan
2016/02/17 11:14:50
Disallow copy and assign.
mattloring
2016/02/17 17:50:21
Done.
| |
58 }; | |
59 | |
60 class AllocationNode { | |
52 public: | 61 public: |
53 FunctionInfo(SharedFunctionInfo* shared, StringsStorage* names); | 62 explicit AllocationNode(const char* const name, int script_id, |
ulan
2016/02/17 11:14:50
No need for explicit here.
mattloring
2016/02/17 17:50:21
Done.
| |
54 explicit FunctionInfo(const char* name) | 63 const int start_position) |
55 : name_(name), | 64 : script_id_(script_id), |
56 script_name_(""), | 65 script_position_(start_position), |
57 script_id_(v8::UnboundScript::kNoScriptId), | 66 name_(name) {} |
58 start_position_(0) {} | 67 ~AllocationNode() { |
59 | 68 for (auto child : children_) { |
60 const char* get_name() const { return name_; } | 69 delete child; |
61 const char* get_script_name() const { return script_name_; } | 70 } |
62 int get_script_id() const { return script_id_; } | 71 } |
63 int get_start_position() const { return start_position_; } | |
64 | 72 |
65 private: | 73 private: |
66 const char* const name_; | 74 std::map<size_t, unsigned int> allocations_; |
67 const char* script_name_; | 75 std::vector<AllocationNode*> children_; |
68 int script_id_; | 76 int script_id_; |
69 const int start_position_; | 77 int script_position_; |
70 }; | 78 const char* name_; |
71 | 79 |
72 class SampledAllocation { | 80 friend class SamplingHeapProfiler; |
73 public: | |
74 SampledAllocation(SamplingHeapProfiler* sampling_heap_profiler, | |
75 Isolate* isolate, Local<Value> local, size_t size, | |
76 int max_frames); | |
77 ~SampledAllocation() { | |
78 for (auto info : stack_) { | |
79 delete info; | |
80 } | |
81 global_.Reset(); // drop the reference. | |
82 } | |
83 size_t get_size() const { return size_; } | |
84 const std::vector<FunctionInfo*>& get_stack() const { return stack_; } | |
85 | 81 |
86 private: | 82 DISALLOW_COPY_AND_ASSIGN(AllocationNode); |
87 static void OnWeakCallback(const WeakCallbackInfo<SampledAllocation>& data); | |
88 | |
89 SamplingHeapProfiler* const sampling_heap_profiler_; | |
90 Global<Value> global_; | |
91 std::vector<FunctionInfo*> stack_; | |
92 const size_t size_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(SampledAllocation); | |
95 }; | 83 }; |
96 | 84 |
97 private: | 85 private: |
98 Heap* heap() const { return heap_; } | 86 Heap* heap() const { return heap_; } |
99 | 87 |
100 void SampleObject(Address soon_object, size_t size); | 88 void SampleObject(Address soon_object, size_t size); |
101 | 89 |
90 static void OnWeakCallback(const WeakCallbackInfo<Sample>& data); | |
91 | |
102 // Methods that construct v8::AllocationProfile. | 92 // Methods that construct v8::AllocationProfile. |
103 v8::AllocationProfile::Node* AddStack( | 93 v8::AllocationProfile::Node* GenerateProfile( |
ulan
2016/02/17 11:14:50
Could you please add a comment describing pre/post
mattloring
2016/02/17 17:50:21
Done.
| |
104 AllocationProfile* profile, const std::map<int, Script*>& scripts, | 94 AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node, |
105 const std::vector<FunctionInfo*>& stack); | 95 const std::map<int, Script*>& scripts); |
106 v8::AllocationProfile::Node* FindOrAddChildNode( | 96 AllocationNode* AddStack(); |
107 AllocationProfile* profile, const std::map<int, Script*>& scripts, | 97 AllocationNode* FindOrAddChildNode(AllocationNode* parent, const char* name, |
108 v8::AllocationProfile::Node* parent, FunctionInfo* function_info); | 98 int script_id, int start_position); |
109 v8::AllocationProfile::Node* AllocateNode( | |
110 AllocationProfile* profile, const std::map<int, Script*>& scripts, | |
111 FunctionInfo* function_info); | |
112 | 99 |
113 Isolate* const isolate_; | 100 Isolate* const isolate_; |
114 Heap* const heap_; | 101 Heap* const heap_; |
115 base::SmartPointer<SamplingAllocationObserver> new_space_observer_; | 102 base::SmartPointer<SamplingAllocationObserver> new_space_observer_; |
116 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; | 103 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; |
117 StringsStorage* const names_; | 104 StringsStorage* const names_; |
118 std::set<SampledAllocation*> samples_; | 105 AllocationNode* profile_root_; |
106 std::set<Sample*> samples_; | |
119 const int stack_depth_; | 107 const int stack_depth_; |
120 | 108 |
121 friend class SamplingAllocationObserver; | 109 friend class SamplingAllocationObserver; |
122 }; | 110 }; |
123 | 111 |
124 class SamplingAllocationObserver : public AllocationObserver { | 112 class SamplingAllocationObserver : public AllocationObserver { |
125 public: | 113 public: |
126 SamplingAllocationObserver(Heap* heap, intptr_t step_size, uint64_t rate, | 114 SamplingAllocationObserver(Heap* heap, intptr_t step_size, uint64_t rate, |
127 SamplingHeapProfiler* profiler, | 115 SamplingHeapProfiler* profiler, |
128 base::RandomNumberGenerator* random) | 116 base::RandomNumberGenerator* random) |
(...skipping 19 matching lines...) Expand all Loading... | |
148 SamplingHeapProfiler* const profiler_; | 136 SamplingHeapProfiler* const profiler_; |
149 Heap* const heap_; | 137 Heap* const heap_; |
150 base::RandomNumberGenerator* const random_; | 138 base::RandomNumberGenerator* const random_; |
151 uint64_t const rate_; | 139 uint64_t const rate_; |
152 }; | 140 }; |
153 | 141 |
154 } // namespace internal | 142 } // namespace internal |
155 } // namespace v8 | 143 } // namespace v8 |
156 | 144 |
157 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | 145 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ |
OLD | NEW |