58 {
59
60
61
62
63
64
65
66
67class CompilerTimings : public MallocAllocated {
68 private:
69#define INC(Name) +1
71#undef INC
72
73 struct Timers : public MallocAllocated {
74 Timer timers_[kNumTimers];
75 std::unique_ptr<Timers> nested_[kNumTimers];
76 };
77
78 public:
79 enum TimerId {
80#define DECLARE_TIMER_ID(Name) k##Name,
82#undef DECLARE_TIMER_ID
83 };
84
85
86 class Scope : public StackResource {
87 public:
88 Scope(Thread* thread, TimerId id)
89 : StackResource(thread), stats_(thread->compiler_timings()) {
90 if (stats_ != nullptr) {
91 outer_nested_ = stats_->nested_;
92 if (*outer_nested_ == nullptr) {
93
94 *outer_nested_ = std::make_unique<Timers>();
95 }
96
97 timer_ = &(*outer_nested_)->timers_[
id];
98 stats_->nested_ = &(*outer_nested_)->nested_[
id];
99
100 timer_->Start();
101 }
102 }
103
104 ~Scope() {
105 if (stats_ != nullptr) {
106 timer_->Stop();
107 stats_->nested_ = outer_nested_;
108 }
109 }
110
111 private:
112 CompilerTimings* const stats_;
113 Timer* timer_;
114 std::unique_ptr<Timers>* outer_nested_;
115 };
116
117 CompilerTimings() { total_.Start(); }
118
119 void RecordInliningStatsByOutcome(bool success, const Timer& timer) {
120 if (success) {
121 try_inlining_success_.AddTotal(timer);
122 } else {
123 try_inlining_failure_.AddTotal(timer);
124 }
125 }
126
127 void Print();
128
129 private:
130 void PrintTimers(Zone* zone,
131 const std::unique_ptr<CompilerTimings::Timers>& timers,
132 const Timer& total,
133 intptr_t level);
134
135 Timer total_;
136 std::unique_ptr<Timers> root_ = std::make_unique<Timers>();
137
138
139 std::unique_ptr<Timers>* nested_ = &root_;
140
141 Timer try_inlining_success_;
142 Timer try_inlining_failure_;
143};
144
145#define TIMER_SCOPE_NAME2(counter) timer_scope_##counter
146#define TIMER_SCOPE_NAME(counter) TIMER_SCOPE_NAME2(counter)
147
148#define COMPILER_TIMINGS_TIMER_SCOPE(thread, timer_id) \
149 CompilerTimings::Scope TIMER_SCOPE_NAME(__COUNTER__)( \
150 thread, CompilerTimings::k##timer_id)
151
152#define COMPILER_TIMINGS_PASS_TIMER_SCOPE(thread, pass_id) \
153 CompilerTimings::Scope TIMER_SCOPE_NAME(__COUNTER__)( \
154 thread, static_cast<CompilerTimings::TimerId>(pass_id))
155
156#define PRECOMPILER_TIMER_SCOPE(precompiler, timer_id) \
157 CompilerTimings::Scope TIMER_SCOPE_NAME(__COUNTER__)( \
158 (precompiler) -> thread(), CompilerTimings::k##timer_id)
159
160}
161
162#endif
#define DECLARE_TIMER_ID(Name)
#define COMPILER_TIMERS_LIST(V)