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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 126 |
127 #include <stddef.h> | 127 #include <stddef.h> |
128 #include <algorithm> | 128 #include <algorithm> |
129 #include <utility> | 129 #include <utility> |
130 | 130 |
131 #include "base/bind.h" | 131 #include "base/bind.h" |
132 #include "base/callback.h" | 132 #include "base/callback.h" |
133 #include "base/location.h" | 133 #include "base/location.h" |
134 #include "base/metrics/histogram_base.h" | 134 #include "base/metrics/histogram_base.h" |
135 #include "base/metrics/histogram_macros.h" | 135 #include "base/metrics/histogram_macros.h" |
| 136 #include "base/metrics/histogram_persistence.h" |
136 #include "base/metrics/histogram_samples.h" | 137 #include "base/metrics/histogram_samples.h" |
137 #include "base/metrics/sparse_histogram.h" | 138 #include "base/metrics/sparse_histogram.h" |
138 #include "base/metrics/statistics_recorder.h" | 139 #include "base/metrics/statistics_recorder.h" |
139 #include "base/prefs/pref_registry_simple.h" | 140 #include "base/prefs/pref_registry_simple.h" |
140 #include "base/prefs/pref_service.h" | 141 #include "base/prefs/pref_service.h" |
141 #include "base/rand_util.h" | 142 #include "base/rand_util.h" |
142 #include "base/single_thread_task_runner.h" | 143 #include "base/single_thread_task_runner.h" |
143 #include "base/strings/string_number_conversions.h" | 144 #include "base/strings/string_number_conversions.h" |
144 #include "base/strings/utf_string_conversions.h" | 145 #include "base/strings/utf_string_conversions.h" |
145 #include "base/thread_task_runner_handle.h" | 146 #include "base/thread_task_runner_handle.h" |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 | 734 |
734 // TODO(jar): Integrate bounds on log recording more consistently, so that we | 735 // TODO(jar): Integrate bounds on log recording more consistently, so that we |
735 // can stop recording logs that are too big much sooner. | 736 // can stop recording logs that are too big much sooner. |
736 if (log_manager_.current_log()->num_events() > kEventLimit) { | 737 if (log_manager_.current_log()->num_events() > kEventLimit) { |
737 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events", | 738 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events", |
738 log_manager_.current_log()->num_events()); | 739 log_manager_.current_log()->num_events()); |
739 log_manager_.DiscardCurrentLog(); | 740 log_manager_.DiscardCurrentLog(); |
740 OpenNewLog(); // Start trivial log to hold our histograms. | 741 OpenNewLog(); // Start trivial log to hold our histograms. |
741 } | 742 } |
742 | 743 |
| 744 // If a persistent allocator is in use, update its internal histograms (such |
| 745 // as how much memory is being used) before reporting. |
| 746 base::PersistentMemoryAllocator* allocator = |
| 747 base::GetPersistentHistogramMemoryAllocator(); |
| 748 if (allocator) |
| 749 allocator->UpdateTrackingHistograms(); |
| 750 |
743 // Put incremental data (histogram deltas, and realtime stats deltas) at the | 751 // Put incremental data (histogram deltas, and realtime stats deltas) at the |
744 // end of all log transmissions (initial log handles this separately). | 752 // end of all log transmissions (initial log handles this separately). |
745 // RecordIncrementalStabilityElements only exists on the derived | 753 // RecordIncrementalStabilityElements only exists on the derived |
746 // MetricsLog class. | 754 // MetricsLog class. |
747 MetricsLog* current_log = log_manager_.current_log(); | 755 MetricsLog* current_log = log_manager_.current_log(); |
748 DCHECK(current_log); | 756 DCHECK(current_log); |
749 RecordCurrentEnvironment(current_log); | 757 RecordCurrentEnvironment(current_log); |
750 base::TimeDelta incremental_uptime; | 758 base::TimeDelta incremental_uptime; |
751 base::TimeDelta uptime; | 759 base::TimeDelta uptime; |
752 GetUptimes(local_state_, &incremental_uptime, &uptime); | 760 GetUptimes(local_state_, &incremental_uptime, &uptime); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 | 1100 |
1093 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) { | 1101 void MetricsService::RecordCurrentEnvironment(MetricsLog* log) { |
1094 std::vector<variations::ActiveGroupId> synthetic_trials; | 1102 std::vector<variations::ActiveGroupId> synthetic_trials; |
1095 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials); | 1103 GetSyntheticFieldTrialsOlderThan(log->creation_time(), &synthetic_trials); |
1096 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials, | 1104 log->RecordEnvironment(metrics_providers_.get(), synthetic_trials, |
1097 GetInstallDate(), GetMetricsReportingEnabledDate()); | 1105 GetInstallDate(), GetMetricsReportingEnabledDate()); |
1098 } | 1106 } |
1099 | 1107 |
1100 void MetricsService::RecordCurrentHistograms() { | 1108 void MetricsService::RecordCurrentHistograms() { |
1101 DCHECK(log_manager_.current_log()); | 1109 DCHECK(log_manager_.current_log()); |
| 1110 // "true" indicates that StatisticsRecorder should include histograms in |
| 1111 // persistent storage. |
1102 histogram_snapshot_manager_.PrepareDeltas( | 1112 histogram_snapshot_manager_.PrepareDeltas( |
| 1113 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), |
1103 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); | 1114 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); |
1104 } | 1115 } |
1105 | 1116 |
1106 void MetricsService::RecordCurrentStabilityHistograms() { | 1117 void MetricsService::RecordCurrentStabilityHistograms() { |
1107 DCHECK(log_manager_.current_log()); | 1118 DCHECK(log_manager_.current_log()); |
| 1119 // "true" indicates that StatisticsRecorder should include histograms in |
| 1120 // persistent storage. |
1108 histogram_snapshot_manager_.PrepareDeltas( | 1121 histogram_snapshot_manager_.PrepareDeltas( |
| 1122 base::StatisticsRecorder::begin(true), base::StatisticsRecorder::end(), |
1109 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); | 1123 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); |
1110 } | 1124 } |
1111 | 1125 |
1112 void MetricsService::LogCleanShutdown() { | 1126 void MetricsService::LogCleanShutdown() { |
1113 // Redundant setting to assure that we always reset this value at shutdown | 1127 // Redundant setting to assure that we always reset this value at shutdown |
1114 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1128 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
1115 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1129 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
1116 | 1130 |
1117 clean_exit_beacon_.WriteBeaconValue(true); | 1131 clean_exit_beacon_.WriteBeaconValue(true); |
1118 RecordCurrentState(local_state_); | 1132 RecordCurrentState(local_state_); |
(...skipping 19 matching lines...) Expand all Loading... |
1138 base::Time::Now().ToTimeT()); | 1152 base::Time::Now().ToTimeT()); |
1139 } | 1153 } |
1140 | 1154 |
1141 void MetricsService::SkipAndDiscardUpload() { | 1155 void MetricsService::SkipAndDiscardUpload() { |
1142 log_manager_.DiscardStagedLog(); | 1156 log_manager_.DiscardStagedLog(); |
1143 scheduler_->UploadCancelled(); | 1157 scheduler_->UploadCancelled(); |
1144 log_upload_in_progress_ = false; | 1158 log_upload_in_progress_ = false; |
1145 } | 1159 } |
1146 | 1160 |
1147 } // namespace metrics | 1161 } // namespace metrics |
OLD | NEW |