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

Unified Diff: components/metrics/metrics_service.cc

Issue 1425533011: Support "shared" histograms between processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: extract common histogram FactoryGet code; extract histogram persistence into seperate files Created 5 years 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
Index: components/metrics/metrics_service.cc
diff --git a/components/metrics/metrics_service.cc b/components/metrics/metrics_service.cc
index 55aa9f10c8c0daaf3e0a764020602c5e3d7c5d1b..e868ea7c9bb1cc087644257b65c44e3edcf9e346 100644
--- a/components/metrics/metrics_service.cc
+++ b/components/metrics/metrics_service.cc
@@ -251,6 +251,40 @@ SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) {
SyntheticTrialGroup::~SyntheticTrialGroup() {
}
+MetricsService::PersistentHistogramIterator::PersistentHistogramIterator(
+ AllocatorSet& allocators,
+ AllocatorSet::iterator pos)
+ : allocators_(allocators),
+ allocator_iter_(pos) {
+ if (pos != allocators_.end()) {
+ (*allocator_iter_)->CreateIterator(&histogram_iter_);
+ // Have to call ++ to advance iterator to the first persistent histogram.
+ operator++();
+ }
+}
+
+MetricsService::PersistentHistogramIterator&
+MetricsService::PersistentHistogramIterator::operator++() {
+ if (allocator_iter_ != allocators_.end()) {
+ for (;;) {
+ base::HistogramBase* h = base::HistogramBase::GetNextPersistentHistogram(
+ *allocator_iter_, &histogram_iter_);
+ if (h) {
+ current_histogram_ = new HistogramPointer(h);
+ break;
+ }
+ allocator_iter_++;
+ if (allocator_iter_ == allocators_.end()) {
+ histogram_iter_.clear(); // Clear so it matches end() iterator.
+ current_histogram_ = nullptr;
+ break;
+ }
+ (*allocator_iter_)->CreateIterator(&histogram_iter_);
+ }
+ }
+ return *this;
+}
+
// static
MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ =
MetricsService::CLEANLY_SHUTDOWN;
@@ -547,6 +581,18 @@ void MetricsService::PushExternalLog(const std::string& log) {
log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG);
}
+void MetricsService::AddPersistentMemorySegment(
+ base::PersistentMemoryAllocator* allocator) {
+ DCHECK(allocators_.find(allocator) == allocators_.end());
+ allocators_.insert(allocator);
+}
+
+void MetricsService::RemovePersistentMemorySegment(
+ base::PersistentMemoryAllocator* allocator) {
+ DCHECK(allocators_.find(allocator) != allocators_.end());
+ allocators_.erase(allocator);
+}
+
//------------------------------------------------------------------------------
// private methods
//------------------------------------------------------------------------------
@@ -746,6 +792,11 @@ void MetricsService::CloseCurrentLog() {
OpenNewLog(); // Start trivial log to hold our histograms.
}
+ base::PersistentMemoryAllocator* allocator =
+ base::HistogramBase::GetDefaultPersistentMemoryAllocator();
+ if (allocator)
+ allocator->UpdateStaticHistograms();
+
// Put incremental data (histogram deltas, and realtime stats deltas) at the
// end of all log transmissions (initial log handles this separately).
// RecordIncrementalStabilityElements only exists on the derived
@@ -1105,12 +1156,17 @@ void MetricsService::RecordCurrentEnvironment(MetricsLog* log) {
void MetricsService::RecordCurrentHistograms() {
DCHECK(log_manager_.current_log());
histogram_snapshot_manager_.PrepareDeltas(
+ base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(),
+ base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag);
+ histogram_snapshot_manager_.PrepareDeltas(
+ persistent_begin(), persistent_end(),
base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag);
}
void MetricsService::RecordCurrentStabilityHistograms() {
DCHECK(log_manager_.current_log());
histogram_snapshot_manager_.PrepareDeltas(
+ base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(),
base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag);
}
@@ -1149,4 +1205,12 @@ void MetricsService::SkipAndDiscardUpload() {
log_upload_in_progress_ = false;
}
+MetricsService::PersistentHistogramIterator MetricsService::persistent_begin() {
+ return PersistentHistogramIterator(allocators_, allocators_.begin());
+}
+
+MetricsService::PersistentHistogramIterator MetricsService::persistent_end() {
+ return PersistentHistogramIterator(allocators_, allocators_.end());
+}
+
} // namespace metrics

Powered by Google App Engine
This is Rietveld 408576698