OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 return SUCCESS; | 281 return SUCCESS; |
282 case 400: | 282 case 400: |
283 return BAD_REQUEST; | 283 return BAD_REQUEST; |
284 case net::URLFetcher::RESPONSE_CODE_INVALID: | 284 case net::URLFetcher::RESPONSE_CODE_INVALID: |
285 return NO_RESPONSE; | 285 return NO_RESPONSE; |
286 default: | 286 default: |
287 return UNKNOWN_FAILURE; | 287 return UNKNOWN_FAILURE; |
288 } | 288 } |
289 } | 289 } |
290 | 290 |
291 void MarkAppCleanShutdownAndCommit() { | 291 void MarkAppCleanShutdownAndCommit(PrefService* local_state) { |
292 PrefService* pref = g_browser_process->local_state(); | 292 local_state->SetBoolean(prefs::kStabilityExitedCleanly, true); |
293 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); | 293 local_state->SetInteger(prefs::kStabilityExecutionPhase, |
294 pref->SetInteger(prefs::kStabilityExecutionPhase, | 294 MetricsService::SHUTDOWN_COMPLETE); |
295 MetricsService::SHUTDOWN_COMPLETE); | |
296 // Start writing right away (write happens on a different thread). | 295 // Start writing right away (write happens on a different thread). |
297 pref->CommitPendingWrite(); | 296 local_state->CommitPendingWrite(); |
298 } | 297 } |
299 | 298 |
300 } // namespace | 299 } // namespace |
301 | 300 |
302 | 301 |
303 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) { | 302 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) { |
304 id.name = trial; | 303 id.name = trial; |
305 id.group = group; | 304 id.group = group; |
306 } | 305 } |
307 | 306 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 AndroidMetricsProvider::RegisterPrefs(registry); | 359 AndroidMetricsProvider::RegisterPrefs(registry); |
361 #endif // defined(OS_ANDROID) | 360 #endif // defined(OS_ANDROID) |
362 | 361 |
363 #if defined(ENABLE_PLUGINS) | 362 #if defined(ENABLE_PLUGINS) |
364 // TODO(asvitkine): Move this out of here. | 363 // TODO(asvitkine): Move this out of here. |
365 PluginMetricsProvider::RegisterPrefs(registry); | 364 PluginMetricsProvider::RegisterPrefs(registry); |
366 #endif | 365 #endif |
367 } | 366 } |
368 | 367 |
369 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, | 368 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, |
370 metrics::MetricsServiceClient* client) | 369 metrics::MetricsServiceClient* client, |
371 : log_manager_(g_browser_process->local_state(), | 370 PrefService* local_state) |
372 kUploadLogAvoidRetransmitSize), | 371 : log_manager_(local_state, kUploadLogAvoidRetransmitSize), |
373 histogram_snapshot_manager_(this), | 372 histogram_snapshot_manager_(this), |
374 state_manager_(state_manager), | 373 state_manager_(state_manager), |
375 client_(client), | 374 client_(client), |
| 375 local_state_(local_state), |
376 recording_active_(false), | 376 recording_active_(false), |
377 reporting_active_(false), | 377 reporting_active_(false), |
378 test_mode_active_(false), | 378 test_mode_active_(false), |
379 state_(INITIALIZED), | 379 state_(INITIALIZED), |
380 has_initial_stability_log_(false), | 380 has_initial_stability_log_(false), |
381 idle_since_last_transmission_(false), | 381 idle_since_last_transmission_(false), |
382 session_id_(-1), | 382 session_id_(-1), |
383 next_window_id_(0), | 383 next_window_id_(0), |
384 self_ptr_factory_(this), | 384 self_ptr_factory_(this), |
385 state_saver_factory_(this), | 385 state_saver_factory_(this), |
386 waiting_for_asynchronous_reporting_step_(false) { | 386 waiting_for_asynchronous_reporting_step_(false) { |
387 DCHECK(IsSingleThreaded()); | 387 DCHECK(IsSingleThreaded()); |
388 DCHECK(state_manager_); | 388 DCHECK(state_manager_); |
389 DCHECK(client_); | 389 DCHECK(client_); |
| 390 DCHECK(local_state_); |
390 | 391 |
391 #if defined(OS_ANDROID) | 392 #if defined(OS_ANDROID) |
392 // TODO(asvitkine): Move this out of MetricsService. | 393 // TODO(asvitkine): Move this out of MetricsService. |
393 RegisterMetricsProvider( | 394 RegisterMetricsProvider( |
394 scoped_ptr<metrics::MetricsProvider>(new AndroidMetricsProvider( | 395 scoped_ptr<metrics::MetricsProvider>(new AndroidMetricsProvider( |
395 g_browser_process->local_state()))); | 396 local_state_))); |
396 #endif // defined(OS_ANDROID) | 397 #endif // defined(OS_ANDROID) |
397 | 398 |
398 // TODO(asvitkine): Move these out of MetricsService. | 399 // TODO(asvitkine): Move these out of MetricsService. |
399 RegisterMetricsProvider( | 400 RegisterMetricsProvider( |
400 scoped_ptr<metrics::MetricsProvider>(new NetworkMetricsProvider)); | 401 scoped_ptr<metrics::MetricsProvider>(new NetworkMetricsProvider)); |
401 RegisterMetricsProvider( | 402 RegisterMetricsProvider( |
402 scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider)); | 403 scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider)); |
403 RegisterMetricsProvider( | 404 RegisterMetricsProvider( |
404 scoped_ptr<metrics::MetricsProvider>(new ChromeStabilityMetricsProvider)); | 405 scoped_ptr<metrics::MetricsProvider>(new ChromeStabilityMetricsProvider)); |
405 RegisterMetricsProvider( | 406 RegisterMetricsProvider( |
406 scoped_ptr<metrics::MetricsProvider>(new GPUMetricsProvider())); | 407 scoped_ptr<metrics::MetricsProvider>(new GPUMetricsProvider())); |
407 | 408 |
408 #if defined(OS_WIN) | 409 #if defined(OS_WIN) |
409 google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin; | 410 google_update_metrics_provider_ = new GoogleUpdateMetricsProviderWin; |
410 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( | 411 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( |
411 google_update_metrics_provider_)); | 412 google_update_metrics_provider_)); |
412 #endif | 413 #endif |
413 | 414 |
414 #if defined(ENABLE_PLUGINS) | 415 #if defined(ENABLE_PLUGINS) |
415 plugin_metrics_provider_ = new PluginMetricsProvider( | 416 plugin_metrics_provider_ = new PluginMetricsProvider(local_state_); |
416 g_browser_process->local_state()); | |
417 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( | 417 RegisterMetricsProvider(scoped_ptr<metrics::MetricsProvider>( |
418 plugin_metrics_provider_)); | 418 plugin_metrics_provider_)); |
419 #endif | 419 #endif |
420 | 420 |
421 #if defined(OS_CHROMEOS) | 421 #if defined(OS_CHROMEOS) |
422 RegisterMetricsProvider( | 422 RegisterMetricsProvider( |
423 scoped_ptr<metrics::MetricsProvider>(new ChromeOSMetricsProvider)); | 423 scoped_ptr<metrics::MetricsProvider>(new ChromeOSMetricsProvider)); |
424 #endif | 424 #endif |
425 } | 425 } |
426 | 426 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 | 574 |
575 void MetricsService::RecordCompletedSessionEnd() { | 575 void MetricsService::RecordCompletedSessionEnd() { |
576 LogCleanShutdown(); | 576 LogCleanShutdown(); |
577 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); | 577 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); |
578 } | 578 } |
579 | 579 |
580 #if defined(OS_ANDROID) || defined(OS_IOS) | 580 #if defined(OS_ANDROID) || defined(OS_IOS) |
581 void MetricsService::OnAppEnterBackground() { | 581 void MetricsService::OnAppEnterBackground() { |
582 scheduler_->Stop(); | 582 scheduler_->Stop(); |
583 | 583 |
584 MarkAppCleanShutdownAndCommit(); | 584 MarkAppCleanShutdownAndCommit(local_state_); |
585 | 585 |
586 // At this point, there's no way of knowing when the process will be | 586 // At this point, there's no way of knowing when the process will be |
587 // killed, so this has to be treated similar to a shutdown, closing and | 587 // killed, so this has to be treated similar to a shutdown, closing and |
588 // persisting all logs. Unlinke a shutdown, the state is primed to be ready | 588 // persisting all logs. Unlinke a shutdown, the state is primed to be ready |
589 // to continue logging and uploading if the process does return. | 589 // to continue logging and uploading if the process does return. |
590 if (recording_active() && state_ >= SENDING_INITIAL_STABILITY_LOG) { | 590 if (recording_active() && state_ >= SENDING_INITIAL_STABILITY_LOG) { |
591 PushPendingLogsToPersistentStorage(); | 591 PushPendingLogsToPersistentStorage(); |
592 // Persisting logs closes the current log, so start recording a new log | 592 // Persisting logs closes the current log, so start recording a new log |
593 // immediately to capture any background work that might be done before the | 593 // immediately to capture any background work that might be done before the |
594 // process is killed. | 594 // process is killed. |
595 OpenNewLog(); | 595 OpenNewLog(); |
596 } | 596 } |
597 } | 597 } |
598 | 598 |
599 void MetricsService::OnAppEnterForeground() { | 599 void MetricsService::OnAppEnterForeground() { |
600 PrefService* pref = g_browser_process->local_state(); | 600 local_state_->SetBoolean(prefs::kStabilityExitedCleanly, false); |
601 pref->SetBoolean(prefs::kStabilityExitedCleanly, false); | |
602 | |
603 StartSchedulerIfNecessary(); | 601 StartSchedulerIfNecessary(); |
604 } | 602 } |
605 #else | 603 #else |
606 void MetricsService::LogNeedForCleanShutdown() { | 604 void MetricsService::LogNeedForCleanShutdown(PrefService* local_state) { |
607 PrefService* pref = g_browser_process->local_state(); | 605 local_state->SetBoolean(prefs::kStabilityExitedCleanly, false); |
608 pref->SetBoolean(prefs::kStabilityExitedCleanly, false); | |
609 // Redundant setting to be sure we call for a clean shutdown. | 606 // Redundant setting to be sure we call for a clean shutdown. |
610 clean_shutdown_status_ = NEED_TO_SHUTDOWN; | 607 clean_shutdown_status_ = NEED_TO_SHUTDOWN; |
611 } | 608 } |
612 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 609 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
613 | 610 |
614 // static | 611 // static |
615 void MetricsService::SetExecutionPhase(ExecutionPhase execution_phase) { | 612 void MetricsService::SetExecutionPhase(ExecutionPhase execution_phase, |
| 613 PrefService* local_state) { |
616 execution_phase_ = execution_phase; | 614 execution_phase_ = execution_phase; |
617 PrefService* pref = g_browser_process->local_state(); | 615 local_state->SetInteger(prefs::kStabilityExecutionPhase, execution_phase_); |
618 pref->SetInteger(prefs::kStabilityExecutionPhase, execution_phase_); | |
619 } | 616 } |
620 | 617 |
621 void MetricsService::RecordBreakpadRegistration(bool success) { | 618 void MetricsService::RecordBreakpadRegistration(bool success) { |
622 if (!success) | 619 if (!success) |
623 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationFail); | 620 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationFail); |
624 else | 621 else |
625 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationSuccess); | 622 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationSuccess); |
626 } | 623 } |
627 | 624 |
628 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { | 625 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { |
629 if (!has_debugger) | 626 if (!has_debugger) |
630 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent); | 627 IncrementPrefValue(prefs::kStabilityDebuggerNotPresent); |
631 else | 628 else |
632 IncrementPrefValue(prefs::kStabilityDebuggerPresent); | 629 IncrementPrefValue(prefs::kStabilityDebuggerPresent); |
633 } | 630 } |
634 | 631 |
635 //------------------------------------------------------------------------------ | 632 //------------------------------------------------------------------------------ |
636 // private methods | 633 // private methods |
637 //------------------------------------------------------------------------------ | 634 //------------------------------------------------------------------------------ |
638 | 635 |
639 | 636 |
640 //------------------------------------------------------------------------------ | 637 //------------------------------------------------------------------------------ |
641 // Initialization methods | 638 // Initialization methods |
642 | 639 |
643 void MetricsService::InitializeMetricsState() { | 640 void MetricsService::InitializeMetricsState() { |
644 PrefService* pref = g_browser_process->local_state(); | 641 local_state_->SetString(prefs::kStabilityStatsVersion, |
645 DCHECK(pref); | 642 client_->GetVersionString()); |
| 643 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, |
| 644 MetricsLog::GetBuildTime()); |
646 | 645 |
647 pref->SetString(prefs::kStabilityStatsVersion, client_->GetVersionString()); | 646 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID); |
648 pref->SetInt64(prefs::kStabilityStatsBuildTime, MetricsLog::GetBuildTime()); | |
649 | 647 |
650 session_id_ = pref->GetInteger(prefs::kMetricsSessionID); | 648 if (!local_state_->GetBoolean(prefs::kStabilityExitedCleanly)) { |
651 | |
652 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { | |
653 IncrementPrefValue(prefs::kStabilityCrashCount); | 649 IncrementPrefValue(prefs::kStabilityCrashCount); |
654 // Reset flag, and wait until we call LogNeedForCleanShutdown() before | 650 // Reset flag, and wait until we call LogNeedForCleanShutdown() before |
655 // monitoring. | 651 // monitoring. |
656 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); | 652 local_state_->SetBoolean(prefs::kStabilityExitedCleanly, true); |
657 | 653 |
658 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 654 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
659 // the registry. | 655 // the registry. |
660 int execution_phase = pref->GetInteger(prefs::kStabilityExecutionPhase); | 656 int execution_phase = |
| 657 local_state_->GetInteger(prefs::kStabilityExecutionPhase); |
661 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 658 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
662 execution_phase); | 659 execution_phase); |
663 | 660 |
664 // If the previous session didn't exit cleanly, then prepare an initial | 661 // If the previous session didn't exit cleanly, then prepare an initial |
665 // stability log if UMA is enabled. | 662 // stability log if UMA is enabled. |
666 if (state_manager_->IsMetricsReportingEnabled()) | 663 if (state_manager_->IsMetricsReportingEnabled()) |
667 PrepareInitialStabilityLog(); | 664 PrepareInitialStabilityLog(); |
668 } | 665 } |
669 | 666 |
670 // Update session ID. | 667 // Update session ID. |
671 ++session_id_; | 668 ++session_id_; |
672 pref->SetInteger(prefs::kMetricsSessionID, session_id_); | 669 local_state_->SetInteger(prefs::kMetricsSessionID, session_id_); |
673 | 670 |
674 // Stability bookkeeping | 671 // Stability bookkeeping |
675 IncrementPrefValue(prefs::kStabilityLaunchCount); | 672 IncrementPrefValue(prefs::kStabilityLaunchCount); |
676 | 673 |
677 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); | 674 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); |
678 SetExecutionPhase(START_METRICS_RECORDING); | 675 SetExecutionPhase(START_METRICS_RECORDING, local_state_); |
679 | 676 |
680 if (!pref->GetBoolean(prefs::kStabilitySessionEndCompleted)) { | 677 if (!local_state_->GetBoolean(prefs::kStabilitySessionEndCompleted)) { |
681 IncrementPrefValue(prefs::kStabilityIncompleteSessionEndCount); | 678 IncrementPrefValue(prefs::kStabilityIncompleteSessionEndCount); |
682 // This is marked false when we get a WM_ENDSESSION. | 679 // This is marked false when we get a WM_ENDSESSION. |
683 pref->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 680 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
684 } | 681 } |
685 | 682 |
686 // Call GetUptimes() for the first time, thus allowing all later calls | 683 // Call GetUptimes() for the first time, thus allowing all later calls |
687 // to record incremental uptimes accurately. | 684 // to record incremental uptimes accurately. |
688 base::TimeDelta ignored_uptime_parameter; | 685 base::TimeDelta ignored_uptime_parameter; |
689 base::TimeDelta startup_uptime; | 686 base::TimeDelta startup_uptime; |
690 GetUptimes(pref, &startup_uptime, &ignored_uptime_parameter); | 687 GetUptimes(local_state_, &startup_uptime, &ignored_uptime_parameter); |
691 DCHECK_EQ(0, startup_uptime.InMicroseconds()); | 688 DCHECK_EQ(0, startup_uptime.InMicroseconds()); |
692 // For backwards compatibility, leave this intact in case Omaha is checking | 689 // For backwards compatibility, leave this intact in case Omaha is checking |
693 // them. prefs::kStabilityLastTimestampSec may also be useless now. | 690 // them. prefs::kStabilityLastTimestampSec may also be useless now. |
694 // TODO(jar): Delete these if they have no uses. | 691 // TODO(jar): Delete these if they have no uses. |
695 pref->SetInt64(prefs::kStabilityLaunchTimeSec, Time::Now().ToTimeT()); | 692 local_state_->SetInt64(prefs::kStabilityLaunchTimeSec, Time::Now().ToTimeT()); |
696 | 693 |
697 // Bookkeeping for the uninstall metrics. | 694 // Bookkeeping for the uninstall metrics. |
698 IncrementLongPrefsValue(prefs::kUninstallLaunchCount); | 695 IncrementLongPrefsValue(prefs::kUninstallLaunchCount); |
699 | 696 |
700 // Kick off the process of saving the state (so the uptime numbers keep | 697 // Kick off the process of saving the state (so the uptime numbers keep |
701 // getting updated) every n minutes. | 698 // getting updated) every n minutes. |
702 ScheduleNextStateSave(); | 699 ScheduleNextStateSave(); |
703 } | 700 } |
704 | 701 |
705 // static | 702 // static |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 void MetricsService::ScheduleNextStateSave() { | 830 void MetricsService::ScheduleNextStateSave() { |
834 state_saver_factory_.InvalidateWeakPtrs(); | 831 state_saver_factory_.InvalidateWeakPtrs(); |
835 | 832 |
836 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 833 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
837 base::Bind(&MetricsService::SaveLocalState, | 834 base::Bind(&MetricsService::SaveLocalState, |
838 state_saver_factory_.GetWeakPtr()), | 835 state_saver_factory_.GetWeakPtr()), |
839 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); | 836 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); |
840 } | 837 } |
841 | 838 |
842 void MetricsService::SaveLocalState() { | 839 void MetricsService::SaveLocalState() { |
843 PrefService* pref = g_browser_process->local_state(); | 840 RecordCurrentState(local_state_); |
844 if (!pref) { | |
845 NOTREACHED(); | |
846 return; | |
847 } | |
848 | |
849 RecordCurrentState(pref); | |
850 | 841 |
851 // TODO(jar):110021 Does this run down the batteries???? | 842 // TODO(jar):110021 Does this run down the batteries???? |
852 ScheduleNextStateSave(); | 843 ScheduleNextStateSave(); |
853 } | 844 } |
854 | 845 |
855 | 846 |
856 //------------------------------------------------------------------------------ | 847 //------------------------------------------------------------------------------ |
857 // Recording control methods | 848 // Recording control methods |
858 | 849 |
859 void MetricsService::OpenNewLog() { | 850 void MetricsService::OpenNewLog() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 // Put incremental data (histogram deltas, and realtime stats deltas) at the | 895 // Put incremental data (histogram deltas, and realtime stats deltas) at the |
905 // end of all log transmissions (initial log handles this separately). | 896 // end of all log transmissions (initial log handles this separately). |
906 // RecordIncrementalStabilityElements only exists on the derived | 897 // RecordIncrementalStabilityElements only exists on the derived |
907 // MetricsLog class. | 898 // MetricsLog class. |
908 MetricsLog* current_log = | 899 MetricsLog* current_log = |
909 static_cast<MetricsLog*>(log_manager_.current_log()); | 900 static_cast<MetricsLog*>(log_manager_.current_log()); |
910 DCHECK(current_log); | 901 DCHECK(current_log); |
911 std::vector<variations::ActiveGroupId> synthetic_trials; | 902 std::vector<variations::ActiveGroupId> synthetic_trials; |
912 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 903 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
913 current_log->RecordEnvironment(metrics_providers_.get(), synthetic_trials); | 904 current_log->RecordEnvironment(metrics_providers_.get(), synthetic_trials); |
914 PrefService* pref = g_browser_process->local_state(); | |
915 base::TimeDelta incremental_uptime; | 905 base::TimeDelta incremental_uptime; |
916 base::TimeDelta uptime; | 906 base::TimeDelta uptime; |
917 GetUptimes(pref, &incremental_uptime, &uptime); | 907 GetUptimes(local_state_, &incremental_uptime, &uptime); |
918 current_log->RecordStabilityMetrics(metrics_providers_.get(), | 908 current_log->RecordStabilityMetrics(metrics_providers_.get(), |
919 incremental_uptime, uptime); | 909 incremental_uptime, uptime); |
920 | 910 |
921 RecordCurrentHistograms(); | 911 RecordCurrentHistograms(); |
922 current_log->RecordGeneralMetrics(metrics_providers_.get()); | 912 current_log->RecordGeneralMetrics(metrics_providers_.get()); |
923 | 913 |
924 log_manager_.FinishCurrentLog(); | 914 log_manager_.FinishCurrentLog(); |
925 } | 915 } |
926 | 916 |
927 void MetricsService::PushPendingLogsToPersistentStorage() { | 917 void MetricsService::PushPendingLogsToPersistentStorage() { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 default: | 1066 default: |
1077 NOTREACHED(); | 1067 NOTREACHED(); |
1078 return; | 1068 return; |
1079 } | 1069 } |
1080 | 1070 |
1081 DCHECK(log_manager_.has_staged_log()); | 1071 DCHECK(log_manager_.has_staged_log()); |
1082 } | 1072 } |
1083 | 1073 |
1084 void MetricsService::PrepareInitialStabilityLog() { | 1074 void MetricsService::PrepareInitialStabilityLog() { |
1085 DCHECK_EQ(INITIALIZED, state_); | 1075 DCHECK_EQ(INITIALIZED, state_); |
1086 PrefService* pref = g_browser_process->local_state(); | 1076 DCHECK_NE(0, local_state_->GetInteger(prefs::kStabilityCrashCount)); |
1087 DCHECK_NE(0, pref->GetInteger(prefs::kStabilityCrashCount)); | |
1088 | 1077 |
1089 scoped_ptr<MetricsLog> initial_stability_log( | 1078 scoped_ptr<MetricsLog> initial_stability_log( |
1090 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); | 1079 CreateLog(MetricsLog::INITIAL_STABILITY_LOG)); |
1091 | 1080 |
1092 // Do not call NotifyOnDidCreateMetricsLog here because the stability | 1081 // Do not call NotifyOnDidCreateMetricsLog here because the stability |
1093 // log describes stats from the _previous_ session. | 1082 // log describes stats from the _previous_ session. |
1094 | 1083 |
1095 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) | 1084 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) |
1096 return; | 1085 return; |
1097 | 1086 |
(...skipping 25 matching lines...) Expand all Loading... |
1123 } | 1112 } |
1124 | 1113 |
1125 void MetricsService::PrepareInitialMetricsLog() { | 1114 void MetricsService::PrepareInitialMetricsLog() { |
1126 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); | 1115 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); |
1127 initial_metrics_log_->set_hardware_class(hardware_class_); | 1116 initial_metrics_log_->set_hardware_class(hardware_class_); |
1128 | 1117 |
1129 std::vector<variations::ActiveGroupId> synthetic_trials; | 1118 std::vector<variations::ActiveGroupId> synthetic_trials; |
1130 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 1119 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
1131 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), | 1120 initial_metrics_log_->RecordEnvironment(metrics_providers_.get(), |
1132 synthetic_trials); | 1121 synthetic_trials); |
1133 PrefService* pref = g_browser_process->local_state(); | |
1134 base::TimeDelta incremental_uptime; | 1122 base::TimeDelta incremental_uptime; |
1135 base::TimeDelta uptime; | 1123 base::TimeDelta uptime; |
1136 GetUptimes(pref, &incremental_uptime, &uptime); | 1124 GetUptimes(local_state_, &incremental_uptime, &uptime); |
1137 | 1125 |
1138 // Histograms only get written to the current log, so make the new log current | 1126 // Histograms only get written to the current log, so make the new log current |
1139 // before writing them. | 1127 // before writing them. |
1140 log_manager_.PauseCurrentLog(); | 1128 log_manager_.PauseCurrentLog(); |
1141 log_manager_.BeginLoggingWithLog( | 1129 log_manager_.BeginLoggingWithLog( |
1142 initial_metrics_log_.PassAs<metrics::MetricsLogBase>()); | 1130 initial_metrics_log_.PassAs<metrics::MetricsLogBase>()); |
1143 | 1131 |
1144 // Note: Some stability providers may record stability stats via histograms, | 1132 // Note: Some stability providers may record stability stats via histograms, |
1145 // so this call has to be after BeginLoggingWithLog(). | 1133 // so this call has to be after BeginLoggingWithLog(). |
1146 MetricsLog* current_log = | 1134 MetricsLog* current_log = |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 if (state_ != SENDING_INITIAL_METRICS_LOG) { | 1296 if (state_ != SENDING_INITIAL_METRICS_LOG) { |
1309 scheduler_->UploadFinished(server_is_healthy, | 1297 scheduler_->UploadFinished(server_is_healthy, |
1310 log_manager_.has_unsent_logs()); | 1298 log_manager_.has_unsent_logs()); |
1311 } | 1299 } |
1312 | 1300 |
1313 if (server_is_healthy) | 1301 if (server_is_healthy) |
1314 client_->OnLogUploadComplete(); | 1302 client_->OnLogUploadComplete(); |
1315 } | 1303 } |
1316 | 1304 |
1317 void MetricsService::IncrementPrefValue(const char* path) { | 1305 void MetricsService::IncrementPrefValue(const char* path) { |
1318 PrefService* pref = g_browser_process->local_state(); | 1306 int value = local_state_->GetInteger(path); |
1319 DCHECK(pref); | 1307 local_state_->SetInteger(path, value + 1); |
1320 int value = pref->GetInteger(path); | |
1321 pref->SetInteger(path, value + 1); | |
1322 } | 1308 } |
1323 | 1309 |
1324 void MetricsService::IncrementLongPrefsValue(const char* path) { | 1310 void MetricsService::IncrementLongPrefsValue(const char* path) { |
1325 PrefService* pref = g_browser_process->local_state(); | 1311 int64 value = local_state_->GetInt64(path); |
1326 DCHECK(pref); | 1312 local_state_->SetInt64(path, value + 1); |
1327 int64 value = pref->GetInt64(path); | |
1328 pref->SetInt64(path, value + 1); | |
1329 } | 1313 } |
1330 | 1314 |
1331 bool MetricsService::UmaMetricsProperlyShutdown() { | 1315 bool MetricsService::UmaMetricsProperlyShutdown() { |
1332 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN || | 1316 CHECK(clean_shutdown_status_ == CLEANLY_SHUTDOWN || |
1333 clean_shutdown_status_ == NEED_TO_SHUTDOWN); | 1317 clean_shutdown_status_ == NEED_TO_SHUTDOWN); |
1334 return clean_shutdown_status_ == CLEANLY_SHUTDOWN; | 1318 return clean_shutdown_status_ == CLEANLY_SHUTDOWN; |
1335 } | 1319 } |
1336 | 1320 |
1337 void MetricsService::RegisterSyntheticFieldTrial( | 1321 void MetricsService::RegisterSyntheticFieldTrial( |
1338 const SyntheticTrialGroup& trial) { | 1322 const SyntheticTrialGroup& trial) { |
(...skipping 29 matching lines...) Expand all Loading... |
1368 synthetic_trials->clear(); | 1352 synthetic_trials->clear(); |
1369 const MetricsLog* current_log = | 1353 const MetricsLog* current_log = |
1370 static_cast<const MetricsLog*>(log_manager_.current_log()); | 1354 static_cast<const MetricsLog*>(log_manager_.current_log()); |
1371 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { | 1355 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { |
1372 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) | 1356 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) |
1373 synthetic_trials->push_back(synthetic_trial_groups_[i].id); | 1357 synthetic_trials->push_back(synthetic_trial_groups_[i].id); |
1374 } | 1358 } |
1375 } | 1359 } |
1376 | 1360 |
1377 scoped_ptr<MetricsLog> MetricsService::CreateLog(MetricsLog::LogType log_type) { | 1361 scoped_ptr<MetricsLog> MetricsService::CreateLog(MetricsLog::LogType log_type) { |
1378 return make_scoped_ptr(new MetricsLog( | 1362 return make_scoped_ptr(new MetricsLog(state_manager_->client_id(), |
1379 state_manager_->client_id(), session_id_, log_type, client_)); | 1363 session_id_, |
| 1364 log_type, |
| 1365 client_, |
| 1366 local_state_)); |
1380 } | 1367 } |
1381 | 1368 |
1382 void MetricsService::RecordCurrentHistograms() { | 1369 void MetricsService::RecordCurrentHistograms() { |
1383 DCHECK(log_manager_.current_log()); | 1370 DCHECK(log_manager_.current_log()); |
1384 histogram_snapshot_manager_.PrepareDeltas( | 1371 histogram_snapshot_manager_.PrepareDeltas( |
1385 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); | 1372 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); |
1386 } | 1373 } |
1387 | 1374 |
1388 void MetricsService::RecordCurrentStabilityHistograms() { | 1375 void MetricsService::RecordCurrentStabilityHistograms() { |
1389 DCHECK(log_manager_.current_log()); | 1376 DCHECK(log_manager_.current_log()); |
1390 histogram_snapshot_manager_.PrepareDeltas( | 1377 histogram_snapshot_manager_.PrepareDeltas( |
1391 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); | 1378 base::Histogram::kNoFlags, base::Histogram::kUmaStabilityHistogramFlag); |
1392 } | 1379 } |
1393 | 1380 |
1394 void MetricsService::LogCleanShutdown() { | 1381 void MetricsService::LogCleanShutdown() { |
1395 // Redundant hack to write pref ASAP. | 1382 // Redundant hack to write pref ASAP. |
1396 MarkAppCleanShutdownAndCommit(); | 1383 MarkAppCleanShutdownAndCommit(local_state_); |
1397 | 1384 |
1398 // Redundant setting to assure that we always reset this value at shutdown | 1385 // Redundant setting to assure that we always reset this value at shutdown |
1399 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1386 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
1400 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1387 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
1401 | 1388 |
1402 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); | 1389 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); |
1403 PrefService* pref = g_browser_process->local_state(); | 1390 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
1404 pref->SetInteger(prefs::kStabilityExecutionPhase, | 1391 MetricsService::SHUTDOWN_COMPLETE); |
1405 MetricsService::SHUTDOWN_COMPLETE); | |
1406 } | 1392 } |
1407 | 1393 |
1408 void MetricsService::LogPluginLoadingError(const base::FilePath& plugin_path) { | 1394 void MetricsService::LogPluginLoadingError(const base::FilePath& plugin_path) { |
1409 #if defined(ENABLE_PLUGINS) | 1395 #if defined(ENABLE_PLUGINS) |
1410 // TODO(asvitkine): Move this out of here. | 1396 // TODO(asvitkine): Move this out of here. |
1411 plugin_metrics_provider_->LogPluginLoadingError(plugin_path); | 1397 plugin_metrics_provider_->LogPluginLoadingError(plugin_path); |
1412 #endif | 1398 #endif |
1413 } | 1399 } |
1414 | 1400 |
1415 bool MetricsService::ShouldLogEvents() { | 1401 bool MetricsService::ShouldLogEvents() { |
1416 // We simply don't log events to UMA if there is a single incognito | 1402 // We simply don't log events to UMA if there is a single incognito |
1417 // session visible. The problem is that we always notify using the orginal | 1403 // session visible. The problem is that we always notify using the orginal |
1418 // profile in order to simplify notification processing. | 1404 // profile in order to simplify notification processing. |
1419 return !client_->IsOffTheRecordSessionActive(); | 1405 return !client_->IsOffTheRecordSessionActive(); |
1420 } | 1406 } |
1421 | 1407 |
1422 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | 1408 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
1423 DCHECK(IsSingleThreaded()); | 1409 DCHECK(IsSingleThreaded()); |
1424 | 1410 local_state_->SetBoolean(path, value); |
1425 PrefService* pref = g_browser_process->local_state(); | 1411 RecordCurrentState(local_state_); |
1426 DCHECK(pref); | |
1427 | |
1428 pref->SetBoolean(path, value); | |
1429 RecordCurrentState(pref); | |
1430 } | 1412 } |
1431 | 1413 |
1432 void MetricsService::RecordCurrentState(PrefService* pref) { | 1414 void MetricsService::RecordCurrentState(PrefService* pref) { |
1433 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); | 1415 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); |
1434 | 1416 |
1435 #if defined(ENABLE_PLUGINS) | 1417 #if defined(ENABLE_PLUGINS) |
1436 plugin_metrics_provider_->RecordPluginChanges(); | 1418 plugin_metrics_provider_->RecordPluginChanges(); |
1437 #endif | 1419 #endif |
1438 } | 1420 } |
OLD | NEW |