Index: components/metrics/metrics_log.cc |
diff --git a/components/metrics/metrics_log.cc b/components/metrics/metrics_log.cc |
index 3d8cc1886a891d566bc3e42237c97ff41b385618..df3ac67dfd1dcb0b39c56a165e27fc6dca0a464a 100644 |
--- a/components/metrics/metrics_log.cc |
+++ b/components/metrics/metrics_log.cc |
@@ -117,9 +117,9 @@ MetricsLog::~MetricsLog() { |
// static |
void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { |
- registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); |
registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0); |
registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0); |
+ registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); |
registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0); |
registry->RegisterIntegerPref( |
prefs::kStabilityBreakpadRegistrationSuccess, 0); |
@@ -129,6 +129,9 @@ void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { |
std::string()); |
registry->RegisterStringPref(prefs::kStabilitySavedSystemProfileHash, |
std::string()); |
+ registry->RegisterIntegerPref(prefs::kStabilityDeferredCount, 0); |
+ registry->RegisterIntegerPref(prefs::kStabilityDiscardCount, 0); |
+ registry->RegisterIntegerPref(prefs::kStabilityVersionMismatchCount, 0); |
} |
// static |
@@ -207,33 +210,59 @@ void MetricsLog::RecordStabilityMetrics( |
if (log_type() != INITIAL_STABILITY_LOG) |
return; |
+ SystemProfileProto::Stability* stability = |
+ system_profile->mutable_stability(); |
+ |
+ // TODO(jar): The following are all optional in SystemProfileProto::Stability, |
+ // so we *could* optimize them for values of zero (and not include them). |
+ |
int incomplete_shutdown_count = |
pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); |
- pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
+ if (incomplete_shutdown_count) |
Alexei Svitkine (slow)
2016/08/30 21:25:59
Maybe break this out in a separate change? Seems u
manzagop (departed)
2016/09/01 21:26:55
Done. http://crrev.com/2294323002
|
+ pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
+ stability->set_incomplete_shutdown_count(incomplete_shutdown_count); |
+ |
int breakpad_registration_success_count = |
pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); |
- pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
+ if (breakpad_registration_success_count) |
+ pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
+ stability->set_breakpad_registration_success_count( |
+ breakpad_registration_success_count); |
+ |
int breakpad_registration_failure_count = |
pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); |
- pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
+ if (breakpad_registration_failure_count) |
+ pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
+ stability->set_breakpad_registration_failure_count( |
+ breakpad_registration_failure_count); |
+ |
int debugger_present_count = |
pref->GetInteger(prefs::kStabilityDebuggerPresent); |
- pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
+ if (debugger_present_count) |
+ pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
+ stability->set_debugger_present_count(debugger_present_count); |
+ |
int debugger_not_present_count = |
pref->GetInteger(prefs::kStabilityDebuggerNotPresent); |
- pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
- |
- // TODO(jar): The following are all optional, so we *could* optimize them for |
- // values of zero (and not include them). |
- SystemProfileProto::Stability* stability = |
- system_profile->mutable_stability(); |
- stability->set_incomplete_shutdown_count(incomplete_shutdown_count); |
- stability->set_breakpad_registration_success_count( |
- breakpad_registration_success_count); |
- stability->set_breakpad_registration_failure_count( |
- breakpad_registration_failure_count); |
- stability->set_debugger_present_count(debugger_present_count); |
+ if (debugger_not_present_count) |
+ pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
stability->set_debugger_not_present_count(debugger_not_present_count); |
+ |
+ int deferred_count = pref->GetInteger(prefs::kStabilityDeferredCount); |
+ if (deferred_count) |
+ local_state_->SetInteger(prefs::kStabilityDeferredCount, 0); |
+ stability->set_deferred_count(deferred_count); |
+ |
+ int discard_count = local_state_->GetInteger(prefs::kStabilityDiscardCount); |
+ if (discard_count) |
+ local_state_->SetInteger(prefs::kStabilityDiscardCount, 0); |
+ stability->set_discard_count(discard_count); |
+ |
+ int version_mismatch_count = |
+ local_state_->GetInteger(prefs::kStabilityVersionMismatchCount); |
+ if (version_mismatch_count) |
+ local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0); |
+ stability->set_version_mismatch_count(version_mismatch_count); |
} |
void MetricsLog::RecordGeneralMetrics( |
@@ -287,7 +316,8 @@ void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); |
pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); |
- pref->SetInteger(prefs::kStabilityCrashCount, 0); |
+ if (crash_count) |
+ pref->SetInteger(prefs::kStabilityCrashCount, 0); |
SystemProfileProto::Stability* stability = |
uma_proto()->mutable_system_profile()->mutable_stability(); |
@@ -379,19 +409,21 @@ void MetricsLog::RecordEnvironment( |
for (size_t i = 0; i < metrics_providers.size(); ++i) |
metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); |
- std::string serialied_system_profile; |
+ std::string serialized_system_profile; |
std::string base64_system_profile; |
- if (system_profile->SerializeToString(&serialied_system_profile)) { |
- base::Base64Encode(serialied_system_profile, &base64_system_profile); |
+ if (system_profile->SerializeToString(&serialized_system_profile)) { |
+ base::Base64Encode(serialized_system_profile, &base64_system_profile); |
PrefService* local_state = local_state_; |
local_state->SetString(prefs::kStabilitySavedSystemProfile, |
base64_system_profile); |
local_state->SetString(prefs::kStabilitySavedSystemProfileHash, |
- ComputeSHA1(serialied_system_profile)); |
+ ComputeSHA1(serialized_system_profile)); |
} |
} |
-bool MetricsLog::LoadSavedEnvironmentFromPrefs() { |
+bool MetricsLog::LoadSavedEnvironmentFromPrefs(std::string* app_version) { |
+ DCHECK(app_version); |
+ |
PrefService* local_state = local_state_; |
const std::string base64_system_profile = |
local_state->GetString(prefs::kStabilitySavedSystemProfile); |
@@ -404,10 +436,14 @@ bool MetricsLog::LoadSavedEnvironmentFromPrefs() { |
local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); |
SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
- std::string serialied_system_profile; |
- return base::Base64Decode(base64_system_profile, &serialied_system_profile) && |
- ComputeSHA1(serialied_system_profile) == system_profile_hash && |
- system_profile->ParseFromString(serialied_system_profile); |
+ std::string serialized_system_profile; |
+ bool success = |
+ base::Base64Decode(base64_system_profile, &serialized_system_profile) && |
+ ComputeSHA1(serialized_system_profile) == system_profile_hash && |
+ system_profile->ParseFromString(serialized_system_profile); |
+ if (success) |
+ *app_version = system_profile->app_version(); |
+ return success; |
} |
void MetricsLog::CloseLog() { |