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

Unified Diff: base/metrics/statistics_recorder.cc

Issue 1876053002: Run SR tests both with and without persistent allocator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix use-after-free in test Created 4 years, 8 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 | « base/metrics/statistics_recorder.h ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/statistics_recorder.cc
diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc
index 9aafe187be23adef5d1fabaf853d109c13fc0033..f0bb9143a9de4515433a40efb8d48e4cb5dab9c2 100644
--- a/base/metrics/statistics_recorder.cc
+++ b/base/metrics/statistics_recorder.cc
@@ -37,6 +37,14 @@ StatisticsRecorder::HistogramIterator::HistogramIterator(
const HistogramMap::iterator& iter, bool include_persistent)
: iter_(iter),
include_persistent_(include_persistent) {
+ // The starting location could point to a persistent histogram when such
+ // is not wanted. If so, skip it.
+ if (!include_persistent_ && iter_ != histograms_->end() &&
+ (iter_->second->flags() & HistogramBase::kIsPersistent)) {
+ // This operator will continue to skip until a non-persistent histogram
+ // is found.
+ operator++();
+ }
}
StatisticsRecorder::HistogramIterator::HistogramIterator(
@@ -287,20 +295,13 @@ void StatisticsRecorder::GetBucketRanges(
// static
HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) {
- if (lock_ == NULL)
- return NULL;
-
- // Import histograms from known persistent storage. Histograms could have
- // been added by other processes and they must be fetched and recognized
- // locally. If the persistent memory segment is not shared between processes,
- // this call does nothing.
// This must be called *before* the lock is acquired below because it will
// call back into this object to register histograms. Those called methods
// will acquire the lock at that time.
- GlobalHistogramAllocator* allocator = GlobalHistogramAllocator::Get();
- if (allocator)
- allocator->ImportHistogramsToStatisticsRecorder();
+ ImportGlobalPersistentHistograms();
+ if (lock_ == NULL)
+ return NULL;
base::AutoLock auto_lock(*lock_);
if (histograms_ == NULL)
return NULL;
@@ -314,6 +315,7 @@ HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) {
// static
StatisticsRecorder::HistogramIterator StatisticsRecorder::begin(
bool include_persistent) {
+ ImportGlobalPersistentHistograms();
return HistogramIterator(histograms_->begin(), include_persistent);
}
@@ -423,6 +425,20 @@ void StatisticsRecorder::UninitializeForTesting() {
g_statistics_recorder_.private_instance_ = 0;
}
+// static
+void StatisticsRecorder::ImportGlobalPersistentHistograms() {
+ if (lock_ == NULL)
+ return;
+
+ // Import histograms from known persistent storage. Histograms could have
+ // been added by other processes and they must be fetched and recognized
+ // locally. If the persistent memory segment is not shared between processes,
+ // this call does nothing.
+ GlobalHistogramAllocator* allocator = GlobalHistogramAllocator::Get();
+ if (allocator)
+ allocator->ImportHistogramsToStatisticsRecorder();
+}
+
// This singleton instance should be started during the single threaded portion
// of main(), and hence it is not thread safe. It initializes globals to
// provide support for all future calls.
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698