Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: src/counters.h

Issue 2929853003: Fix use of history timers in background threads. (Closed)
Patch Set: Merge with master Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
Mircea Trofin 2017/06/22 18:42:24 why is non-nested in brackets?
kschimpf 2017/06/22 20:38:31 Removing parenthesis and fixing to say nested. Thi
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 void AddTimeSample();
274 };
264 275
265 // Start the timer. 276 // Helper class for scoping a TimedHistogram.
266 void Start(); 277 class TimedHistogramScope {
278 public:
279 explicit TimedHistogramScope(TimedHistogram* histogram,
280 Isolate* isolate = nullptr)
281 : histogram_(histogram), isolate_(isolate) {
282 histogram_->Start(&timer_, isolate);
283 }
284 ~TimedHistogramScope() { histogram_->Stop(&timer_, isolate_); }
267 285
268 // Stop the timer and record the results. 286 private:
269 void Stop(); 287 base::ElapsedTimer timer_;
288 TimedHistogram* histogram_;
289 Isolate* isolate_;
290
291 DISALLOW_IMPLICIT_CONSTRUCTORS(TimedHistogramScope);
292 };
293
294 // A HistogramTimer allows distributions of (non-nested) timed results
Mircea Trofin 2017/06/22 18:42:23 non-nested in brackets
kschimpf 2017/06/22 20:38:31 Done.
295 // to be created. WARNING: This class is not thread safe and can only
296 // be run on the foreground thread.
297 class HistogramTimer : public TimedHistogram {
Mircea Trofin 2017/06/22 18:42:23 Is the difference between the two their thread saf
kschimpf 2017/06/22 20:38:31 The base class is the more general solution, as it
298 public:
299 // Note: public for testing purposes only.
300 HistogramTimer(const char* name, int min, int max,
301 HistogramTimerResolution resolution, int num_buckets,
302 Counters* counters)
303 : TimedHistogram(name, min, max, resolution, num_buckets, counters) {}
304
305 inline void Start();
306 inline void Stop();
270 307
271 // Returns true if the timer is running. 308 // Returns true if the timer is running.
272 bool Running() { 309 bool Running() {
273 return Enabled() && timer_.IsStarted(); 310 return Enabled() && timer_.IsStarted();
274 } 311 }
275 312
276 // TODO(bmeurer): Remove this when HistogramTimerScope is fixed. 313 // TODO(bmeurer): Remove this when HistogramTimerScope is fixed.
277 #ifdef DEBUG 314 #ifdef DEBUG
278 base::ElapsedTimer* timer() { return &timer_; } 315 base::ElapsedTimer* timer() { return &timer_; }
279 #endif 316 #endif
280 317
281 private: 318 private:
282 friend class Counters; 319 friend class Counters;
283 320
284 base::ElapsedTimer timer_; 321 base::ElapsedTimer timer_;
285 Resolution resolution_;
286 322
287 HistogramTimer() {} 323 HistogramTimer() {}
288 }; 324 };
289 325
290 // Helper class for scoping a HistogramTimer. 326 // Helper class for scoping a HistogramTimer.
291 // TODO(bmeurer): The ifdeffery is an ugly hack around the fact that the 327 // 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 328 // Parser is currently reentrant (when it throws an error, we call back
293 // into JavaScript and all bets are off), but ElapsedTimer is not 329 // into JavaScript and all bets are off), but ElapsedTimer is not
294 // reentry-safe. Fix this properly and remove |allow_nesting|. 330 // reentry-safe. Fix this properly and remove |allow_nesting|.
295 class HistogramTimerScope BASE_EMBEDDED { 331 class HistogramTimerScope BASE_EMBEDDED {
(...skipping 24 matching lines...) Expand all
320 #endif 356 #endif
321 } 357 }
322 358
323 private: 359 private:
324 HistogramTimer* timer_; 360 HistogramTimer* timer_;
325 #ifdef DEBUG 361 #ifdef DEBUG
326 bool skipped_timer_start_; 362 bool skipped_timer_start_;
327 #endif 363 #endif
328 }; 364 };
329 365
330
331 // A histogram timer that can aggregate events within a larger scope. 366 // A histogram timer that can aggregate events within a larger scope.
332 // 367 //
333 // Intended use of this timer is to have an outer (aggregating) and an inner 368 // 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, 369 // (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. 370 // 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 371 // An example use might be to aggregate the time spent in lazy compilation
337 // while running a script. 372 // while running a script.
338 // 373 //
339 // Helpers: 374 // Helpers:
340 // - AggregatingHistogramTimerScope, the "outer" scope within which 375 // - AggregatingHistogramTimerScope, the "outer" scope within which
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 MICROSECOND) \ 1035 MICROSECOND) \
1001 /* Total compilation time incl. caching/parsing */ \ 1036 /* Total compilation time incl. caching/parsing */ \
1002 HT(compile_script, V8.CompileScriptMicroSeconds, 1000000, MICROSECOND) \ 1037 HT(compile_script, V8.CompileScriptMicroSeconds, 1000000, MICROSECOND) \
1003 /* Total JavaScript execution time (including callbacks and runtime calls */ \ 1038 /* Total JavaScript execution time (including callbacks and runtime calls */ \
1004 HT(execute, V8.Execute, 1000000, MICROSECOND) \ 1039 HT(execute, V8.Execute, 1000000, MICROSECOND) \
1005 /* Asm/Wasm */ \ 1040 /* Asm/Wasm */ \
1006 HT(wasm_instantiate_asm_module_time, \ 1041 HT(wasm_instantiate_asm_module_time, \
1007 V8.WasmInstantiateModuleMicroSeconds.asm, 10000000, MICROSECOND) \ 1042 V8.WasmInstantiateModuleMicroSeconds.asm, 10000000, MICROSECOND) \
1008 HT(wasm_instantiate_wasm_module_time, \ 1043 HT(wasm_instantiate_wasm_module_time, \
1009 V8.WasmInstantiateModuleMicroSeconds.wasm, 10000000, MICROSECOND) \ 1044 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, \ 1045 HT(wasm_compile_function_time, V8.WasmCompileFunctionMicroSeconds, 1000000, \
1023 MICROSECOND) \ 1046 MICROSECOND) \
1024 HT(asm_wasm_translation_time, V8.AsmWasmTranslationMicroSeconds, 1000000, \ 1047 HT(asm_wasm_translation_time, V8.AsmWasmTranslationMicroSeconds, 1000000, \
1025 MICROSECOND) \ 1048 MICROSECOND) \
1026 HT(wasm_lazy_compilation_time, V8.WasmLazyCompilationMicroSeconds, 1000000, \ 1049 HT(wasm_lazy_compilation_time, V8.WasmLazyCompilationMicroSeconds, 1000000, \
1027 MICROSECOND) 1050 MICROSECOND)
1028 1051
1052 #define TIMED_HISTOGRAM_LIST(HT) \
1053 HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \
1054 1000000, MICROSECOND) \
1055 HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \
1056 1000000, MICROSECOND) \
1057 HT(wasm_decode_asm_function_time, V8.WasmDecodeFunctionMicroSeconds.asm, \
1058 1000000, MICROSECOND) \
1059 HT(wasm_decode_wasm_function_time, V8.WasmDecodeFunctionMicroSeconds.wasm, \
1060 1000000, MICROSECOND) \
1061 HT(wasm_compile_asm_module_time, V8.WasmCompileModuleMicroSeconds.asm, \
1062 10000000, MICROSECOND) \
1063 HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \
1064 10000000, MICROSECOND)
1065
1029 #define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \ 1066 #define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \
1030 AHT(compile_lazy, V8.CompileLazyMicroSeconds) 1067 AHT(compile_lazy, V8.CompileLazyMicroSeconds)
1031 1068
1032 #define HISTOGRAM_PERCENTAGE_LIST(HP) \ 1069 #define HISTOGRAM_PERCENTAGE_LIST(HP) \
1033 /* Heap fragmentation. */ \ 1070 /* Heap fragmentation. */ \
1034 HP(external_fragmentation_total, V8.MemoryExternalFragmentationTotal) \ 1071 HP(external_fragmentation_total, V8.MemoryExternalFragmentationTotal) \
1035 HP(external_fragmentation_old_space, V8.MemoryExternalFragmentationOldSpace) \ 1072 HP(external_fragmentation_old_space, V8.MemoryExternalFragmentationOldSpace) \
1036 HP(external_fragmentation_code_space, \ 1073 HP(external_fragmentation_code_space, \
1037 V8.MemoryExternalFragmentationCodeSpace) \ 1074 V8.MemoryExternalFragmentationCodeSpace) \
1038 HP(external_fragmentation_map_space, V8.MemoryExternalFragmentationMapSpace) \ 1075 HP(external_fragmentation_map_space, V8.MemoryExternalFragmentationMapSpace) \
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 #define HR(name, caption, min, max, num_buckets) \ 1266 #define HR(name, caption, min, max, num_buckets) \
1230 Histogram* name() { return &name##_; } 1267 Histogram* name() { return &name##_; }
1231 HISTOGRAM_RANGE_LIST(HR) 1268 HISTOGRAM_RANGE_LIST(HR)
1232 #undef HR 1269 #undef HR
1233 1270
1234 #define HT(name, caption, max, res) \ 1271 #define HT(name, caption, max, res) \
1235 HistogramTimer* name() { return &name##_; } 1272 HistogramTimer* name() { return &name##_; }
1236 HISTOGRAM_TIMER_LIST(HT) 1273 HISTOGRAM_TIMER_LIST(HT)
1237 #undef HT 1274 #undef HT
1238 1275
1276 #define HT(name, caption, max, res) \
1277 TimedHistogram* name() { return &name##_; }
1278 TIMED_HISTOGRAM_LIST(HT)
1279 #undef HT
1280
1239 #define AHT(name, caption) \ 1281 #define AHT(name, caption) \
1240 AggregatableHistogramTimer* name() { return &name##_; } 1282 AggregatableHistogramTimer* name() { return &name##_; }
1241 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) 1283 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
1242 #undef AHT 1284 #undef AHT
1243 1285
1244 #define HP(name, caption) \ 1286 #define HP(name, caption) \
1245 Histogram* name() { return &name##_; } 1287 Histogram* name() { return &name##_; }
1246 HISTOGRAM_PERCENTAGE_LIST(HP) 1288 HISTOGRAM_PERCENTAGE_LIST(HP)
1247 #undef HP 1289 #undef HP
1248 1290
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 { return &count_of_CODE_AGE_##name##_; } \ 1339 { return &count_of_CODE_AGE_##name##_; } \
1298 StatsCounter* size_of_CODE_AGE_##name() \ 1340 StatsCounter* size_of_CODE_AGE_##name() \
1299 { return &size_of_CODE_AGE_##name##_; } 1341 { return &size_of_CODE_AGE_##name##_; }
1300 CODE_AGE_LIST_COMPLETE(SC) 1342 CODE_AGE_LIST_COMPLETE(SC)
1301 #undef SC 1343 #undef SC
1302 1344
1303 // clang-format off 1345 // clang-format off
1304 enum Id { 1346 enum Id {
1305 #define RATE_ID(name, caption, max, res) k_##name, 1347 #define RATE_ID(name, caption, max, res) k_##name,
1306 HISTOGRAM_TIMER_LIST(RATE_ID) 1348 HISTOGRAM_TIMER_LIST(RATE_ID)
1349 TIMED_HISTOGRAM_LIST(RATE_ID)
1307 #undef RATE_ID 1350 #undef RATE_ID
1308 #define AGGREGATABLE_ID(name, caption) k_##name, 1351 #define AGGREGATABLE_ID(name, caption) k_##name,
1309 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID) 1352 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID)
1310 #undef AGGREGATABLE_ID 1353 #undef AGGREGATABLE_ID
1311 #define PERCENTAGE_ID(name, caption) k_##name, 1354 #define PERCENTAGE_ID(name, caption) k_##name,
1312 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID) 1355 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID)
1313 #undef PERCENTAGE_ID 1356 #undef PERCENTAGE_ID
1314 #define MEMORY_ID(name, caption) k_##name, 1357 #define MEMORY_ID(name, caption) k_##name,
1315 HISTOGRAM_LEGACY_MEMORY_LIST(MEMORY_ID) 1358 HISTOGRAM_LEGACY_MEMORY_LIST(MEMORY_ID)
1316 HISTOGRAM_MEMORY_LIST(MEMORY_ID) 1359 HISTOGRAM_MEMORY_LIST(MEMORY_ID)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 Isolate* isolate() { return isolate_; } 1408 Isolate* isolate() { return isolate_; }
1366 1409
1367 #define HR(name, caption, min, max, num_buckets) Histogram name##_; 1410 #define HR(name, caption, min, max, num_buckets) Histogram name##_;
1368 HISTOGRAM_RANGE_LIST(HR) 1411 HISTOGRAM_RANGE_LIST(HR)
1369 #undef HR 1412 #undef HR
1370 1413
1371 #define HT(name, caption, max, res) HistogramTimer name##_; 1414 #define HT(name, caption, max, res) HistogramTimer name##_;
1372 HISTOGRAM_TIMER_LIST(HT) 1415 HISTOGRAM_TIMER_LIST(HT)
1373 #undef HT 1416 #undef HT
1374 1417
1418 #define HT(name, caption, max, res) TimedHistogram name##_;
1419 TIMED_HISTOGRAM_LIST(HT)
1420 #undef HT
1421
1375 #define AHT(name, caption) \ 1422 #define AHT(name, caption) \
1376 AggregatableHistogramTimer name##_; 1423 AggregatableHistogramTimer name##_;
1377 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) 1424 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
1378 #undef AHT 1425 #undef AHT
1379 1426
1380 #define HP(name, caption) \ 1427 #define HP(name, caption) \
1381 Histogram name##_; 1428 Histogram name##_;
1382 HISTOGRAM_PERCENTAGE_LIST(HP) 1429 HISTOGRAM_PERCENTAGE_LIST(HP)
1383 #undef HP 1430 #undef HP
1384 1431
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 StatsCounter size_of_CODE_AGE_##name##_; \ 1472 StatsCounter size_of_CODE_AGE_##name##_; \
1426 StatsCounter count_of_CODE_AGE_##name##_; 1473 StatsCounter count_of_CODE_AGE_##name##_;
1427 CODE_AGE_LIST_COMPLETE(SC) 1474 CODE_AGE_LIST_COMPLETE(SC)
1428 #undef SC 1475 #undef SC
1429 1476
1430 RuntimeCallStats runtime_call_stats_; 1477 RuntimeCallStats runtime_call_stats_;
1431 1478
1432 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); 1479 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
1433 }; 1480 };
1434 1481
1482 void HistogramTimer::Start() {
1483 TimedHistogram::Start(&timer_, counters()->isolate());
1484 }
1485
1486 void HistogramTimer::Stop() {
1487 TimedHistogram::Stop(&timer_, counters()->isolate());
1488 }
1489
1435 } // namespace internal 1490 } // namespace internal
1436 } // namespace v8 1491 } // namespace v8
1437 1492
1438 #endif // V8_COUNTERS_H_ 1493 #endif // V8_COUNTERS_H_
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/counters.cc » ('j') | src/counters.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698