OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_COUNTERS_H_ | 5 #ifndef V8_COUNTERS_H_ |
6 #define V8_COUNTERS_H_ | 6 #define V8_COUNTERS_H_ |
7 | 7 |
8 #include "include/v8.h" | 8 #include "include/v8.h" |
9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
10 #include "src/base/atomic-utils.h" | 10 #include "src/base/atomic-utils.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 void* CreateHistogram() const; | 241 void* CreateHistogram() const; |
242 | 242 |
243 const char* name_; | 243 const char* name_; |
244 int min_; | 244 int min_; |
245 int max_; | 245 int max_; |
246 int num_buckets_; | 246 int num_buckets_; |
247 void* histogram_; | 247 void* histogram_; |
248 Counters* counters_; | 248 Counters* counters_; |
249 }; | 249 }; |
250 | 250 |
251 // A HistogramTimer allows distributions of results to be created. | 251 enum class HistogramTimerResolution { MILLISECOND, MICROSECOND }; |
252 class HistogramTimer : public Histogram { | 252 |
| 253 // A thread safe histogram timer, allowing distributions of |
| 254 // (non-nested) timed results. |
| 255 class TimedHistogram : public Histogram { |
253 public: | 256 public: |
254 enum Resolution { | 257 // Start the timer. Log if isolate non-null. |
255 MILLISECOND, | 258 void Start(base::ElapsedTimer* timer, Isolate* isolate); |
256 MICROSECOND | |
257 }; | |
258 | 259 |
259 // Note: public for testing purposes only. | 260 // Stop the timer and record the results. Log if isolate non-null. |
260 HistogramTimer(const char* name, int min, int max, Resolution resolution, | 261 void Stop(base::ElapsedTimer* timer, Isolate* isolate); |
261 int num_buckets, Counters* counters) | 262 |
| 263 protected: |
| 264 friend class Counters; |
| 265 HistogramTimerResolution resolution_; |
| 266 |
| 267 TimedHistogram() {} |
| 268 TimedHistogram(const char* name, int min, int max, |
| 269 HistogramTimerResolution resolution, int num_buckets, |
| 270 Counters* counters) |
262 : Histogram(name, min, max, num_buckets, counters), | 271 : Histogram(name, min, max, num_buckets, counters), |
263 resolution_(resolution) {} | 272 resolution_(resolution) {} |
| 273 }; |
264 | 274 |
265 // Start the timer. | 275 // Helper class for scoping a TimedHistogram. |
| 276 class TimedHistogramScope { |
| 277 public: |
| 278 explicit TimedHistogramScope(TimedHistogram* histogram, |
| 279 Isolate* isolate = nullptr) |
| 280 : histogram_(histogram), isolate_(isolate) { |
| 281 histogram_->Start(&timer_, isolate); |
| 282 } |
| 283 ~TimedHistogramScope() { histogram_->Stop(&timer_, isolate_); } |
| 284 |
| 285 private: |
| 286 base::ElapsedTimer timer_; |
| 287 TimedHistogram* histogram_; |
| 288 Isolate* isolate_; |
| 289 |
| 290 DISALLOW_IMPLICIT_CONSTRUCTORS(TimedHistogramScope); |
| 291 }; |
| 292 |
| 293 // A HistogramTimer allows distributions of (non-nested) timed results |
| 294 // to be created. WARNING: This class is not thread safe and can only |
| 295 // be run on the foreground thread. |
| 296 class HistogramTimer : public TimedHistogram { |
| 297 public: |
| 298 // Note: public for testing purposes only. |
| 299 HistogramTimer(const char* name, int min, int max, |
| 300 HistogramTimerResolution resolution, int num_buckets, |
| 301 Counters* counters) |
| 302 : TimedHistogram(name, min, max, resolution, num_buckets, counters) {} |
| 303 |
266 void Start(); | 304 void Start(); |
267 | |
268 // Stop the timer and record the results. | |
269 void Stop(); | 305 void Stop(); |
270 | 306 |
271 // Returns true if the timer is running. | 307 // Returns true if the timer is running. |
272 bool Running() { | 308 bool Running() { |
273 return Enabled() && timer_.IsStarted(); | 309 return Enabled() && timer_.IsStarted(); |
274 } | 310 } |
275 | 311 |
276 // TODO(bmeurer): Remove this when HistogramTimerScope is fixed. | 312 // TODO(bmeurer): Remove this when HistogramTimerScope is fixed. |
277 #ifdef DEBUG | 313 #ifdef DEBUG |
278 base::ElapsedTimer* timer() { return &timer_; } | 314 base::ElapsedTimer* timer() { return &timer_; } |
279 #endif | 315 #endif |
280 | 316 |
281 private: | 317 private: |
282 friend class Counters; | 318 friend class Counters; |
283 | 319 |
284 base::ElapsedTimer timer_; | 320 base::ElapsedTimer timer_; |
285 Resolution resolution_; | |
286 | 321 |
287 HistogramTimer() {} | 322 HistogramTimer() {} |
288 }; | 323 }; |
289 | 324 |
290 // Helper class for scoping a HistogramTimer. | 325 // Helper class for scoping a HistogramTimer. |
291 // TODO(bmeurer): The ifdeffery is an ugly hack around the fact that the | 326 // TODO(bmeurer): The ifdeffery is an ugly hack around the fact that the |
292 // Parser is currently reentrant (when it throws an error, we call back | 327 // Parser is currently reentrant (when it throws an error, we call back |
293 // into JavaScript and all bets are off), but ElapsedTimer is not | 328 // into JavaScript and all bets are off), but ElapsedTimer is not |
294 // reentry-safe. Fix this properly and remove |allow_nesting|. | 329 // reentry-safe. Fix this properly and remove |allow_nesting|. |
295 class HistogramTimerScope BASE_EMBEDDED { | 330 class HistogramTimerScope BASE_EMBEDDED { |
(...skipping 24 matching lines...) Expand all Loading... |
320 #endif | 355 #endif |
321 } | 356 } |
322 | 357 |
323 private: | 358 private: |
324 HistogramTimer* timer_; | 359 HistogramTimer* timer_; |
325 #ifdef DEBUG | 360 #ifdef DEBUG |
326 bool skipped_timer_start_; | 361 bool skipped_timer_start_; |
327 #endif | 362 #endif |
328 }; | 363 }; |
329 | 364 |
330 | |
331 // A histogram timer that can aggregate events within a larger scope. | 365 // A histogram timer that can aggregate events within a larger scope. |
332 // | 366 // |
333 // Intended use of this timer is to have an outer (aggregating) and an inner | 367 // Intended use of this timer is to have an outer (aggregating) and an inner |
334 // (to be aggregated) scope, where the inner scope measure the time of events, | 368 // (to be aggregated) scope, where the inner scope measure the time of events, |
335 // and all those inner scope measurements will be summed up by the outer scope. | 369 // and all those inner scope measurements will be summed up by the outer scope. |
336 // An example use might be to aggregate the time spent in lazy compilation | 370 // An example use might be to aggregate the time spent in lazy compilation |
337 // while running a script. | 371 // while running a script. |
338 // | 372 // |
339 // Helpers: | 373 // Helpers: |
340 // - AggregatingHistogramTimerScope, the "outer" scope within which | 374 // - AggregatingHistogramTimerScope, the "outer" scope within which |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 MICROSECOND) \ | 1034 MICROSECOND) \ |
1001 /* Total compilation time incl. caching/parsing */ \ | 1035 /* Total compilation time incl. caching/parsing */ \ |
1002 HT(compile_script, V8.CompileScriptMicroSeconds, 1000000, MICROSECOND) \ | 1036 HT(compile_script, V8.CompileScriptMicroSeconds, 1000000, MICROSECOND) \ |
1003 /* Total JavaScript execution time (including callbacks and runtime calls */ \ | 1037 /* Total JavaScript execution time (including callbacks and runtime calls */ \ |
1004 HT(execute, V8.Execute, 1000000, MICROSECOND) \ | 1038 HT(execute, V8.Execute, 1000000, MICROSECOND) \ |
1005 /* Asm/Wasm */ \ | 1039 /* Asm/Wasm */ \ |
1006 HT(wasm_instantiate_asm_module_time, \ | 1040 HT(wasm_instantiate_asm_module_time, \ |
1007 V8.WasmInstantiateModuleMicroSeconds.asm, 10000000, MICROSECOND) \ | 1041 V8.WasmInstantiateModuleMicroSeconds.asm, 10000000, MICROSECOND) \ |
1008 HT(wasm_instantiate_wasm_module_time, \ | 1042 HT(wasm_instantiate_wasm_module_time, \ |
1009 V8.WasmInstantiateModuleMicroSeconds.wasm, 10000000, MICROSECOND) \ | 1043 V8.WasmInstantiateModuleMicroSeconds.wasm, 10000000, MICROSECOND) \ |
1010 HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \ | |
1011 1000000, MICROSECOND) \ | |
1012 HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \ | |
1013 1000000, MICROSECOND) \ | |
1014 HT(wasm_decode_asm_function_time, V8.WasmDecodeFunctionMicroSeconds.asm, \ | |
1015 1000000, MICROSECOND) \ | |
1016 HT(wasm_decode_wasm_function_time, V8.WasmDecodeFunctionMicroSeconds.wasm, \ | |
1017 1000000, MICROSECOND) \ | |
1018 HT(wasm_compile_asm_module_time, V8.WasmCompileModuleMicroSeconds.asm, \ | |
1019 10000000, MICROSECOND) \ | |
1020 HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \ | |
1021 10000000, MICROSECOND) \ | |
1022 HT(wasm_compile_function_time, V8.WasmCompileFunctionMicroSeconds, 1000000, \ | 1044 HT(wasm_compile_function_time, V8.WasmCompileFunctionMicroSeconds, 1000000, \ |
1023 MICROSECOND) \ | 1045 MICROSECOND) \ |
1024 HT(asm_wasm_translation_time, V8.AsmWasmTranslationMicroSeconds, 1000000, \ | 1046 HT(asm_wasm_translation_time, V8.AsmWasmTranslationMicroSeconds, 1000000, \ |
1025 MICROSECOND) \ | 1047 MICROSECOND) \ |
1026 HT(wasm_lazy_compilation_time, V8.WasmLazyCompilationMicroSeconds, 1000000, \ | 1048 HT(wasm_lazy_compilation_time, V8.WasmLazyCompilationMicroSeconds, 1000000, \ |
1027 MICROSECOND) | 1049 MICROSECOND) |
1028 | 1050 |
| 1051 #define TIMED_HISTOGRAM_LIST(HT) \ |
| 1052 HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \ |
| 1053 1000000, MICROSECOND) \ |
| 1054 HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \ |
| 1055 1000000, MICROSECOND) \ |
| 1056 HT(wasm_decode_asm_function_time, V8.WasmDecodeFunctionMicroSeconds.asm, \ |
| 1057 1000000, MICROSECOND) \ |
| 1058 HT(wasm_decode_wasm_function_time, V8.WasmDecodeFunctionMicroSeconds.wasm, \ |
| 1059 1000000, MICROSECOND) \ |
| 1060 HT(wasm_compile_asm_module_time, V8.WasmCompileModuleMicroSeconds.asm, \ |
| 1061 10000000, MICROSECOND) \ |
| 1062 HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \ |
| 1063 10000000, MICROSECOND) |
| 1064 |
1029 #define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \ | 1065 #define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \ |
1030 AHT(compile_lazy, V8.CompileLazyMicroSeconds) | 1066 AHT(compile_lazy, V8.CompileLazyMicroSeconds) |
1031 | 1067 |
1032 #define HISTOGRAM_PERCENTAGE_LIST(HP) \ | 1068 #define HISTOGRAM_PERCENTAGE_LIST(HP) \ |
1033 /* Heap fragmentation. */ \ | 1069 /* Heap fragmentation. */ \ |
1034 HP(external_fragmentation_total, V8.MemoryExternalFragmentationTotal) \ | 1070 HP(external_fragmentation_total, V8.MemoryExternalFragmentationTotal) \ |
1035 HP(external_fragmentation_old_space, V8.MemoryExternalFragmentationOldSpace) \ | 1071 HP(external_fragmentation_old_space, V8.MemoryExternalFragmentationOldSpace) \ |
1036 HP(external_fragmentation_code_space, \ | 1072 HP(external_fragmentation_code_space, \ |
1037 V8.MemoryExternalFragmentationCodeSpace) \ | 1073 V8.MemoryExternalFragmentationCodeSpace) \ |
1038 HP(external_fragmentation_map_space, V8.MemoryExternalFragmentationMapSpace) \ | 1074 HP(external_fragmentation_map_space, V8.MemoryExternalFragmentationMapSpace) \ |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 #define HR(name, caption, min, max, num_buckets) \ | 1266 #define HR(name, caption, min, max, num_buckets) \ |
1231 Histogram* name() { return &name##_; } | 1267 Histogram* name() { return &name##_; } |
1232 HISTOGRAM_RANGE_LIST(HR) | 1268 HISTOGRAM_RANGE_LIST(HR) |
1233 #undef HR | 1269 #undef HR |
1234 | 1270 |
1235 #define HT(name, caption, max, res) \ | 1271 #define HT(name, caption, max, res) \ |
1236 HistogramTimer* name() { return &name##_; } | 1272 HistogramTimer* name() { return &name##_; } |
1237 HISTOGRAM_TIMER_LIST(HT) | 1273 HISTOGRAM_TIMER_LIST(HT) |
1238 #undef HT | 1274 #undef HT |
1239 | 1275 |
| 1276 #define HT(name, caption, max, res) \ |
| 1277 TimedHistogram* name() { return &name##_; } |
| 1278 TIMED_HISTOGRAM_LIST(HT) |
| 1279 #undef HT |
| 1280 |
1240 #define AHT(name, caption) \ | 1281 #define AHT(name, caption) \ |
1241 AggregatableHistogramTimer* name() { return &name##_; } | 1282 AggregatableHistogramTimer* name() { return &name##_; } |
1242 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) | 1283 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |
1243 #undef AHT | 1284 #undef AHT |
1244 | 1285 |
1245 #define HP(name, caption) \ | 1286 #define HP(name, caption) \ |
1246 Histogram* name() { return &name##_; } | 1287 Histogram* name() { return &name##_; } |
1247 HISTOGRAM_PERCENTAGE_LIST(HP) | 1288 HISTOGRAM_PERCENTAGE_LIST(HP) |
1248 #undef HP | 1289 #undef HP |
1249 | 1290 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 { return &count_of_CODE_AGE_##name##_; } \ | 1339 { return &count_of_CODE_AGE_##name##_; } \ |
1299 StatsCounter* size_of_CODE_AGE_##name() \ | 1340 StatsCounter* size_of_CODE_AGE_##name() \ |
1300 { return &size_of_CODE_AGE_##name##_; } | 1341 { return &size_of_CODE_AGE_##name##_; } |
1301 CODE_AGE_LIST_COMPLETE(SC) | 1342 CODE_AGE_LIST_COMPLETE(SC) |
1302 #undef SC | 1343 #undef SC |
1303 | 1344 |
1304 // clang-format off | 1345 // clang-format off |
1305 enum Id { | 1346 enum Id { |
1306 #define RATE_ID(name, caption, max, res) k_##name, | 1347 #define RATE_ID(name, caption, max, res) k_##name, |
1307 HISTOGRAM_TIMER_LIST(RATE_ID) | 1348 HISTOGRAM_TIMER_LIST(RATE_ID) |
| 1349 TIMED_HISTOGRAM_LIST(RATE_ID) |
1308 #undef RATE_ID | 1350 #undef RATE_ID |
1309 #define AGGREGATABLE_ID(name, caption) k_##name, | 1351 #define AGGREGATABLE_ID(name, caption) k_##name, |
1310 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID) | 1352 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID) |
1311 #undef AGGREGATABLE_ID | 1353 #undef AGGREGATABLE_ID |
1312 #define PERCENTAGE_ID(name, caption) k_##name, | 1354 #define PERCENTAGE_ID(name, caption) k_##name, |
1313 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID) | 1355 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID) |
1314 #undef PERCENTAGE_ID | 1356 #undef PERCENTAGE_ID |
1315 #define MEMORY_ID(name, caption) k_##name, | 1357 #define MEMORY_ID(name, caption) k_##name, |
1316 HISTOGRAM_LEGACY_MEMORY_LIST(MEMORY_ID) | 1358 HISTOGRAM_LEGACY_MEMORY_LIST(MEMORY_ID) |
1317 HISTOGRAM_MEMORY_LIST(MEMORY_ID) | 1359 HISTOGRAM_MEMORY_LIST(MEMORY_ID) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 Isolate* isolate() { return isolate_; } | 1408 Isolate* isolate() { return isolate_; } |
1367 | 1409 |
1368 #define HR(name, caption, min, max, num_buckets) Histogram name##_; | 1410 #define HR(name, caption, min, max, num_buckets) Histogram name##_; |
1369 HISTOGRAM_RANGE_LIST(HR) | 1411 HISTOGRAM_RANGE_LIST(HR) |
1370 #undef HR | 1412 #undef HR |
1371 | 1413 |
1372 #define HT(name, caption, max, res) HistogramTimer name##_; | 1414 #define HT(name, caption, max, res) HistogramTimer name##_; |
1373 HISTOGRAM_TIMER_LIST(HT) | 1415 HISTOGRAM_TIMER_LIST(HT) |
1374 #undef HT | 1416 #undef HT |
1375 | 1417 |
| 1418 #define HT(name, caption, max, res) TimedHistogram name##_; |
| 1419 TIMED_HISTOGRAM_LIST(HT) |
| 1420 #undef HT |
| 1421 |
1376 #define AHT(name, caption) \ | 1422 #define AHT(name, caption) \ |
1377 AggregatableHistogramTimer name##_; | 1423 AggregatableHistogramTimer name##_; |
1378 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) | 1424 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |
1379 #undef AHT | 1425 #undef AHT |
1380 | 1426 |
1381 #define HP(name, caption) \ | 1427 #define HP(name, caption) \ |
1382 Histogram name##_; | 1428 Histogram name##_; |
1383 HISTOGRAM_PERCENTAGE_LIST(HP) | 1429 HISTOGRAM_PERCENTAGE_LIST(HP) |
1384 #undef HP | 1430 #undef HP |
1385 | 1431 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 | 1476 |
1431 RuntimeCallStats runtime_call_stats_; | 1477 RuntimeCallStats runtime_call_stats_; |
1432 | 1478 |
1433 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 1479 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); |
1434 }; | 1480 }; |
1435 | 1481 |
1436 } // namespace internal | 1482 } // namespace internal |
1437 } // namespace v8 | 1483 } // namespace v8 |
1438 | 1484 |
1439 #endif // V8_COUNTERS_H_ | 1485 #endif // V8_COUNTERS_H_ |
OLD | NEW |