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. |