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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 public: | 73 public: |
74 AllocationNode(AllocationNode* parent, const char* name, int script_id, | 74 AllocationNode(AllocationNode* parent, const char* name, int script_id, |
75 int start_position) | 75 int start_position) |
76 : parent_(parent), | 76 : parent_(parent), |
77 script_id_(script_id), | 77 script_id_(script_id), |
78 script_position_(start_position), | 78 script_position_(start_position), |
79 name_(name), | 79 name_(name), |
80 pinned_(false) {} | 80 pinned_(false) {} |
81 ~AllocationNode() { | 81 ~AllocationNode() { |
82 for (auto child : children_) { | 82 for (auto child : children_) { |
83 delete child; | 83 delete child.second; |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 private: | 87 private: |
88 typedef uint64_t FunctionId; | |
89 static FunctionId function_id(int script_id, int start_position, | |
ulan
2016/05/13 09:05:00
Please add a comment describing what this function
alph
2016/05/13 18:34:35
Done.
| |
90 const char* name) { | |
ulan
2016/05/12 10:01:20
Instead of relying on name pointers, can we use "i
| |
91 return script_id != v8::UnboundScript::kNoScriptId | |
92 ? (static_cast<uint64_t>(script_id) << 32) + | |
93 (start_position << 1) | |
ulan
2016/05/13 09:05:00
DCHECK(start_position >= 0 && start_position < (1
alph
2016/05/13 18:34:35
Done.
| |
94 : reinterpret_cast<intptr_t>(name) | 1; | |
95 } | |
96 AllocationNode* FindOrAddChildNode(const char* name, int script_id, | |
97 int start_position); | |
98 // TODO(alph): make use of unordered_map's here. Pay attention to | |
99 // iterator invalidation during TranslateAllocationNode. | |
88 std::map<size_t, unsigned int> allocations_; | 100 std::map<size_t, unsigned int> allocations_; |
89 std::vector<AllocationNode*> children_; | 101 std::map<FunctionId, AllocationNode*> children_; |
90 AllocationNode* const parent_; | 102 AllocationNode* const parent_; |
91 const int script_id_; | 103 const int script_id_; |
92 const int script_position_; | 104 const int script_position_; |
93 const char* const name_; | 105 const char* const name_; |
94 bool pinned_; | 106 bool pinned_; |
95 | 107 |
96 friend class SamplingHeapProfiler; | 108 friend class SamplingHeapProfiler; |
97 | 109 |
98 DISALLOW_COPY_AND_ASSIGN(AllocationNode); | 110 DISALLOW_COPY_AND_ASSIGN(AllocationNode); |
99 }; | 111 }; |
(...skipping 11 matching lines...) Expand all Loading... | |
111 // AllocationProfile::Node. The newly created AllocationProfile::Node is added | 123 // AllocationProfile::Node. The newly created AllocationProfile::Node is added |
112 // to the provided AllocationProfile *profile*. Line numbers, column numbers, | 124 // to the provided AllocationProfile *profile*. Line numbers, column numbers, |
113 // and script names are resolved using *scripts* which maps all currently | 125 // and script names are resolved using *scripts* which maps all currently |
114 // loaded scripts keyed by their script id. | 126 // loaded scripts keyed by their script id. |
115 v8::AllocationProfile::Node* TranslateAllocationNode( | 127 v8::AllocationProfile::Node* TranslateAllocationNode( |
116 AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node, | 128 AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node, |
117 const std::map<int, Handle<Script>>& scripts); | 129 const std::map<int, Handle<Script>>& scripts); |
118 v8::AllocationProfile::Allocation ScaleSample(size_t size, | 130 v8::AllocationProfile::Allocation ScaleSample(size_t size, |
119 unsigned int count); | 131 unsigned int count); |
120 AllocationNode* AddStack(); | 132 AllocationNode* AddStack(); |
121 AllocationNode* FindOrAddChildNode(AllocationNode* parent, const char* name, | |
122 int script_id, int start_position); | |
123 | 133 |
124 Isolate* const isolate_; | 134 Isolate* const isolate_; |
125 Heap* const heap_; | 135 Heap* const heap_; |
126 base::SmartPointer<SamplingAllocationObserver> new_space_observer_; | 136 base::SmartPointer<SamplingAllocationObserver> new_space_observer_; |
127 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; | 137 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; |
128 StringsStorage* const names_; | 138 StringsStorage* const names_; |
129 AllocationNode profile_root_; | 139 AllocationNode profile_root_; |
130 std::set<Sample*> samples_; | 140 std::set<Sample*> samples_; |
131 const int stack_depth_; | 141 const int stack_depth_; |
132 const uint64_t rate_; | 142 const uint64_t rate_; |
(...skipping 29 matching lines...) Expand all Loading... | |
162 SamplingHeapProfiler* const profiler_; | 172 SamplingHeapProfiler* const profiler_; |
163 Heap* const heap_; | 173 Heap* const heap_; |
164 base::RandomNumberGenerator* const random_; | 174 base::RandomNumberGenerator* const random_; |
165 uint64_t const rate_; | 175 uint64_t const rate_; |
166 }; | 176 }; |
167 | 177 |
168 } // namespace internal | 178 } // namespace internal |
169 } // namespace v8 | 179 } // namespace v8 |
170 | 180 |
171 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | 181 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ |
OLD | NEW |