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