• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
6 
7 #include "src/compilation-info.h"
8 #include "src/compiler/pipeline-statistics.h"
9 #include "src/compiler/zone-stats.h"
10 #include "src/isolate.h"
11 
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15 
Begin(PipelineStatistics * pipeline_stats)16 void PipelineStatistics::CommonStats::Begin(
17     PipelineStatistics* pipeline_stats) {
18   DCHECK(!scope_);
19   scope_.reset(new ZoneStats::StatsScope(pipeline_stats->zone_stats_));
20   timer_.Start();
21   outer_zone_initial_size_ = pipeline_stats->OuterZoneSize();
22   allocated_bytes_at_start_ =
23       outer_zone_initial_size_ -
24       pipeline_stats->total_stats_.outer_zone_initial_size_ +
25       pipeline_stats->zone_stats_->GetCurrentAllocatedBytes();
26 }
27 
28 
End(PipelineStatistics * pipeline_stats,CompilationStatistics::BasicStats * diff)29 void PipelineStatistics::CommonStats::End(
30     PipelineStatistics* pipeline_stats,
31     CompilationStatistics::BasicStats* diff) {
32   DCHECK(scope_);
33   diff->function_name_ = pipeline_stats->function_name_;
34   diff->delta_ = timer_.Elapsed();
35   size_t outer_zone_diff =
36       pipeline_stats->OuterZoneSize() - outer_zone_initial_size_;
37   diff->max_allocated_bytes_ = outer_zone_diff + scope_->GetMaxAllocatedBytes();
38   diff->absolute_max_allocated_bytes_ =
39       diff->max_allocated_bytes_ + allocated_bytes_at_start_;
40   diff->total_allocated_bytes_ =
41       outer_zone_diff + scope_->GetTotalAllocatedBytes();
42   scope_.reset();
43   timer_.Stop();
44 }
45 
PipelineStatistics(CompilationInfo * info,ZoneStats * zone_stats)46 PipelineStatistics::PipelineStatistics(CompilationInfo* info,
47                                        ZoneStats* zone_stats)
48     : isolate_(info->isolate()),
49       outer_zone_(info->zone()),
50       zone_stats_(zone_stats),
51       compilation_stats_(isolate_->GetTurboStatistics()),
52       source_size_(0),
53       phase_kind_name_(nullptr),
54       phase_name_(nullptr) {
55   if (info->has_shared_info()) {
56     source_size_ = static_cast<size_t>(info->shared_info()->SourceSize());
57     std::unique_ptr<char[]> name =
58         info->shared_info()->DebugName()->ToCString();
59     function_name_ = name.get();
60   }
61   total_stats_.Begin(this);
62 }
63 
64 
~PipelineStatistics()65 PipelineStatistics::~PipelineStatistics() {
66   if (InPhaseKind()) EndPhaseKind();
67   CompilationStatistics::BasicStats diff;
68   total_stats_.End(this, &diff);
69   compilation_stats_->RecordTotalStats(source_size_, diff);
70 }
71 
72 
BeginPhaseKind(const char * phase_kind_name)73 void PipelineStatistics::BeginPhaseKind(const char* phase_kind_name) {
74   DCHECK(!InPhase());
75   if (InPhaseKind()) EndPhaseKind();
76   phase_kind_name_ = phase_kind_name;
77   phase_kind_stats_.Begin(this);
78 }
79 
80 
EndPhaseKind()81 void PipelineStatistics::EndPhaseKind() {
82   DCHECK(!InPhase());
83   CompilationStatistics::BasicStats diff;
84   phase_kind_stats_.End(this, &diff);
85   compilation_stats_->RecordPhaseKindStats(phase_kind_name_, diff);
86 }
87 
88 
BeginPhase(const char * name)89 void PipelineStatistics::BeginPhase(const char* name) {
90   DCHECK(InPhaseKind());
91   phase_name_ = name;
92   phase_stats_.Begin(this);
93 }
94 
95 
EndPhase()96 void PipelineStatistics::EndPhase() {
97   DCHECK(InPhaseKind());
98   CompilationStatistics::BasicStats diff;
99   phase_stats_.End(this, &diff);
100   compilation_stats_->RecordPhaseStats(phase_kind_name_, phase_name_, diff);
101 }
102 
103 }  // namespace compiler
104 }  // namespace internal
105 }  // namespace v8
106