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