OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #include "src/profiler/profile-generator.h" | 5 #include "src/profiler/profile-generator.h" |
6 | 6 |
7 #include "src/base/adapters.h" | 7 #include "src/base/adapters.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/global-handles.h" | 10 #include "src/global-handles.h" |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 : title_(title), | 405 : title_(title), |
406 record_samples_(record_samples), | 406 record_samples_(record_samples), |
407 start_time_(base::TimeTicks::HighResolutionNow()), | 407 start_time_(base::TimeTicks::HighResolutionNow()), |
408 top_down_(profiler->isolate()), | 408 top_down_(profiler->isolate()), |
409 profiler_(profiler), | 409 profiler_(profiler), |
410 streaming_next_sample_(0) { | 410 streaming_next_sample_(0) { |
411 auto value = TracedValue::Create(); | 411 auto value = TracedValue::Create(); |
412 value->SetDouble("startTime", | 412 value->SetDouble("startTime", |
413 (start_time_ - base::TimeTicks()).InMicroseconds()); | 413 (start_time_ - base::TimeTicks()).InMicroseconds()); |
414 TRACE_EVENT_SAMPLE_WITH_ID1(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"), | 414 TRACE_EVENT_SAMPLE_WITH_ID1(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"), |
415 "Profile", this, "data", std::move(value)); | 415 "CpuProfile", this, "data", std::move(value)); |
416 } | 416 } |
417 | 417 |
418 void CpuProfile::AddPath(base::TimeTicks timestamp, | 418 void CpuProfile::AddPath(base::TimeTicks timestamp, |
419 const std::vector<CodeEntry*>& path, int src_line, | 419 const std::vector<CodeEntry*>& path, int src_line, |
420 bool update_stats) { | 420 bool update_stats) { |
421 ProfileNode* top_frame_node = | 421 ProfileNode* top_frame_node = |
422 top_down_.AddPathFromEnd(path, src_line, update_stats); | 422 top_down_.AddPathFromEnd(path, src_line, update_stats); |
423 if (record_samples_ && !timestamp.IsNull()) { | 423 if (record_samples_ && !timestamp.IsNull()) { |
424 timestamps_.Add(timestamp); | 424 timestamps_.Add(timestamp); |
425 samples_.Add(top_frame_node); | 425 samples_.Add(top_frame_node); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 } | 459 } |
460 } | 460 } |
461 | 461 |
462 } // namespace | 462 } // namespace |
463 | 463 |
464 void CpuProfile::StreamPendingTraceEvents() { | 464 void CpuProfile::StreamPendingTraceEvents() { |
465 std::vector<const ProfileNode*> pending_nodes = top_down_.TakePendingNodes(); | 465 std::vector<const ProfileNode*> pending_nodes = top_down_.TakePendingNodes(); |
466 if (pending_nodes.empty() && !samples_.length()) return; | 466 if (pending_nodes.empty() && !samples_.length()) return; |
467 auto value = TracedValue::Create(); | 467 auto value = TracedValue::Create(); |
468 | 468 |
469 if (!pending_nodes.empty() || streaming_next_sample_ != samples_.length()) { | 469 if (!pending_nodes.empty()) { |
470 value->BeginDictionary("cpuProfile"); | 470 value->BeginArray("nodes"); |
471 if (!pending_nodes.empty()) { | 471 for (auto node : pending_nodes) { |
472 value->BeginArray("nodes"); | 472 value->BeginDictionary(); |
473 for (auto node : pending_nodes) { | 473 BuildNodeValue(node, value.get()); |
474 value->BeginDictionary(); | 474 value->EndDictionary(); |
475 BuildNodeValue(node, value.get()); | |
476 value->EndDictionary(); | |
477 } | |
478 value->EndArray(); | |
479 } | 475 } |
480 if (streaming_next_sample_ != samples_.length()) { | 476 value->EndArray(); |
481 value->BeginArray("samples"); | 477 } |
482 for (int i = streaming_next_sample_; i < samples_.length(); ++i) { | 478 |
483 value->AppendInteger(samples_[i]->id()); | 479 if (streaming_next_sample_ != samples_.length()) { |
484 } | 480 value->BeginArray("samples"); |
485 value->EndArray(); | 481 for (int i = streaming_next_sample_; i < samples_.length(); ++i) { |
| 482 value->AppendInteger(samples_[i]->id()); |
486 } | 483 } |
487 value->EndDictionary(); | 484 value->EndArray(); |
488 } | |
489 if (streaming_next_sample_ != samples_.length()) { | |
490 value->BeginArray("timeDeltas"); | 485 value->BeginArray("timeDeltas"); |
491 base::TimeTicks lastTimestamp = | 486 base::TimeTicks lastTimestamp = |
492 streaming_next_sample_ ? timestamps_[streaming_next_sample_ - 1] | 487 streaming_next_sample_ ? timestamps_[streaming_next_sample_ - 1] |
493 : start_time(); | 488 : start_time(); |
494 for (int i = streaming_next_sample_; i < timestamps_.length(); ++i) { | 489 for (int i = streaming_next_sample_; i < timestamps_.length(); ++i) { |
495 value->AppendInteger( | 490 value->AppendInteger( |
496 static_cast<int>((timestamps_[i] - lastTimestamp).InMicroseconds())); | 491 static_cast<int>((timestamps_[i] - lastTimestamp).InMicroseconds())); |
497 lastTimestamp = timestamps_[i]; | 492 lastTimestamp = timestamps_[i]; |
498 } | 493 } |
499 value->EndArray(); | 494 value->EndArray(); |
500 DCHECK(samples_.length() == timestamps_.length()); | 495 DCHECK(samples_.length() == timestamps_.length()); |
501 streaming_next_sample_ = samples_.length(); | 496 streaming_next_sample_ = samples_.length(); |
502 } | 497 } |
503 | 498 |
504 TRACE_EVENT_SAMPLE_WITH_ID1(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"), | 499 TRACE_EVENT_SAMPLE_WITH_ID1(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"), |
505 "ProfileChunk", this, "data", std::move(value)); | 500 "CpuProfileChunk", this, "data", |
| 501 std::move(value)); |
506 } | 502 } |
507 | 503 |
508 void CpuProfile::FinishProfile() { | 504 void CpuProfile::FinishProfile() { |
509 end_time_ = base::TimeTicks::HighResolutionNow(); | 505 end_time_ = base::TimeTicks::HighResolutionNow(); |
510 StreamPendingTraceEvents(); | 506 StreamPendingTraceEvents(); |
511 auto value = TracedValue::Create(); | 507 auto value = TracedValue::Create(); |
512 value->SetDouble("endTime", (end_time_ - base::TimeTicks()).InMicroseconds()); | 508 value->SetDouble("endTime", (end_time_ - base::TimeTicks()).InMicroseconds()); |
513 TRACE_EVENT_SAMPLE_WITH_ID1(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"), | 509 TRACE_EVENT_SAMPLE_WITH_ID1(TRACE_DISABLED_BY_DEFAULT("v8.cpu_profiler"), |
514 "ProfileChunk", this, "data", std::move(value)); | 510 "CpuProfileChunk", this, "data", |
| 511 std::move(value)); |
515 } | 512 } |
516 | 513 |
517 void CpuProfile::Print() { | 514 void CpuProfile::Print() { |
518 base::OS::Print("[Top down]:\n"); | 515 base::OS::Print("[Top down]:\n"); |
519 top_down_.Print(); | 516 top_down_.Print(); |
520 } | 517 } |
521 | 518 |
522 void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) { | 519 void CodeMap::AddCode(Address addr, CodeEntry* entry, unsigned size) { |
523 DeleteAllCoveredCode(addr, addr + size); | 520 DeleteAllCoveredCode(addr, addr + size); |
524 code_map_.insert({addr, CodeEntryInfo(entry, size)}); | 521 code_map_.insert({addr, CodeEntryInfo(entry, size)}); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 case EXTERNAL: | 767 case EXTERNAL: |
771 return CodeEntry::program_entry(); | 768 return CodeEntry::program_entry(); |
772 case IDLE: | 769 case IDLE: |
773 return CodeEntry::idle_entry(); | 770 return CodeEntry::idle_entry(); |
774 default: return NULL; | 771 default: return NULL; |
775 } | 772 } |
776 } | 773 } |
777 | 774 |
778 } // namespace internal | 775 } // namespace internal |
779 } // namespace v8 | 776 } // namespace v8 |
OLD | NEW |