blob: b98f837ee9714435922fb0208b3859b9b3650a50 [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// 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 "src/compiler.h"
6#include "src/compiler/pipeline-statistics.h"
7#include "src/compiler/zone-pool.h"
8
9namespace v8 {
10namespace internal {
11namespace compiler {
12
13void PipelineStatistics::CommonStats::Begin(
14 PipelineStatistics* pipeline_stats) {
15 DCHECK(scope_.is_empty());
16 scope_.Reset(new ZonePool::StatsScope(pipeline_stats->zone_pool_));
17 timer_.Start();
18 outer_zone_initial_size_ = pipeline_stats->OuterZoneSize();
19 allocated_bytes_at_start_ =
20 outer_zone_initial_size_ -
21 pipeline_stats->total_stats_.outer_zone_initial_size_ +
22 pipeline_stats->zone_pool_->GetCurrentAllocatedBytes();
23}
24
25
26void PipelineStatistics::CommonStats::End(
27 PipelineStatistics* pipeline_stats,
28 CompilationStatistics::BasicStats* diff) {
29 DCHECK(!scope_.is_empty());
30 diff->function_name_ = pipeline_stats->function_name_;
31 diff->delta_ = timer_.Elapsed();
32 size_t outer_zone_diff =
33 pipeline_stats->OuterZoneSize() - outer_zone_initial_size_;
34 diff->max_allocated_bytes_ = outer_zone_diff + scope_->GetMaxAllocatedBytes();
35 diff->absolute_max_allocated_bytes_ =
36 diff->max_allocated_bytes_ + allocated_bytes_at_start_;
37 diff->total_allocated_bytes_ =
38 outer_zone_diff + scope_->GetTotalAllocatedBytes();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000039 scope_.Reset(nullptr);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040040 timer_.Stop();
41}
42
43
44PipelineStatistics::PipelineStatistics(CompilationInfo* info,
45 ZonePool* zone_pool)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000046 : isolate_(info->isolate()),
Emily Bernierd0a1eb72015-03-24 16:35:39 -040047 outer_zone_(info->zone()),
48 zone_pool_(zone_pool),
49 compilation_stats_(isolate_->GetTurboStatistics()),
50 source_size_(0),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000051 phase_kind_name_(nullptr),
52 phase_name_(nullptr) {
53 if (info->has_shared_info()) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040054 source_size_ = static_cast<size_t>(info->shared_info()->SourceSize());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000055 base::SmartArrayPointer<char> name =
Emily Bernierd0a1eb72015-03-24 16:35:39 -040056 info->shared_info()->DebugName()->ToCString();
57 function_name_ = name.get();
58 }
59 total_stats_.Begin(this);
60}
61
62
63PipelineStatistics::~PipelineStatistics() {
64 if (InPhaseKind()) EndPhaseKind();
65 CompilationStatistics::BasicStats diff;
66 total_stats_.End(this, &diff);
67 compilation_stats_->RecordTotalStats(source_size_, diff);
68}
69
70
71void PipelineStatistics::BeginPhaseKind(const char* phase_kind_name) {
72 DCHECK(!InPhase());
73 if (InPhaseKind()) EndPhaseKind();
74 phase_kind_name_ = phase_kind_name;
75 phase_kind_stats_.Begin(this);
76}
77
78
79void PipelineStatistics::EndPhaseKind() {
80 DCHECK(!InPhase());
81 CompilationStatistics::BasicStats diff;
82 phase_kind_stats_.End(this, &diff);
83 compilation_stats_->RecordPhaseKindStats(phase_kind_name_, diff);
84}
85
86
87void PipelineStatistics::BeginPhase(const char* name) {
88 DCHECK(InPhaseKind());
89 phase_name_ = name;
90 phase_stats_.Begin(this);
91}
92
93
94void PipelineStatistics::EndPhase() {
95 DCHECK(InPhaseKind());
96 CompilationStatistics::BasicStats diff;
97 phase_stats_.End(this, &diff);
98 compilation_stats_->RecordPhaseStats(phase_kind_name_, phase_name_, diff);
99}
100
101} // namespace compiler
102} // namespace internal
103} // namespace v8