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

Side by Side Diff: chrome/browser/metrics/metrics_service.cc

Issue 137623002: Let MetricsService know about some Android Activities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments on patch set 5 + a unit test Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 475
476 registry->RegisterListPref(prefs::kMetricsInitialLogs); 476 registry->RegisterListPref(prefs::kMetricsInitialLogs);
477 registry->RegisterListPref(prefs::kMetricsOngoingLogs); 477 registry->RegisterListPref(prefs::kMetricsOngoingLogs);
478 478
479 registry->RegisterInt64Pref(prefs::kInstallDate, 0); 479 registry->RegisterInt64Pref(prefs::kInstallDate, 0);
480 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); 480 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0);
481 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); 481 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0);
482 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); 482 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0);
483 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0); 483 registry->RegisterInt64Pref(prefs::kUninstallLastLaunchTimeSec, 0);
484 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0); 484 registry->RegisterInt64Pref(prefs::kUninstallLastObservedRunTimeSec, 0);
485
486 #if defined(OS_ANDROID)
487 RegisterPrefsAndroid(registry);
488 #endif // defined(OS_ANDROID)
485 } 489 }
486 490
487 // static 491 // static
488 void MetricsService::DiscardOldStabilityStats(PrefService* local_state) { 492 void MetricsService::DiscardOldStabilityStats(PrefService* local_state) {
489 local_state->SetBoolean(prefs::kStabilityExitedCleanly, true); 493 local_state->SetBoolean(prefs::kStabilityExitedCleanly, true);
490 local_state->SetInteger(prefs::kStabilityExecutionPhase, UNINITIALIZED_PHASE); 494 local_state->SetInteger(prefs::kStabilityExecutionPhase, UNINITIALIZED_PHASE);
491 local_state->SetBoolean(prefs::kStabilitySessionEndCompleted, true); 495 local_state->SetBoolean(prefs::kStabilitySessionEndCompleted, true);
492 496
493 local_state->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); 497 local_state->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
494 local_state->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); 498 local_state->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
495 local_state->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); 499 local_state->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
496 local_state->SetInteger(prefs::kStabilityDebuggerPresent, 0); 500 local_state->SetInteger(prefs::kStabilityDebuggerPresent, 0);
497 local_state->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); 501 local_state->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
498 502
499 local_state->SetInteger(prefs::kStabilityLaunchCount, 0); 503 local_state->SetInteger(prefs::kStabilityLaunchCount, 0);
500 local_state->SetInteger(prefs::kStabilityCrashCount, 0); 504 local_state->SetInteger(prefs::kStabilityCrashCount, 0);
501 505
502 local_state->SetInteger(prefs::kStabilityPageLoadCount, 0); 506 local_state->SetInteger(prefs::kStabilityPageLoadCount, 0);
503 local_state->SetInteger(prefs::kStabilityRendererCrashCount, 0); 507 local_state->SetInteger(prefs::kStabilityRendererCrashCount, 0);
504 local_state->SetInteger(prefs::kStabilityRendererHangCount, 0); 508 local_state->SetInteger(prefs::kStabilityRendererHangCount, 0);
505 509
506 local_state->SetInt64(prefs::kStabilityLaunchTimeSec, 0); 510 local_state->SetInt64(prefs::kStabilityLaunchTimeSec, 0);
507 local_state->SetInt64(prefs::kStabilityLastTimestampSec, 0); 511 local_state->SetInt64(prefs::kStabilityLastTimestampSec, 0);
508 512
509 local_state->ClearPref(prefs::kStabilityPluginStats); 513 local_state->ClearPref(prefs::kStabilityPluginStats);
510 514
511 local_state->ClearPref(prefs::kMetricsInitialLogs); 515 local_state->ClearPref(prefs::kMetricsInitialLogs);
512 local_state->ClearPref(prefs::kMetricsOngoingLogs); 516 local_state->ClearPref(prefs::kMetricsOngoingLogs);
517
518 #if defined(OS_ANDROID)
519 DiscardOldStabilityStatsAndroid(local_state);
520 #endif // defined(OS_ANDROID)
513 } 521 }
514 522
515 MetricsService::MetricsService() 523 MetricsService::MetricsService()
516 : recording_active_(false), 524 : recording_active_(false),
517 reporting_active_(false), 525 reporting_active_(false),
518 test_mode_active_(false), 526 test_mode_active_(false),
519 state_(INITIALIZED), 527 state_(INITIALIZED),
520 has_initial_stability_log_(false), 528 has_initial_stability_log_(false),
521 low_entropy_source_(kLowEntropySourceNotSet), 529 low_entropy_source_(kLowEntropySourceNotSet),
522 idle_since_last_transmission_(false), 530 idle_since_last_transmission_(false),
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 // old version with info that we upload. 947 // old version with info that we upload.
940 DiscardOldStabilityStats(pref); 948 DiscardOldStabilityStats(pref);
941 pref->SetString(prefs::kStabilityStatsVersion, 949 pref->SetString(prefs::kStabilityStatsVersion,
942 MetricsLog::GetVersionString()); 950 MetricsLog::GetVersionString());
943 pref->SetInt64(prefs::kStabilityStatsBuildTime, 951 pref->SetInt64(prefs::kStabilityStatsBuildTime,
944 MetricsLog::GetBuildTime()); 952 MetricsLog::GetBuildTime());
945 } 953 }
946 954
947 session_id_ = pref->GetInteger(prefs::kMetricsSessionID); 955 session_id_ = pref->GetInteger(prefs::kMetricsSessionID);
948 956
957 #if defined(OS_ANDROID)
958 LogAndroidStabilityToPrefs(pref);
959 #endif // defined(OS_ANDROID)
960
949 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) { 961 if (!pref->GetBoolean(prefs::kStabilityExitedCleanly)) {
950 IncrementPrefValue(prefs::kStabilityCrashCount); 962 IncrementPrefValue(prefs::kStabilityCrashCount);
951 // Reset flag, and wait until we call LogNeedForCleanShutdown() before 963 // Reset flag, and wait until we call LogNeedForCleanShutdown() before
952 // monitoring. 964 // monitoring.
953 pref->SetBoolean(prefs::kStabilityExitedCleanly, true); 965 pref->SetBoolean(prefs::kStabilityExitedCleanly, true);
954 966
955 // TODO(rtenneti): On windows, consider saving/getting execution_phase from 967 // TODO(rtenneti): On windows, consider saving/getting execution_phase from
956 // the registry. 968 // the registry.
957 int execution_phase = pref->GetInteger(prefs::kStabilityExecutionPhase); 969 int execution_phase = pref->GetInteger(prefs::kStabilityExecutionPhase);
958 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", 970 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase",
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 static_cast<MetricsLog*>(log_manager_.current_log()); 1279 static_cast<MetricsLog*>(log_manager_.current_log());
1268 DCHECK(current_log); 1280 DCHECK(current_log);
1269 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; 1281 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
1270 GetCurrentSyntheticFieldTrials(&synthetic_trials); 1282 GetCurrentSyntheticFieldTrials(&synthetic_trials);
1271 current_log->RecordEnvironment(plugins_, google_update_metrics_, 1283 current_log->RecordEnvironment(plugins_, google_update_metrics_,
1272 synthetic_trials); 1284 synthetic_trials);
1273 PrefService* pref = g_browser_process->local_state(); 1285 PrefService* pref = g_browser_process->local_state();
1274 current_log->RecordStabilityMetrics(GetIncrementalUptime(pref), 1286 current_log->RecordStabilityMetrics(GetIncrementalUptime(pref),
1275 MetricsLog::ONGOING_LOG); 1287 MetricsLog::ONGOING_LOG);
1276 1288
1289 #if defined(OS_ANDROID)
1290 ConvertAndroidStabilityPrefsToHistograms(pref);
Kibeom Kim (inactive) 2014/01/24 19:45:09 dfalcantara@ -- Q : This was in your last patch se
gone 2014/01/24 20:03:07 Yeah, I think it should be fine. I think you move
Kibeom Kim (inactive) 2014/01/24 23:21:34 Done.
1291 #endif // defined(OS_ANDROID)
1277 RecordCurrentHistograms(); 1292 RecordCurrentHistograms();
1278 1293
1279 log_manager_.FinishCurrentLog(); 1294 log_manager_.FinishCurrentLog();
1280 } 1295 }
1281 1296
1282 void MetricsService::PushPendingLogsToPersistentStorage() { 1297 void MetricsService::PushPendingLogsToPersistentStorage() {
1283 if (state_ < SENDING_INITIAL_STABILITY_LOG) 1298 if (state_ < SENDING_INITIAL_STABILITY_LOG)
1284 return; // We didn't and still don't have time to get plugin list etc. 1299 return; // We didn't and still don't have time to get plugin list etc.
1285 1300
1286 if (log_manager_.has_staged_log()) { 1301 if (log_manager_.has_staged_log()) {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 new MetricsLog(client_id_, session_id_)); 1542 new MetricsLog(client_id_, session_id_));
1528 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) 1543 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs())
1529 return; 1544 return;
1530 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), 1545 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(),
1531 MetricsLog::INITIAL_LOG); 1546 MetricsLog::INITIAL_LOG);
1532 log_manager_.LoadPersistedUnsentLogs(); 1547 log_manager_.LoadPersistedUnsentLogs();
1533 1548
1534 log_manager_.PauseCurrentLog(); 1549 log_manager_.PauseCurrentLog();
1535 log_manager_.BeginLoggingWithLog(initial_stability_log.release(), 1550 log_manager_.BeginLoggingWithLog(initial_stability_log.release(),
1536 MetricsLog::INITIAL_LOG); 1551 MetricsLog::INITIAL_LOG);
1552 #if defined(OS_ANDROID)
1553 ConvertAndroidStabilityPrefsToHistograms(pref);
1554 RecordCurrentStabilityHistograms();
1555 #endif // defined(OS_ANDROID)
1537 log_manager_.FinishCurrentLog(); 1556 log_manager_.FinishCurrentLog();
1538 log_manager_.ResumePausedLog(); 1557 log_manager_.ResumePausedLog();
1539 1558
1540 // Store unsent logs, including the stability log that was just saved, so 1559 // Store unsent logs, including the stability log that was just saved, so
1541 // that they're not lost in case of a crash before upload time. 1560 // that they're not lost in case of a crash before upload time.
1542 log_manager_.PersistUnsentLogs(); 1561 log_manager_.PersistUnsentLogs();
1543 1562
1544 has_initial_stability_log_ = true; 1563 has_initial_stability_log_ = true;
1545 } 1564 }
1546 1565
1547 void MetricsService::PrepareInitialMetricsLog(MetricsLog::LogType log_type) { 1566 void MetricsService::PrepareInitialMetricsLog(MetricsLog::LogType log_type) {
1548 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); 1567 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG);
1549 initial_metrics_log_->set_hardware_class(hardware_class_); 1568 initial_metrics_log_->set_hardware_class(hardware_class_);
1550 1569
1551 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; 1570 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
1552 GetCurrentSyntheticFieldTrials(&synthetic_trials); 1571 GetCurrentSyntheticFieldTrials(&synthetic_trials);
1553 initial_metrics_log_->RecordEnvironment(plugins_, google_update_metrics_, 1572 initial_metrics_log_->RecordEnvironment(plugins_, google_update_metrics_,
1554 synthetic_trials); 1573 synthetic_trials);
1555 PrefService* pref = g_browser_process->local_state(); 1574 PrefService* pref = g_browser_process->local_state();
1556 initial_metrics_log_->RecordStabilityMetrics(GetIncrementalUptime(pref), 1575 initial_metrics_log_->RecordStabilityMetrics(GetIncrementalUptime(pref),
1557 log_type); 1576 log_type);
1558 1577
1559 // Histograms only get written to the current log, so make the new log current 1578 // Histograms only get written to the current log, so make the new log current
1560 // before writing them. 1579 // before writing them.
1561 log_manager_.PauseCurrentLog(); 1580 log_manager_.PauseCurrentLog();
1562 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release(), log_type); 1581 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release(), log_type);
1582 #if defined(OS_ANDROID)
1583 ConvertAndroidStabilityPrefsToHistograms(pref);
1584 #endif // defined(OS_ANDROID)
1563 RecordCurrentHistograms(); 1585 RecordCurrentHistograms();
1564 log_manager_.FinishCurrentLog(); 1586 log_manager_.FinishCurrentLog();
1565 log_manager_.ResumePausedLog(); 1587 log_manager_.ResumePausedLog();
1566 1588
1567 DCHECK(!log_manager_.has_staged_log()); 1589 DCHECK(!log_manager_.has_staged_log());
1568 log_manager_.StageNextLogForUpload(); 1590 log_manager_.StageNextLogForUpload();
1569 } 1591 }
1570 1592
1571 void MetricsService::SendStagedLog() { 1593 void MetricsService::SendStagedLog() {
1572 DCHECK(log_manager_.has_staged_log()); 1594 DCHECK(log_manager_.has_staged_log());
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 if (local_state) { 2038 if (local_state) {
2017 const PrefService::Preference* uma_pref = 2039 const PrefService::Preference* uma_pref =
2018 local_state->FindPreference(prefs::kMetricsReportingEnabled); 2040 local_state->FindPreference(prefs::kMetricsReportingEnabled);
2019 if (uma_pref) { 2041 if (uma_pref) {
2020 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 2042 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
2021 DCHECK(success); 2043 DCHECK(success);
2022 } 2044 }
2023 } 2045 }
2024 return result; 2046 return result;
2025 } 2047 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/browser/metrics/metrics_service_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698