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

Unified Diff: components/metrics/metrics_log.cc

Issue 2294323002: Avoid some pref writes in MetricsLog. Ensure some stability metrics are cleared. (Closed)
Patch Set: Fix unittests Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/metrics/metrics_log_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/metrics/metrics_log.cc
diff --git a/components/metrics/metrics_log.cc b/components/metrics/metrics_log.cc
index 3d8cc1886a891d566bc3e42237c97ff41b385618..691a946f9e6796d0ecd7051eddcbf569d51cc4d6 100644
--- a/components/metrics/metrics_log.cc
+++ b/components/metrics/metrics_log.cc
@@ -203,37 +203,45 @@ void MetricsLog::RecordStabilityMetrics(
metrics_providers[i]->ProvideStabilityMetrics(system_profile);
}
- // Omit some stats unless this is the initial stability log.
- if (log_type() != INITIAL_STABILITY_LOG)
- return;
+ SystemProfileProto::Stability* stability =
+ system_profile->mutable_stability();
int incomplete_shutdown_count =
pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
- pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
+ if (incomplete_shutdown_count) {
+ 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);
- stability->set_debugger_not_present_count(debugger_not_present_count);
+ if (debugger_not_present_count) {
+ pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
+ stability->set_debugger_not_present_count(debugger_not_present_count);
+ }
}
void MetricsLog::RecordGeneralMetrics(
@@ -285,9 +293,11 @@ bool MetricsLog::HasStabilityMetrics() const {
// protobufs is complete.
void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
- pref->SetInteger(prefs::kStabilityLaunchCount, 0);
+ if (launch_count)
+ 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,15 +389,15 @@ 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));
}
}
@@ -404,10 +414,11 @@ 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;
+ return base::Base64Decode(base64_system_profile,
+ &serialized_system_profile) &&
+ ComputeSHA1(serialized_system_profile) == system_profile_hash &&
+ system_profile->ParseFromString(serialized_system_profile);
}
void MetricsLog::CloseLog() {
« no previous file with comments | « no previous file | components/metrics/metrics_log_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698