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

Unified Diff: src/counters.h

Issue 2929853003: Fix use of history timers in background threads. (Closed)
Patch Set: Make explicit when async_counters is needed. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/counters.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/counters.h
diff --git a/src/counters.h b/src/counters.h
index 2a13bf6a6db9555700872e4c0fa2fbc283fa3a84..bb7dda4714c899dffb07ec277df1b0c01cdde2b8 100644
--- a/src/counters.h
+++ b/src/counters.h
@@ -248,25 +248,62 @@ class Histogram {
Counters* counters_;
};
-// A HistogramTimer allows distributions of results to be created.
-class HistogramTimer : public Histogram {
+enum class HistogramTimerResolution { MILLISECOND, MICROSECOND };
+
+// A thread safe histogram timer. It also allows distributions of
+// nested timed results.
+class TimedHistogram : public Histogram {
public:
- enum Resolution {
- MILLISECOND,
- MICROSECOND
- };
+ // Start the timer. Log if isolate non-null.
+ void Start(base::ElapsedTimer* timer, Isolate* isolate);
- // Note: public for testing purposes only.
- HistogramTimer(const char* name, int min, int max, Resolution resolution,
- int num_buckets, Counters* counters)
+ // Stop the timer and record the results. Log if isolate non-null.
+ void Stop(base::ElapsedTimer* timer, Isolate* isolate);
+
+ protected:
+ friend class Counters;
+ HistogramTimerResolution resolution_;
+
+ TimedHistogram() {}
+ TimedHistogram(const char* name, int min, int max,
+ HistogramTimerResolution resolution, int num_buckets,
+ Counters* counters)
: Histogram(name, min, max, num_buckets, counters),
resolution_(resolution) {}
+ void AddTimeSample();
+};
+
+// Helper class for scoping a TimedHistogram.
+class TimedHistogramScope {
+ public:
+ explicit TimedHistogramScope(TimedHistogram* histogram,
+ Isolate* isolate = nullptr)
+ : histogram_(histogram), isolate_(isolate) {
+ histogram_->Start(&timer_, isolate);
+ }
+ ~TimedHistogramScope() { histogram_->Stop(&timer_, isolate_); }
+
+ private:
+ base::ElapsedTimer timer_;
+ TimedHistogram* histogram_;
+ Isolate* isolate_;
- // Start the timer.
- void Start();
+ DISALLOW_IMPLICIT_CONSTRUCTORS(TimedHistogramScope);
+};
+
+// A HistogramTimer allows distributions of non-nested timed results
+// to be created. WARNING: This class is not thread safe and can only
+// be run on the foreground thread.
+class HistogramTimer : public TimedHistogram {
+ public:
+ // Note: public for testing purposes only.
+ HistogramTimer(const char* name, int min, int max,
+ HistogramTimerResolution resolution, int num_buckets,
+ Counters* counters)
+ : TimedHistogram(name, min, max, resolution, num_buckets, counters) {}
- // Stop the timer and record the results.
- void Stop();
+ inline void Start();
+ inline void Stop();
// Returns true if the timer is running.
bool Running() {
@@ -282,7 +319,6 @@ class HistogramTimer : public Histogram {
friend class Counters;
base::ElapsedTimer timer_;
- Resolution resolution_;
HistogramTimer() {}
};
@@ -327,7 +363,6 @@ class HistogramTimerScope BASE_EMBEDDED {
#endif
};
-
// A histogram timer that can aggregate events within a larger scope.
//
// Intended use of this timer is to have an outer (aggregating) and an inner
@@ -1009,18 +1044,6 @@ class RuntimeCallTimerScope {
V8.WasmInstantiateModuleMicroSeconds.asm, 10000000, MICROSECOND) \
HT(wasm_instantiate_wasm_module_time, \
V8.WasmInstantiateModuleMicroSeconds.wasm, 10000000, MICROSECOND) \
- HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \
- 1000000, MICROSECOND) \
- HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \
- 1000000, MICROSECOND) \
- HT(wasm_decode_asm_function_time, V8.WasmDecodeFunctionMicroSeconds.asm, \
- 1000000, MICROSECOND) \
- HT(wasm_decode_wasm_function_time, V8.WasmDecodeFunctionMicroSeconds.wasm, \
- 1000000, MICROSECOND) \
- HT(wasm_compile_asm_module_time, V8.WasmCompileModuleMicroSeconds.asm, \
- 10000000, MICROSECOND) \
- HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \
- 10000000, MICROSECOND) \
HT(wasm_compile_function_time, V8.WasmCompileFunctionMicroSeconds, 1000000, \
MICROSECOND) \
HT(asm_wasm_translation_time, V8.AsmWasmTranslationMicroSeconds, 1000000, \
@@ -1028,6 +1051,20 @@ class RuntimeCallTimerScope {
HT(wasm_lazy_compilation_time, V8.WasmLazyCompilationMicroSeconds, 1000000, \
MICROSECOND)
+#define TIMED_HISTOGRAM_LIST(HT) \
+ HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \
+ 1000000, MICROSECOND) \
+ HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \
+ 1000000, MICROSECOND) \
+ HT(wasm_decode_asm_function_time, V8.WasmDecodeFunctionMicroSeconds.asm, \
+ 1000000, MICROSECOND) \
+ HT(wasm_decode_wasm_function_time, V8.WasmDecodeFunctionMicroSeconds.wasm, \
+ 1000000, MICROSECOND) \
+ HT(wasm_compile_asm_module_time, V8.WasmCompileModuleMicroSeconds.asm, \
+ 10000000, MICROSECOND) \
+ HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \
+ 10000000, MICROSECOND)
+
#define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \
AHT(compile_lazy, V8.CompileLazyMicroSeconds)
@@ -1238,6 +1275,11 @@ class Counters : public std::enable_shared_from_this<Counters> {
HISTOGRAM_TIMER_LIST(HT)
#undef HT
+#define HT(name, caption, max, res) \
+ TimedHistogram* name() { return &name##_; }
+ TIMED_HISTOGRAM_LIST(HT)
+#undef HT
+
#define AHT(name, caption) \
AggregatableHistogramTimer* name() { return &name##_; }
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
@@ -1306,6 +1348,7 @@ class Counters : public std::enable_shared_from_this<Counters> {
enum Id {
#define RATE_ID(name, caption, max, res) k_##name,
HISTOGRAM_TIMER_LIST(RATE_ID)
+ TIMED_HISTOGRAM_LIST(RATE_ID)
#undef RATE_ID
#define AGGREGATABLE_ID(name, caption) k_##name,
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID)
@@ -1374,6 +1417,10 @@ class Counters : public std::enable_shared_from_this<Counters> {
HISTOGRAM_TIMER_LIST(HT)
#undef HT
+#define HT(name, caption, max, res) TimedHistogram name##_;
+ TIMED_HISTOGRAM_LIST(HT)
+#undef HT
+
#define AHT(name, caption) \
AggregatableHistogramTimer name##_;
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT)
@@ -1434,6 +1481,14 @@ class Counters : public std::enable_shared_from_this<Counters> {
DISALLOW_IMPLICIT_CONSTRUCTORS(Counters);
};
+void HistogramTimer::Start() {
+ TimedHistogram::Start(&timer_, counters()->isolate());
+}
+
+void HistogramTimer::Stop() {
+ TimedHistogram::Stop(&timer_, counters()->isolate());
+}
+
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | src/counters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698