Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/metrics/metrics_log.h" | 5 #include "components/metrics/metrics_log.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 #if defined(SYZYASAN) | 110 #if defined(SYZYASAN) |
| 111 system_profile->set_is_asan_build(true); | 111 system_profile->set_is_asan_build(true); |
| 112 #endif | 112 #endif |
| 113 } | 113 } |
| 114 | 114 |
| 115 MetricsLog::~MetricsLog() { | 115 MetricsLog::~MetricsLog() { |
| 116 } | 116 } |
| 117 | 117 |
| 118 // static | 118 // static |
| 119 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { | 119 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { |
| 120 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); | |
| 121 registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0); | 120 registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0); |
| 122 registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0); | 121 registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 122 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); | |
| 123 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0); | 123 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 124 registry->RegisterIntegerPref( | 124 registry->RegisterIntegerPref( |
| 125 prefs::kStabilityBreakpadRegistrationSuccess, 0); | 125 prefs::kStabilityBreakpadRegistrationSuccess, 0); |
| 126 registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0); | 126 registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0); |
| 127 registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0); | 127 registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0); |
| 128 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfile, | 128 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfile, |
| 129 std::string()); | 129 std::string()); |
| 130 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfileHash, | 130 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfileHash, |
| 131 std::string()); | 131 std::string()); |
| 132 registry->RegisterIntegerPref(prefs::kStabilityDeferredCount, 0); | |
| 133 registry->RegisterIntegerPref(prefs::kStabilityDiscardCount, 0); | |
| 134 registry->RegisterIntegerPref(prefs::kStabilityVersionMismatchCount, 0); | |
| 132 } | 135 } |
| 133 | 136 |
| 134 // static | 137 // static |
| 135 uint64_t MetricsLog::Hash(const std::string& value) { | 138 uint64_t MetricsLog::Hash(const std::string& value) { |
| 136 uint64_t hash = base::HashMetricName(value); | 139 uint64_t hash = base::HashMetricName(value); |
| 137 | 140 |
| 138 // The following log is VERY helpful when folks add some named histogram into | 141 // The following log is VERY helpful when folks add some named histogram into |
| 139 // the code, but forgot to update the descriptive list of histograms. When | 142 // the code, but forgot to update the descriptive list of histograms. When |
| 140 // that happens, all we get to see (server side) is a hash of the histogram | 143 // that happens, all we get to see (server side) is a hash of the histogram |
| 141 // name. We can then use this logging to find out what histogram name was | 144 // name. We can then use this logging to find out what histogram name was |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 for (size_t i = 0; i < metrics_providers.size(); ++i) { | 203 for (size_t i = 0; i < metrics_providers.size(); ++i) { |
| 201 if (log_type() == INITIAL_STABILITY_LOG) | 204 if (log_type() == INITIAL_STABILITY_LOG) |
| 202 metrics_providers[i]->ProvideInitialStabilityMetrics(system_profile); | 205 metrics_providers[i]->ProvideInitialStabilityMetrics(system_profile); |
| 203 metrics_providers[i]->ProvideStabilityMetrics(system_profile); | 206 metrics_providers[i]->ProvideStabilityMetrics(system_profile); |
| 204 } | 207 } |
| 205 | 208 |
| 206 // Omit some stats unless this is the initial stability log. | 209 // Omit some stats unless this is the initial stability log. |
| 207 if (log_type() != INITIAL_STABILITY_LOG) | 210 if (log_type() != INITIAL_STABILITY_LOG) |
| 208 return; | 211 return; |
| 209 | 212 |
| 213 SystemProfileProto::Stability* stability = | |
| 214 system_profile->mutable_stability(); | |
| 215 | |
| 216 // TODO(jar): The following are all optional in SystemProfileProto::Stability, | |
| 217 // so we *could* optimize them for values of zero (and not include them). | |
| 218 | |
| 210 int incomplete_shutdown_count = | 219 int incomplete_shutdown_count = |
| 211 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); | 220 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); |
| 212 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 221 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
| |
| 222 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | |
| 223 stability->set_incomplete_shutdown_count(incomplete_shutdown_count); | |
| 224 | |
| 213 int breakpad_registration_success_count = | 225 int breakpad_registration_success_count = |
| 214 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); | 226 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); |
| 215 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); | 227 if (breakpad_registration_success_count) |
| 228 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); | |
| 229 stability->set_breakpad_registration_success_count( | |
| 230 breakpad_registration_success_count); | |
| 231 | |
| 216 int breakpad_registration_failure_count = | 232 int breakpad_registration_failure_count = |
| 217 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); | 233 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); |
| 218 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); | 234 if (breakpad_registration_failure_count) |
| 235 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); | |
| 236 stability->set_breakpad_registration_failure_count( | |
| 237 breakpad_registration_failure_count); | |
| 238 | |
| 219 int debugger_present_count = | 239 int debugger_present_count = |
| 220 pref->GetInteger(prefs::kStabilityDebuggerPresent); | 240 pref->GetInteger(prefs::kStabilityDebuggerPresent); |
| 221 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); | 241 if (debugger_present_count) |
| 242 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); | |
| 243 stability->set_debugger_present_count(debugger_present_count); | |
| 244 | |
| 222 int debugger_not_present_count = | 245 int debugger_not_present_count = |
| 223 pref->GetInteger(prefs::kStabilityDebuggerNotPresent); | 246 pref->GetInteger(prefs::kStabilityDebuggerNotPresent); |
| 224 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); | 247 if (debugger_not_present_count) |
| 248 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); | |
| 249 stability->set_debugger_not_present_count(debugger_not_present_count); | |
| 225 | 250 |
| 226 // TODO(jar): The following are all optional, so we *could* optimize them for | 251 int deferred_count = pref->GetInteger(prefs::kStabilityDeferredCount); |
| 227 // values of zero (and not include them). | 252 if (deferred_count) |
| 228 SystemProfileProto::Stability* stability = | 253 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0); |
| 229 system_profile->mutable_stability(); | 254 stability->set_deferred_count(deferred_count); |
| 230 stability->set_incomplete_shutdown_count(incomplete_shutdown_count); | 255 |
| 231 stability->set_breakpad_registration_success_count( | 256 int discard_count = local_state_->GetInteger(prefs::kStabilityDiscardCount); |
| 232 breakpad_registration_success_count); | 257 if (discard_count) |
| 233 stability->set_breakpad_registration_failure_count( | 258 local_state_->SetInteger(prefs::kStabilityDiscardCount, 0); |
| 234 breakpad_registration_failure_count); | 259 stability->set_discard_count(discard_count); |
| 235 stability->set_debugger_present_count(debugger_present_count); | 260 |
| 236 stability->set_debugger_not_present_count(debugger_not_present_count); | 261 int version_mismatch_count = |
| 262 local_state_->GetInteger(prefs::kStabilityVersionMismatchCount); | |
| 263 if (version_mismatch_count) | |
| 264 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0); | |
| 265 stability->set_version_mismatch_count(version_mismatch_count); | |
| 237 } | 266 } |
| 238 | 267 |
| 239 void MetricsLog::RecordGeneralMetrics( | 268 void MetricsLog::RecordGeneralMetrics( |
| 240 const std::vector<MetricsProvider*>& metrics_providers) { | 269 const std::vector<MetricsProvider*>& metrics_providers) { |
| 241 for (size_t i = 0; i < metrics_providers.size(); ++i) | 270 for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 242 metrics_providers[i]->ProvideGeneralMetrics(uma_proto()); | 271 metrics_providers[i]->ProvideGeneralMetrics(uma_proto()); |
| 243 } | 272 } |
| 244 | 273 |
| 245 void MetricsLog::GetFieldTrialIds( | 274 void MetricsLog::GetFieldTrialIds( |
| 246 std::vector<ActiveGroupId>* field_trial_ids) const { | 275 std::vector<ActiveGroupId>* field_trial_ids) const { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 } | 309 } |
| 281 | 310 |
| 282 // The server refuses data that doesn't have certain values. crashcount and | 311 // The server refuses data that doesn't have certain values. crashcount and |
| 283 // launchcount are currently "required" in the "stability" group. | 312 // launchcount are currently "required" in the "stability" group. |
| 284 // TODO(isherman): Stop writing these attributes specially once the migration to | 313 // TODO(isherman): Stop writing these attributes specially once the migration to |
| 285 // protobufs is complete. | 314 // protobufs is complete. |
| 286 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { | 315 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
| 287 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); | 316 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); |
| 288 pref->SetInteger(prefs::kStabilityLaunchCount, 0); | 317 pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 289 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); | 318 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); |
| 290 pref->SetInteger(prefs::kStabilityCrashCount, 0); | 319 if (crash_count) |
| 320 pref->SetInteger(prefs::kStabilityCrashCount, 0); | |
| 291 | 321 |
| 292 SystemProfileProto::Stability* stability = | 322 SystemProfileProto::Stability* stability = |
| 293 uma_proto()->mutable_system_profile()->mutable_stability(); | 323 uma_proto()->mutable_system_profile()->mutable_stability(); |
| 294 stability->set_launch_count(launch_count); | 324 stability->set_launch_count(launch_count); |
| 295 stability->set_crash_count(crash_count); | 325 stability->set_crash_count(crash_count); |
| 296 } | 326 } |
| 297 | 327 |
| 298 void MetricsLog::WriteRealtimeStabilityAttributes( | 328 void MetricsLog::WriteRealtimeStabilityAttributes( |
| 299 PrefService* pref, | 329 PrefService* pref, |
| 300 base::TimeDelta incremental_uptime, | 330 base::TimeDelta incremental_uptime, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 cpu->set_num_cores(base::SysInfo::NumberOfProcessors()); | 402 cpu->set_num_cores(base::SysInfo::NumberOfProcessors()); |
| 373 | 403 |
| 374 std::vector<ActiveGroupId> field_trial_ids; | 404 std::vector<ActiveGroupId> field_trial_ids; |
| 375 GetFieldTrialIds(&field_trial_ids); | 405 GetFieldTrialIds(&field_trial_ids); |
| 376 WriteFieldTrials(field_trial_ids, system_profile); | 406 WriteFieldTrials(field_trial_ids, system_profile); |
| 377 WriteFieldTrials(synthetic_trials, system_profile); | 407 WriteFieldTrials(synthetic_trials, system_profile); |
| 378 | 408 |
| 379 for (size_t i = 0; i < metrics_providers.size(); ++i) | 409 for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 380 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); | 410 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); |
| 381 | 411 |
| 382 std::string serialied_system_profile; | 412 std::string serialized_system_profile; |
| 383 std::string base64_system_profile; | 413 std::string base64_system_profile; |
| 384 if (system_profile->SerializeToString(&serialied_system_profile)) { | 414 if (system_profile->SerializeToString(&serialized_system_profile)) { |
| 385 base::Base64Encode(serialied_system_profile, &base64_system_profile); | 415 base::Base64Encode(serialized_system_profile, &base64_system_profile); |
| 386 PrefService* local_state = local_state_; | 416 PrefService* local_state = local_state_; |
| 387 local_state->SetString(prefs::kStabilitySavedSystemProfile, | 417 local_state->SetString(prefs::kStabilitySavedSystemProfile, |
| 388 base64_system_profile); | 418 base64_system_profile); |
| 389 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, | 419 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, |
| 390 ComputeSHA1(serialied_system_profile)); | 420 ComputeSHA1(serialized_system_profile)); |
| 391 } | 421 } |
| 392 } | 422 } |
| 393 | 423 |
| 394 bool MetricsLog::LoadSavedEnvironmentFromPrefs() { | 424 bool MetricsLog::LoadSavedEnvironmentFromPrefs(std::string* app_version) { |
| 425 DCHECK(app_version); | |
| 426 | |
| 395 PrefService* local_state = local_state_; | 427 PrefService* local_state = local_state_; |
| 396 const std::string base64_system_profile = | 428 const std::string base64_system_profile = |
| 397 local_state->GetString(prefs::kStabilitySavedSystemProfile); | 429 local_state->GetString(prefs::kStabilitySavedSystemProfile); |
| 398 if (base64_system_profile.empty()) | 430 if (base64_system_profile.empty()) |
| 399 return false; | 431 return false; |
| 400 | 432 |
| 401 const std::string system_profile_hash = | 433 const std::string system_profile_hash = |
| 402 local_state->GetString(prefs::kStabilitySavedSystemProfileHash); | 434 local_state->GetString(prefs::kStabilitySavedSystemProfileHash); |
| 403 local_state->ClearPref(prefs::kStabilitySavedSystemProfile); | 435 local_state->ClearPref(prefs::kStabilitySavedSystemProfile); |
| 404 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); | 436 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); |
| 405 | 437 |
| 406 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); | 438 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
| 407 std::string serialied_system_profile; | 439 std::string serialized_system_profile; |
| 408 return base::Base64Decode(base64_system_profile, &serialied_system_profile) && | 440 bool success = |
| 409 ComputeSHA1(serialied_system_profile) == system_profile_hash && | 441 base::Base64Decode(base64_system_profile, &serialized_system_profile) && |
| 410 system_profile->ParseFromString(serialied_system_profile); | 442 ComputeSHA1(serialized_system_profile) == system_profile_hash && |
| 443 system_profile->ParseFromString(serialized_system_profile); | |
| 444 if (success) | |
| 445 *app_version = system_profile->app_version(); | |
| 446 return success; | |
| 411 } | 447 } |
| 412 | 448 |
| 413 void MetricsLog::CloseLog() { | 449 void MetricsLog::CloseLog() { |
| 414 DCHECK(!closed_); | 450 DCHECK(!closed_); |
| 415 closed_ = true; | 451 closed_ = true; |
| 416 } | 452 } |
| 417 | 453 |
| 418 void MetricsLog::GetEncodedLog(std::string* encoded_log) { | 454 void MetricsLog::GetEncodedLog(std::string* encoded_log) { |
| 419 DCHECK(closed_); | 455 DCHECK(closed_); |
| 420 uma_proto_.SerializeToString(encoded_log); | 456 uma_proto_.SerializeToString(encoded_log); |
| 421 } | 457 } |
| 422 | 458 |
| 423 } // namespace metrics | 459 } // namespace metrics |
| OLD | NEW |