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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 // Since |abs(STATUS_GUARD_PAGE_VIOLATION) == MAX_INT| it causes problems in | 313 // Since |abs(STATUS_GUARD_PAGE_VIOLATION) == MAX_INT| it causes problems in |
314 // histograms.cc. Solve this by remapping it to a smaller value, which | 314 // histograms.cc. Solve this by remapping it to a smaller value, which |
315 // hopefully doesn't conflict with other codes. | 315 // hopefully doesn't conflict with other codes. |
316 if (exit_code == STATUS_GUARD_PAGE_VIOLATION) | 316 if (exit_code == STATUS_GUARD_PAGE_VIOLATION) |
317 return 0x1FCF7EC3; // Randomly picked number. | 317 return 0x1FCF7EC3; // Randomly picked number. |
318 #endif | 318 #endif |
319 | 319 |
320 return std::abs(exit_code); | 320 return std::abs(exit_code); |
321 } | 321 } |
322 | 322 |
323 void MarkAppCleanShutdownAndCommit() { | 323 void MarkAppCleanShutdownAndCommit(PrefService* local_state) { |
324 PrefService* pref = g_browser_process->local_state(); | 324 local_state->SetBoolean(prefs::kStabilityExitedCleanly, true); |
325 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); | 325 local_state->SetInteger(prefs::kStabilityExecutionPhase, |
326 pref->SetInteger(prefs::kStabilityExecutionPhase, | 326 MetricsService::SHUTDOWN_COMPLETE); |
327 MetricsService::SHUTDOWN_COMPLETE); | |
328 // Start writing right away (write happens on a different thread). | 327 // Start writing right away (write happens on a different thread). |
329 pref->CommitPendingWrite(); | 328 local_state->CommitPendingWrite(); |
330 } | 329 } |
331 | 330 |
332 } // namespace | 331 } // namespace |
333 | 332 |
334 | 333 |
335 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) { | 334 SyntheticTrialGroup::SyntheticTrialGroup(uint32 trial, uint32 group) { |
336 id.name = trial; | 335 id.name = trial; |
337 id.group = group; | 336 id.group = group; |
338 } | 337 } |
339 | 338 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); | 451 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); |
453 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); | 452 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); |
454 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); | 453 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); |
455 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); | 454 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); |
456 | 455 |
457 #if defined(OS_ANDROID) | 456 #if defined(OS_ANDROID) |
458 RegisterPrefsAndroid(registry); | 457 RegisterPrefsAndroid(registry); |
459 #endif // defined(OS_ANDROID) | 458 #endif // defined(OS_ANDROID) |
460 } | 459 } |
461 | 460 |
462 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager) | 461 MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, |
463 : MetricsServiceBase(g_browser_process->local_state(), | 462 PrefService* local_state) |
464 kUploadLogAvoidRetransmitSize), | 463 : MetricsServiceBase(local_state, kUploadLogAvoidRetransmitSize), |
465 state_manager_(state_manager), | 464 state_manager_(state_manager), |
465 local_state_(local_state), | |
466 recording_active_(false), | 466 recording_active_(false), |
467 reporting_active_(false), | 467 reporting_active_(false), |
468 test_mode_active_(false), | 468 test_mode_active_(false), |
469 state_(INITIALIZED), | 469 state_(INITIALIZED), |
470 has_initial_stability_log_(false), | 470 has_initial_stability_log_(false), |
471 idle_since_last_transmission_(false), | 471 idle_since_last_transmission_(false), |
472 session_id_(-1), | 472 session_id_(-1), |
473 next_window_id_(0), | 473 next_window_id_(0), |
474 self_ptr_factory_(this), | 474 self_ptr_factory_(this), |
475 state_saver_factory_(this), | 475 state_saver_factory_(this), |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
718 | 718 |
719 void MetricsService::RecordCompletedSessionEnd() { | 719 void MetricsService::RecordCompletedSessionEnd() { |
720 LogCleanShutdown(); | 720 LogCleanShutdown(); |
721 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); | 721 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); |
722 } | 722 } |
723 | 723 |
724 #if defined(OS_ANDROID) || defined(OS_IOS) | 724 #if defined(OS_ANDROID) || defined(OS_IOS) |
725 void MetricsService::OnAppEnterBackground() { | 725 void MetricsService::OnAppEnterBackground() { |
726 scheduler_->Stop(); | 726 scheduler_->Stop(); |
727 | 727 |
728 MarkAppCleanShutdownAndCommit(); | 728 MarkAppCleanShutdownAndCommit(local_state_); |
729 | 729 |
730 // At this point, there's no way of knowing when the process will be | 730 // At this point, there's no way of knowing when the process will be |
731 // killed, so this has to be treated similar to a shutdown, closing and | 731 // killed, so this has to be treated similar to a shutdown, closing and |
732 // persisting all logs. Unlinke a shutdown, the state is primed to be ready | 732 // persisting all logs. Unlinke a shutdown, the state is primed to be ready |
733 // to continue logging and uploading if the process does return. | 733 // to continue logging and uploading if the process does return. |
734 if (recording_active() && state_ >= SENDING_INITIAL_STABILITY_LOG) { | 734 if (recording_active() && state_ >= SENDING_INITIAL_STABILITY_LOG) { |
735 PushPendingLogsToPersistentStorage(); | 735 PushPendingLogsToPersistentStorage(); |
736 // Persisting logs closes the current log, so start recording a new log | 736 // Persisting logs closes the current log, so start recording a new log |
737 // immediately to capture any background work that might be done before the | 737 // immediately to capture any background work that might be done before the |
738 // process is killed. | 738 // process is killed. |
739 OpenNewLog(); | 739 OpenNewLog(); |
740 } | 740 } |
741 } | 741 } |
742 | 742 |
743 void MetricsService::OnAppEnterForeground() { | 743 void MetricsService::OnAppEnterForeground() { |
744 PrefService* pref = g_browser_process->local_state(); | 744 local_state_->SetBoolean(prefs::kStabilityExitedCleanly, false); |
745 pref->SetBoolean(prefs::kStabilityExitedCleanly, false); | |
746 | |
747 StartSchedulerIfNecessary(); | 745 StartSchedulerIfNecessary(); |
748 } | 746 } |
749 #else | 747 #else |
750 void MetricsService::LogNeedForCleanShutdown() { | 748 void MetricsService::LogNeedForCleanShutdown(PrefService* local_state) { |
751 PrefService* pref = g_browser_process->local_state(); | 749 local_state->SetBoolean(prefs::kStabilityExitedCleanly, false); |
752 pref->SetBoolean(prefs::kStabilityExitedCleanly, false); | |
753 // Redundant setting to be sure we call for a clean shutdown. | 750 // Redundant setting to be sure we call for a clean shutdown. |
754 clean_shutdown_status_ = NEED_TO_SHUTDOWN; | 751 clean_shutdown_status_ = NEED_TO_SHUTDOWN; |
755 } | 752 } |
756 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 753 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
757 | 754 |
758 // static | 755 // static |
759 void MetricsService::SetExecutionPhase(ExecutionPhase execution_phase) { | 756 void MetricsService::SetExecutionPhase(ExecutionPhase execution_phase, |
757 PrefService* local_state) { | |
760 execution_phase_ = execution_phase; | 758 execution_phase_ = execution_phase; |
761 PrefService* pref = g_browser_process->local_state(); | 759 local_state->SetInteger(prefs::kStabilityExecutionPhase, execution_phase_); |
762 pref->SetInteger(prefs::kStabilityExecutionPhase, execution_phase_); | |
763 } | 760 } |
764 | 761 |
765 void MetricsService::RecordBreakpadRegistration(bool success) { | 762 void MetricsService::RecordBreakpadRegistration(bool success) { |
766 if (!success) | 763 if (!success) |
767 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationFail); | 764 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationFail); |
768 else | 765 else |
769 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationSuccess); | 766 IncrementPrefValue(prefs::kStabilityBreakpadRegistrationSuccess); |
770 } | 767 } |
771 | 768 |
772 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { | 769 void MetricsService::RecordBreakpadHasDebugger(bool has_debugger) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 void MetricsService::InitializeMetricsState() { | 836 void MetricsService::InitializeMetricsState() { |
840 #if defined(OS_POSIX) | 837 #if defined(OS_POSIX) |
841 network_stats_server_ = chrome_common_net::kEchoTestServerLocation; | 838 network_stats_server_ = chrome_common_net::kEchoTestServerLocation; |
842 http_pipelining_test_server_ = chrome_common_net::kPipelineTestServerBaseUrl; | 839 http_pipelining_test_server_ = chrome_common_net::kPipelineTestServerBaseUrl; |
843 #else | 840 #else |
844 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 841 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
845 network_stats_server_ = dist->GetNetworkStatsServer(); | 842 network_stats_server_ = dist->GetNetworkStatsServer(); |
846 http_pipelining_test_server_ = dist->GetHttpPipeliningTestServer(); | 843 http_pipelining_test_server_ = dist->GetHttpPipeliningTestServer(); |
847 #endif | 844 #endif |
848 | 845 |
849 PrefService* pref = g_browser_process->local_state(); | 846 DCHECK(local_state_); |
850 DCHECK(pref); | |
851 | 847 |
852 pref->SetString(prefs::kStabilityStatsVersion, | 848 local_state_->SetString(prefs::kStabilityStatsVersion, |
853 MetricsLog::GetVersionString()); | 849 MetricsLog::GetVersionString()); |
854 pref->SetInt64(prefs::kStabilityStatsBuildTime, MetricsLog::GetBuildTime()); | 850 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, |
851 MetricsLog::GetBuildTime()); | |
855 | 852 |
856 session_id_ = pref->GetInteger(prefs::kMetricsSessionID); | 853 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID); |
857 | 854 |
858 #if defined(OS_ANDROID) | 855 #if defined(OS_ANDROID) |
859 LogAndroidStabilityToPrefs(pref); | 856 LogAndroidStabilityToPrefs(pref); |
860 #endif // defined(OS_ANDROID) | 857 #endif // defined(OS_ANDROID) |
861 | 858 |
862 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { | 859 if (!local_state_->GetBoolean(prefs::kStabilityExitedCleanly)) { |
863 IncrementPrefValue(prefs::kStabilityCrashCount); | 860 IncrementPrefValue(prefs::kStabilityCrashCount); |
864 // Reset flag, and wait until we call LogNeedForCleanShutdown() before | 861 // Reset flag, and wait until we call LogNeedForCleanShutdown() before |
865 // monitoring. | 862 // monitoring. |
866 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); | 863 local_state_->SetBoolean(prefs::kStabilityExitedCleanly, true); |
867 | 864 |
868 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 865 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
869 // the registry. | 866 // the registry. |
870 int execution_phase = pref->GetInteger(prefs::kStabilityExecutionPhase); | 867 int execution_phase = |
868 local_state_->GetInteger(prefs::kStabilityExecutionPhase); | |
871 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 869 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
872 execution_phase); | 870 execution_phase); |
873 | 871 |
874 // If the previous session didn't exit cleanly, then prepare an initial | 872 // If the previous session didn't exit cleanly, then prepare an initial |
875 // stability log if UMA is enabled. | 873 // stability log if UMA is enabled. |
876 if (state_manager_->IsMetricsReportingEnabled()) | 874 if (state_manager_->IsMetricsReportingEnabled()) |
877 PrepareInitialStabilityLog(); | 875 PrepareInitialStabilityLog(); |
878 } | 876 } |
879 | 877 |
880 // Update session ID. | 878 // Update session ID. |
881 ++session_id_; | 879 ++session_id_; |
882 pref->SetInteger(prefs::kMetricsSessionID, session_id_); | 880 local_state_->SetInteger(prefs::kMetricsSessionID, session_id_); |
883 | 881 |
884 // Stability bookkeeping | 882 // Stability bookkeeping |
885 IncrementPrefValue(prefs::kStabilityLaunchCount); | 883 IncrementPrefValue(prefs::kStabilityLaunchCount); |
886 | 884 |
887 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); | 885 DCHECK_EQ(UNINITIALIZED_PHASE, execution_phase_); |
888 SetExecutionPhase(START_METRICS_RECORDING); | 886 SetExecutionPhase(START_METRICS_RECORDING, local_state_); |
889 | 887 |
890 #if defined(OS_WIN) | 888 #if defined(OS_WIN) |
891 CountBrowserCrashDumpAttempts(); | 889 CountBrowserCrashDumpAttempts(); |
892 #endif // defined(OS_WIN) | 890 #endif // defined(OS_WIN) |
893 | 891 |
894 if (!pref->GetBoolean(prefs::kStabilitySessionEndCompleted)) { | 892 if (!local_state_->GetBoolean(prefs::kStabilitySessionEndCompleted)) { |
895 IncrementPrefValue(prefs::kStabilityIncompleteSessionEndCount); | 893 IncrementPrefValue(prefs::kStabilityIncompleteSessionEndCount); |
896 // This is marked false when we get a WM_ENDSESSION. | 894 // This is marked false when we get a WM_ENDSESSION. |
897 pref->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 895 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
898 } | 896 } |
899 | 897 |
900 // Call GetUptimes() for the first time, thus allowing all later calls | 898 // Call GetUptimes() for the first time, thus allowing all later calls |
901 // to record incremental uptimes accurately. | 899 // to record incremental uptimes accurately. |
902 base::TimeDelta ignored_uptime_parameter; | 900 base::TimeDelta ignored_uptime_parameter; |
903 base::TimeDelta startup_uptime; | 901 base::TimeDelta startup_uptime; |
904 GetUptimes(pref, &startup_uptime, &ignored_uptime_parameter); | 902 GetUptimes(local_state_, &startup_uptime, &ignored_uptime_parameter); |
905 DCHECK_EQ(0, startup_uptime.InMicroseconds()); | 903 DCHECK_EQ(0, startup_uptime.InMicroseconds()); |
906 // For backwards compatibility, leave this intact in case Omaha is checking | 904 // For backwards compatibility, leave this intact in case Omaha is checking |
907 // them. prefs::kStabilityLastTimestampSec may also be useless now. | 905 // them. prefs::kStabilityLastTimestampSec may also be useless now. |
908 // TODO(jar): Delete these if they have no uses. | 906 // TODO(jar): Delete these if they have no uses. |
909 pref->SetInt64(prefs::kStabilityLaunchTimeSec, Time::Now().ToTimeT()); | 907 local_state_->SetInt64(prefs::kStabilityLaunchTimeSec, Time::Now().ToTimeT()); |
910 | 908 |
911 // Bookkeeping for the uninstall metrics. | 909 // Bookkeeping for the uninstall metrics. |
912 IncrementLongPrefsValue(prefs::kUninstallLaunchCount); | 910 IncrementLongPrefsValue(prefs::kUninstallLaunchCount); |
913 | 911 |
914 // Get stats on use of command line. | 912 // Get stats on use of command line. |
915 const CommandLine* command_line(CommandLine::ForCurrentProcess()); | 913 const CommandLine* command_line(CommandLine::ForCurrentProcess()); |
916 size_t common_commands = 0; | 914 size_t common_commands = 0; |
917 if (command_line->HasSwitch(switches::kUserDataDir)) { | 915 if (command_line->HasSwitch(switches::kUserDataDir)) { |
918 ++common_commands; | 916 ++common_commands; |
919 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineDatDirCount", 1); | 917 UMA_HISTOGRAM_COUNTS_100("Chrome.CommandLineDatDirCount", 1); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 } | 1027 } |
1030 | 1028 |
1031 void MetricsService::ReceivedProfilerData( | 1029 void MetricsService::ReceivedProfilerData( |
1032 const tracked_objects::ProcessDataSnapshot& process_data, | 1030 const tracked_objects::ProcessDataSnapshot& process_data, |
1033 int process_type) { | 1031 int process_type) { |
1034 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 1032 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
1035 | 1033 |
1036 // Upon the first callback, create the initial log so that we can immediately | 1034 // Upon the first callback, create the initial log so that we can immediately |
1037 // save the profiler data. | 1035 // save the profiler data. |
1038 if (!initial_metrics_log_.get()) { | 1036 if (!initial_metrics_log_.get()) { |
1039 initial_metrics_log_.reset( | 1037 initial_metrics_log_.reset(new MetricsLog(state_manager_->client_id(), |
1040 new MetricsLog(state_manager_->client_id(), session_id_, | 1038 session_id_, |
1041 MetricsLog::ONGOING_LOG)); | 1039 MetricsLog::ONGOING_LOG, |
1040 local_state_)); | |
1042 NotifyOnDidCreateMetricsLog(); | 1041 NotifyOnDidCreateMetricsLog(); |
1043 } | 1042 } |
1044 | 1043 |
1045 initial_metrics_log_->RecordProfilerData(process_data, process_type); | 1044 initial_metrics_log_->RecordProfilerData(process_data, process_type); |
1046 } | 1045 } |
1047 | 1046 |
1048 void MetricsService::FinishedReceivingProfilerData() { | 1047 void MetricsService::FinishedReceivingProfilerData() { |
1049 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 1048 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
1050 state_ = INIT_TASK_DONE; | 1049 state_ = INIT_TASK_DONE; |
1051 scheduler_->InitTaskComplete(); | 1050 scheduler_->InitTaskComplete(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1095 void MetricsService::ScheduleNextStateSave() { | 1094 void MetricsService::ScheduleNextStateSave() { |
1096 state_saver_factory_.InvalidateWeakPtrs(); | 1095 state_saver_factory_.InvalidateWeakPtrs(); |
1097 | 1096 |
1098 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1097 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
1099 base::Bind(&MetricsService::SaveLocalState, | 1098 base::Bind(&MetricsService::SaveLocalState, |
1100 state_saver_factory_.GetWeakPtr()), | 1099 state_saver_factory_.GetWeakPtr()), |
1101 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); | 1100 base::TimeDelta::FromMinutes(kSaveStateIntervalMinutes)); |
1102 } | 1101 } |
1103 | 1102 |
1104 void MetricsService::SaveLocalState() { | 1103 void MetricsService::SaveLocalState() { |
1105 PrefService* pref = g_browser_process->local_state(); | 1104 if (!local_state_) { |
Alexei Svitkine (slow)
2014/05/19 13:13:54
Nit: Shouldn't be possible - just remove this if.
blundell
2014/05/19 13:49:28
Done.
| |
1106 if (!pref) { | |
1107 NOTREACHED(); | 1105 NOTREACHED(); |
1108 return; | 1106 return; |
1109 } | 1107 } |
1110 | 1108 |
1111 RecordCurrentState(pref); | 1109 RecordCurrentState(local_state_); |
1112 | 1110 |
1113 // TODO(jar):110021 Does this run down the batteries???? | 1111 // TODO(jar):110021 Does this run down the batteries???? |
1114 ScheduleNextStateSave(); | 1112 ScheduleNextStateSave(); |
1115 } | 1113 } |
1116 | 1114 |
1117 | 1115 |
1118 //------------------------------------------------------------------------------ | 1116 //------------------------------------------------------------------------------ |
1119 // Recording control methods | 1117 // Recording control methods |
1120 | 1118 |
1121 void MetricsService::OpenNewLog() { | 1119 void MetricsService::OpenNewLog() { |
1122 DCHECK(!log_manager_.current_log()); | 1120 DCHECK(!log_manager_.current_log()); |
1123 | 1121 |
1124 log_manager_.BeginLoggingWithLog( | 1122 log_manager_.BeginLoggingWithLog(new MetricsLog(state_manager_->client_id(), |
1125 new MetricsLog(state_manager_->client_id(), session_id_, | 1123 session_id_, |
1126 MetricsLog::ONGOING_LOG)); | 1124 MetricsLog::ONGOING_LOG, |
1125 local_state_)); | |
1127 NotifyOnDidCreateMetricsLog(); | 1126 NotifyOnDidCreateMetricsLog(); |
1128 if (state_ == INITIALIZED) { | 1127 if (state_ == INITIALIZED) { |
1129 // We only need to schedule that run once. | 1128 // We only need to schedule that run once. |
1130 state_ = INIT_TASK_SCHEDULED; | 1129 state_ = INIT_TASK_SCHEDULED; |
1131 | 1130 |
1132 // Schedules a task on the file thread for execution of slower | 1131 // Schedules a task on the file thread for execution of slower |
1133 // initialization steps (such as plugin list generation) necessary | 1132 // initialization steps (such as plugin list generation) necessary |
1134 // for sending the initial log. This avoids blocking the main UI | 1133 // for sending the initial log. This avoids blocking the main UI |
1135 // thread. | 1134 // thread. |
1136 BrowserThread::PostDelayedTask( | 1135 BrowserThread::PostDelayedTask( |
(...skipping 26 matching lines...) Expand all Loading... | |
1163 // end of all log transmissions (initial log handles this separately). | 1162 // end of all log transmissions (initial log handles this separately). |
1164 // RecordIncrementalStabilityElements only exists on the derived | 1163 // RecordIncrementalStabilityElements only exists on the derived |
1165 // MetricsLog class. | 1164 // MetricsLog class. |
1166 MetricsLog* current_log = | 1165 MetricsLog* current_log = |
1167 static_cast<MetricsLog*>(log_manager_.current_log()); | 1166 static_cast<MetricsLog*>(log_manager_.current_log()); |
1168 DCHECK(current_log); | 1167 DCHECK(current_log); |
1169 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; | 1168 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; |
1170 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 1169 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
1171 current_log->RecordEnvironment(plugins_, google_update_metrics_, | 1170 current_log->RecordEnvironment(plugins_, google_update_metrics_, |
1172 synthetic_trials); | 1171 synthetic_trials); |
1173 PrefService* pref = g_browser_process->local_state(); | |
1174 base::TimeDelta incremental_uptime; | 1172 base::TimeDelta incremental_uptime; |
1175 base::TimeDelta uptime; | 1173 base::TimeDelta uptime; |
1176 GetUptimes(pref, &incremental_uptime, &uptime); | 1174 GetUptimes(local_state_, &incremental_uptime, &uptime); |
1177 current_log->RecordStabilityMetrics(incremental_uptime, uptime); | 1175 current_log->RecordStabilityMetrics(incremental_uptime, uptime); |
1178 | 1176 |
1179 RecordCurrentHistograms(); | 1177 RecordCurrentHistograms(); |
1180 | 1178 |
1181 log_manager_.FinishCurrentLog(); | 1179 log_manager_.FinishCurrentLog(); |
1182 } | 1180 } |
1183 | 1181 |
1184 void MetricsService::PushPendingLogsToPersistentStorage() { | 1182 void MetricsService::PushPendingLogsToPersistentStorage() { |
1185 if (state_ < SENDING_INITIAL_STABILITY_LOG) | 1183 if (state_ < SENDING_INITIAL_STABILITY_LOG) |
1186 return; // We didn't and still don't have time to get plugin list etc. | 1184 return; // We didn't and still don't have time to get plugin list etc. |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1409 default: | 1407 default: |
1410 NOTREACHED(); | 1408 NOTREACHED(); |
1411 return; | 1409 return; |
1412 } | 1410 } |
1413 | 1411 |
1414 DCHECK(log_manager_.has_staged_log()); | 1412 DCHECK(log_manager_.has_staged_log()); |
1415 } | 1413 } |
1416 | 1414 |
1417 void MetricsService::PrepareInitialStabilityLog() { | 1415 void MetricsService::PrepareInitialStabilityLog() { |
1418 DCHECK_EQ(INITIALIZED, state_); | 1416 DCHECK_EQ(INITIALIZED, state_); |
1419 PrefService* pref = g_browser_process->local_state(); | 1417 DCHECK_NE(0, local_state_->GetInteger(prefs::kStabilityCrashCount)); |
1420 DCHECK_NE(0, pref->GetInteger(prefs::kStabilityCrashCount)); | |
1421 | 1418 |
1422 scoped_ptr<MetricsLog> initial_stability_log( | 1419 scoped_ptr<MetricsLog> initial_stability_log( |
1423 new MetricsLog(state_manager_->client_id(), session_id_, | 1420 new MetricsLog(state_manager_->client_id(), |
1424 MetricsLog::INITIAL_STABILITY_LOG)); | 1421 session_id_, |
1422 MetricsLog::INITIAL_STABILITY_LOG, | |
1423 local_state_)); | |
1425 | 1424 |
1426 // Do not call NotifyOnDidCreateMetricsLog here because the stability | 1425 // Do not call NotifyOnDidCreateMetricsLog here because the stability |
1427 // log describes stats from the _previous_ session. | 1426 // log describes stats from the _previous_ session. |
1428 | 1427 |
1429 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) | 1428 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) |
1430 return; | 1429 return; |
1431 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), | 1430 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), |
1432 base::TimeDelta()); | 1431 base::TimeDelta()); |
1433 log_manager_.LoadPersistedUnsentLogs(); | 1432 log_manager_.LoadPersistedUnsentLogs(); |
1434 | 1433 |
(...skipping 14 matching lines...) Expand all Loading... | |
1449 } | 1448 } |
1450 | 1449 |
1451 void MetricsService::PrepareInitialMetricsLog() { | 1450 void MetricsService::PrepareInitialMetricsLog() { |
1452 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); | 1451 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); |
1453 initial_metrics_log_->set_hardware_class(hardware_class_); | 1452 initial_metrics_log_->set_hardware_class(hardware_class_); |
1454 | 1453 |
1455 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; | 1454 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; |
1456 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 1455 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
1457 initial_metrics_log_->RecordEnvironment(plugins_, google_update_metrics_, | 1456 initial_metrics_log_->RecordEnvironment(plugins_, google_update_metrics_, |
1458 synthetic_trials); | 1457 synthetic_trials); |
1459 PrefService* pref = g_browser_process->local_state(); | |
1460 base::TimeDelta incremental_uptime; | 1458 base::TimeDelta incremental_uptime; |
1461 base::TimeDelta uptime; | 1459 base::TimeDelta uptime; |
1462 GetUptimes(pref, &incremental_uptime, &uptime); | 1460 GetUptimes(local_state_, &incremental_uptime, &uptime); |
1463 initial_metrics_log_->RecordStabilityMetrics(incremental_uptime, uptime); | 1461 initial_metrics_log_->RecordStabilityMetrics(incremental_uptime, uptime); |
1464 | 1462 |
1465 // Histograms only get written to the current log, so make the new log current | 1463 // Histograms only get written to the current log, so make the new log current |
1466 // before writing them. | 1464 // before writing them. |
1467 log_manager_.PauseCurrentLog(); | 1465 log_manager_.PauseCurrentLog(); |
1468 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release()); | 1466 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release()); |
1469 #if defined(OS_ANDROID) | 1467 #if defined(OS_ANDROID) |
1470 ConvertAndroidStabilityPrefsToHistograms(pref); | 1468 ConvertAndroidStabilityPrefsToHistograms(pref); |
1471 #endif // defined(OS_ANDROID) | 1469 #endif // defined(OS_ANDROID) |
1472 RecordCurrentHistograms(); | 1470 RecordCurrentHistograms(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1635 chrome_browser_net::CollectNetworkStats(network_stats_server_, io_thread); | 1633 chrome_browser_net::CollectNetworkStats(network_stats_server_, io_thread); |
1636 chrome_browser_net::CollectPipeliningCapabilityStatsOnUIThread( | 1634 chrome_browser_net::CollectPipeliningCapabilityStatsOnUIThread( |
1637 http_pipelining_test_server_, io_thread); | 1635 http_pipelining_test_server_, io_thread); |
1638 #if defined(OS_WIN) | 1636 #if defined(OS_WIN) |
1639 chrome::CollectTimeTicksStats(); | 1637 chrome::CollectTimeTicksStats(); |
1640 #endif | 1638 #endif |
1641 } | 1639 } |
1642 } | 1640 } |
1643 | 1641 |
1644 void MetricsService::IncrementPrefValue(const char* path) { | 1642 void MetricsService::IncrementPrefValue(const char* path) { |
1645 PrefService* pref = g_browser_process->local_state(); | 1643 DCHECK(local_state_); |
1646 DCHECK(pref); | 1644 int value = local_state_->GetInteger(path); |
1647 int value = pref->GetInteger(path); | 1645 local_state_->SetInteger(path, value + 1); |
1648 pref->SetInteger(path, value + 1); | |
1649 } | 1646 } |
1650 | 1647 |
1651 void MetricsService::IncrementLongPrefsValue(const char* path) { | 1648 void MetricsService::IncrementLongPrefsValue(const char* path) { |
1652 PrefService* pref = g_browser_process->local_state(); | 1649 DCHECK(local_state_); |
1653 DCHECK(pref); | 1650 int64 value = local_state_->GetInt64(path); |
1654 int64 value = pref->GetInt64(path); | 1651 local_state_->SetInt64(path, value + 1); |
1655 pref->SetInt64(path, value + 1); | |
1656 } | 1652 } |
1657 | 1653 |
1658 void MetricsService::LogLoadStarted(content::WebContents* web_contents) { | 1654 void MetricsService::LogLoadStarted(content::WebContents* web_contents) { |
1659 content::RecordAction(base::UserMetricsAction("PageLoad")); | 1655 content::RecordAction(base::UserMetricsAction("PageLoad")); |
1660 HISTOGRAM_ENUMERATION("Chrome.UmaPageloadCounter", 1, 2); | 1656 HISTOGRAM_ENUMERATION("Chrome.UmaPageloadCounter", 1, 2); |
1661 IncrementPrefValue(prefs::kStabilityPageLoadCount); | 1657 IncrementPrefValue(prefs::kStabilityPageLoadCount); |
1662 IncrementLongPrefsValue(prefs::kUninstallMetricsPageLoadCount); | 1658 IncrementLongPrefsValue(prefs::kUninstallMetricsPageLoadCount); |
1663 // We need to save the prefs, as page load count is a critical stat, and it | 1659 // We need to save the prefs, as page load count is a critical stat, and it |
1664 // might be lost due to a crash :-(. | 1660 // might be lost due to a crash :-(. |
1665 } | 1661 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1733 const MetricsLog* current_log = | 1729 const MetricsLog* current_log = |
1734 static_cast<const MetricsLog*>(log_manager_.current_log()); | 1730 static_cast<const MetricsLog*>(log_manager_.current_log()); |
1735 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { | 1731 for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) { |
1736 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) | 1732 if (synthetic_trial_groups_[i].start_time <= current_log->creation_time()) |
1737 synthetic_trials->push_back(synthetic_trial_groups_[i].id); | 1733 synthetic_trials->push_back(synthetic_trial_groups_[i].id); |
1738 } | 1734 } |
1739 } | 1735 } |
1740 | 1736 |
1741 void MetricsService::LogCleanShutdown() { | 1737 void MetricsService::LogCleanShutdown() { |
1742 // Redundant hack to write pref ASAP. | 1738 // Redundant hack to write pref ASAP. |
1743 MarkAppCleanShutdownAndCommit(); | 1739 MarkAppCleanShutdownAndCommit(local_state_); |
1744 | 1740 |
1745 // Redundant setting to assure that we always reset this value at shutdown | 1741 // Redundant setting to assure that we always reset this value at shutdown |
1746 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1742 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
1747 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1743 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
1748 | 1744 |
1749 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); | 1745 RecordBooleanPrefValue(prefs::kStabilityExitedCleanly, true); |
1750 PrefService* pref = g_browser_process->local_state(); | 1746 local_state_->SetInteger(prefs::kStabilityExecutionPhase, |
1751 pref->SetInteger(prefs::kStabilityExecutionPhase, | 1747 MetricsService::SHUTDOWN_COMPLETE); |
1752 MetricsService::SHUTDOWN_COMPLETE); | |
1753 } | 1748 } |
1754 | 1749 |
1755 #if defined(OS_CHROMEOS) | 1750 #if defined(OS_CHROMEOS) |
1756 void MetricsService::LogChromeOSCrash(const std::string &crash_type) { | 1751 void MetricsService::LogChromeOSCrash(const std::string &crash_type) { |
1757 if (crash_type == "user") | 1752 if (crash_type == "user") |
1758 IncrementPrefValue(prefs::kStabilityOtherUserCrashCount); | 1753 IncrementPrefValue(prefs::kStabilityOtherUserCrashCount); |
1759 else if (crash_type == "kernel") | 1754 else if (crash_type == "kernel") |
1760 IncrementPrefValue(prefs::kStabilityKernelCrashCount); | 1755 IncrementPrefValue(prefs::kStabilityKernelCrashCount); |
1761 else if (crash_type == "uncleanshutdown") | 1756 else if (crash_type == "uncleanshutdown") |
1762 IncrementPrefValue(prefs::kStabilitySystemUncleanShutdownCount); | 1757 IncrementPrefValue(prefs::kStabilitySystemUncleanShutdownCount); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1887 | 1882 |
1888 bool MetricsService::ShouldLogEvents() { | 1883 bool MetricsService::ShouldLogEvents() { |
1889 // We simply don't log events to UMA if there is a single incognito | 1884 // We simply don't log events to UMA if there is a single incognito |
1890 // session visible. The problem is that we always notify using the orginal | 1885 // session visible. The problem is that we always notify using the orginal |
1891 // profile in order to simplify notification processing. | 1886 // profile in order to simplify notification processing. |
1892 return !chrome::IsOffTheRecordSessionActive(); | 1887 return !chrome::IsOffTheRecordSessionActive(); |
1893 } | 1888 } |
1894 | 1889 |
1895 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | 1890 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
1896 DCHECK(IsSingleThreaded()); | 1891 DCHECK(IsSingleThreaded()); |
1892 DCHECK(local_state_); | |
Alexei Svitkine (slow)
2014/05/19 13:13:54
I think we can just have a single DCHECK in the ct
blundell
2014/05/19 13:49:28
Done.
| |
1897 | 1893 |
1898 PrefService* pref = g_browser_process->local_state(); | 1894 local_state_->SetBoolean(path, value); |
1899 DCHECK(pref); | 1895 RecordCurrentState(local_state_); |
1900 | |
1901 pref->SetBoolean(path, value); | |
1902 RecordCurrentState(pref); | |
1903 } | 1896 } |
1904 | 1897 |
1905 void MetricsService::RecordCurrentState(PrefService* pref) { | 1898 void MetricsService::RecordCurrentState(PrefService* pref) { |
1906 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); | 1899 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); |
1907 | 1900 |
1908 RecordPluginChanges(pref); | 1901 RecordPluginChanges(pref); |
1909 } | 1902 } |
1910 | 1903 |
1911 // static | 1904 // static |
1912 bool MetricsService::IsPluginProcess(int process_type) { | 1905 bool MetricsService::IsPluginProcess(int process_type) { |
1913 return (process_type == content::PROCESS_TYPE_PLUGIN || | 1906 return (process_type == content::PROCESS_TYPE_PLUGIN || |
1914 process_type == content::PROCESS_TYPE_PPAPI_PLUGIN || | 1907 process_type == content::PROCESS_TYPE_PPAPI_PLUGIN || |
1915 process_type == content::PROCESS_TYPE_PPAPI_BROKER); | 1908 process_type == content::PROCESS_TYPE_PPAPI_BROKER); |
1916 } | 1909 } |
1917 | 1910 |
1918 #if defined(OS_CHROMEOS) | 1911 #if defined(OS_CHROMEOS) |
1919 void MetricsService::StartExternalMetrics() { | 1912 void MetricsService::StartExternalMetrics() { |
1920 external_metrics_ = new chromeos::ExternalMetrics; | 1913 external_metrics_ = new chromeos::ExternalMetrics; |
1921 external_metrics_->Start(); | 1914 external_metrics_->Start(); |
1922 } | 1915 } |
1923 #endif | 1916 #endif |
1924 | 1917 |
1925 // static | 1918 // static |
1926 bool MetricsServiceHelper::IsMetricsReportingEnabled() { | 1919 bool MetricsServiceHelper::IsMetricsReportingEnabled( |
1920 const PrefService* local_state) { | |
1927 bool result = false; | 1921 bool result = false; |
1928 const PrefService* local_state = g_browser_process->local_state(); | |
1929 if (local_state) { | 1922 if (local_state) { |
1930 const PrefService::Preference* uma_pref = | 1923 const PrefService::Preference* uma_pref = |
1931 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1924 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
1932 if (uma_pref) { | 1925 if (uma_pref) { |
1933 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1926 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
1934 DCHECK(success); | 1927 DCHECK(success); |
1935 } | 1928 } |
1936 } | 1929 } |
1937 return result; | 1930 return result; |
1938 } | 1931 } |
1939 | 1932 |
1940 bool MetricsServiceHelper::IsCrashReportingEnabled() { | 1933 bool MetricsServiceHelper::IsCrashReportingEnabled( |
1934 const PrefService* local_state) { | |
1941 #if defined(GOOGLE_CHROME_BUILD) | 1935 #if defined(GOOGLE_CHROME_BUILD) |
1942 #if defined(OS_CHROMEOS) | 1936 #if defined(OS_CHROMEOS) |
1943 bool reporting_enabled = false; | 1937 bool reporting_enabled = false; |
1944 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, | 1938 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, |
1945 &reporting_enabled); | 1939 &reporting_enabled); |
1946 return reporting_enabled; | 1940 return reporting_enabled; |
1947 #elif defined(OS_ANDROID) | 1941 #elif defined(OS_ANDROID) |
1948 // Android has its own settings for metrics / crash uploading. | 1942 // Android has its own settings for metrics / crash uploading. |
1949 const PrefService* prefs = g_browser_process->local_state(); | 1943 return local_state->GetBoolean(prefs::kCrashReportingEnabled); |
1950 return prefs->GetBoolean(prefs::kCrashReportingEnabled); | |
1951 #else | 1944 #else |
1952 return MetricsServiceHelper::IsMetricsReportingEnabled(); | 1945 return MetricsServiceHelper::IsMetricsReportingEnabled(local_state); |
1953 #endif | 1946 #endif |
1954 #else | 1947 #else |
1955 return false; | 1948 return false; |
1956 #endif | 1949 #endif |
1957 } | 1950 } |
1958 | 1951 |
1959 void MetricsServiceHelper::AddMetricsServiceObserver( | 1952 void MetricsServiceHelper::AddMetricsServiceObserver( |
1960 MetricsServiceObserver* observer) { | 1953 MetricsServiceObserver* observer) { |
1961 MetricsService* metrics_service = g_browser_process->metrics_service(); | 1954 MetricsService* metrics_service = g_browser_process->metrics_service(); |
1962 if (metrics_service) | 1955 if (metrics_service) |
1963 metrics_service->AddObserver(observer); | 1956 metrics_service->AddObserver(observer); |
1964 } | 1957 } |
1965 | 1958 |
1966 void MetricsServiceHelper::RemoveMetricsServiceObserver( | 1959 void MetricsServiceHelper::RemoveMetricsServiceObserver( |
1967 MetricsServiceObserver* observer) { | 1960 MetricsServiceObserver* observer) { |
1968 MetricsService* metrics_service = g_browser_process->metrics_service(); | 1961 MetricsService* metrics_service = g_browser_process->metrics_service(); |
1969 if (metrics_service) | 1962 if (metrics_service) |
1970 metrics_service->RemoveObserver(observer); | 1963 metrics_service->RemoveObserver(observer); |
1971 } | 1964 } |
OLD | NEW |