Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/compiler.h" |
| 6 | #include "src/compiler/pipeline-statistics.h" |
| 7 | #include "src/compiler/zone-pool.h" |
| 8 | |
| 9 | namespace v8 { |
| 10 | namespace internal { |
| 11 | namespace compiler { |
| 12 | |
| 13 | void PipelineStatistics::CommonStats::Begin( |
| 14 | PipelineStatistics* pipeline_stats) { |
| 15 | DCHECK(scope_.is_empty()); |
| 16 | scope_.Reset(new ZonePool::StatsScope(pipeline_stats->zone_pool_)); |
| 17 | timer_.Start(); |
| 18 | outer_zone_initial_size_ = pipeline_stats->OuterZoneSize(); |
| 19 | allocated_bytes_at_start_ = |
| 20 | outer_zone_initial_size_ - |
| 21 | pipeline_stats->total_stats_.outer_zone_initial_size_ + |
| 22 | pipeline_stats->zone_pool_->GetCurrentAllocatedBytes(); |
| 23 | } |
| 24 | |
| 25 | |
| 26 | void PipelineStatistics::CommonStats::End( |
| 27 | PipelineStatistics* pipeline_stats, |
| 28 | CompilationStatistics::BasicStats* diff) { |
| 29 | DCHECK(!scope_.is_empty()); |
| 30 | diff->function_name_ = pipeline_stats->function_name_; |
| 31 | diff->delta_ = timer_.Elapsed(); |
| 32 | size_t outer_zone_diff = |
| 33 | pipeline_stats->OuterZoneSize() - outer_zone_initial_size_; |
| 34 | diff->max_allocated_bytes_ = outer_zone_diff + scope_->GetMaxAllocatedBytes(); |
| 35 | diff->absolute_max_allocated_bytes_ = |
| 36 | diff->max_allocated_bytes_ + allocated_bytes_at_start_; |
| 37 | diff->total_allocated_bytes_ = |
| 38 | outer_zone_diff + scope_->GetTotalAllocatedBytes(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 39 | scope_.Reset(nullptr); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 40 | timer_.Stop(); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | PipelineStatistics::PipelineStatistics(CompilationInfo* info, |
| 45 | ZonePool* zone_pool) |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 46 | : isolate_(info->isolate()), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 47 | outer_zone_(info->zone()), |
| 48 | zone_pool_(zone_pool), |
| 49 | compilation_stats_(isolate_->GetTurboStatistics()), |
| 50 | source_size_(0), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 51 | phase_kind_name_(nullptr), |
| 52 | phase_name_(nullptr) { |
| 53 | if (info->has_shared_info()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 54 | source_size_ = static_cast<size_t>(info->shared_info()->SourceSize()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 55 | base::SmartArrayPointer<char> name = |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 56 | info->shared_info()->DebugName()->ToCString(); |
| 57 | function_name_ = name.get(); |
| 58 | } |
| 59 | total_stats_.Begin(this); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | PipelineStatistics::~PipelineStatistics() { |
| 64 | if (InPhaseKind()) EndPhaseKind(); |
| 65 | CompilationStatistics::BasicStats diff; |
| 66 | total_stats_.End(this, &diff); |
| 67 | compilation_stats_->RecordTotalStats(source_size_, diff); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | void PipelineStatistics::BeginPhaseKind(const char* phase_kind_name) { |
| 72 | DCHECK(!InPhase()); |
| 73 | if (InPhaseKind()) EndPhaseKind(); |
| 74 | phase_kind_name_ = phase_kind_name; |
| 75 | phase_kind_stats_.Begin(this); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | void PipelineStatistics::EndPhaseKind() { |
| 80 | DCHECK(!InPhase()); |
| 81 | CompilationStatistics::BasicStats diff; |
| 82 | phase_kind_stats_.End(this, &diff); |
| 83 | compilation_stats_->RecordPhaseKindStats(phase_kind_name_, diff); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | void PipelineStatistics::BeginPhase(const char* name) { |
| 88 | DCHECK(InPhaseKind()); |
| 89 | phase_name_ = name; |
| 90 | phase_stats_.Begin(this); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | void PipelineStatistics::EndPhase() { |
| 95 | DCHECK(InPhaseKind()); |
| 96 | CompilationStatistics::BasicStats diff; |
| 97 | phase_stats_.End(this, &diff); |
| 98 | compilation_stats_->RecordPhaseStats(phase_kind_name_, phase_name_, diff); |
| 99 | } |
| 100 | |
| 101 | } // namespace compiler |
| 102 | } // namespace internal |
| 103 | } // namespace v8 |