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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 #include "components/metrics/stability_metrics_provider.h" | 155 #include "components/metrics/stability_metrics_provider.h" |
156 #include "components/metrics/url_constants.h" | 156 #include "components/metrics/url_constants.h" |
157 #include "components/prefs/pref_registry_simple.h" | 157 #include "components/prefs/pref_registry_simple.h" |
158 #include "components/prefs/pref_service.h" | 158 #include "components/prefs/pref_service.h" |
159 #include "components/variations/entropy_provider.h" | 159 #include "components/variations/entropy_provider.h" |
160 | 160 |
161 namespace metrics { | 161 namespace metrics { |
162 | 162 |
163 namespace { | 163 namespace { |
164 | 164 |
165 // This drops records if the number of events (user action and omnibox) exceeds | |
166 // the kEventLimit. | |
167 const base::Feature kUMAThrottleEvents{"UMAThrottleEvents", | |
168 base::FEATURE_ENABLED_BY_DEFAULT}; | |
169 | |
170 // The delay, in seconds, after starting recording before doing expensive | 165 // The delay, in seconds, after starting recording before doing expensive |
171 // initialization work. | 166 // initialization work. |
172 #if defined(OS_ANDROID) || defined(OS_IOS) | 167 #if defined(OS_ANDROID) || defined(OS_IOS) |
173 // On mobile devices, a significant portion of sessions last less than a minute. | 168 // On mobile devices, a significant portion of sessions last less than a minute. |
174 // Use a shorter timer on these platforms to avoid losing data. | 169 // Use a shorter timer on these platforms to avoid losing data. |
175 // TODO(dfalcantara): To avoid delaying startup, tighten up initialization so | 170 // TODO(dfalcantara): To avoid delaying startup, tighten up initialization so |
176 // that it occurs after the user gets their initial page. | 171 // that it occurs after the user gets their initial page. |
177 const int kInitializationDelaySeconds = 5; | 172 const int kInitializationDelaySeconds = 5; |
178 #else | 173 #else |
179 const int kInitializationDelaySeconds = 30; | 174 const int kInitializationDelaySeconds = 30; |
180 #endif | 175 #endif |
181 | 176 |
182 // The maximum number of events in a log uploaded to the UMA server. | |
183 const int kEventLimit = 2400; | |
184 | |
185 #if defined(OS_ANDROID) || defined(OS_IOS) | 177 #if defined(OS_ANDROID) || defined(OS_IOS) |
186 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon, | 178 void MarkAppCleanShutdownAndCommit(CleanExitBeacon* clean_exit_beacon, |
187 PrefService* local_state) { | 179 PrefService* local_state) { |
188 clean_exit_beacon->WriteBeaconValue(true); | 180 clean_exit_beacon->WriteBeaconValue(true); |
189 ExecutionPhaseManager(local_state).OnAppEnterBackground(); | 181 ExecutionPhaseManager(local_state).OnAppEnterBackground(); |
190 // Start writing right away (write happens on a different thread). | 182 // Start writing right away (write happens on a different thread). |
191 local_state->CommitPendingWrite(); | 183 local_state->CommitPendingWrite(); |
192 } | 184 } |
193 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 185 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
194 | 186 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 void MetricsService::StartInitTask() { | 631 void MetricsService::StartInitTask() { |
640 client_->InitializeSystemProfileMetrics( | 632 client_->InitializeSystemProfileMetrics( |
641 base::Bind(&MetricsService::FinishedInitTask, | 633 base::Bind(&MetricsService::FinishedInitTask, |
642 self_ptr_factory_.GetWeakPtr())); | 634 self_ptr_factory_.GetWeakPtr())); |
643 } | 635 } |
644 | 636 |
645 void MetricsService::CloseCurrentLog() { | 637 void MetricsService::CloseCurrentLog() { |
646 if (!log_manager_.current_log()) | 638 if (!log_manager_.current_log()) |
647 return; | 639 return; |
648 | 640 |
649 // TODO(rkaplow): Evaluate if this is needed. | |
650 if (log_manager_.current_log()->num_events() > kEventLimit) { | |
651 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events", | |
652 log_manager_.current_log()->num_events()); | |
653 if (base::FeatureList::IsEnabled(kUMAThrottleEvents)) { | |
654 log_manager_.DiscardCurrentLog(); | |
655 OpenNewLog(); // Start trivial log to hold our histograms. | |
656 } | |
657 } | |
658 | |
659 // If a persistent allocator is in use, update its internal histograms (such | 641 // If a persistent allocator is in use, update its internal histograms (such |
660 // as how much memory is being used) before reporting. | 642 // as how much memory is being used) before reporting. |
661 base::PersistentHistogramAllocator* allocator = | 643 base::PersistentHistogramAllocator* allocator = |
662 base::GlobalHistogramAllocator::Get(); | 644 base::GlobalHistogramAllocator::Get(); |
663 if (allocator) | 645 if (allocator) |
664 allocator->UpdateTrackingHistograms(); | 646 allocator->UpdateTrackingHistograms(); |
665 | 647 |
666 // Put incremental data (histogram deltas, and realtime stats deltas) at the | 648 // Put incremental data (histogram deltas, and realtime stats deltas) at the |
667 // end of all log transmissions (initial log handles this separately). | 649 // end of all log transmissions (initial log handles this separately). |
668 // RecordIncrementalStabilityElements only exists on the derived | 650 // RecordIncrementalStabilityElements only exists on the derived |
669 // MetricsLog class. | 651 // MetricsLog class. |
670 MetricsLog* current_log = log_manager_.current_log(); | 652 MetricsLog* current_log = log_manager_.current_log(); |
671 DCHECK(current_log); | 653 DCHECK(current_log); |
672 RecordCurrentEnvironment(current_log); | 654 RecordCurrentEnvironment(current_log); |
673 base::TimeDelta incremental_uptime; | 655 base::TimeDelta incremental_uptime; |
674 base::TimeDelta uptime; | 656 base::TimeDelta uptime; |
675 GetUptimes(local_state_, &incremental_uptime, &uptime); | 657 GetUptimes(local_state_, &incremental_uptime, &uptime); |
676 current_log->RecordStabilityMetrics(metrics_providers_, incremental_uptime, | 658 current_log->RecordStabilityMetrics(metrics_providers_, incremental_uptime, |
677 uptime); | 659 uptime); |
678 | 660 |
679 current_log->RecordGeneralMetrics(metrics_providers_); | 661 current_log->RecordGeneralMetrics(metrics_providers_); |
680 RecordCurrentHistograms(); | 662 RecordCurrentHistograms(); |
| 663 current_log->TruncateEvents(); |
681 DVLOG(1) << "Generated an ongoing log."; | 664 DVLOG(1) << "Generated an ongoing log."; |
682 log_manager_.FinishCurrentLog(log_store()); | 665 log_manager_.FinishCurrentLog(log_store()); |
683 } | 666 } |
684 | 667 |
685 void MetricsService::PushPendingLogsToPersistentStorage() { | 668 void MetricsService::PushPendingLogsToPersistentStorage() { |
686 if (state_ < SENDING_LOGS) | 669 if (state_ < SENDING_LOGS) |
687 return; // We didn't and still don't have time to get plugin list etc. | 670 return; // We didn't and still don't have time to get plugin list etc. |
688 | 671 |
689 CloseCurrentLog(); | 672 CloseCurrentLog(); |
690 log_store()->PersistUnsentLogs(); | 673 log_store()->PersistUnsentLogs(); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 // Redundant setting to assure that we always reset this value at shutdown | 976 // Redundant setting to assure that we always reset this value at shutdown |
994 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 977 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
995 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 978 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
996 client_->OnLogCleanShutdown(); | 979 client_->OnLogCleanShutdown(); |
997 clean_exit_beacon_.WriteBeaconValue(true); | 980 clean_exit_beacon_.WriteBeaconValue(true); |
998 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); | 981 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); |
999 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed); | 982 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed); |
1000 } | 983 } |
1001 | 984 |
1002 } // namespace metrics | 985 } // namespace metrics |
OLD | NEW |