| 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 { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 double MonotonicallyIncreasingTimeInMs() { | 14 double MonotonicallyIncreasingTimeInMs() { |
| 15 return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() * | 15 return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() * |
| 16 static_cast<double>(base::Time::kMillisecondsPerSecond); | 16 static_cast<double>(base::Time::kMillisecondsPerSecond); |
| 17 } | 17 } |
| 18 | 18 |
| 19 const double kEstimatedRuntimeWithoutData = 1.0; |
| 20 |
| 19 } // namespace | 21 } // namespace |
| 20 | 22 |
| 21 CompilerDispatcherTracer::Scope::Scope(CompilerDispatcherTracer* tracer, | 23 CompilerDispatcherTracer::Scope::Scope(CompilerDispatcherTracer* tracer, |
| 22 ScopeID scope_id, size_t num) | 24 ScopeID scope_id, size_t num) |
| 23 : tracer_(tracer), scope_id_(scope_id), num_(num) { | 25 : tracer_(tracer), scope_id_(scope_id), num_(num) { |
| 24 start_time_ = MonotonicallyIncreasingTimeInMs(); | 26 start_time_ = MonotonicallyIncreasingTimeInMs(); |
| 25 // TODO(cbruni): remove once we fully moved to a trace-based system. | 27 // TODO(cbruni): remove once we fully moved to a trace-based system. |
| 26 if (V8_UNLIKELY(FLAG_runtime_stats)) { | 28 if (V8_UNLIKELY(FLAG_runtime_stats)) { |
| 27 RuntimeCallStats::Enter(tracer_->runtime_call_stats_, &timer_, | 29 RuntimeCallStats::Enter(tracer_->runtime_call_stats_, &timer_, |
| 28 &RuntimeCallStats::CompilerDispatcher); | 30 &RuntimeCallStats::CompilerDispatcher); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 double CompilerDispatcherTracer::EstimatePrepareToParseInMs() const { | 124 double CompilerDispatcherTracer::EstimatePrepareToParseInMs() const { |
| 123 base::LockGuard<base::Mutex> lock(&mutex_); | 125 base::LockGuard<base::Mutex> lock(&mutex_); |
| 124 return Average(prepare_parse_events_); | 126 return Average(prepare_parse_events_); |
| 125 } | 127 } |
| 126 | 128 |
| 127 double CompilerDispatcherTracer::EstimateParseInMs(size_t source_length) const { | 129 double CompilerDispatcherTracer::EstimateParseInMs(size_t source_length) const { |
| 128 base::LockGuard<base::Mutex> lock(&mutex_); | 130 base::LockGuard<base::Mutex> lock(&mutex_); |
| 129 return Estimate(parse_events_, source_length); | 131 return Estimate(parse_events_, source_length); |
| 130 } | 132 } |
| 131 | 133 |
| 132 double CompilerDispatcherTracer::EstimateFinalizeParsingInMs() { | 134 double CompilerDispatcherTracer::EstimateFinalizeParsingInMs() const { |
| 133 base::LockGuard<base::Mutex> lock(&mutex_); | 135 base::LockGuard<base::Mutex> lock(&mutex_); |
| 134 return Average(finalize_parsing_events_); | 136 return Average(finalize_parsing_events_); |
| 135 } | 137 } |
| 136 | 138 |
| 137 double CompilerDispatcherTracer::EstimatePrepareToCompileInMs() { | 139 double CompilerDispatcherTracer::EstimatePrepareToCompileInMs() const { |
| 138 base::LockGuard<base::Mutex> lock(&mutex_); | 140 base::LockGuard<base::Mutex> lock(&mutex_); |
| 139 return Average(prepare_compile_events_); | 141 return Average(prepare_compile_events_); |
| 140 } | 142 } |
| 141 | 143 |
| 142 double CompilerDispatcherTracer::EstimateCompileInMs(size_t ast_size_in_bytes) { | 144 double CompilerDispatcherTracer::EstimateCompileInMs( |
| 145 size_t ast_size_in_bytes) const { |
| 143 base::LockGuard<base::Mutex> lock(&mutex_); | 146 base::LockGuard<base::Mutex> lock(&mutex_); |
| 144 return Estimate(compile_events_, ast_size_in_bytes); | 147 return Estimate(compile_events_, ast_size_in_bytes); |
| 145 } | 148 } |
| 146 | 149 |
| 147 double CompilerDispatcherTracer::EstimateFinalizeCompilingInMs() { | 150 double CompilerDispatcherTracer::EstimateFinalizeCompilingInMs() const { |
| 148 base::LockGuard<base::Mutex> lock(&mutex_); | 151 base::LockGuard<base::Mutex> lock(&mutex_); |
| 149 return Average(finalize_compiling_events_); | 152 return Average(finalize_compiling_events_); |
| 150 } | 153 } |
| 151 | 154 |
| 152 double CompilerDispatcherTracer::Average( | 155 double CompilerDispatcherTracer::Average( |
| 153 const base::RingBuffer<double>& buffer) { | 156 const base::RingBuffer<double>& buffer) { |
| 154 if (buffer.Count() == 0) return 0.0; | 157 if (buffer.Count() == 0) return 0.0; |
| 155 double sum = buffer.Sum([](double a, double b) { return a + b; }, 0.0); | 158 double sum = buffer.Sum([](double a, double b) { return a + b; }, 0.0); |
| 156 return sum / buffer.Count(); | 159 return sum / buffer.Count(); |
| 157 } | 160 } |
| 158 | 161 |
| 159 double CompilerDispatcherTracer::Estimate( | 162 double CompilerDispatcherTracer::Estimate( |
| 160 const base::RingBuffer<std::pair<size_t, double>>& buffer, size_t num) { | 163 const base::RingBuffer<std::pair<size_t, double>>& buffer, size_t num) { |
| 161 if (buffer.Count() == 0) return 0.0; | 164 if (buffer.Count() == 0) return kEstimatedRuntimeWithoutData; |
| 162 std::pair<size_t, double> sum = buffer.Sum( | 165 std::pair<size_t, double> sum = buffer.Sum( |
| 163 [](std::pair<size_t, double> a, std::pair<size_t, double> b) { | 166 [](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); | 167 return std::make_pair(a.first + b.first, a.second + b.second); |
| 165 }, | 168 }, |
| 166 std::make_pair(0, 0.0)); | 169 std::make_pair(0, 0.0)); |
| 167 return num * (sum.second / sum.first); | 170 return num * (sum.second / sum.first); |
| 168 } | 171 } |
| 169 | 172 |
| 170 } // namespace internal | 173 } // namespace internal |
| 171 } // namespace v8 | 174 } // namespace v8 |
| OLD | NEW |