blob: c52c61cd85c387c145c09ea731367030b7108136 [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#ifndef V8_COMPILER_PIPELINE_STATISTICS_H_
6#define V8_COMPILER_PIPELINE_STATISTICS_H_
7
8#include <string>
9
Ben Murdochc5610432016-08-08 18:44:38 +010010#include "src/base/platform/elapsed-timer.h"
11#include "src/base/smart-pointers.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040012#include "src/compilation-statistics.h"
13#include "src/compiler/zone-pool.h"
14
15namespace v8 {
16namespace internal {
17namespace compiler {
18
19class PhaseScope;
20
21class PipelineStatistics : public Malloced {
22 public:
23 PipelineStatistics(CompilationInfo* info, ZonePool* zone_pool);
24 ~PipelineStatistics();
25
26 void BeginPhaseKind(const char* phase_kind_name);
Ben Murdochc5610432016-08-08 18:44:38 +010027 void EndPhaseKind();
Emily Bernierd0a1eb72015-03-24 16:35:39 -040028
29 private:
30 size_t OuterZoneSize() {
31 return static_cast<size_t>(outer_zone_->allocation_size());
32 }
33
34 class CommonStats {
35 public:
36 CommonStats() : outer_zone_initial_size_(0) {}
37
38 void Begin(PipelineStatistics* pipeline_stats);
39 void End(PipelineStatistics* pipeline_stats,
40 CompilationStatistics::BasicStats* diff);
41
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000042 base::SmartPointer<ZonePool::StatsScope> scope_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040043 base::ElapsedTimer timer_;
44 size_t outer_zone_initial_size_;
45 size_t allocated_bytes_at_start_;
46 };
47
48 bool InPhaseKind() { return !phase_kind_stats_.scope_.is_empty(); }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040049
50 friend class PhaseScope;
51 bool InPhase() { return !phase_stats_.scope_.is_empty(); }
52 void BeginPhase(const char* name);
53 void EndPhase();
54
55 Isolate* isolate_;
56 Zone* outer_zone_;
57 ZonePool* zone_pool_;
58 CompilationStatistics* compilation_stats_;
59 std::string function_name_;
60
61 // Stats for the entire compilation.
62 CommonStats total_stats_;
63 size_t source_size_;
64
65 // Stats for phase kind.
66 const char* phase_kind_name_;
67 CommonStats phase_kind_stats_;
68
69 // Stats for phase.
70 const char* phase_name_;
71 CommonStats phase_stats_;
72
73 DISALLOW_COPY_AND_ASSIGN(PipelineStatistics);
74};
75
76
77class PhaseScope {
78 public:
79 PhaseScope(PipelineStatistics* pipeline_stats, const char* name)
80 : pipeline_stats_(pipeline_stats) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000081 if (pipeline_stats_ != nullptr) pipeline_stats_->BeginPhase(name);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040082 }
83 ~PhaseScope() {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000084 if (pipeline_stats_ != nullptr) pipeline_stats_->EndPhase();
Emily Bernierd0a1eb72015-03-24 16:35:39 -040085 }
86
87 private:
88 PipelineStatistics* const pipeline_stats_;
89
90 DISALLOW_COPY_AND_ASSIGN(PhaseScope);
91};
92
93} // namespace compiler
94} // namespace internal
95} // namespace v8
96
97#endif