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

Side by Side Diff: components/metrics/metrics_service.cc

Issue 1818613002: Implement UMA log throttling for cellular connections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: singleton pattern removed Created 4 years, 8 months 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 #include "base/strings/string_number_conversions.h" 142 #include "base/strings/string_number_conversions.h"
143 #include "base/strings/utf_string_conversions.h" 143 #include "base/strings/utf_string_conversions.h"
144 #include "base/thread_task_runner_handle.h" 144 #include "base/thread_task_runner_handle.h"
145 #include "base/threading/platform_thread.h" 145 #include "base/threading/platform_thread.h"
146 #include "base/threading/thread.h" 146 #include "base/threading/thread.h"
147 #include "base/threading/thread_restrictions.h" 147 #include "base/threading/thread_restrictions.h"
148 #include "base/time/time.h" 148 #include "base/time/time.h"
149 #include "base/tracked_objects.h" 149 #include "base/tracked_objects.h"
150 #include "base/values.h" 150 #include "base/values.h"
151 #include "build/build_config.h" 151 #include "build/build_config.h"
152 #include "components/metrics/data_use_tracker.h"
152 #include "components/metrics/metrics_log.h" 153 #include "components/metrics/metrics_log.h"
153 #include "components/metrics/metrics_log_manager.h" 154 #include "components/metrics/metrics_log_manager.h"
154 #include "components/metrics/metrics_log_uploader.h" 155 #include "components/metrics/metrics_log_uploader.h"
155 #include "components/metrics/metrics_pref_names.h" 156 #include "components/metrics/metrics_pref_names.h"
156 #include "components/metrics/metrics_reporting_scheduler.h" 157 #include "components/metrics/metrics_reporting_scheduler.h"
157 #include "components/metrics/metrics_service_client.h" 158 #include "components/metrics/metrics_service_client.h"
158 #include "components/metrics/metrics_state_manager.h" 159 #include "components/metrics/metrics_state_manager.h"
159 #include "components/prefs/pref_registry_simple.h" 160 #include "components/prefs/pref_registry_simple.h"
160 #include "components/prefs/pref_service.h" 161 #include "components/prefs/pref_service.h"
161 #include "components/variations/entropy_provider.h" 162 #include "components/variations/entropy_provider.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 MetricsService::CLEANLY_SHUTDOWN; 252 MetricsService::CLEANLY_SHUTDOWN;
252 253
253 MetricsService::ExecutionPhase MetricsService::execution_phase_ = 254 MetricsService::ExecutionPhase MetricsService::execution_phase_ =
254 MetricsService::UNINITIALIZED_PHASE; 255 MetricsService::UNINITIALIZED_PHASE;
255 256
256 // static 257 // static
257 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) { 258 void MetricsService::RegisterPrefs(PrefRegistrySimple* registry) {
258 DCHECK(IsSingleThreaded()); 259 DCHECK(IsSingleThreaded());
259 MetricsStateManager::RegisterPrefs(registry); 260 MetricsStateManager::RegisterPrefs(registry);
260 MetricsLog::RegisterPrefs(registry); 261 MetricsLog::RegisterPrefs(registry);
262 DataUseTracker::RegisterPrefs(registry);
261 263
262 registry->RegisterInt64Pref(prefs::kInstallDate, 0); 264 registry->RegisterInt64Pref(prefs::kInstallDate, 0);
263 265
264 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0); 266 registry->RegisterInt64Pref(prefs::kStabilityLaunchTimeSec, 0);
265 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0); 267 registry->RegisterInt64Pref(prefs::kStabilityLastTimestampSec, 0);
266 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string()); 268 registry->RegisterStringPref(prefs::kStabilityStatsVersion, std::string());
267 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0); 269 registry->RegisterInt64Pref(prefs::kStabilityStatsBuildTime, 0);
268 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true); 270 registry->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true);
269 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase, 271 registry->RegisterIntegerPref(prefs::kStabilityExecutionPhase,
270 UNINITIALIZED_PHASE); 272 UNINITIALIZED_PHASE);
271 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true); 273 registry->RegisterBooleanPref(prefs::kStabilitySessionEndCompleted, true);
272 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1); 274 registry->RegisterIntegerPref(prefs::kMetricsSessionID, -1);
273 275
274 registry->RegisterListPref(prefs::kMetricsInitialLogs); 276 registry->RegisterListPref(prefs::kMetricsInitialLogs);
275 registry->RegisterListPref(prefs::kMetricsOngoingLogs); 277 registry->RegisterListPref(prefs::kMetricsOngoingLogs);
276 278
277 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); 279 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0);
278 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); 280 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0);
279 } 281 }
280 282
281 MetricsService::MetricsService(MetricsStateManager* state_manager, 283 MetricsService::MetricsService(MetricsStateManager* state_manager,
282 MetricsServiceClient* client, 284 MetricsServiceClient* client,
283 PrefService* local_state) 285 PrefService* local_state,
286 base::Callback<void(bool*)> cellular_callback)
284 : log_manager_(local_state, kUploadLogAvoidRetransmitSize), 287 : log_manager_(local_state, kUploadLogAvoidRetransmitSize),
285 histogram_snapshot_manager_(this), 288 histogram_snapshot_manager_(this),
286 state_manager_(state_manager), 289 state_manager_(state_manager),
287 client_(client), 290 client_(client),
288 local_state_(local_state), 291 local_state_(local_state),
289 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state), 292 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state),
290 recording_state_(UNSET), 293 recording_state_(UNSET),
291 reporting_active_(false), 294 reporting_active_(false),
292 test_mode_active_(false), 295 test_mode_active_(false),
293 state_(INITIALIZED), 296 state_(INITIALIZED),
294 log_upload_in_progress_(false), 297 log_upload_in_progress_(false),
295 idle_since_last_transmission_(false), 298 idle_since_last_transmission_(false),
296 session_id_(-1), 299 session_id_(-1),
300 cellular_callback_(cellular_callback),
297 self_ptr_factory_(this), 301 self_ptr_factory_(this),
298 state_saver_factory_(this) { 302 state_saver_factory_(this) {
299 DCHECK(IsSingleThreaded()); 303 DCHECK(IsSingleThreaded());
300 DCHECK(state_manager_); 304 DCHECK(state_manager_);
301 DCHECK(client_); 305 DCHECK(client_);
302 DCHECK(local_state_); 306 DCHECK(local_state_);
303 307
304 // Set the install date if this is our first run. 308 // Set the install date if this is our first run.
305 int64_t install_date = local_state_->GetInt64(prefs::kInstallDate); 309 int64_t install_date = local_state_->GetInt64(prefs::kInstallDate);
306 if (install_date == 0) 310 if (install_date == 0)
307 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT()); 311 local_state_->SetInt64(prefs::kInstallDate, base::Time::Now().ToTimeT());
312 data_use_tracker_.reset(new DataUseTracker(local_state_));
308 } 313 }
309 314
310 MetricsService::~MetricsService() { 315 MetricsService::~MetricsService() {
311 DisableRecording(); 316 DisableRecording();
312 } 317 }
313 318
314 void MetricsService::InitializeMetricsRecordingState() { 319 void MetricsService::InitializeMetricsRecordingState() {
315 InitializeMetricsState(); 320 InitializeMetricsState();
316 321
317 base::Closure upload_callback = 322 base::Closure upload_callback =
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 UNINITIALIZED_PHASE); 543 UNINITIALIZED_PHASE);
539 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); 544 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
540 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); 545 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0);
541 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); 546 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true);
542 } 547 }
543 548
544 void MetricsService::PushExternalLog(const std::string& log) { 549 void MetricsService::PushExternalLog(const std::string& log) {
545 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); 550 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG);
546 } 551 }
547 552
553 base::WeakPtr<DataUseTracker> MetricsService::GetDataUseTracker() {
554 return data_use_tracker_->GetWeakPtr();
555 }
556
548 //------------------------------------------------------------------------------ 557 //------------------------------------------------------------------------------
549 // private methods 558 // private methods
550 //------------------------------------------------------------------------------ 559 //------------------------------------------------------------------------------
551 560
552 561
553 //------------------------------------------------------------------------------ 562 //------------------------------------------------------------------------------
554 // Initialization methods 563 // Initialization methods
555 564
556 void MetricsService::InitializeMetricsState() { 565 void MetricsService::InitializeMetricsState() {
557 const int64_t buildtime = MetricsLog::GetBuildTime(); 566 const int64_t buildtime = MetricsLog::GetBuildTime();
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 } 868 }
860 if (!log_manager_.has_unsent_logs()) { 869 if (!log_manager_.has_unsent_logs()) {
861 // Should only get here if serializing the log failed somehow. 870 // Should only get here if serializing the log failed somehow.
862 // Just tell the scheduler it was uploaded and wait for the next log 871 // Just tell the scheduler it was uploaded and wait for the next log
863 // interval. 872 // interval.
864 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); 873 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs());
865 return; 874 return;
866 } 875 }
867 if (!log_manager_.has_staged_log()) 876 if (!log_manager_.has_staged_log())
868 log_manager_.StageNextLogForUpload(); 877 log_manager_.StageNextLogForUpload();
869 SendStagedLog(); 878
879 // Proceed to stage the log for upload if log size satisfies cellular log
880 // upload constrains.
881 bool is_cellular = false;
882
883 if (!cellular_callback_.is_null()) {
884 cellular_callback_.Run(&is_cellular);
885 }
886
887 if (is_cellular &&
888 data_use_tracker_->CanUploadUMALog(log_manager_.staged_log_hash().size()))
889 SendStagedLog();
890 else
891 scheduler_->UploadCancelled();
870 } 892 }
871 893
872 bool MetricsService::ProvidersHaveInitialStabilityMetrics() { 894 bool MetricsService::ProvidersHaveInitialStabilityMetrics() {
873 // Check whether any metrics provider has initial stability metrics. 895 // Check whether any metrics provider has initial stability metrics.
874 for (MetricsProvider* provider : metrics_providers_) { 896 for (MetricsProvider* provider : metrics_providers_) {
875 if (provider->HasInitialStabilityMetrics()) 897 if (provider->HasInitialStabilityMetrics())
876 return true; 898 return true;
877 } 899 }
878 900
879 return false; 901 return false;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 base::Time::Now().ToTimeT()); 1183 base::Time::Now().ToTimeT());
1162 } 1184 }
1163 1185
1164 void MetricsService::SkipAndDiscardUpload() { 1186 void MetricsService::SkipAndDiscardUpload() {
1165 log_manager_.DiscardStagedLog(); 1187 log_manager_.DiscardStagedLog();
1166 scheduler_->UploadCancelled(); 1188 scheduler_->UploadCancelled();
1167 log_upload_in_progress_ = false; 1189 log_upload_in_progress_ = false;
1168 } 1190 }
1169 1191
1170 } // namespace metrics 1192 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698