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