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