OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler-dispatcher/compiler-dispatcher-tracer.h" | 5 #include "src/compiler-dispatcher/compiler-dispatcher-tracer.h" |
6 | 6 |
7 #include "src/isolate.h" | 7 #include "src/isolate.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 double CompilerDispatcherTracer::EstimatePrepareToParseInMs() const { | 122 double CompilerDispatcherTracer::EstimatePrepareToParseInMs() const { |
123 base::LockGuard<base::Mutex> lock(&mutex_); | 123 base::LockGuard<base::Mutex> lock(&mutex_); |
124 return Average(prepare_parse_events_); | 124 return Average(prepare_parse_events_); |
125 } | 125 } |
126 | 126 |
127 double CompilerDispatcherTracer::EstimateParseInMs(size_t source_length) const { | 127 double CompilerDispatcherTracer::EstimateParseInMs(size_t source_length) const { |
128 base::LockGuard<base::Mutex> lock(&mutex_); | 128 base::LockGuard<base::Mutex> lock(&mutex_); |
129 return Estimate(parse_events_, source_length); | 129 return Estimate(parse_events_, source_length); |
130 } | 130 } |
131 | 131 |
132 double CompilerDispatcherTracer::EstimateFinalizeParsingInMs() { | 132 double CompilerDispatcherTracer::EstimateFinalizeParsingInMs() const { |
133 base::LockGuard<base::Mutex> lock(&mutex_); | 133 base::LockGuard<base::Mutex> lock(&mutex_); |
134 return Average(finalize_parsing_events_); | 134 return Average(finalize_parsing_events_); |
135 } | 135 } |
136 | 136 |
137 double CompilerDispatcherTracer::EstimatePrepareToCompileInMs() { | 137 double CompilerDispatcherTracer::EstimatePrepareToCompileInMs() const { |
138 base::LockGuard<base::Mutex> lock(&mutex_); | 138 base::LockGuard<base::Mutex> lock(&mutex_); |
139 return Average(prepare_compile_events_); | 139 return Average(prepare_compile_events_); |
140 } | 140 } |
141 | 141 |
142 double CompilerDispatcherTracer::EstimateCompileInMs(size_t ast_size_in_bytes) { | 142 double CompilerDispatcherTracer::EstimateCompileInMs( |
| 143 size_t ast_size_in_bytes) const { |
143 base::LockGuard<base::Mutex> lock(&mutex_); | 144 base::LockGuard<base::Mutex> lock(&mutex_); |
144 return Estimate(compile_events_, ast_size_in_bytes); | 145 return Estimate(compile_events_, ast_size_in_bytes); |
145 } | 146 } |
146 | 147 |
147 double CompilerDispatcherTracer::EstimateFinalizeCompilingInMs() { | 148 double CompilerDispatcherTracer::EstimateFinalizeCompilingInMs() const { |
148 base::LockGuard<base::Mutex> lock(&mutex_); | 149 base::LockGuard<base::Mutex> lock(&mutex_); |
149 return Average(finalize_compiling_events_); | 150 return Average(finalize_compiling_events_); |
150 } | 151 } |
151 | 152 |
152 double CompilerDispatcherTracer::Average( | 153 double CompilerDispatcherTracer::Average( |
153 const base::RingBuffer<double>& buffer) { | 154 const base::RingBuffer<double>& buffer) { |
154 if (buffer.Count() == 0) return 0.0; | 155 if (buffer.Count() == 0) return 0.0; |
155 double sum = buffer.Sum([](double a, double b) { return a + b; }, 0.0); | 156 double sum = buffer.Sum([](double a, double b) { return a + b; }, 0.0); |
156 return sum / buffer.Count(); | 157 return sum / buffer.Count(); |
157 } | 158 } |
158 | 159 |
159 double CompilerDispatcherTracer::Estimate( | 160 double CompilerDispatcherTracer::Estimate( |
160 const base::RingBuffer<std::pair<size_t, double>>& buffer, size_t num) { | 161 const base::RingBuffer<std::pair<size_t, double>>& buffer, size_t num) { |
161 if (buffer.Count() == 0) return 0.0; | 162 if (buffer.Count() == 0) return 0.0; |
162 std::pair<size_t, double> sum = buffer.Sum( | 163 std::pair<size_t, double> sum = buffer.Sum( |
163 [](std::pair<size_t, double> a, std::pair<size_t, double> b) { | 164 [](std::pair<size_t, double> a, std::pair<size_t, double> b) { |
164 return std::make_pair(a.first + b.first, a.second + b.second); | 165 return std::make_pair(a.first + b.first, a.second + b.second); |
165 }, | 166 }, |
166 std::make_pair(0, 0.0)); | 167 std::make_pair(0, 0.0)); |
167 return num * (sum.second / sum.first); | 168 return num * (sum.second / sum.first); |
168 } | 169 } |
169 | 170 |
170 } // namespace internal | 171 } // namespace internal |
171 } // namespace v8 | 172 } // namespace v8 |
OLD | NEW |