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

Unified Diff: webrtc/system_wrappers/source/metrics_default.cc

Issue 2654473002: Remove static locals from histograms. (Closed)
Patch Set: use another HistogramBase constructor for enumerations Created 3 years, 11 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 | « webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/system_wrappers/source/metrics_default.cc
diff --git a/webrtc/system_wrappers/source/metrics_default.cc b/webrtc/system_wrappers/source/metrics_default.cc
index 6ca90dafdc84933c8805f0f550809c1ceb36fe66..e1e4e807b3487ffe9902b63329ab498ea7c121e9 100644
--- a/webrtc/system_wrappers/source/metrics_default.cc
+++ b/webrtc/system_wrappers/source/metrics_default.cc
@@ -253,6 +253,18 @@ const std::string& GetHistogramName(Histogram* histogram_pointer) {
// Fast path. Adds |sample| to cached |histogram_pointer|.
void HistogramAdd(Histogram* histogram_pointer, int sample) {
+ if (g_rtc_histogram_map == nullptr) {
+ // Histograms are disabled, so the pointer is invalid. Check on this instead
+ // of histogram_pointer being NULL so that we don't accidentally miss
+ // instances where HistogramAdd(histogram_, sample) is called with
+ // histogram_ uninitialized.
+ //
+ // This doesn't happen in Chromium since base::Histogram::FactoryGet and
+ // base::LinearHistogram::FactoryGet always return valid base::HistogramBase
+ // pointers. We could consider returning a null object, but having
+ // RtcHistogram virtual makes function calls to it slower.
+ return;
+ }
RtcHistogram* ptr = reinterpret_cast<RtcHistogram*>(histogram_pointer);
ptr->Add(sample);
}
@@ -267,6 +279,8 @@ SampleInfo::~SampleInfo() {}
// Implementation of global functions in metrics_default.h.
void Enable() {
+ // TODO(pbos): Make sure that no callers have called HistogramFactoryGet*,
+ // HistogramAdd or GetMap() at this point.
RTC_DCHECK(g_rtc_histogram_map == nullptr);
#if RTC_DCHECK_IS_ON
RTC_DCHECK_EQ(0, rtc::AtomicOps::AcquireLoad(&g_rtc_histogram_called));
« no previous file with comments | « webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698