| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // uma log upload, just as we send histogram data. | 196 // uma log upload, just as we send histogram data. |
| 197 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime); | 197 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime); |
| 198 | 198 |
| 199 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); | 199 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
| 200 for (size_t i = 0; i < metrics_providers.size(); ++i) { | 200 for (size_t i = 0; i < metrics_providers.size(); ++i) { |
| 201 if (log_type() == INITIAL_STABILITY_LOG) | 201 if (log_type() == INITIAL_STABILITY_LOG) |
| 202 metrics_providers[i]->ProvideInitialStabilityMetrics(system_profile); | 202 metrics_providers[i]->ProvideInitialStabilityMetrics(system_profile); |
| 203 metrics_providers[i]->ProvideStabilityMetrics(system_profile); | 203 metrics_providers[i]->ProvideStabilityMetrics(system_profile); |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Omit some stats unless this is the initial stability log. | 206 SystemProfileProto::Stability* stability = |
| 207 if (log_type() != INITIAL_STABILITY_LOG) | 207 system_profile->mutable_stability(); |
| 208 return; | |
| 209 | 208 |
| 210 int incomplete_shutdown_count = | 209 int incomplete_shutdown_count = |
| 211 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); | 210 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); |
| 212 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 211 if (incomplete_shutdown_count) { |
| 212 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 213 stability->set_incomplete_shutdown_count(incomplete_shutdown_count); |
| 214 } |
| 215 |
| 213 int breakpad_registration_success_count = | 216 int breakpad_registration_success_count = |
| 214 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); | 217 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); |
| 215 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); | 218 if (breakpad_registration_success_count) { |
| 219 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
| 220 stability->set_breakpad_registration_success_count( |
| 221 breakpad_registration_success_count); |
| 222 } |
| 223 |
| 216 int breakpad_registration_failure_count = | 224 int breakpad_registration_failure_count = |
| 217 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); | 225 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); |
| 218 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); | 226 if (breakpad_registration_failure_count) { |
| 227 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
| 228 stability->set_breakpad_registration_failure_count( |
| 229 breakpad_registration_failure_count); |
| 230 } |
| 231 |
| 219 int debugger_present_count = | 232 int debugger_present_count = |
| 220 pref->GetInteger(prefs::kStabilityDebuggerPresent); | 233 pref->GetInteger(prefs::kStabilityDebuggerPresent); |
| 221 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); | 234 if (debugger_present_count) { |
| 235 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
| 236 stability->set_debugger_present_count(debugger_present_count); |
| 237 } |
| 238 |
| 222 int debugger_not_present_count = | 239 int debugger_not_present_count = |
| 223 pref->GetInteger(prefs::kStabilityDebuggerNotPresent); | 240 pref->GetInteger(prefs::kStabilityDebuggerNotPresent); |
| 224 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); | 241 if (debugger_not_present_count) { |
| 225 | 242 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
| 226 // TODO(jar): The following are all optional, so we *could* optimize them for | 243 stability->set_debugger_not_present_count(debugger_not_present_count); |
| 227 // values of zero (and not include them). | 244 } |
| 228 SystemProfileProto::Stability* stability = | |
| 229 system_profile->mutable_stability(); | |
| 230 stability->set_incomplete_shutdown_count(incomplete_shutdown_count); | |
| 231 stability->set_breakpad_registration_success_count( | |
| 232 breakpad_registration_success_count); | |
| 233 stability->set_breakpad_registration_failure_count( | |
| 234 breakpad_registration_failure_count); | |
| 235 stability->set_debugger_present_count(debugger_present_count); | |
| 236 stability->set_debugger_not_present_count(debugger_not_present_count); | |
| 237 } | 245 } |
| 238 | 246 |
| 239 void MetricsLog::RecordGeneralMetrics( | 247 void MetricsLog::RecordGeneralMetrics( |
| 240 const std::vector<MetricsProvider*>& metrics_providers) { | 248 const std::vector<MetricsProvider*>& metrics_providers) { |
| 241 for (size_t i = 0; i < metrics_providers.size(); ++i) | 249 for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 242 metrics_providers[i]->ProvideGeneralMetrics(uma_proto()); | 250 metrics_providers[i]->ProvideGeneralMetrics(uma_proto()); |
| 243 } | 251 } |
| 244 | 252 |
| 245 void MetricsLog::GetFieldTrialIds( | 253 void MetricsLog::GetFieldTrialIds( |
| 246 std::vector<ActiveGroupId>* field_trial_ids) const { | 254 std::vector<ActiveGroupId>* field_trial_ids) const { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 bool MetricsLog::HasStabilityMetrics() const { | 286 bool MetricsLog::HasStabilityMetrics() const { |
| 279 return uma_proto()->system_profile().stability().has_launch_count(); | 287 return uma_proto()->system_profile().stability().has_launch_count(); |
| 280 } | 288 } |
| 281 | 289 |
| 282 // The server refuses data that doesn't have certain values. crashcount and | 290 // The server refuses data that doesn't have certain values. crashcount and |
| 283 // launchcount are currently "required" in the "stability" group. | 291 // launchcount are currently "required" in the "stability" group. |
| 284 // TODO(isherman): Stop writing these attributes specially once the migration to | 292 // TODO(isherman): Stop writing these attributes specially once the migration to |
| 285 // protobufs is complete. | 293 // protobufs is complete. |
| 286 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { | 294 void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
| 287 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); | 295 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); |
| 288 pref->SetInteger(prefs::kStabilityLaunchCount, 0); | 296 if (launch_count) |
| 297 pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 289 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); | 298 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); |
| 290 pref->SetInteger(prefs::kStabilityCrashCount, 0); | 299 if (crash_count) |
| 300 pref->SetInteger(prefs::kStabilityCrashCount, 0); |
| 291 | 301 |
| 292 SystemProfileProto::Stability* stability = | 302 SystemProfileProto::Stability* stability = |
| 293 uma_proto()->mutable_system_profile()->mutable_stability(); | 303 uma_proto()->mutable_system_profile()->mutable_stability(); |
| 294 stability->set_launch_count(launch_count); | 304 stability->set_launch_count(launch_count); |
| 295 stability->set_crash_count(crash_count); | 305 stability->set_crash_count(crash_count); |
| 296 } | 306 } |
| 297 | 307 |
| 298 void MetricsLog::WriteRealtimeStabilityAttributes( | 308 void MetricsLog::WriteRealtimeStabilityAttributes( |
| 299 PrefService* pref, | 309 PrefService* pref, |
| 300 base::TimeDelta incremental_uptime, | 310 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()); | 382 cpu->set_num_cores(base::SysInfo::NumberOfProcessors()); |
| 373 | 383 |
| 374 std::vector<ActiveGroupId> field_trial_ids; | 384 std::vector<ActiveGroupId> field_trial_ids; |
| 375 GetFieldTrialIds(&field_trial_ids); | 385 GetFieldTrialIds(&field_trial_ids); |
| 376 WriteFieldTrials(field_trial_ids, system_profile); | 386 WriteFieldTrials(field_trial_ids, system_profile); |
| 377 WriteFieldTrials(synthetic_trials, system_profile); | 387 WriteFieldTrials(synthetic_trials, system_profile); |
| 378 | 388 |
| 379 for (size_t i = 0; i < metrics_providers.size(); ++i) | 389 for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 380 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); | 390 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); |
| 381 | 391 |
| 382 std::string serialied_system_profile; | 392 std::string serialized_system_profile; |
| 383 std::string base64_system_profile; | 393 std::string base64_system_profile; |
| 384 if (system_profile->SerializeToString(&serialied_system_profile)) { | 394 if (system_profile->SerializeToString(&serialized_system_profile)) { |
| 385 base::Base64Encode(serialied_system_profile, &base64_system_profile); | 395 base::Base64Encode(serialized_system_profile, &base64_system_profile); |
| 386 PrefService* local_state = local_state_; | 396 PrefService* local_state = local_state_; |
| 387 local_state->SetString(prefs::kStabilitySavedSystemProfile, | 397 local_state->SetString(prefs::kStabilitySavedSystemProfile, |
| 388 base64_system_profile); | 398 base64_system_profile); |
| 389 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, | 399 local_state->SetString(prefs::kStabilitySavedSystemProfileHash, |
| 390 ComputeSHA1(serialied_system_profile)); | 400 ComputeSHA1(serialized_system_profile)); |
| 391 } | 401 } |
| 392 } | 402 } |
| 393 | 403 |
| 394 bool MetricsLog::LoadSavedEnvironmentFromPrefs() { | 404 bool MetricsLog::LoadSavedEnvironmentFromPrefs() { |
| 395 PrefService* local_state = local_state_; | 405 PrefService* local_state = local_state_; |
| 396 const std::string base64_system_profile = | 406 const std::string base64_system_profile = |
| 397 local_state->GetString(prefs::kStabilitySavedSystemProfile); | 407 local_state->GetString(prefs::kStabilitySavedSystemProfile); |
| 398 if (base64_system_profile.empty()) | 408 if (base64_system_profile.empty()) |
| 399 return false; | 409 return false; |
| 400 | 410 |
| 401 const std::string system_profile_hash = | 411 const std::string system_profile_hash = |
| 402 local_state->GetString(prefs::kStabilitySavedSystemProfileHash); | 412 local_state->GetString(prefs::kStabilitySavedSystemProfileHash); |
| 403 local_state->ClearPref(prefs::kStabilitySavedSystemProfile); | 413 local_state->ClearPref(prefs::kStabilitySavedSystemProfile); |
| 404 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); | 414 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash); |
| 405 | 415 |
| 406 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); | 416 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
| 407 std::string serialied_system_profile; | 417 std::string serialized_system_profile; |
| 408 return base::Base64Decode(base64_system_profile, &serialied_system_profile) && | 418 return base::Base64Decode(base64_system_profile, |
| 409 ComputeSHA1(serialied_system_profile) == system_profile_hash && | 419 &serialized_system_profile) && |
| 410 system_profile->ParseFromString(serialied_system_profile); | 420 ComputeSHA1(serialized_system_profile) == system_profile_hash && |
| 421 system_profile->ParseFromString(serialized_system_profile); |
| 411 } | 422 } |
| 412 | 423 |
| 413 void MetricsLog::CloseLog() { | 424 void MetricsLog::CloseLog() { |
| 414 DCHECK(!closed_); | 425 DCHECK(!closed_); |
| 415 closed_ = true; | 426 closed_ = true; |
| 416 } | 427 } |
| 417 | 428 |
| 418 void MetricsLog::GetEncodedLog(std::string* encoded_log) { | 429 void MetricsLog::GetEncodedLog(std::string* encoded_log) { |
| 419 DCHECK(closed_); | 430 DCHECK(closed_); |
| 420 uma_proto_.SerializeToString(encoded_log); | 431 uma_proto_.SerializeToString(encoded_log); |
| 421 } | 432 } |
| 422 | 433 |
| 423 } // namespace metrics | 434 } // namespace metrics |
| OLD | NEW |