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

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: rebase Created 6 years, 10 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 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 new MetricsLog(client_id_, session_id_)); 1539 new MetricsLog(client_id_, session_id_));
1528 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs()) 1540 if (!initial_stability_log->LoadSavedEnvironmentFromPrefs())
1529 return; 1541 return;
1530 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(), 1542 initial_stability_log->RecordStabilityMetrics(base::TimeDelta(),
1531 MetricsLog::INITIAL_LOG); 1543 MetricsLog::INITIAL_LOG);
1532 log_manager_.LoadPersistedUnsentLogs(); 1544 log_manager_.LoadPersistedUnsentLogs();
1533 1545
1534 log_manager_.PauseCurrentLog(); 1546 log_manager_.PauseCurrentLog();
1535 log_manager_.BeginLoggingWithLog(initial_stability_log.release(), 1547 log_manager_.BeginLoggingWithLog(initial_stability_log.release(),
1536 MetricsLog::INITIAL_LOG); 1548 MetricsLog::INITIAL_LOG);
1549 #if defined(OS_ANDROID)
1550 ConvertAndroidStabilityPrefsToHistograms(pref);
1551 RecordCurrentStabilityHistograms();
1552 #endif // defined(OS_ANDROID)
1537 log_manager_.FinishCurrentLog(); 1553 log_manager_.FinishCurrentLog();
1538 log_manager_.ResumePausedLog(); 1554 log_manager_.ResumePausedLog();
1539 1555
1540 // Store unsent logs, including the stability log that was just saved, so 1556 // 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. 1557 // that they're not lost in case of a crash before upload time.
1542 log_manager_.PersistUnsentLogs(); 1558 log_manager_.PersistUnsentLogs();
1543 1559
1544 has_initial_stability_log_ = true; 1560 has_initial_stability_log_ = true;
1545 } 1561 }
1546 1562
1547 void MetricsService::PrepareInitialMetricsLog(MetricsLog::LogType log_type) { 1563 void MetricsService::PrepareInitialMetricsLog(MetricsLog::LogType log_type) {
1548 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG); 1564 DCHECK(state_ == INIT_TASK_DONE || state_ == SENDING_INITIAL_STABILITY_LOG);
1549 initial_metrics_log_->set_hardware_class(hardware_class_); 1565 initial_metrics_log_->set_hardware_class(hardware_class_);
1550 1566
1551 std::vector<chrome_variations::ActiveGroupId> synthetic_trials; 1567 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
1552 GetCurrentSyntheticFieldTrials(&synthetic_trials); 1568 GetCurrentSyntheticFieldTrials(&synthetic_trials);
1553 initial_metrics_log_->RecordEnvironment(plugins_, google_update_metrics_, 1569 initial_metrics_log_->RecordEnvironment(plugins_, google_update_metrics_,
1554 synthetic_trials); 1570 synthetic_trials);
1555 PrefService* pref = g_browser_process->local_state(); 1571 PrefService* pref = g_browser_process->local_state();
1556 initial_metrics_log_->RecordStabilityMetrics(GetIncrementalUptime(pref), 1572 initial_metrics_log_->RecordStabilityMetrics(GetIncrementalUptime(pref),
1557 log_type); 1573 log_type);
1558 1574
1559 // Histograms only get written to the current log, so make the new log current 1575 // Histograms only get written to the current log, so make the new log current
1560 // before writing them. 1576 // before writing them.
1561 log_manager_.PauseCurrentLog(); 1577 log_manager_.PauseCurrentLog();
1562 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release(), log_type); 1578 log_manager_.BeginLoggingWithLog(initial_metrics_log_.release(), log_type);
1579 #if defined(OS_ANDROID)
1580 ConvertAndroidStabilityPrefsToHistograms(pref);
1581 #endif // defined(OS_ANDROID)
1563 RecordCurrentHistograms(); 1582 RecordCurrentHistograms();
1564 log_manager_.FinishCurrentLog(); 1583 log_manager_.FinishCurrentLog();
1565 log_manager_.ResumePausedLog(); 1584 log_manager_.ResumePausedLog();
1566 1585
1567 DCHECK(!log_manager_.has_staged_log()); 1586 DCHECK(!log_manager_.has_staged_log());
1568 log_manager_.StageNextLogForUpload(); 1587 log_manager_.StageNextLogForUpload();
1569 } 1588 }
1570 1589
1571 void MetricsService::SendStagedLog() { 1590 void MetricsService::SendStagedLog() {
1572 DCHECK(log_manager_.has_staged_log()); 1591 DCHECK(log_manager_.has_staged_log());
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 if (local_state) { 2035 if (local_state) {
2017 const PrefService::Preference* uma_pref = 2036 const PrefService::Preference* uma_pref =
2018 local_state->FindPreference(prefs::kMetricsReportingEnabled); 2037 local_state->FindPreference(prefs::kMetricsReportingEnabled);
2019 if (uma_pref) { 2038 if (uma_pref) {
2020 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 2039 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
2021 DCHECK(success); 2040 DCHECK(success);
2022 } 2041 }
2023 } 2042 }
2024 return result; 2043 return result;
2025 } 2044 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698