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 #include "src/utils.h" | 8 #include "src/utils.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 21 matching lines...) Expand all Loading... |
32 switch (scope_id_) { | 32 switch (scope_id_) { |
33 case ScopeID::kPrepareToParse: | 33 case ScopeID::kPrepareToParse: |
34 tracer_->RecordPrepareToParse(elapsed); | 34 tracer_->RecordPrepareToParse(elapsed); |
35 break; | 35 break; |
36 case ScopeID::kParse: | 36 case ScopeID::kParse: |
37 tracer_->RecordParse(elapsed, num_); | 37 tracer_->RecordParse(elapsed, num_); |
38 break; | 38 break; |
39 case ScopeID::kFinalizeParsing: | 39 case ScopeID::kFinalizeParsing: |
40 tracer_->RecordFinalizeParsing(elapsed); | 40 tracer_->RecordFinalizeParsing(elapsed); |
41 break; | 41 break; |
| 42 case ScopeID::kAnalyze: |
| 43 tracer_->RecordAnalyze(elapsed); |
| 44 break; |
42 case ScopeID::kPrepareToCompile: | 45 case ScopeID::kPrepareToCompile: |
43 tracer_->RecordPrepareToCompile(elapsed); | 46 tracer_->RecordPrepareToCompile(elapsed); |
44 break; | 47 break; |
45 case ScopeID::kCompile: | 48 case ScopeID::kCompile: |
46 tracer_->RecordCompile(elapsed, num_); | 49 tracer_->RecordCompile(elapsed, num_); |
47 break; | 50 break; |
48 case ScopeID::kFinalizeCompiling: | 51 case ScopeID::kFinalizeCompiling: |
49 tracer_->RecordFinalizeCompiling(elapsed); | 52 tracer_->RecordFinalizeCompiling(elapsed); |
50 break; | 53 break; |
51 } | 54 } |
52 } | 55 } |
53 | 56 |
54 // static | 57 // static |
55 const char* CompilerDispatcherTracer::Scope::Name(ScopeID scope_id) { | 58 const char* CompilerDispatcherTracer::Scope::Name(ScopeID scope_id) { |
56 switch (scope_id) { | 59 switch (scope_id) { |
57 case ScopeID::kPrepareToParse: | 60 case ScopeID::kPrepareToParse: |
58 return "V8.BackgroundCompile_PrepareToParse"; | 61 return "V8.BackgroundCompile_PrepareToParse"; |
59 case ScopeID::kParse: | 62 case ScopeID::kParse: |
60 return "V8.BackgroundCompile_Parse"; | 63 return "V8.BackgroundCompile_Parse"; |
61 case ScopeID::kFinalizeParsing: | 64 case ScopeID::kFinalizeParsing: |
62 return "V8.BackgroundCompile_FinalizeParsing"; | 65 return "V8.BackgroundCompile_FinalizeParsing"; |
| 66 case ScopeID::kAnalyze: |
| 67 return "V8.BackgroundCompile_Analyze"; |
63 case ScopeID::kPrepareToCompile: | 68 case ScopeID::kPrepareToCompile: |
64 return "V8.BackgroundCompile_PrepareToCompile"; | 69 return "V8.BackgroundCompile_PrepareToCompile"; |
65 case ScopeID::kCompile: | 70 case ScopeID::kCompile: |
66 return "V8.BackgroundCompile_Compile"; | 71 return "V8.BackgroundCompile_Compile"; |
67 case ScopeID::kFinalizeCompiling: | 72 case ScopeID::kFinalizeCompiling: |
68 return "V8.BackgroundCompile_FinalizeCompiling"; | 73 return "V8.BackgroundCompile_FinalizeCompiling"; |
69 } | 74 } |
70 UNREACHABLE(); | 75 UNREACHABLE(); |
71 return nullptr; | 76 return nullptr; |
72 } | 77 } |
(...skipping 17 matching lines...) Expand all Loading... |
90 size_t source_length) { | 95 size_t source_length) { |
91 base::LockGuard<base::Mutex> lock(&mutex_); | 96 base::LockGuard<base::Mutex> lock(&mutex_); |
92 parse_events_.Push(std::make_pair(source_length, duration_ms)); | 97 parse_events_.Push(std::make_pair(source_length, duration_ms)); |
93 } | 98 } |
94 | 99 |
95 void CompilerDispatcherTracer::RecordFinalizeParsing(double duration_ms) { | 100 void CompilerDispatcherTracer::RecordFinalizeParsing(double duration_ms) { |
96 base::LockGuard<base::Mutex> lock(&mutex_); | 101 base::LockGuard<base::Mutex> lock(&mutex_); |
97 finalize_parsing_events_.Push(duration_ms); | 102 finalize_parsing_events_.Push(duration_ms); |
98 } | 103 } |
99 | 104 |
| 105 void CompilerDispatcherTracer::RecordAnalyze(double duration_ms) { |
| 106 base::LockGuard<base::Mutex> lock(&mutex_); |
| 107 analyze_events_.Push(duration_ms); |
| 108 } |
| 109 |
100 void CompilerDispatcherTracer::RecordPrepareToCompile(double duration_ms) { | 110 void CompilerDispatcherTracer::RecordPrepareToCompile(double duration_ms) { |
101 base::LockGuard<base::Mutex> lock(&mutex_); | 111 base::LockGuard<base::Mutex> lock(&mutex_); |
102 prepare_compile_events_.Push(duration_ms); | 112 prepare_compile_events_.Push(duration_ms); |
103 } | 113 } |
104 | 114 |
105 void CompilerDispatcherTracer::RecordCompile(double duration_ms, | 115 void CompilerDispatcherTracer::RecordCompile(double duration_ms, |
106 size_t ast_size_in_bytes) { | 116 size_t ast_size_in_bytes) { |
107 base::LockGuard<base::Mutex> lock(&mutex_); | 117 base::LockGuard<base::Mutex> lock(&mutex_); |
108 compile_events_.Push(std::make_pair(ast_size_in_bytes, duration_ms)); | 118 compile_events_.Push(std::make_pair(ast_size_in_bytes, duration_ms)); |
109 } | 119 } |
(...skipping 11 matching lines...) Expand all Loading... |
121 double CompilerDispatcherTracer::EstimateParseInMs(size_t source_length) const { | 131 double CompilerDispatcherTracer::EstimateParseInMs(size_t source_length) const { |
122 base::LockGuard<base::Mutex> lock(&mutex_); | 132 base::LockGuard<base::Mutex> lock(&mutex_); |
123 return Estimate(parse_events_, source_length); | 133 return Estimate(parse_events_, source_length); |
124 } | 134 } |
125 | 135 |
126 double CompilerDispatcherTracer::EstimateFinalizeParsingInMs() const { | 136 double CompilerDispatcherTracer::EstimateFinalizeParsingInMs() const { |
127 base::LockGuard<base::Mutex> lock(&mutex_); | 137 base::LockGuard<base::Mutex> lock(&mutex_); |
128 return Average(finalize_parsing_events_); | 138 return Average(finalize_parsing_events_); |
129 } | 139 } |
130 | 140 |
| 141 double CompilerDispatcherTracer::EstimateAnalyzeInMs() const { |
| 142 base::LockGuard<base::Mutex> lock(&mutex_); |
| 143 return Average(analyze_events_); |
| 144 } |
| 145 |
131 double CompilerDispatcherTracer::EstimatePrepareToCompileInMs() const { | 146 double CompilerDispatcherTracer::EstimatePrepareToCompileInMs() const { |
132 base::LockGuard<base::Mutex> lock(&mutex_); | 147 base::LockGuard<base::Mutex> lock(&mutex_); |
133 return Average(prepare_compile_events_); | 148 return Average(prepare_compile_events_); |
134 } | 149 } |
135 | 150 |
136 double CompilerDispatcherTracer::EstimateCompileInMs( | 151 double CompilerDispatcherTracer::EstimateCompileInMs( |
137 size_t ast_size_in_bytes) const { | 152 size_t ast_size_in_bytes) const { |
138 base::LockGuard<base::Mutex> lock(&mutex_); | 153 base::LockGuard<base::Mutex> lock(&mutex_); |
139 return Estimate(compile_events_, ast_size_in_bytes); | 154 return Estimate(compile_events_, ast_size_in_bytes); |
140 } | 155 } |
141 | 156 |
142 double CompilerDispatcherTracer::EstimateFinalizeCompilingInMs() const { | 157 double CompilerDispatcherTracer::EstimateFinalizeCompilingInMs() const { |
143 base::LockGuard<base::Mutex> lock(&mutex_); | 158 base::LockGuard<base::Mutex> lock(&mutex_); |
144 return Average(finalize_compiling_events_); | 159 return Average(finalize_compiling_events_); |
145 } | 160 } |
146 | 161 |
147 void CompilerDispatcherTracer::DumpStatistics() const { | 162 void CompilerDispatcherTracer::DumpStatistics() const { |
148 PrintF( | 163 PrintF( |
149 "CompilerDispatcherTracer: " | 164 "CompilerDispatcherTracer: " |
150 "prepare_parsing=%.2lfms parsing=%.2lfms/kb finalize_parsing=%.2lfms " | 165 "prepare_parsing=%.2lfms parsing=%.2lfms/kb finalize_parsing=%.2lfms " |
151 "prepare_compiling=%.2lfms compiling=%.2lfms/kb " | 166 "analyze=%.2lfms prepare_compiling=%.2lfms compiling=%.2lfms/kb " |
152 "finalize_compilig=%.2lfms\n", | 167 "finalize_compiling=%.2lfms\n", |
153 EstimatePrepareToParseInMs(), EstimateParseInMs(1 * KB), | 168 EstimatePrepareToParseInMs(), EstimateParseInMs(1 * KB), |
154 EstimateFinalizeParsingInMs(), EstimatePrepareToCompileInMs(), | 169 EstimateFinalizeParsingInMs(), EstimateAnalyzeInMs(), |
155 EstimateCompileInMs(1 * KB), EstimateFinalizeCompilingInMs()); | 170 EstimatePrepareToCompileInMs(), EstimateCompileInMs(1 * KB), |
| 171 EstimateFinalizeCompilingInMs()); |
156 } | 172 } |
157 | 173 |
158 double CompilerDispatcherTracer::Average( | 174 double CompilerDispatcherTracer::Average( |
159 const base::RingBuffer<double>& buffer) { | 175 const base::RingBuffer<double>& buffer) { |
160 if (buffer.Count() == 0) return 0.0; | 176 if (buffer.Count() == 0) return 0.0; |
161 double sum = buffer.Sum([](double a, double b) { return a + b; }, 0.0); | 177 double sum = buffer.Sum([](double a, double b) { return a + b; }, 0.0); |
162 return sum / buffer.Count(); | 178 return sum / buffer.Count(); |
163 } | 179 } |
164 | 180 |
165 double CompilerDispatcherTracer::Estimate( | 181 double CompilerDispatcherTracer::Estimate( |
166 const base::RingBuffer<std::pair<size_t, double>>& buffer, size_t num) { | 182 const base::RingBuffer<std::pair<size_t, double>>& buffer, size_t num) { |
167 if (buffer.Count() == 0) return kEstimatedRuntimeWithoutData; | 183 if (buffer.Count() == 0) return kEstimatedRuntimeWithoutData; |
168 std::pair<size_t, double> sum = buffer.Sum( | 184 std::pair<size_t, double> sum = buffer.Sum( |
169 [](std::pair<size_t, double> a, std::pair<size_t, double> b) { | 185 [](std::pair<size_t, double> a, std::pair<size_t, double> b) { |
170 return std::make_pair(a.first + b.first, a.second + b.second); | 186 return std::make_pair(a.first + b.first, a.second + b.second); |
171 }, | 187 }, |
172 std::make_pair(0, 0.0)); | 188 std::make_pair(0, 0.0)); |
173 return num * (sum.second / sum.first); | 189 return num * (sum.second / sum.first); |
174 } | 190 } |
175 | 191 |
176 } // namespace internal | 192 } // namespace internal |
177 } // namespace v8 | 193 } // namespace v8 |
OLD | NEW |