Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: src/profiler/sampling-heap-profiler.h

Issue 1967673002: Sampling heap profiler: use map instead of vector for children. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressing comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/profiler/sampling-heap-profiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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,
90 const char* name) {
91 // script_id == kNoScriptId case:
92 // Use function name pointer as an id. Names derived from VM state
93 // must not collide with the builtin names. The least significant bit
94 // of the id is set to 1.
95 if (script_id == v8::UnboundScript::kNoScriptId) {
96 return reinterpret_cast<intptr_t>(name) | 1;
97 }
98 // script_id != kNoScriptId case:
99 // Use script_id, start_position pair to uniquelly identify the node.
100 // The least significant bit of the id is set to 0.
101 DCHECK(static_cast<unsigned>(start_position) < (1u << 31));
102 return (static_cast<uint64_t>(script_id) << 32) + (start_position << 1);
103 }
104 AllocationNode* FindOrAddChildNode(const char* name, int script_id,
105 int start_position);
106 // TODO(alph): make use of unordered_map's here. Pay attention to
107 // iterator invalidation during TranslateAllocationNode.
88 std::map<size_t, unsigned int> allocations_; 108 std::map<size_t, unsigned int> allocations_;
89 std::vector<AllocationNode*> children_; 109 std::map<FunctionId, AllocationNode*> children_;
90 AllocationNode* const parent_; 110 AllocationNode* const parent_;
91 const int script_id_; 111 const int script_id_;
92 const int script_position_; 112 const int script_position_;
93 const char* const name_; 113 const char* const name_;
94 bool pinned_; 114 bool pinned_;
95 115
96 friend class SamplingHeapProfiler; 116 friend class SamplingHeapProfiler;
97 117
98 DISALLOW_COPY_AND_ASSIGN(AllocationNode); 118 DISALLOW_COPY_AND_ASSIGN(AllocationNode);
99 }; 119 };
(...skipping 11 matching lines...) Expand all
111 // AllocationProfile::Node. The newly created AllocationProfile::Node is added 131 // AllocationProfile::Node. The newly created AllocationProfile::Node is added
112 // to the provided AllocationProfile *profile*. Line numbers, column numbers, 132 // to the provided AllocationProfile *profile*. Line numbers, column numbers,
113 // and script names are resolved using *scripts* which maps all currently 133 // and script names are resolved using *scripts* which maps all currently
114 // loaded scripts keyed by their script id. 134 // loaded scripts keyed by their script id.
115 v8::AllocationProfile::Node* TranslateAllocationNode( 135 v8::AllocationProfile::Node* TranslateAllocationNode(
116 AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node, 136 AllocationProfile* profile, SamplingHeapProfiler::AllocationNode* node,
117 const std::map<int, Handle<Script>>& scripts); 137 const std::map<int, Handle<Script>>& scripts);
118 v8::AllocationProfile::Allocation ScaleSample(size_t size, 138 v8::AllocationProfile::Allocation ScaleSample(size_t size,
119 unsigned int count); 139 unsigned int count);
120 AllocationNode* AddStack(); 140 AllocationNode* AddStack();
121 AllocationNode* FindOrAddChildNode(AllocationNode* parent, const char* name,
122 int script_id, int start_position);
123 141
124 Isolate* const isolate_; 142 Isolate* const isolate_;
125 Heap* const heap_; 143 Heap* const heap_;
126 base::SmartPointer<SamplingAllocationObserver> new_space_observer_; 144 base::SmartPointer<SamplingAllocationObserver> new_space_observer_;
127 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_; 145 base::SmartPointer<SamplingAllocationObserver> other_spaces_observer_;
128 StringsStorage* const names_; 146 StringsStorage* const names_;
129 AllocationNode profile_root_; 147 AllocationNode profile_root_;
130 std::set<Sample*> samples_; 148 std::set<Sample*> samples_;
131 const int stack_depth_; 149 const int stack_depth_;
132 const uint64_t rate_; 150 const uint64_t rate_;
(...skipping 29 matching lines...) Expand all
162 SamplingHeapProfiler* const profiler_; 180 SamplingHeapProfiler* const profiler_;
163 Heap* const heap_; 181 Heap* const heap_;
164 base::RandomNumberGenerator* const random_; 182 base::RandomNumberGenerator* const random_;
165 uint64_t const rate_; 183 uint64_t const rate_;
166 }; 184 };
167 185
168 } // namespace internal 186 } // namespace internal
169 } // namespace v8 187 } // namespace v8
170 188
171 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_ 189 #endif // V8_PROFILER_SAMPLING_HEAP_PROFILER_H_
OLDNEW
« no previous file with comments | « no previous file | src/profiler/sampling-heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698