Chromium Code Reviews| 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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 registry->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0); | 439 registry->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0); |
| 440 registry->RegisterIntegerPref(prefs::kStabilityExtensionRendererCrashCount, | 440 registry->RegisterIntegerPref(prefs::kStabilityExtensionRendererCrashCount, |
| 441 0); | 441 0); |
| 442 registry->RegisterIntegerPref(prefs::kStabilityRendererHangCount, 0); | 442 registry->RegisterIntegerPref(prefs::kStabilityRendererHangCount, 0); |
| 443 registry->RegisterIntegerPref(prefs::kStabilityChildProcessCrashCount, 0); | 443 registry->RegisterIntegerPref(prefs::kStabilityChildProcessCrashCount, 0); |
| 444 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0); | 444 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 445 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationSuccess, | 445 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationSuccess, |
| 446 0); | 446 0); |
| 447 registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0); | 447 registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0); |
| 448 registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0); | 448 registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0); |
| 449 #if defined(OS_CHROMEOS) | 449 #if defined(OS_ANDROID) |
| 450 registry->RegisterIntegerPref(prefs::kStabilityForegroundActivity, | |
| 451 ActivityTypeIds::ACTIVITY_NONE); | |
| 452 registry->RegisterIntegerPref(prefs::kStabilityLaunchedActivityFlags, | |
| 453 ActivityTypeIds::ACTIVITY_NONE); | |
| 454 | |
| 455 registry->RegisterIntegerPref(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 456 registry->RegisterIntegerPref(prefs::kStabilityLaunchCountFullScreenActivity, | |
| 457 0); | |
| 458 | |
| 459 registry->RegisterIntegerPref(prefs::kStabilityCrashCountMainActivity, 0); | |
| 460 registry->RegisterIntegerPref(prefs::kStabilityCrashCountFullScreenActivity, | |
| 461 0); | |
| 462 #elif defined(OS_CHROMEOS) | |
| 450 registry->RegisterIntegerPref(prefs::kStabilityOtherUserCrashCount, 0); | 463 registry->RegisterIntegerPref(prefs::kStabilityOtherUserCrashCount, 0); |
| 451 registry->RegisterIntegerPref(prefs::kStabilityKernelCrashCount, 0); | 464 registry->RegisterIntegerPref(prefs::kStabilityKernelCrashCount, 0); |
| 452 registry->RegisterIntegerPref(prefs::kStabilitySystemUncleanShutdownCount, 0); | 465 registry->RegisterIntegerPref(prefs::kStabilitySystemUncleanShutdownCount, 0); |
| 453 #endif // OS_CHROMEOS | 466 #endif |
| 454 | 467 |
| 455 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfile, | 468 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfile, |
| 456 std::string()); | 469 std::string()); |
| 457 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfileHash, | 470 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfileHash, |
| 458 std::string()); | 471 std::string()); |
| 459 | 472 |
| 460 registry->RegisterListPref(prefs::kMetricsInitialLogs); | 473 registry->RegisterListPref(prefs::kMetricsInitialLogs); |
| 461 registry->RegisterListPref(prefs::kMetricsOngoingLogs); | 474 registry->RegisterListPref(prefs::kMetricsOngoingLogs); |
| 462 | 475 |
| 463 registry->RegisterInt64Pref(prefs::kInstallDate, 0); | 476 registry->RegisterInt64Pref(prefs::kInstallDate, 0); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 476 | 489 |
| 477 local_state->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 490 local_state->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 478 local_state->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); | 491 local_state->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
| 479 local_state->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); | 492 local_state->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 480 local_state->SetInteger(prefs::kStabilityDebuggerPresent, 0); | 493 local_state->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
| 481 local_state->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); | 494 local_state->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
| 482 | 495 |
| 483 local_state->SetInteger(prefs::kStabilityLaunchCount, 0); | 496 local_state->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 484 local_state->SetInteger(prefs::kStabilityCrashCount, 0); | 497 local_state->SetInteger(prefs::kStabilityCrashCount, 0); |
| 485 | 498 |
| 499 #if defined(OS_ANDROID) | |
| 500 local_state->SetInteger(prefs::kStabilityForegroundActivity, | |
| 501 ActivityTypeIds::ACTIVITY_NONE); | |
| 502 local_state->SetInteger(prefs::kStabilityLaunchedActivityFlags, | |
| 503 ActivityTypeIds::ACTIVITY_NONE); | |
| 504 | |
| 505 local_state->SetInteger(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 506 local_state->SetInteger(prefs::kStabilityLaunchCountFullScreenActivity, 0); | |
| 507 | |
| 508 local_state->SetInteger(prefs::kStabilityCrashCountMainActivity, 0); | |
| 509 local_state->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); | |
| 510 #endif // defined(OS_ANDROID) | |
| 511 | |
| 486 local_state->SetInteger(prefs::kStabilityPageLoadCount, 0); | 512 local_state->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 487 local_state->SetInteger(prefs::kStabilityRendererCrashCount, 0); | 513 local_state->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 488 local_state->SetInteger(prefs::kStabilityRendererHangCount, 0); | 514 local_state->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 489 | 515 |
| 490 local_state->SetInt64(prefs::kStabilityLaunchTimeSec, 0); | 516 local_state->SetInt64(prefs::kStabilityLaunchTimeSec, 0); |
| 491 local_state->SetInt64(prefs::kStabilityLastTimestampSec, 0); | 517 local_state->SetInt64(prefs::kStabilityLastTimestampSec, 0); |
| 492 | 518 |
| 493 local_state->ClearPref(prefs::kStabilityPluginStats); | 519 local_state->ClearPref(prefs::kStabilityPluginStats); |
| 494 | 520 |
| 495 local_state->ClearPref(prefs::kMetricsInitialLogs); | 521 local_state->ClearPref(prefs::kMetricsInitialLogs); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 void MetricsService::RecordStartOfSessionEnd() { | 797 void MetricsService::RecordStartOfSessionEnd() { |
| 772 LogCleanShutdown(); | 798 LogCleanShutdown(); |
| 773 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, false); | 799 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, false); |
| 774 } | 800 } |
| 775 | 801 |
| 776 void MetricsService::RecordCompletedSessionEnd() { | 802 void MetricsService::RecordCompletedSessionEnd() { |
| 777 LogCleanShutdown(); | 803 LogCleanShutdown(); |
| 778 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); | 804 RecordBooleanPrefValue(prefs::kStabilitySessionEndCompleted, true); |
| 779 } | 805 } |
| 780 | 806 |
| 807 #if defined(OS_ANDROID) | |
| 808 void MetricsService::OnForegroundActivityChanged(ActivityTypeIds::Type type) { | |
| 809 PrefService* pref = g_browser_process->local_state(); | |
| 810 | |
| 811 // Record that the Activity is now in the foreground. | |
| 812 pref->SetInteger(prefs::kStabilityForegroundActivity, type); | |
| 813 | |
| 814 // Record that the Activity was launched. | |
| 815 int launched_activities = | |
| 816 pref->GetInteger(prefs::kStabilityLaunchedActivityFlags) | type; | |
| 817 pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, launched_activities); | |
| 818 | |
| 819 pref->CommitPendingWrite(); | |
| 820 } | |
| 821 #endif // defined(OS_ANDROID) | |
| 822 | |
| 781 #if defined(OS_ANDROID) || defined(OS_IOS) | 823 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 782 void MetricsService::OnAppEnterBackground() { | 824 void MetricsService::OnAppEnterBackground() { |
| 783 scheduler_->Stop(); | 825 scheduler_->Stop(); |
| 784 | 826 |
| 785 MarkAppCleanShutdownAndCommit(); | 827 MarkAppCleanShutdownAndCommit(); |
| 786 | 828 |
| 787 // At this point, there's no way of knowing when the process will be | 829 // At this point, there's no way of knowing when the process will be |
| 788 // killed, so this has to be treated similar to a shutdown, closing and | 830 // killed, so this has to be treated similar to a shutdown, closing and |
| 789 // persisting all logs. Unlinke a shutdown, the state is primed to be ready | 831 // persisting all logs. Unlinke a shutdown, the state is primed to be ready |
| 790 // to continue logging and uploading if the process does return. | 832 // to continue logging and uploading if the process does return. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 920 } | 962 } |
| 921 | 963 |
| 922 // Update session ID | 964 // Update session ID |
| 923 session_id_ = pref->GetInteger(prefs::kMetricsSessionID); | 965 session_id_ = pref->GetInteger(prefs::kMetricsSessionID); |
| 924 ++session_id_; | 966 ++session_id_; |
| 925 pref->SetInteger(prefs::kMetricsSessionID, session_id_); | 967 pref->SetInteger(prefs::kMetricsSessionID, session_id_); |
| 926 | 968 |
| 927 // Stability bookkeeping | 969 // Stability bookkeeping |
| 928 IncrementPrefValue(prefs::kStabilityLaunchCount); | 970 IncrementPrefValue(prefs::kStabilityLaunchCount); |
| 929 | 971 |
| 972 #if defined(OS_ANDROID) | |
| 973 // Track which Activities were launched by the user. | |
| 974 int launched_activities = | |
| 975 pref->GetInteger(prefs::kStabilityLaunchedActivityFlags); | |
| 976 if (launched_activities & ActivityTypeIds::ACTIVITY_MAIN) { | |
| 977 IncrementPrefValue(prefs::kStabilityLaunchCountMainActivity); | |
| 978 } | |
| 979 if (launched_activities & ActivityTypeIds::ACTIVITY_FULLSCREEN) { | |
| 980 IncrementPrefValue(prefs::kStabilityLaunchCountFullScreenActivity); | |
| 981 } | |
| 982 pref->SetInteger(prefs::kStabilityLaunchedActivityFlags, | |
| 983 ActivityTypeIds::ACTIVITY_NONE); | |
| 984 | |
| 985 // If an Activity was in the foreground when Chrome died, then Chrome was | |
| 986 // improperly shut down. Record it as a crash for that particular Activity. | |
| 987 int foreground = pref->GetInteger(prefs::kStabilityForegroundActivity); | |
|
Yaron
2013/12/10 01:48:17
So you'll get onForegroundActivityChanged(ACTIVITY
gone
2013/12/10 01:59:39
Yep:
https://chrome-internal-review.googlesource.c
| |
| 988 switch (foreground) { | |
| 989 case ActivityTypeIds::ACTIVITY_MAIN: | |
| 990 IncrementPrefValue(prefs::kStabilityCrashCountMainActivity); | |
| 991 break; | |
| 992 case ActivityTypeIds::ACTIVITY_FULLSCREEN: | |
| 993 IncrementPrefValue(prefs::kStabilityCrashCountFullScreenActivity); | |
| 994 break; | |
| 995 default: | |
| 996 break; | |
| 997 } | |
| 998 pref->SetInteger(prefs::kStabilityForegroundActivity, | |
| 999 ActivityTypeIds::ACTIVITY_NONE); | |
| 1000 #endif // defined(OS_ANDROID) | |
| 1001 | |
| 930 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { | 1002 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { |
| 931 IncrementPrefValue(prefs::kStabilityCrashCount); | 1003 IncrementPrefValue(prefs::kStabilityCrashCount); |
| 932 // Reset flag, and wait until we call LogNeedForCleanShutdown() before | 1004 // Reset flag, and wait until we call LogNeedForCleanShutdown() before |
| 933 // monitoring. | 1005 // monitoring. |
| 934 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); | 1006 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); |
| 935 | 1007 |
| 936 // TODO(rtenneti): On windows, consider saving/getting execution_phase from | 1008 // TODO(rtenneti): On windows, consider saving/getting execution_phase from |
| 937 // the registry. | 1009 // the registry. |
| 938 int execution_phase = pref->GetInteger(prefs::kStabilityExecutionPhase); | 1010 int execution_phase = pref->GetInteger(prefs::kStabilityExecutionPhase); |
| 939 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 1011 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 BrowserThread::PostDelayedTask( | 1275 BrowserThread::PostDelayedTask( |
| 1204 BrowserThread::FILE, | 1276 BrowserThread::FILE, |
| 1205 FROM_HERE, | 1277 FROM_HERE, |
| 1206 base::Bind(&MetricsService::InitTaskGetHardwareClass, | 1278 base::Bind(&MetricsService::InitTaskGetHardwareClass, |
| 1207 self_ptr_factory_.GetWeakPtr(), | 1279 self_ptr_factory_.GetWeakPtr(), |
| 1208 base::MessageLoop::current()->message_loop_proxy()), | 1280 base::MessageLoop::current()->message_loop_proxy()), |
| 1209 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); | 1281 base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); |
| 1210 } | 1282 } |
| 1211 } | 1283 } |
| 1212 | 1284 |
| 1285 #if defined(OS_ANDROID) | |
| 1286 void MetricsService::RecordAndroidStabilityHistograms() { | |
| 1287 PrefService* pref = g_browser_process->local_state(); | |
| 1288 | |
| 1289 // Track which Activities were launched by the user. | |
| 1290 int main_launch_count = | |
| 1291 pref->GetInteger(prefs::kStabilityLaunchCountMainActivity); | |
| 1292 for (int i = 0; i < main_launch_count; ++i) { | |
| 1293 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.LaunchCounts", | |
| 1294 ActivityTypeIds::ACTIVITY_MAIN); | |
| 1295 } | |
| 1296 pref->SetInteger(prefs::kStabilityLaunchCountMainActivity, 0); | |
| 1297 | |
| 1298 int full_screen_launch_count = | |
| 1299 pref->GetInteger(prefs::kStabilityLaunchCountFullScreenActivity); | |
| 1300 for (int i = 0; i < full_screen_launch_count; ++i) { | |
| 1301 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.LaunchCounts", | |
| 1302 ActivityTypeIds::ACTIVITY_FULLSCREEN); | |
| 1303 } | |
| 1304 pref->SetInteger(prefs::kStabilityLaunchCountFullScreenActivity, 0); | |
| 1305 | |
| 1306 // Track which Activities were in the foreground when Chrome died. | |
| 1307 int main_crash_count = | |
| 1308 pref->GetInteger(prefs::kStabilityCrashCountMainActivity); | |
| 1309 for (int i = 0; i < main_crash_count; ++i) { | |
| 1310 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.CrashCounts", | |
| 1311 ActivityTypeIds::ACTIVITY_MAIN); | |
| 1312 } | |
| 1313 pref->SetInteger(prefs::kStabilityCrashCountMainActivity, 0); | |
| 1314 | |
| 1315 int full_screen_crash_count = | |
| 1316 pref->GetInteger(prefs::kStabilityCrashCountFullScreenActivity); | |
| 1317 for (int i = 0; i < full_screen_crash_count; ++i) { | |
| 1318 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Android.Activity.CrashCounts", | |
| 1319 ActivityTypeIds::ACTIVITY_FULLSCREEN); | |
| 1320 } | |
| 1321 pref->SetInteger(prefs::kStabilityCrashCountFullScreenActivity, 0); | |
| 1322 } | |
| 1323 #endif | |
| 1324 | |
| 1213 void MetricsService::CloseCurrentLog() { | 1325 void MetricsService::CloseCurrentLog() { |
| 1214 if (!log_manager_.current_log()) | 1326 if (!log_manager_.current_log()) |
| 1215 return; | 1327 return; |
| 1216 | 1328 |
| 1217 // TODO(jar): Integrate bounds on log recording more consistently, so that we | 1329 // TODO(jar): Integrate bounds on log recording more consistently, so that we |
| 1218 // can stop recording logs that are too big much sooner. | 1330 // can stop recording logs that are too big much sooner. |
| 1219 if (log_manager_.current_log()->num_events() > kEventLimit) { | 1331 if (log_manager_.current_log()->num_events() > kEventLimit) { |
| 1220 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events", | 1332 UMA_HISTOGRAM_COUNTS("UMA.Discarded Log Events", |
| 1221 log_manager_.current_log()->num_events()); | 1333 log_manager_.current_log()->num_events()); |
| 1222 log_manager_.DiscardCurrentLog(); | 1334 log_manager_.DiscardCurrentLog(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1234 static_cast<MetricsLog*>(log_manager_.current_log()); | 1346 static_cast<MetricsLog*>(log_manager_.current_log()); |
| 1235 DCHECK(current_log); | 1347 DCHECK(current_log); |
| 1236 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; | 1348 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; |
| 1237 GetCurrentSyntheticFieldTrials(&synthetic_trials); | 1349 GetCurrentSyntheticFieldTrials(&synthetic_trials); |
| 1238 current_log->RecordEnvironment(plugins_, google_update_metrics_, | 1350 current_log->RecordEnvironment(plugins_, google_update_metrics_, |
| 1239 synthetic_trials); | 1351 synthetic_trials); |
| 1240 PrefService* pref = g_browser_process->local_state(); | 1352 PrefService* pref = g_browser_process->local_state(); |
| 1241 current_log->RecordStabilityMetrics(GetIncrementalUptime(pref), | 1353 current_log->RecordStabilityMetrics(GetIncrementalUptime(pref), |
| 1242 MetricsLog::ONGOING_LOG); | 1354 MetricsLog::ONGOING_LOG); |
| 1243 | 1355 |
| 1356 #if defined(OS_ANDROID) | |
| 1357 RecordAndroidStabilityHistograms(); | |
| 1358 #endif | |
| 1244 RecordCurrentHistograms(); | 1359 RecordCurrentHistograms(); |
| 1245 | 1360 |
| 1246 log_manager_.FinishCurrentLog(); | 1361 log_manager_.FinishCurrentLog(); |
| 1247 } | 1362 } |
| 1248 | 1363 |
| 1249 void MetricsService::PushPendingLogsToPersistentStorage() { | 1364 void MetricsService::PushPendingLogsToPersistentStorage() { |
| 1250 if (state_ < INITIAL_LOG_READY) | 1365 if (state_ < INITIAL_LOG_READY) |
| 1251 return; // We didn't and still don't have time to get plugin list etc. | 1366 return; // We didn't and still don't have time to get plugin list etc. |
| 1252 | 1367 |
| 1253 if (log_manager_.has_staged_log()) { | 1368 if (log_manager_.has_staged_log()) { |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1932 if (local_state) { | 2047 if (local_state) { |
| 1933 const PrefService::Preference* uma_pref = | 2048 const PrefService::Preference* uma_pref = |
| 1934 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 2049 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
| 1935 if (uma_pref) { | 2050 if (uma_pref) { |
| 1936 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 2051 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
| 1937 DCHECK(success); | 2052 DCHECK(success); |
| 1938 } | 2053 } |
| 1939 } | 2054 } |
| 1940 return result; | 2055 return result; |
| 1941 } | 2056 } |
| OLD | NEW |