| 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 241 } |
| 242 | 242 |
| 243 void MetricsService::InitializeMetricsRecordingState() { | 243 void MetricsService::InitializeMetricsRecordingState() { |
| 244 reporting_service_.Initialize(); | 244 reporting_service_.Initialize(); |
| 245 InitializeMetricsState(); | 245 InitializeMetricsState(); |
| 246 | 246 |
| 247 base::Closure upload_callback = | 247 base::Closure upload_callback = |
| 248 base::Bind(&MetricsService::StartScheduledUpload, | 248 base::Bind(&MetricsService::StartScheduledUpload, |
| 249 self_ptr_factory_.GetWeakPtr()); | 249 self_ptr_factory_.GetWeakPtr()); |
| 250 | 250 |
| 251 UMA_HISTOGRAM_BOOLEAN("UMA.Dbg.InitiateRecording", true); |
| 251 rotation_scheduler_.reset(new MetricsRotationScheduler( | 252 rotation_scheduler_.reset(new MetricsRotationScheduler( |
| 252 upload_callback, | 253 upload_callback, |
| 253 // MetricsServiceClient outlives MetricsService, and | 254 // MetricsServiceClient outlives MetricsService, and |
| 254 // MetricsRotationScheduler is tied to the lifetime of |this|. | 255 // MetricsRotationScheduler is tied to the lifetime of |this|. |
| 255 base::Bind(&MetricsServiceClient::GetStandardUploadInterval, | 256 base::Bind(&MetricsServiceClient::GetStandardUploadInterval, |
| 256 base::Unretained(client_)))); | 257 base::Unretained(client_)))); |
| 257 | 258 |
| 258 for (auto& provider : metrics_providers_) | 259 for (auto& provider : metrics_providers_) |
| 259 provider->Init(); | 260 provider->Init(); |
| 260 } | 261 } |
| 261 | 262 |
| 262 void MetricsService::Start() { | 263 void MetricsService::Start() { |
| 264 UMA_HISTOGRAM_BOOLEAN("UMA.Dbg.MetricsService.Start", true); |
| 263 HandleIdleSinceLastTransmission(false); | 265 HandleIdleSinceLastTransmission(false); |
| 264 EnableRecording(); | 266 EnableRecording(); |
| 265 EnableReporting(); | 267 EnableReporting(); |
| 266 } | 268 } |
| 267 | 269 |
| 268 void MetricsService::StartRecordingForTests() { | 270 void MetricsService::StartRecordingForTests() { |
| 269 test_mode_active_ = true; | 271 test_mode_active_ = true; |
| 270 EnableRecording(); | 272 EnableRecording(); |
| 271 DisableReporting(); | 273 DisableReporting(); |
| 272 } | 274 } |
| 273 | 275 |
| 274 void MetricsService::Stop() { | 276 void MetricsService::Stop() { |
| 275 HandleIdleSinceLastTransmission(false); | 277 HandleIdleSinceLastTransmission(false); |
| 276 DisableReporting(); | 278 DisableReporting(); |
| 277 DisableRecording(); | 279 DisableRecording(); |
| 278 } | 280 } |
| 279 | 281 |
| 280 void MetricsService::EnableReporting() { | 282 void MetricsService::EnableReporting() { |
| 281 if (reporting_service_.reporting_active()) | 283 if (reporting_service_.reporting_active()) |
| 282 return; | 284 return; |
| 285 UMA_HISTOGRAM_BOOLEAN("UMA.Dbg.EnableReporting", true); |
| 283 reporting_service_.EnableReporting(); | 286 reporting_service_.EnableReporting(); |
| 284 StartSchedulerIfNecessary(); | 287 StartSchedulerIfNecessary(); |
| 285 } | 288 } |
| 286 | 289 |
| 287 void MetricsService::DisableReporting() { | 290 void MetricsService::DisableReporting() { |
| 288 reporting_service_.DisableReporting(); | 291 reporting_service_.DisableReporting(); |
| 289 } | 292 } |
| 290 | 293 |
| 291 std::string MetricsService::GetClientId() { | 294 std::string MetricsService::GetClientId() { |
| 292 return state_manager_->client_id(); | 295 return state_manager_->client_id(); |
| 293 } | 296 } |
| 294 | 297 |
| 295 int64_t MetricsService::GetInstallDate() { | 298 int64_t MetricsService::GetInstallDate() { |
| 296 return local_state_->GetInt64(prefs::kInstallDate); | 299 return local_state_->GetInt64(prefs::kInstallDate); |
| 297 } | 300 } |
| 298 | 301 |
| 299 int64_t MetricsService::GetMetricsReportingEnabledDate() { | 302 int64_t MetricsService::GetMetricsReportingEnabledDate() { |
| 300 return local_state_->GetInt64(prefs::kMetricsReportingEnabledTimestamp); | 303 return local_state_->GetInt64(prefs::kMetricsReportingEnabledTimestamp); |
| 301 } | 304 } |
| 302 | 305 |
| 303 bool MetricsService::WasLastShutdownClean() const { | 306 bool MetricsService::WasLastShutdownClean() const { |
| 304 return clean_exit_beacon_.exited_cleanly(); | 307 return clean_exit_beacon_.exited_cleanly(); |
| 305 } | 308 } |
| 306 | 309 |
| 307 void MetricsService::EnableRecording() { | 310 void MetricsService::EnableRecording() { |
| 308 DCHECK(thread_checker_.CalledOnValidThread()); | 311 DCHECK(thread_checker_.CalledOnValidThread()); |
| 309 | 312 |
| 310 if (recording_state_ == ACTIVE) | 313 if (recording_state_ == ACTIVE) |
| 311 return; | 314 return; |
| 315 UMA_HISTOGRAM_BOOLEAN("UMA.Dbg.EnableRecording", true); |
| 312 recording_state_ = ACTIVE; | 316 recording_state_ = ACTIVE; |
| 313 | 317 |
| 314 state_manager_->ForceClientIdCreation(); | 318 state_manager_->ForceClientIdCreation(); |
| 315 client_->SetMetricsClientId(state_manager_->client_id()); | 319 client_->SetMetricsClientId(state_manager_->client_id()); |
| 316 if (!log_manager_.current_log()) | 320 if (!log_manager_.current_log()) |
| 317 OpenNewLog(); | 321 OpenNewLog(); |
| 318 | 322 |
| 319 for (auto& provider : metrics_providers_) | 323 for (auto& provider : metrics_providers_) |
| 320 provider->OnRecordingEnabled(); | 324 provider->OnRecordingEnabled(); |
| 321 | 325 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 for (auto& provider : metrics_providers_) | 611 for (auto& provider : metrics_providers_) |
| 608 provider->OnDidCreateMetricsLog(); | 612 provider->OnDidCreateMetricsLog(); |
| 609 } | 613 } |
| 610 | 614 |
| 611 | 615 |
| 612 //------------------------------------------------------------------------------ | 616 //------------------------------------------------------------------------------ |
| 613 // Recording control methods | 617 // Recording control methods |
| 614 | 618 |
| 615 void MetricsService::OpenNewLog() { | 619 void MetricsService::OpenNewLog() { |
| 616 DCHECK(!log_manager_.current_log()); | 620 DCHECK(!log_manager_.current_log()); |
| 621 UMA_HISTOGRAM_BOOLEAN("UMA.Dbg.OpenNewLog", true); |
| 617 | 622 |
| 618 log_manager_.BeginLoggingWithLog(CreateLog(MetricsLog::ONGOING_LOG)); | 623 log_manager_.BeginLoggingWithLog(CreateLog(MetricsLog::ONGOING_LOG)); |
| 619 NotifyOnDidCreateMetricsLog(); | 624 NotifyOnDidCreateMetricsLog(); |
| 620 if (state_ == INITIALIZED) { | 625 if (state_ == INITIALIZED) { |
| 621 // We only need to schedule that run once. | 626 // We only need to schedule that run once. |
| 622 state_ = INIT_TASK_SCHEDULED; | 627 state_ = INIT_TASK_SCHEDULED; |
| 623 | 628 |
| 624 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 629 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 625 FROM_HERE, base::Bind(&MetricsService::StartInitTask, | 630 FROM_HERE, base::Bind(&MetricsService::StartInitTask, |
| 626 self_ptr_factory_.GetWeakPtr()), | 631 self_ptr_factory_.GetWeakPtr()), |
| 627 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); | 632 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); |
| 628 | 633 |
| 629 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 634 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 630 FROM_HERE, | 635 FROM_HERE, |
| 631 base::Bind(&MetricsService::PrepareProviderMetricsTask, | 636 base::Bind(&MetricsService::PrepareProviderMetricsTask, |
| 632 self_ptr_factory_.GetWeakPtr()), | 637 self_ptr_factory_.GetWeakPtr()), |
| 633 base::TimeDelta::FromSeconds(2 * kInitializationDelaySeconds)); | 638 base::TimeDelta::FromSeconds(2 * kInitializationDelaySeconds)); |
| 634 } | 639 } |
| 635 } | 640 } |
| 636 | 641 |
| 637 void MetricsService::StartInitTask() { | 642 void MetricsService::StartInitTask() { |
| 638 client_->InitializeSystemProfileMetrics( | 643 client_->InitializeSystemProfileMetrics( |
| 639 base::Bind(&MetricsService::FinishedInitTask, | 644 base::Bind(&MetricsService::FinishedInitTask, |
| 640 self_ptr_factory_.GetWeakPtr())); | 645 self_ptr_factory_.GetWeakPtr())); |
| 641 } | 646 } |
| 642 | 647 |
| 643 void MetricsService::CloseCurrentLog() { | 648 void MetricsService::CloseCurrentLog() { |
| 644 if (!log_manager_.current_log()) | 649 if (!log_manager_.current_log()) |
| 645 return; | 650 return; |
| 651 UMA_HISTOGRAM_BOOLEAN("UMA.Dbg.CloseCurrentLog", true); |
| 646 | 652 |
| 647 // If a persistent allocator is in use, update its internal histograms (such | 653 // If a persistent allocator is in use, update its internal histograms (such |
| 648 // as how much memory is being used) before reporting. | 654 // as how much memory is being used) before reporting. |
| 649 base::PersistentHistogramAllocator* allocator = | 655 base::PersistentHistogramAllocator* allocator = |
| 650 base::GlobalHistogramAllocator::Get(); | 656 base::GlobalHistogramAllocator::Get(); |
| 651 if (allocator) | 657 if (allocator) |
| 652 allocator->UpdateTrackingHistograms(); | 658 allocator->UpdateTrackingHistograms(); |
| 653 | 659 |
| 654 // Put incremental data (histogram deltas, and realtime stats deltas) at the | 660 // Put incremental data (histogram deltas, and realtime stats deltas) at the |
| 655 // end of all log transmissions (initial log handles this separately). | 661 // end of all log transmissions (initial log handles this separately). |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 | 803 |
| 798 // Store unsent logs, including the stability log that was just saved, so | 804 // Store unsent logs, including the stability log that was just saved, so |
| 799 // that they're not lost in case of a crash before upload time. | 805 // that they're not lost in case of a crash before upload time. |
| 800 log_store()->PersistUnsentLogs(); | 806 log_store()->PersistUnsentLogs(); |
| 801 | 807 |
| 802 return true; | 808 return true; |
| 803 } | 809 } |
| 804 | 810 |
| 805 void MetricsService::PrepareInitialMetricsLog() { | 811 void MetricsService::PrepareInitialMetricsLog() { |
| 806 DCHECK_EQ(INIT_TASK_DONE, state_); | 812 DCHECK_EQ(INIT_TASK_DONE, state_); |
| 813 UMA_HISTOGRAM_BOOLEAN("UMA.Dbg.PrepareInitialMetricsLog", true); |
| 807 | 814 |
| 808 RecordCurrentEnvironment(initial_metrics_log_.get()); | 815 RecordCurrentEnvironment(initial_metrics_log_.get()); |
| 809 base::TimeDelta incremental_uptime; | 816 base::TimeDelta incremental_uptime; |
| 810 base::TimeDelta uptime; | 817 base::TimeDelta uptime; |
| 811 GetUptimes(local_state_, &incremental_uptime, &uptime); | 818 GetUptimes(local_state_, &incremental_uptime, &uptime); |
| 812 | 819 |
| 813 // Histograms only get written to the current log, so make the new log current | 820 // Histograms only get written to the current log, so make the new log current |
| 814 // before writing them. | 821 // before writing them. |
| 815 log_manager_.PauseCurrentLog(); | 822 log_manager_.PauseCurrentLog(); |
| 816 log_manager_.BeginLoggingWithLog(std::move(initial_metrics_log_)); | 823 log_manager_.BeginLoggingWithLog(std::move(initial_metrics_log_)); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 // Redundant setting to assure that we always reset this value at shutdown | 1020 // Redundant setting to assure that we always reset this value at shutdown |
| 1014 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1021 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
| 1015 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1022 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
| 1016 client_->OnLogCleanShutdown(); | 1023 client_->OnLogCleanShutdown(); |
| 1017 clean_exit_beacon_.WriteBeaconValue(true); | 1024 clean_exit_beacon_.WriteBeaconValue(true); |
| 1018 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); | 1025 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); |
| 1019 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed); | 1026 StabilityMetricsProvider(local_state_).MarkSessionEndCompleted(end_completed); |
| 1020 } | 1027 } |
| 1021 | 1028 |
| 1022 } // namespace metrics | 1029 } // namespace metrics |
| OLD | NEW |