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