Replace the usage of RTC_HISTOGRAM_COMMON_BLOCK with
RTC_HISTOGRAM_COMMON_BLOCK_SLOW.
The macro RTC_HISTOGRAM_COMMON_BLOCK uses a static variable for caching,
which causes its usage to behave unlike that of a regular method,
introducing subtble bugs. For example, if this macro is used inside a
member function to log an instance-dependent metric, all instances of
the same class will share the same cached histogram handle and thus
incorrect reports. Before we move away from these macro-based
implementation for metrics, we should avoid using the non-slow macro
unless the caching in logging metrics become performance-critical.
Bug: webrtc:10188, chromium:921023
Change-Id: I8835978498f3e67c5d97580fc916792f38817ff5
Reviewed-on: https://webrtc-review.googlesource.com/c/118022
Commit-Queue: Minyue Li <minyue@webrtc.org>
Reviewed-by: Minyue Li <minyue@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26334}
diff --git a/system_wrappers/include/metrics.h b/system_wrappers/include/metrics.h
index 6b29018..bad0f65 100644
--- a/system_wrappers/include/metrics.h
+++ b/system_wrappers/include/metrics.h
@@ -134,7 +134,7 @@
// TODO(qingsi): Refactor the default implementation given by RtcHistogram,
// which is already sparse, and remove the boundary argument from the macro.
#define RTC_HISTOGRAM_ENUMERATION_SPARSE(name, sample, boundary) \
- RTC_HISTOGRAM_COMMON_BLOCK( \
+ RTC_HISTOGRAM_COMMON_BLOCK_SLOW( \
name, sample, \
webrtc::metrics::SparseHistogramFactoryGetEnumeration(name, boundary))
@@ -149,7 +149,7 @@
// Histogram for enumerators (evenly spaced buckets).
// |boundary| should be above the max enumerator sample.
#define RTC_HISTOGRAM_ENUMERATION(name, sample, boundary) \
- RTC_HISTOGRAM_COMMON_BLOCK( \
+ RTC_HISTOGRAM_COMMON_BLOCK_SLOW( \
name, sample, \
webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary))
@@ -176,7 +176,6 @@
} \
} while (0)
-// Deprecated.
// The histogram is constructed/found for each call.
// May be used for histograms with infrequent updates.`
#define RTC_HISTOGRAM_COMMON_BLOCK_SLOW(name, sample, factory_get_invocation) \