| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 else | 96 else |
| 97 uma_proto_.set_client_id(Hash(client_id)); | 97 uma_proto_.set_client_id(Hash(client_id)); |
| 98 | 98 |
| 99 uma_proto_.set_session_id(session_id); | 99 uma_proto_.set_session_id(session_id); |
| 100 | 100 |
| 101 const int32_t product = client_->GetProduct(); | 101 const int32_t product = client_->GetProduct(); |
| 102 // Only set the product if it differs from the default value. | 102 // Only set the product if it differs from the default value. |
| 103 if (product != uma_proto_.product()) | 103 if (product != uma_proto_.product()) |
| 104 uma_proto_.set_product(product); | 104 uma_proto_.set_product(product); |
| 105 | 105 |
| 106 SystemProfileProto* system_profile = uma_proto_.mutable_system_profile(); | 106 RecordCoreSystemProfile(client_, uma_proto_.mutable_system_profile()); |
| 107 system_profile->set_build_timestamp(GetBuildTime()); | |
| 108 system_profile->set_app_version(client_->GetVersionString()); | |
| 109 system_profile->set_channel(client_->GetChannel()); | |
| 110 #if defined(SYZYASAN) | |
| 111 system_profile->set_is_asan_build(true); | |
| 112 #endif | |
| 113 } | 107 } |
| 114 | 108 |
| 115 MetricsLog::~MetricsLog() { | 109 MetricsLog::~MetricsLog() { |
| 116 } | 110 } |
| 117 | 111 |
| 118 // static | 112 // static |
| 119 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { | 113 void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { |
| 120 registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0); | 114 registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0); |
| 121 registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0); | 115 registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 122 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); | 116 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 157 } |
| 164 | 158 |
| 165 void MetricsLog::RecordUserAction(const std::string& key) { | 159 void MetricsLog::RecordUserAction(const std::string& key) { |
| 166 DCHECK(!closed_); | 160 DCHECK(!closed_); |
| 167 | 161 |
| 168 UserActionEventProto* user_action = uma_proto_.add_user_action_event(); | 162 UserActionEventProto* user_action = uma_proto_.add_user_action_event(); |
| 169 user_action->set_name_hash(Hash(key)); | 163 user_action->set_name_hash(Hash(key)); |
| 170 user_action->set_time(GetCurrentTime()); | 164 user_action->set_time(GetCurrentTime()); |
| 171 } | 165 } |
| 172 | 166 |
| 167 void MetricsLog::RecordCoreSystemProfile(MetricsServiceClient* client, |
| 168 SystemProfileProto* system_profile) { |
| 169 system_profile->set_build_timestamp(metrics::MetricsLog::GetBuildTime()); |
| 170 system_profile->set_app_version(client->GetVersionString()); |
| 171 system_profile->set_channel(client->GetChannel()); |
| 172 system_profile->set_application_locale(client->GetApplicationLocale()); |
| 173 |
| 174 #if defined(SYZYASAN) |
| 175 system_profile->set_is_asan_build(true); |
| 176 #endif |
| 177 |
| 178 metrics::SystemProfileProto::Hardware* hardware = |
| 179 system_profile->mutable_hardware(); |
| 180 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); |
| 181 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); |
| 182 hardware->set_hardware_class(base::SysInfo::HardwareModelName()); |
| 183 #if defined(OS_WIN) |
| 184 hardware->set_dll_base(reinterpret_cast<uint64_t>(CURRENT_MODULE())); |
| 185 #endif |
| 186 |
| 187 metrics::SystemProfileProto::OS* os = system_profile->mutable_os(); |
| 188 os->set_name(base::SysInfo::OperatingSystemName()); |
| 189 os->set_version(base::SysInfo::OperatingSystemVersion()); |
| 190 #if defined(OS_ANDROID) |
| 191 os->set_fingerprint( |
| 192 base::android::BuildInfo::GetInstance()->android_build_fp()); |
| 193 #endif |
| 194 } |
| 195 |
| 173 void MetricsLog::RecordHistogramDelta(const std::string& histogram_name, | 196 void MetricsLog::RecordHistogramDelta(const std::string& histogram_name, |
| 174 const base::HistogramSamples& snapshot) { | 197 const base::HistogramSamples& snapshot) { |
| 175 DCHECK(!closed_); | 198 DCHECK(!closed_); |
| 176 EncodeHistogramDelta(histogram_name, snapshot, &uma_proto_); | 199 EncodeHistogramDelta(histogram_name, snapshot, &uma_proto_); |
| 177 } | 200 } |
| 178 | 201 |
| 179 void MetricsLog::RecordStabilityMetrics( | 202 void MetricsLog::RecordStabilityMetrics( |
| 180 const std::vector<MetricsProvider*>& metrics_providers, | 203 const std::vector<MetricsProvider*>& metrics_providers, |
| 181 base::TimeDelta incremental_uptime, | 204 base::TimeDelta incremental_uptime, |
| 182 base::TimeDelta uptime) { | 205 base::TimeDelta uptime) { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 if (client_->GetBrand(&brand_code)) | 391 if (client_->GetBrand(&brand_code)) |
| 369 system_profile->set_brand_code(brand_code); | 392 system_profile->set_brand_code(brand_code); |
| 370 | 393 |
| 371 // Reduce granularity of the enabled_date field to nearest hour. | 394 // Reduce granularity of the enabled_date field to nearest hour. |
| 372 system_profile->set_uma_enabled_date( | 395 system_profile->set_uma_enabled_date( |
| 373 RoundSecondsToHour(metrics_reporting_enabled_date)); | 396 RoundSecondsToHour(metrics_reporting_enabled_date)); |
| 374 | 397 |
| 375 // Reduce granularity of the install_date field to nearest hour. | 398 // Reduce granularity of the install_date field to nearest hour. |
| 376 system_profile->set_install_date(RoundSecondsToHour(install_date)); | 399 system_profile->set_install_date(RoundSecondsToHour(install_date)); |
| 377 | 400 |
| 378 system_profile->set_application_locale(client_->GetApplicationLocale()); | 401 SystemProfileProto::Hardware::CPU* cpu = |
| 379 | 402 system_profile->mutable_hardware()->mutable_cpu(); |
| 380 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); | |
| 381 | |
| 382 // HardwareModelName() will return an empty string on platforms where it's | |
| 383 // not implemented or if an error occured. | |
| 384 hardware->set_hardware_class(base::SysInfo::HardwareModelName()); | |
| 385 | |
| 386 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); | |
| 387 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); | |
| 388 #if defined(OS_WIN) | |
| 389 hardware->set_dll_base(reinterpret_cast<uint64_t>(CURRENT_MODULE())); | |
| 390 #endif | |
| 391 | |
| 392 SystemProfileProto::OS* os = system_profile->mutable_os(); | |
| 393 std::string os_name = base::SysInfo::OperatingSystemName(); | |
| 394 os->set_name(os_name); | |
| 395 | |
| 396 os->set_version(base::SysInfo::OperatingSystemVersion()); | |
| 397 #if defined(OS_ANDROID) | |
| 398 os->set_fingerprint( | |
| 399 base::android::BuildInfo::GetInstance()->android_build_fp()); | |
| 400 #endif | |
| 401 | |
| 402 base::CPU cpu_info; | 403 base::CPU cpu_info; |
| 403 SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu(); | |
| 404 cpu->set_vendor_name(cpu_info.vendor_name()); | 404 cpu->set_vendor_name(cpu_info.vendor_name()); |
| 405 cpu->set_signature(cpu_info.signature()); | 405 cpu->set_signature(cpu_info.signature()); |
| 406 cpu->set_num_cores(base::SysInfo::NumberOfProcessors()); | 406 cpu->set_num_cores(base::SysInfo::NumberOfProcessors()); |
| 407 | 407 |
| 408 std::vector<ActiveGroupId> field_trial_ids; | 408 std::vector<ActiveGroupId> field_trial_ids; |
| 409 GetFieldTrialIds(&field_trial_ids); | 409 GetFieldTrialIds(&field_trial_ids); |
| 410 WriteFieldTrials(field_trial_ids, system_profile); | 410 WriteFieldTrials(field_trial_ids, system_profile); |
| 411 WriteFieldTrials(synthetic_trials, system_profile); | 411 WriteFieldTrials(synthetic_trials, system_profile); |
| 412 | 412 |
| 413 for (size_t i = 0; i < metrics_providers.size(); ++i) | 413 for (size_t i = 0; i < metrics_providers.size(); ++i) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 DCHECK(!closed_); | 457 DCHECK(!closed_); |
| 458 closed_ = true; | 458 closed_ = true; |
| 459 } | 459 } |
| 460 | 460 |
| 461 void MetricsLog::GetEncodedLog(std::string* encoded_log) { | 461 void MetricsLog::GetEncodedLog(std::string* encoded_log) { |
| 462 DCHECK(closed_); | 462 DCHECK(closed_); |
| 463 uma_proto_.SerializeToString(encoded_log); | 463 uma_proto_.SerializeToString(encoded_log); |
| 464 } | 464 } |
| 465 | 465 |
| 466 } // namespace metrics | 466 } // namespace metrics |
| OLD | NEW |