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; | |
ofrobots
2016/05/11 16:48:13
Going forward it would be better to call this `Cal
alph
2016/05/11 17:37:17
I assume (need) it to be the function start positi
ofrobots
2016/05/11 22:48:09
I am considering making it the call-site position
alph
2016/05/11 23:17:34
It just reflects the current state of the nodes, w
ofrobots
2016/05/12 00:03:05
sgtm.
| |
89 static FunctionId function_id(int script_id, int start_position, | |
90 const char* name) { | |
91 return script_id | |
92 ? (static_cast<uint64_t>(script_id) << 32) + start_position | |
93 : static_cast<uint32_t>(reinterpret_cast<intptr_t>(name)); | |
ofrobots
2016/05/11 16:48:13
Why the truncation to 32 bits on 64-bit platforms?
alph
2016/05/11 17:37:17
The name is used only for system "functions", i.e.
ofrobots
2016/05/11 22:48:09
When called from sampling-heap-profiler.cc:204 (or
alph
2016/05/11 23:17:34
Yes, you can reach it for builtin functions like c
ofrobots
2016/05/12 00:03:05
If easy to do, it would be best to avoid the possi
alph
2016/05/12 01:37:44
Well, these are not pointers to arbitrary chars, b
| |
94 } | |
95 AllocationNode* FindOrAddChildNode(const char* name, int script_id, | |
96 int start_position); | |
97 // TODO(alph): make use of unordered_map's here. Pay attention to | |
98 // iterator invalidation during TranslateAllocationNode. | |
88 std::map<size_t, unsigned int> allocations_; | 99 std::map<size_t, unsigned int> allocations_; |
89 std::vector<AllocationNode*> children_; | 100 std::map<FunctionId, AllocationNode*> children_; |
90 AllocationNode* const parent_; | 101 AllocationNode* const parent_; |
91 const int script_id_; | 102 const int script_id_; |
92 const int script_position_; | 103 const int script_position_; |
93 const char* const name_; | 104 const char* const name_; |
94 bool pinned_; | 105 bool pinned_; |
95 | 106 |
96 friend class SamplingHeapProfiler; | 107 friend class SamplingHeapProfiler; |
97 | 108 |
98 DISALLOW_COPY_AND_ASSIGN(AllocationNode); | 109 DISALLOW_COPY_AND_ASSIGN(AllocationNode); |
99 }; | 110 }; |
(...skipping 11 matching lines...) Expand all Loading... | |
111 // AllocationProfile::Node. The newly created AllocationProfile::Node is added | 122 // AllocationProfile::Node. The newly created AllocationProfile::Node is added |
112 // to the provided AllocationProfile *profile*. Line numbers, column numbers, | 123 // to the provided AllocationProfile *profile*. Line numbers, column numbers, |
113 // and script names are resolved using *scripts* which maps all currently | 124 // and script names are resolved using *scripts* which maps all currently |
114 // loaded scripts keyed by their script id. | 125 // loaded scripts keyed by their script id. |
115 v8::AllocationProfile::Node* TranslateAllocationNode( | 126 v8::AllocationProfile::Node* TranslateAllocationNode( |
116 AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node, | 127 AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node, |
117 const std::map<int, Handle<Script>>& scripts); | 128 const std::map<int, Handle<Script>>& scripts); |
118 v8::AllocationProfile::Allocation ScaleSample(size_t size, | 129 v8::AllocationProfile::Allocation ScaleSample(size_t size, |
119 unsigned int count); | 130 unsigned int count); |
120 AllocationNode* AddStack(); | 131 AllocationNode* AddStack(); |
121 AllocationNode* FindOrAddChildNode(AllocationNode* parent, const char* name, | |
122 int script_id, int start_position); | |
123 | 132 |
124 Isolate* const isolate_; | 133 Isolate* const isolate_; |
125 Heap* const heap_; | 134 Heap* const heap_; |
126 base::SmartPointer<SamplingAllocationObserver> new_space_observer_; | 135 base::SmartPointer<SamplingAllocationObserver> new_space_observer_; |
127 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; | 136 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; |
128 StringsStorage* const names_; | 137 StringsStorage* const names_; |
129 AllocationNode profile_root_; | 138 AllocationNode profile_root_; |
130 std::set<Sample*> samples_; | 139 std::set<Sample*> samples_; |
131 const int stack_depth_; | 140 const int stack_depth_; |
132 const uint64_t rate_; | 141 const uint64_t rate_; |
(...skipping 29 matching lines...) Expand all Loading... | |
162 SamplingHeapProfiler* const profiler_; | 171 SamplingHeapProfiler* const profiler_; |
163 Heap* const heap_; | 172 Heap* const heap_; |
164 base::RandomNumberGenerator* const random_; | 173 base::RandomNumberGenerator* const random_; |
165 uint64_t const rate_; | 174 uint64_t const rate_; |
166 }; | 175 }; |
167 | 176 |
168 } // namespace internal | 177 } // namespace internal |
169 } // namespace v8 | 178 } // namespace v8 |
170 | 179 |
171 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ | 180 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ |
OLD | NEW |