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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 //------------------------------------------------------------------------------ 5 //------------------------------------------------------------------------------
6 // Description of the life cycle of a instance of MetricsService. 6 // Description of the life cycle of a instance of MetricsService.
7 // 7 //
8 // OVERVIEW 8 // OVERVIEW
9 // 9 //
10 // A MetricsService instance is typically created at application startup. It is 10 // A MetricsService instance is typically created at application startup. It is
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 244
245 245
246 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) { 246 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) {
247 id.name = trial; 247 id.name = trial;
248 id.group = group; 248 id.group = group;
249 } 249 }
250 250
251 SyntheticTrialGroup::~SyntheticTrialGroup() { 251 SyntheticTrialGroup::~SyntheticTrialGroup() {
252 } 252 }
253 253
254 MetricsService::PersistentHistogramIterator::PersistentHistogramIterator(
255 AllocatorSet& allocators,
256 AllocatorSet::iterator pos)
257 : allocators_(allocators),
258 allocator_iter_(pos) {
259 if (pos != allocators_.end()) {
260 (*allocator_iter_)->CreateIterator(&histogram_iter_);
261 // Have to call ++ to advance iterator to the first persistent histogram.
262 operator++();
263 }
264 }
265
266 MetricsService::PersistentHistogramIterator&
267 MetricsService::PersistentHistogramIterator::operator++() {
268 if (allocator_iter_ != allocators_.end()) {
269 for (;;) {
270 base::HistogramBase* h = base::HistogramBase::GetNextPersistentHistogram(
271 *allocator_iter_, &histogram_iter_);
272 if (h) {
273 current_histogram_ = new HistogramPointer(h);
274 break;
275 }
276 allocator_iter_++;
277 if (allocator_iter_ == allocators_.end()) {
278 histogram_iter_.clear(); // Clear so it matches end() iterator.
279 current_histogram_ = nullptr;
280 break;
281 }
282 (*allocator_iter_)->CreateIterator(&histogram_iter_);
283 }
284 }
285 return *this;
286 }
287
254 // static 288 // static
255 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ = 289 MetricsService::ShutdownCleanliness MetricsService::clean_shutdown_status_ =
256 MetricsService::CLEANLY_SHUTDOWN; 290 MetricsService::CLEANLY_SHUTDOWN;
257 291
258 MetricsService::ExecutionPhase MetricsService::execution_phase_ = 292 MetricsService::ExecutionPhase MetricsService::execution_phase_ =
259 MetricsService::UNINITIALIZED_PHASE; 293 MetricsService::UNINITIALIZED_PHASE;
260 294
261 // static 295 // static
262 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { 296 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) {
263 DCHECK(IsSingleThreaded()); 297 DCHECK(IsSingleThreaded());
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 UNINITIALIZED_PHASE); 574 UNINITIALIZED_PHASE);
541 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); 575 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
542 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); 576 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0);
543 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); 577 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true);
544 } 578 }
545 579
546 void MetricsService::PushExternalLog(const std::string& log) { 580 void MetricsService::PushExternalLog(const std::string& log) {
547 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); 581 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG);
548 } 582 }
549 583
584 void MetricsService::AddPersistentMemorySegment(
585 base::PersistentMemoryAllocator* allocator) {
586 DCHECK(allocators_.find(allocator) == allocators_.end());
587 allocators_.insert(allocator);
588 }
589
590 void MetricsService::RemovePersistentMemorySegment(
591 base::PersistentMemoryAllocator* allocator) {
592 DCHECK(allocators_.find(allocator) != allocators_.end());
593 allocators_.erase(allocator);
594 }
595
550 //------------------------------------------------------------------------------ 596 //------------------------------------------------------------------------------
551 // private methods 597 // private methods
552 //------------------------------------------------------------------------------ 598 //------------------------------------------------------------------------------
553 599
554 600
555 //------------------------------------------------------------------------------ 601 //------------------------------------------------------------------------------
556 // Initialization methods 602 // Initialization methods
557 603
558 void MetricsService::InitializeMetricsState() { 604 void MetricsService::InitializeMetricsState() {
559 const int64 buildtime = MetricsLog::GetBuildTime(); 605 const int64 buildtime = MetricsLog::GetBuildTime();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 785
740 // TODO(jar): Integrate bounds on log recording more consistently, so that we 786 // TODO(jar): Integrate bounds on log recording more consistently, so that we
741 // can stop recording logs that are too big much sooner. 787 // can stop recording logs that are too big much sooner.
742 if (log_manager_.current_log()->num_events() > kEventLimit) { 788 if (log_manager_.current_log()->num_events() > kEventLimit) {
743 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events", 789 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events",
744 log_manager_.current_log()->num_events()); 790 log_manager_.current_log()->num_events());
745 log_manager_.DiscardCurrentLog(); 791 log_manager_.DiscardCurrentLog();
746 OpenNewLog(); // Start trivial log to hold our histograms. 792 OpenNewLog(); // Start trivial log to hold our histograms.
747 } 793 }
748 794
795 base::PersistentMemoryAllocator* allocator =
796 base::HistogramBase::GetDefaultPersistentMemoryAllocator();
797 if (allocator)
798 allocator->UpdateStaticHistograms();
799
749 // Put incremental data (histogram deltas, and realtime stats deltas) at the 800 // Put incremental data (histogram deltas, and realtime stats deltas) at the
750 // end of all log transmissions (initial log handles this separately). 801 // end of all log transmissions (initial log handles this separately).
751 // RecordIncrementalStabilityElements only exists on the derived 802 // RecordIncrementalStabilityElements only exists on the derived
752 // MetricsLog class. 803 // MetricsLog class.
753 MetricsLog* current_log = log_manager_.current_log(); 804 MetricsLog* current_log = log_manager_.current_log();
754 DCHECK(current_log); 805 DCHECK(current_log);
755 RecordCurrentEnvironment(current_log); 806 RecordCurrentEnvironment(current_log);
756 base::TimeDelta incremental_uptime; 807 base::TimeDelta incremental_uptime;
757 base::TimeDelta uptime; 808 base::TimeDelta uptime;
758 GetUptimes(local_state_, &incremental_uptime, &uptime); 809 GetUptimes(local_state_, &incremental_uptime, &uptime);
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) { 1149 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) {
1099 std::vector<variations::ActiveGroupId> synthetic_trials; 1150 std::vector<variations::ActiveGroupId> synthetic_trials;
1100 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials); 1151 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials);
1101 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials, 1152 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials,
1102 GetInstallDate(), GetMetricsReportingEnabledDate()); 1153 GetInstallDate(), GetMetricsReportingEnabledDate());
1103 } 1154 }
1104 1155
1105 void MetricsService::RecordCurrentHistograms() { 1156 void MetricsService::RecordCurrentHistograms() {
1106 DCHECK(log_manager_.current_log()); 1157 DCHECK(log_manager_.current_log());
1107 histogram_snapshot_manager_.PrepareDeltas( 1158 histogram_snapshot_manager_.PrepareDeltas(
1159 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(),
1160 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag);
1161 histogram_snapshot_manager_.PrepareDeltas(
1162 persistent_begin(), persistent_end(),
1108 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); 1163 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag);
1109 } 1164 }
1110 1165
1111 void MetricsService::RecordCurrentStabilityHistograms() { 1166 void MetricsService::RecordCurrentStabilityHistograms() {
1112 DCHECK(log_manager_.current_log()); 1167 DCHECK(log_manager_.current_log());
1113 histogram_snapshot_manager_.PrepareDeltas( 1168 histogram_snapshot_manager_.PrepareDeltas(
1169 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(),
1114 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); 1170 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag);
1115 } 1171 }
1116 1172
1117 void MetricsService::LogCleanShutdown() { 1173 void MetricsService::LogCleanShutdown() {
1118 // Redundant setting to assure that we always reset this value at shutdown 1174 // Redundant setting to assure that we always reset this value at shutdown
1119 // (and that we don't use some alternate path, and not call LogCleanShutdown). 1175 // (and that we don't use some alternate path, and not call LogCleanShutdown).
1120 clean_shutdown_status_ = CLEANLY_SHUTDOWN; 1176 clean_shutdown_status_ = CLEANLY_SHUTDOWN;
1121 1177
1122 clean_exit_beacon_.WriteBeaconValue(true); 1178 clean_exit_beacon_.WriteBeaconValue(true);
1123 RecordCurrentState(local_state_); 1179 RecordCurrentState(local_state_);
(...skipping 18 matching lines...) Expand all
1142 pref->SetInt64(prefs::kStabilityLastTimestampSec, 1198 pref->SetInt64(prefs::kStabilityLastTimestampSec,
1143 base::Time::Now().ToTimeT()); 1199 base::Time::Now().ToTimeT());
1144 } 1200 }
1145 1201
1146 void MetricsService::SkipAndDiscardUpload() { 1202 void MetricsService::SkipAndDiscardUpload() {
1147 log_manager_.DiscardStagedLog(); 1203 log_manager_.DiscardStagedLog();
1148 scheduler_->UploadCancelled(); 1204 scheduler_->UploadCancelled();
1149 log_upload_in_progress_ = false; 1205 log_upload_in_progress_ = false;
1150 } 1206 }
1151 1207
1208 MetricsService::PersistentHistogramIterator MetricsService::persistent_begin() {
1209 return PersistentHistogramIterator(allocators_, allocators_.begin());
1210 }
1211
1212 MetricsService::PersistentHistogramIterator MetricsService::persistent_end() {
1213 return PersistentHistogramIterator(allocators_, allocators_.end());
1214 }
1215
1152 } // namespace metrics 1216 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698