OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 class ProfileTree; | 124 class ProfileTree; |
125 | 125 |
126 class ProfileNode { | 126 class ProfileNode { |
127 public: | 127 public: |
128 INLINE(ProfileNode(ProfileTree* tree, CodeEntry* entry)); | 128 INLINE(ProfileNode(ProfileTree* tree, CodeEntry* entry)); |
129 | 129 |
130 ProfileNode* FindChild(CodeEntry* entry); | 130 ProfileNode* FindChild(CodeEntry* entry); |
131 ProfileNode* FindOrAddChild(CodeEntry* entry); | 131 ProfileNode* FindOrAddChild(CodeEntry* entry); |
132 INLINE(void IncrementSelfTicks()) { ++self_ticks_; } | 132 INLINE(void IncrementSelfTicks()) { ++self_ticks_; } |
133 INLINE(void IncreaseSelfTicks(unsigned amount)) { self_ticks_ += amount; } | 133 INLINE(void IncreaseSelfTicks(unsigned amount)) { self_ticks_ += amount; } |
134 INLINE(void IncreaseTotalTicks(unsigned amount)) { total_ticks_ += amount; } | |
135 | 134 |
136 INLINE(CodeEntry* entry() const) { return entry_; } | 135 INLINE(CodeEntry* entry() const) { return entry_; } |
137 INLINE(unsigned self_ticks() const) { return self_ticks_; } | 136 INLINE(unsigned self_ticks() const) { return self_ticks_; } |
138 INLINE(unsigned total_ticks() const) { return total_ticks_; } | |
139 INLINE(const List<ProfileNode*>* children() const) { return &children_list_; } | 137 INLINE(const List<ProfileNode*>* children() const) { return &children_list_; } |
140 double GetSelfMillis() const; | |
141 double GetTotalMillis() const; | |
142 unsigned id() const { return id_; } | 138 unsigned id() const { return id_; } |
143 | 139 |
144 void Print(int indent); | 140 void Print(int indent); |
145 | 141 |
146 private: | 142 private: |
147 INLINE(static bool CodeEntriesMatch(void* entry1, void* entry2)) { | 143 INLINE(static bool CodeEntriesMatch(void* entry1, void* entry2)) { |
148 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( | 144 return reinterpret_cast<CodeEntry*>(entry1)->IsSameAs( |
149 reinterpret_cast<CodeEntry*>(entry2)); | 145 reinterpret_cast<CodeEntry*>(entry2)); |
150 } | 146 } |
151 | 147 |
152 INLINE(static uint32_t CodeEntryHash(CodeEntry* entry)) { | 148 INLINE(static uint32_t CodeEntryHash(CodeEntry* entry)) { |
153 return entry->GetCallUid(); | 149 return entry->GetCallUid(); |
154 } | 150 } |
155 | 151 |
156 ProfileTree* tree_; | 152 ProfileTree* tree_; |
157 CodeEntry* entry_; | 153 CodeEntry* entry_; |
158 unsigned total_ticks_; | |
159 unsigned self_ticks_; | 154 unsigned self_ticks_; |
160 // Mapping from CodeEntry* to ProfileNode* | 155 // Mapping from CodeEntry* to ProfileNode* |
161 HashMap children_; | 156 HashMap children_; |
162 List<ProfileNode*> children_list_; | 157 List<ProfileNode*> children_list_; |
163 unsigned id_; | 158 unsigned id_; |
164 | 159 |
165 DISALLOW_COPY_AND_ASSIGN(ProfileNode); | 160 DISALLOW_COPY_AND_ASSIGN(ProfileNode); |
166 }; | 161 }; |
167 | 162 |
168 | 163 |
169 class ProfileTree { | 164 class ProfileTree { |
170 public: | 165 public: |
171 ProfileTree(); | 166 ProfileTree(); |
172 ~ProfileTree(); | 167 ~ProfileTree(); |
173 | 168 |
174 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path); | 169 ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path); |
175 void AddPathFromStart(const Vector<CodeEntry*>& path); | 170 void AddPathFromStart(const Vector<CodeEntry*>& path); |
176 void CalculateTotalTicks(); | |
177 | |
178 double TicksToMillis(unsigned ticks) const { | |
179 return ticks * ms_to_ticks_scale_; | |
180 } | |
181 ProfileNode* root() const { return root_; } | 171 ProfileNode* root() const { return root_; } |
182 void SetTickRatePerMs(double ticks_per_ms); | |
183 | |
184 unsigned next_node_id() { return next_node_id_++; } | 172 unsigned next_node_id() { return next_node_id_++; } |
185 | 173 |
186 void ShortPrint(); | |
187 void Print() { | 174 void Print() { |
188 root_->Print(0); | 175 root_->Print(0); |
189 } | 176 } |
190 | 177 |
191 private: | 178 private: |
192 template <typename Callback> | 179 template <typename Callback> |
193 void TraverseDepthFirst(Callback* callback); | 180 void TraverseDepthFirst(Callback* callback); |
194 | 181 |
195 CodeEntry root_entry_; | 182 CodeEntry root_entry_; |
196 unsigned next_node_id_; | 183 unsigned next_node_id_; |
197 ProfileNode* root_; | 184 ProfileNode* root_; |
198 double ms_to_ticks_scale_; | |
199 | 185 |
200 DISALLOW_COPY_AND_ASSIGN(ProfileTree); | 186 DISALLOW_COPY_AND_ASSIGN(ProfileTree); |
201 }; | 187 }; |
202 | 188 |
203 | 189 |
204 class CpuProfile { | 190 class CpuProfile { |
205 public: | 191 public: |
206 CpuProfile(const char* title, unsigned uid, bool record_samples); | 192 CpuProfile(const char* title, unsigned uid, bool record_samples); |
207 | 193 |
208 // Add pc -> ... -> main() call path to the profile. | 194 // Add pc -> ... -> main() call path to the profile. |
209 void AddPath(const Vector<CodeEntry*>& path); | 195 void AddPath(const Vector<CodeEntry*>& path); |
210 void CalculateTotalTicksAndSamplingRate(); | 196 void CalculateTotalTicksAndSamplingRate(); |
211 | 197 |
212 const char* title() const { return title_; } | 198 const char* title() const { return title_; } |
213 unsigned uid() const { return uid_; } | 199 unsigned uid() const { return uid_; } |
214 const ProfileTree* top_down() const { return &top_down_; } | 200 const ProfileTree* top_down() const { return &top_down_; } |
215 | 201 |
216 int samples_count() const { return samples_.length(); } | 202 int samples_count() const { return samples_.length(); } |
217 ProfileNode* sample(int index) const { return samples_.at(index); } | 203 ProfileNode* sample(int index) const { return samples_.at(index); } |
218 | 204 |
219 int64_t start_time_us() const { return start_time_us_; } | 205 int64_t start_time_us() const { return start_time_us_; } |
220 int64_t end_time_us() const { return end_time_us_; } | 206 int64_t end_time_us() const { return end_time_us_; } |
221 | 207 |
222 void UpdateTicksScale(); | 208 void UpdateTicksScale(); |
223 | 209 |
224 void ShortPrint(); | |
225 void Print(); | 210 void Print(); |
226 | 211 |
227 private: | 212 private: |
228 const char* title_; | 213 const char* title_; |
229 unsigned uid_; | 214 unsigned uid_; |
230 bool record_samples_; | 215 bool record_samples_; |
231 int64_t start_time_us_; | 216 int64_t start_time_us_; |
232 int64_t end_time_us_; | 217 int64_t end_time_us_; |
233 List<ProfileNode*> samples_; | 218 List<ProfileNode*> samples_; |
234 ProfileTree top_down_; | 219 ProfileTree top_down_; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 CodeEntry* gc_entry_; | 343 CodeEntry* gc_entry_; |
359 CodeEntry* unresolved_entry_; | 344 CodeEntry* unresolved_entry_; |
360 | 345 |
361 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); | 346 DISALLOW_COPY_AND_ASSIGN(ProfileGenerator); |
362 }; | 347 }; |
363 | 348 |
364 | 349 |
365 } } // namespace v8::internal | 350 } } // namespace v8::internal |
366 | 351 |
367 #endif // V8_PROFILE_GENERATOR_H_ | 352 #endif // V8_PROFILE_GENERATOR_H_ |
OLD | NEW |