OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 if (map_entry->value == NULL) { | 202 if (map_entry->value == NULL) { |
203 // New node added. | 203 // New node added. |
204 ProfileNode* new_node = new ProfileNode(tree_, entry); | 204 ProfileNode* new_node = new ProfileNode(tree_, entry); |
205 map_entry->value = new_node; | 205 map_entry->value = new_node; |
206 children_list_.Add(new_node); | 206 children_list_.Add(new_node); |
207 } | 207 } |
208 return reinterpret_cast<ProfileNode*>(map_entry->value); | 208 return reinterpret_cast<ProfileNode*>(map_entry->value); |
209 } | 209 } |
210 | 210 |
211 | 211 |
212 double ProfileNode::GetSelfMillis() const { | |
213 return tree_->TicksToMillis(self_ticks_); | |
214 } | |
215 | |
216 | |
217 double ProfileNode::GetTotalMillis() const { | |
218 return tree_->TicksToMillis(total_ticks_); | |
219 } | |
220 | |
221 | |
222 void ProfileNode::Print(int indent) { | 212 void ProfileNode::Print(int indent) { |
223 OS::Print("%5u %5u %*c %s%s %d #%d", | 213 OS::Print("%5u %*c %s%s %d #%d", |
224 total_ticks_, self_ticks_, | 214 self_ticks_, |
225 indent, ' ', | 215 indent, ' ', |
226 entry_->name_prefix(), | 216 entry_->name_prefix(), |
227 entry_->name(), | 217 entry_->name(), |
228 entry_->script_id(), | 218 entry_->script_id(), |
229 id()); | 219 id()); |
230 if (entry_->resource_name()[0] != '\0') | 220 if (entry_->resource_name()[0] != '\0') |
231 OS::Print(" %s:%d", entry_->resource_name(), entry_->line_number()); | 221 OS::Print(" %s:%d", entry_->resource_name(), entry_->line_number()); |
232 OS::Print("\n"); | 222 OS::Print("\n"); |
233 for (HashMap::Entry* p = children_.Start(); | 223 for (HashMap::Entry* p = children_.Start(); |
234 p != NULL; | 224 p != NULL; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 281 |
292 | 282 |
293 struct NodesPair { | 283 struct NodesPair { |
294 NodesPair(ProfileNode* src, ProfileNode* dst) | 284 NodesPair(ProfileNode* src, ProfileNode* dst) |
295 : src(src), dst(dst) { } | 285 : src(src), dst(dst) { } |
296 ProfileNode* src; | 286 ProfileNode* src; |
297 ProfileNode* dst; | 287 ProfileNode* dst; |
298 }; | 288 }; |
299 | 289 |
300 | 290 |
301 void ProfileTree::SetTickRatePerMs(double ticks_per_ms) { | |
302 ms_to_ticks_scale_ = ticks_per_ms > 0 ? 1.0 / ticks_per_ms : 1.0; | |
303 } | |
304 | |
305 | |
306 class Position { | 291 class Position { |
307 public: | 292 public: |
308 explicit Position(ProfileNode* node) | 293 explicit Position(ProfileNode* node) |
309 : node(node), child_idx_(0) { } | 294 : node(node), child_idx_(0) { } |
310 INLINE(ProfileNode* current_child()) { | 295 INLINE(ProfileNode* current_child()) { |
311 return node->children()->at(child_idx_); | 296 return node->children()->at(child_idx_); |
312 } | 297 } |
313 INLINE(bool has_current_child()) { | 298 INLINE(bool has_current_child()) { |
314 return child_idx_ < node->children()->length(); | 299 return child_idx_ < node->children()->length(); |
315 } | 300 } |
(...skipping 22 matching lines...) Expand all Loading... |
338 callback->AfterChildTraversed(parent.node, current.node); | 323 callback->AfterChildTraversed(parent.node, current.node); |
339 parent.next_child(); | 324 parent.next_child(); |
340 } | 325 } |
341 // Remove child from the stack. | 326 // Remove child from the stack. |
342 stack.RemoveLast(); | 327 stack.RemoveLast(); |
343 } | 328 } |
344 } | 329 } |
345 } | 330 } |
346 | 331 |
347 | 332 |
348 class CalculateTotalTicksCallback { | |
349 public: | |
350 void BeforeTraversingChild(ProfileNode*, ProfileNode*) { } | |
351 | |
352 void AfterAllChildrenTraversed(ProfileNode* node) { | |
353 node->IncreaseTotalTicks(node->self_ticks()); | |
354 } | |
355 | |
356 void AfterChildTraversed(ProfileNode* parent, ProfileNode* child) { | |
357 parent->IncreaseTotalTicks(child->total_ticks()); | |
358 } | |
359 }; | |
360 | |
361 | |
362 void ProfileTree::CalculateTotalTicks() { | |
363 CalculateTotalTicksCallback cb; | |
364 TraverseDepthFirst(&cb); | |
365 } | |
366 | |
367 | |
368 void ProfileTree::ShortPrint() { | |
369 OS::Print("root: %u %u %.2fms %.2fms\n", | |
370 root_->total_ticks(), root_->self_ticks(), | |
371 root_->GetTotalMillis(), root_->GetSelfMillis()); | |
372 } | |
373 | |
374 | |
375 CpuProfile::CpuProfile(const char* title, unsigned uid, bool record_samples) | 333 CpuProfile::CpuProfile(const char* title, unsigned uid, bool record_samples) |
376 : title_(title), | 334 : title_(title), |
377 uid_(uid), | 335 uid_(uid), |
378 record_samples_(record_samples), | 336 record_samples_(record_samples), |
379 start_time_us_(OS::Ticks()), | 337 start_time_us_(OS::Ticks()), |
380 end_time_us_(0) { | 338 end_time_us_(0) { |
381 } | 339 } |
382 | 340 |
383 | 341 |
384 void CpuProfile::AddPath(const Vector<CodeEntry*>& path) { | 342 void CpuProfile::AddPath(const Vector<CodeEntry*>& path) { |
385 ProfileNode* top_frame_node = top_down_.AddPathFromEnd(path); | 343 ProfileNode* top_frame_node = top_down_.AddPathFromEnd(path); |
386 if (record_samples_) samples_.Add(top_frame_node); | 344 if (record_samples_) samples_.Add(top_frame_node); |
387 } | 345 } |
388 | 346 |
389 | 347 |
390 void CpuProfile::CalculateTotalTicksAndSamplingRate() { | 348 void CpuProfile::CalculateTotalTicksAndSamplingRate() { |
391 end_time_us_ = OS::Ticks(); | 349 end_time_us_ = OS::Ticks(); |
392 top_down_.CalculateTotalTicks(); | |
393 | |
394 double duration_ms = (end_time_us_ - start_time_us_) / 1000.; | |
395 if (duration_ms < 1) duration_ms = 1; | |
396 unsigned ticks = top_down_.root()->total_ticks(); | |
397 double rate = ticks / duration_ms; | |
398 top_down_.SetTickRatePerMs(rate); | |
399 } | 350 } |
400 | 351 |
401 | 352 |
402 void CpuProfile::ShortPrint() { | |
403 OS::Print("top down "); | |
404 top_down_.ShortPrint(); | |
405 } | |
406 | |
407 | |
408 void CpuProfile::Print() { | 353 void CpuProfile::Print() { |
409 OS::Print("[Top down]:\n"); | 354 OS::Print("[Top down]:\n"); |
410 top_down_.Print(); | 355 top_down_.Print(); |
411 } | 356 } |
412 | 357 |
413 | 358 |
414 CodeEntry* const CodeMap::kSharedFunctionCodeEntry = NULL; | 359 CodeEntry* const CodeMap::kSharedFunctionCodeEntry = NULL; |
415 const CodeMap::CodeTreeConfig::Key CodeMap::CodeTreeConfig::kNoKey = NULL; | 360 const CodeMap::CodeTreeConfig::Key CodeMap::CodeTreeConfig::kNoKey = NULL; |
416 | 361 |
417 | 362 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 if (no_symbolized_entries) { | 652 if (no_symbolized_entries) { |
708 *entry++ = EntryForVMState(sample.state); | 653 *entry++ = EntryForVMState(sample.state); |
709 } | 654 } |
710 } | 655 } |
711 | 656 |
712 profiles_->AddPathToCurrentProfiles(entries); | 657 profiles_->AddPathToCurrentProfiles(entries); |
713 } | 658 } |
714 | 659 |
715 | 660 |
716 } } // namespace v8::internal | 661 } } // namespace v8::internal |
OLD | NEW |