[email protected] | 91b1d91 | 2014-06-05 10:52:08 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 91b1d91 | 2014-06-05 10:52:08 | [diff] [blame] | 5 | #include "components/metrics/metrics_log.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 9 | #include <algorithm> |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 10 | #include <string> |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 11 | |
sebmarchand | 2f4ed50 | 2014-10-31 15:28:19 | [diff] [blame] | 12 | #include "base/build_time.h" |
[email protected] | 5c8f89f69 | 2013-07-18 11:13:28 | [diff] [blame] | 13 | #include "base/cpu.h" |
asvitkine | f5d4ee56 | 2016-11-07 18:57:08 | [diff] [blame] | 14 | #include "base/metrics/histogram_macros.h" |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 15 | #include "base/metrics/histogram_samples.h" |
bcwhite | 502b229 | 2015-11-30 22:31:01 | [diff] [blame] | 16 | #include "base/metrics/metrics_hashes.h" |
[email protected] | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 17 | #include "base/sys_info.h" |
[email protected] | 8481347 | 2013-06-28 00:25:19 | [diff] [blame] | 18 | #include "base/time/time.h" |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 19 | #include "build/build_config.h" |
holte | 1bf273c | 2017-02-23 00:22:28 | [diff] [blame] | 20 | #include "components/metrics/environment_recorder.h" |
rtenneti | 7254696 | 2014-12-15 21:41:59 | [diff] [blame] | 21 | #include "components/metrics/histogram_encoder.h" |
[email protected] | 91b1d91 | 2014-06-05 10:52:08 | [diff] [blame] | 22 | #include "components/metrics/metrics_pref_names.h" |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 23 | #include "components/metrics/metrics_provider.h" |
[email protected] | 09dee82d | 2014-05-22 14:00:53 | [diff] [blame] | 24 | #include "components/metrics/metrics_service_client.h" |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 25 | #include "components/metrics/proto/histogram_event.pb.h" |
[email protected] | 064107e | 2014-05-02 00:59:06 | [diff] [blame] | 26 | #include "components/metrics/proto/system_profile.pb.h" |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 27 | #include "components/metrics/proto/user_action_event.pb.h" |
brettw | 06650868 | 2016-02-03 08:22:02 | [diff] [blame] | 28 | #include "components/prefs/pref_registry_simple.h" |
| 29 | #include "components/prefs/pref_service.h" |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 30 | #include "components/variations/active_field_trials.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 31 | |
[email protected] | 5106b3a | 2012-10-03 20:10:44 | [diff] [blame] | 32 | #if defined(OS_ANDROID) |
| 33 | #include "base/android/build_info.h" |
| 34 | #endif |
| 35 | |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 36 | #if defined(OS_WIN) |
thakis | d62f5447 | 2016-04-04 02:21:10 | [diff] [blame] | 37 | #include "base/win/current_module.h" |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 38 | #endif |
| 39 | |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 40 | using base::SampleCountIterator; |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 41 | typedef variations::ActiveGroupId ActiveGroupId; |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 42 | |
asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 43 | namespace metrics { |
| 44 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 45 | namespace { |
| 46 | |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 47 | // Any id less than 16 bytes is considered to be a testing id. |
| 48 | bool IsTestingID(const std::string& id) { |
| 49 | return id.size() < 16; |
| 50 | } |
| 51 | |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 52 | void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids, |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 53 | SystemProfileProto* system_profile) { |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 54 | for (std::vector<ActiveGroupId>::const_iterator it = |
[email protected] | ad2461c | 2012-04-27 21:11:03 | [diff] [blame] | 55 | field_trial_ids.begin(); it != field_trial_ids.end(); ++it) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 56 | SystemProfileProto::FieldTrial* field_trial = |
| 57 | system_profile->add_field_trial(); |
| 58 | field_trial->set_name_id(it->name); |
| 59 | field_trial->set_group_id(it->group); |
| 60 | } |
| 61 | } |
| 62 | |
[email protected] | 86573d1 | 2013-07-11 19:48:32 | [diff] [blame] | 63 | // Round a timestamp measured in seconds since epoch to one with a granularity |
| 64 | // of an hour. This can be used before uploaded potentially sensitive |
| 65 | // timestamps. |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 66 | int64_t RoundSecondsToHour(int64_t time_in_seconds) { |
[email protected] | 86573d1 | 2013-07-11 19:48:32 | [diff] [blame] | 67 | return 3600 * (time_in_seconds / 3600); |
| 68 | } |
| 69 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 70 | } // namespace |
| 71 | |
[email protected] | 9eae403 | 2014-04-09 19:15:19 | [diff] [blame] | 72 | MetricsLog::MetricsLog(const std::string& client_id, |
| 73 | int session_id, |
[email protected] | 09dee82d | 2014-05-22 14:00:53 | [diff] [blame] | 74 | LogType log_type, |
asvitkine | 4c1d1ef | 2014-09-29 20:57:32 | [diff] [blame] | 75 | MetricsServiceClient* client, |
[email protected] | 24f81ca | 2014-05-26 15:59:34 | [diff] [blame] | 76 | PrefService* local_state) |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 77 | : closed_(false), |
| 78 | log_type_(log_type), |
[email protected] | 09dee82d | 2014-05-22 14:00:53 | [diff] [blame] | 79 | client_(client), |
[email protected] | 24f81ca | 2014-05-26 15:59:34 | [diff] [blame] | 80 | creation_time_(base::TimeTicks::Now()), |
| 81 | local_state_(local_state) { |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 82 | if (IsTestingID(client_id)) |
| 83 | uma_proto_.set_client_id(0); |
| 84 | else |
| 85 | uma_proto_.set_client_id(Hash(client_id)); |
| 86 | |
| 87 | uma_proto_.set_session_id(session_id); |
| 88 | |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 89 | const int32_t product = client_->GetProduct(); |
asvitkine | 4c1d1ef | 2014-09-29 20:57:32 | [diff] [blame] | 90 | // Only set the product if it differs from the default value. |
| 91 | if (product != uma_proto_.product()) |
| 92 | uma_proto_.set_product(product); |
| 93 | |
rkaplow | 2b85c62 | 2017-01-30 16:57:17 | [diff] [blame] | 94 | RecordCoreSystemProfile(client_, uma_proto_.mutable_system_profile()); |
[email protected] | afc03f0 | 2013-10-11 06:01:35 | [diff] [blame] | 95 | } |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 96 | |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 97 | MetricsLog::~MetricsLog() { |
| 98 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | |
[email protected] | 91b1d91 | 2014-06-05 10:52:08 | [diff] [blame] | 100 | // static |
| 101 | void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { |
holte | 1bf273c | 2017-02-23 00:22:28 | [diff] [blame] | 102 | EnvironmentRecorder::RegisterPrefs(registry); |
[email protected] | 91b1d91 | 2014-06-05 10:52:08 | [diff] [blame] | 103 | } |
| 104 | |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 105 | // static |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 106 | uint64_t MetricsLog::Hash(const std::string& value) { |
| 107 | uint64_t hash = base::HashMetricName(value); |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 108 | |
| 109 | // The following log is VERY helpful when folks add some named histogram into |
| 110 | // the code, but forgot to update the descriptive list of histograms. When |
| 111 | // that happens, all we get to see (server side) is a hash of the histogram |
| 112 | // name. We can then use this logging to find out what histogram name was |
| 113 | // being hashed to a given MD5 value by just running the version of Chromium |
| 114 | // in question with --enable-logging. |
| 115 | DVLOG(1) << "Metrics: Hash numeric [" << value << "]=[" << hash << "]"; |
| 116 | |
| 117 | return hash; |
| 118 | } |
| 119 | |
| 120 | // static |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 121 | int64_t MetricsLog::GetBuildTime() { |
| 122 | static int64_t integral_build_time = 0; |
sebmarchand | 2f4ed50 | 2014-10-31 15:28:19 | [diff] [blame] | 123 | if (!integral_build_time) |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 124 | integral_build_time = static_cast<int64_t>(base::GetBuildTime().ToTimeT()); |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 125 | return integral_build_time; |
| 126 | } |
| 127 | |
| 128 | // static |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 129 | int64_t MetricsLog::GetCurrentTime() { |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 130 | return (base::TimeTicks::Now() - base::TimeTicks()).InSeconds(); |
| 131 | } |
| 132 | |
| 133 | void MetricsLog::RecordUserAction(const std::string& key) { |
| 134 | DCHECK(!closed_); |
| 135 | |
| 136 | UserActionEventProto* user_action = uma_proto_.add_user_action_event(); |
| 137 | user_action->set_name_hash(Hash(key)); |
| 138 | user_action->set_time(GetCurrentTime()); |
| 139 | } |
| 140 | |
rkaplow | 2b85c62 | 2017-01-30 16:57:17 | [diff] [blame] | 141 | void MetricsLog::RecordCoreSystemProfile(MetricsServiceClient* client, |
| 142 | SystemProfileProto* system_profile) { |
| 143 | system_profile->set_build_timestamp(metrics::MetricsLog::GetBuildTime()); |
| 144 | system_profile->set_app_version(client->GetVersionString()); |
| 145 | system_profile->set_channel(client->GetChannel()); |
| 146 | system_profile->set_application_locale(client->GetApplicationLocale()); |
| 147 | |
| 148 | #if defined(SYZYASAN) |
| 149 | system_profile->set_is_asan_build(true); |
| 150 | #endif |
| 151 | |
| 152 | metrics::SystemProfileProto::Hardware* hardware = |
| 153 | system_profile->mutable_hardware(); |
asvitkine | a86e8e1 | 2017-02-01 19:33:59 | [diff] [blame] | 154 | #if !defined(OS_IOS) |
| 155 | // On iOS, OperatingSystemArchitecture() returns values like iPad4,4 which is |
| 156 | // not the actual CPU architecture. Don't set it until the API is fixed. See |
| 157 | // crbug.com/370104 for details. |
rkaplow | 2b85c62 | 2017-01-30 16:57:17 | [diff] [blame] | 158 | hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); |
asvitkine | a86e8e1 | 2017-02-01 19:33:59 | [diff] [blame] | 159 | #endif |
rkaplow | 2b85c62 | 2017-01-30 16:57:17 | [diff] [blame] | 160 | hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); |
| 161 | hardware->set_hardware_class(base::SysInfo::HardwareModelName()); |
| 162 | #if defined(OS_WIN) |
| 163 | hardware->set_dll_base(reinterpret_cast<uint64_t>(CURRENT_MODULE())); |
| 164 | #endif |
| 165 | |
| 166 | metrics::SystemProfileProto::OS* os = system_profile->mutable_os(); |
| 167 | os->set_name(base::SysInfo::OperatingSystemName()); |
| 168 | os->set_version(base::SysInfo::OperatingSystemVersion()); |
| 169 | #if defined(OS_ANDROID) |
| 170 | os->set_fingerprint( |
| 171 | base::android::BuildInfo::GetInstance()->android_build_fp()); |
| 172 | #endif |
| 173 | } |
| 174 | |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 175 | void MetricsLog::RecordHistogramDelta(const std::string& histogram_name, |
| 176 | const base::HistogramSamples& snapshot) { |
| 177 | DCHECK(!closed_); |
rtenneti | 7254696 | 2014-12-15 21:41:59 | [diff] [blame] | 178 | EncodeHistogramDelta(histogram_name, snapshot, &uma_proto_); |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 179 | } |
| 180 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 181 | void MetricsLog::RecordStabilityMetrics( |
ke.he | a9da80c | 2017-02-16 12:45:00 | [diff] [blame] | 182 | const std::vector<std::unique_ptr<MetricsProvider>>& metrics_providers, |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 183 | base::TimeDelta incremental_uptime, |
| 184 | base::TimeDelta uptime) { |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 185 | DCHECK(!closed_); |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 186 | DCHECK(HasEnvironment()); |
| 187 | DCHECK(!HasStabilityMetrics()); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 188 | |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 189 | // Record recent delta for critical stability metrics. We can't wait for a |
| 190 | // restart to gather these, as that delay biases our observation away from |
| 191 | // users that run happily for a looooong time. We send increments with each |
| 192 | // uma log upload, just as we send histogram data. |
holte | 1bf273c | 2017-02-23 00:22:28 | [diff] [blame] | 193 | WriteRealtimeStabilityAttributes(incremental_uptime, uptime); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 194 | |
[email protected] | 48ff2c7f | 2014-05-23 09:57:45 | [diff] [blame] | 195 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
lpromero | ca8cb6f | 2015-04-30 18:16:53 | [diff] [blame] | 196 | for (size_t i = 0; i < metrics_providers.size(); ++i) { |
| 197 | if (log_type() == INITIAL_STABILITY_LOG) |
| 198 | metrics_providers[i]->ProvideInitialStabilityMetrics(system_profile); |
[email protected] | 48ff2c7f | 2014-05-23 09:57:45 | [diff] [blame] | 199 | metrics_providers[i]->ProvideStabilityMetrics(system_profile); |
lpromero | ca8cb6f | 2015-04-30 18:16:53 | [diff] [blame] | 200 | } |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 201 | } |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 202 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 203 | void MetricsLog::RecordGeneralMetrics( |
ke.he | a9da80c | 2017-02-16 12:45:00 | [diff] [blame] | 204 | const std::vector<std::unique_ptr<MetricsProvider>>& metrics_providers) { |
asvitkine | 1359e8d | 2017-02-06 17:37:10 | [diff] [blame] | 205 | if (local_state_->GetBoolean(prefs::kMetricsResetIds)) |
| 206 | UMA_HISTOGRAM_BOOLEAN("UMA.IsClonedInstall", true); |
| 207 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 208 | for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 209 | metrics_providers[i]->ProvideGeneralMetrics(uma_proto()); |
| 210 | } |
| 211 | |
[email protected] | 0edf876 | 2013-11-21 18:33:30 | [diff] [blame] | 212 | void MetricsLog::GetFieldTrialIds( |
| 213 | std::vector<ActiveGroupId>* field_trial_ids) const { |
[email protected] | b3610d4 | 2014-05-19 18:07:23 | [diff] [blame] | 214 | variations::GetFieldTrialActiveGroupIds(field_trial_ids); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 215 | } |
| 216 | |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 217 | bool MetricsLog::HasEnvironment() const { |
| 218 | return uma_proto()->system_profile().has_uma_enabled_date(); |
| 219 | } |
| 220 | |
gayane | daaf3a0 | 2016-06-15 16:30:21 | [diff] [blame] | 221 | void MetricsLog::WriteMetricsEnableDefault(EnableMetricsDefault metrics_default, |
| 222 | SystemProfileProto* system_profile) { |
jwd | 421086f | 2016-03-21 14:40:42 | [diff] [blame] | 223 | if (client_->IsReportingPolicyManaged()) { |
| 224 | // If it's managed, then it must be reporting, otherwise we wouldn't be |
| 225 | // sending metrics. |
| 226 | system_profile->set_uma_default_state( |
| 227 | SystemProfileProto_UmaDefaultState_POLICY_FORCED_ENABLED); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | switch (metrics_default) { |
gayane | daaf3a0 | 2016-06-15 16:30:21 | [diff] [blame] | 232 | case EnableMetricsDefault::DEFAULT_UNKNOWN: |
jwd | 421086f | 2016-03-21 14:40:42 | [diff] [blame] | 233 | // Don't set the field if it's unknown. |
| 234 | break; |
gayane | daaf3a0 | 2016-06-15 16:30:21 | [diff] [blame] | 235 | case EnableMetricsDefault::OPT_IN: |
jwd | 421086f | 2016-03-21 14:40:42 | [diff] [blame] | 236 | system_profile->set_uma_default_state( |
| 237 | SystemProfileProto_UmaDefaultState_OPT_IN); |
| 238 | break; |
gayane | daaf3a0 | 2016-06-15 16:30:21 | [diff] [blame] | 239 | case EnableMetricsDefault::OPT_OUT: |
jwd | 421086f | 2016-03-21 14:40:42 | [diff] [blame] | 240 | system_profile->set_uma_default_state( |
| 241 | SystemProfileProto_UmaDefaultState_OPT_OUT); |
| 242 | } |
| 243 | } |
| 244 | |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 245 | bool MetricsLog::HasStabilityMetrics() const { |
| 246 | return uma_proto()->system_profile().stability().has_launch_count(); |
| 247 | } |
| 248 | |
[email protected] | c68a2b9b | 2013-10-09 18:16:36 | [diff] [blame] | 249 | void MetricsLog::WriteRealtimeStabilityAttributes( |
[email protected] | 076961c | 2014-03-12 22:23:56 | [diff] [blame] | 250 | base::TimeDelta incremental_uptime, |
| 251 | base::TimeDelta uptime) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 252 | // Update the stats which are critical for real-time stability monitoring. |
| 253 | // Since these are "optional," only list ones that are non-zero, as the counts |
[email protected] | 250f7b66 | 2013-11-23 02:36:51 | [diff] [blame] | 254 | // are aggregated (summed) server side. |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 255 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 256 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 257 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 258 | |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 259 | const uint64_t incremental_uptime_sec = incremental_uptime.InSeconds(); |
[email protected] | 076961c | 2014-03-12 22:23:56 | [diff] [blame] | 260 | if (incremental_uptime_sec) |
| 261 | stability->set_incremental_uptime_sec(incremental_uptime_sec); |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 262 | const uint64_t uptime_sec = uptime.InSeconds(); |
[email protected] | c68a2b9b | 2013-10-09 18:16:36 | [diff] [blame] | 263 | if (uptime_sec) |
| 264 | stability->set_uptime_sec(uptime_sec); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 265 | } |
| 266 | |
manzagop | a5d6688d | 2016-10-25 20:16:03 | [diff] [blame] | 267 | std::string MetricsLog::RecordEnvironment( |
ke.he | a9da80c | 2017-02-16 12:45:00 | [diff] [blame] | 268 | const std::vector<std::unique_ptr<MetricsProvider>>& metrics_providers, |
[email protected] | 6580145 | 2014-07-09 05:42:41 | [diff] [blame] | 269 | const std::vector<variations::ActiveGroupId>& synthetic_trials, |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 270 | int64_t install_date, |
| 271 | int64_t metrics_reporting_enabled_date) { |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 272 | DCHECK(!HasEnvironment()); |
| 273 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 274 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
[email protected] | 24b9bb39 | 2013-01-29 20:29:29 | [diff] [blame] | 275 | |
gayane | daaf3a0 | 2016-06-15 16:30:21 | [diff] [blame] | 276 | WriteMetricsEnableDefault(client_->GetMetricsReportingDefaultState(), |
| 277 | system_profile); |
jwd | 421086f | 2016-03-21 14:40:42 | [diff] [blame] | 278 | |
[email protected] | 24b9bb39 | 2013-01-29 20:29:29 | [diff] [blame] | 279 | std::string brand_code; |
[email protected] | 09dee82d | 2014-05-22 14:00:53 | [diff] [blame] | 280 | if (client_->GetBrand(&brand_code)) |
[email protected] | 24b9bb39 | 2013-01-29 20:29:29 | [diff] [blame] | 281 | system_profile->set_brand_code(brand_code); |
| 282 | |
[email protected] | 86573d1 | 2013-07-11 19:48:32 | [diff] [blame] | 283 | // Reduce granularity of the enabled_date field to nearest hour. |
olivierrobin | c3dfc5b | 2015-04-07 19:12:00 | [diff] [blame] | 284 | system_profile->set_uma_enabled_date( |
| 285 | RoundSecondsToHour(metrics_reporting_enabled_date)); |
[email protected] | 86573d1 | 2013-07-11 19:48:32 | [diff] [blame] | 286 | |
[email protected] | 86573d1 | 2013-07-11 19:48:32 | [diff] [blame] | 287 | // Reduce granularity of the install_date field to nearest hour. |
| 288 | system_profile->set_install_date(RoundSecondsToHour(install_date)); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 289 | |
rkaplow | 2b85c62 | 2017-01-30 16:57:17 | [diff] [blame] | 290 | SystemProfileProto::Hardware::CPU* cpu = |
| 291 | system_profile->mutable_hardware()->mutable_cpu(); |
[email protected] | 5c8f89f69 | 2013-07-18 11:13:28 | [diff] [blame] | 292 | base::CPU cpu_info; |
[email protected] | 5c8f89f69 | 2013-07-18 11:13:28 | [diff] [blame] | 293 | cpu->set_vendor_name(cpu_info.vendor_name()); |
| 294 | cpu->set_signature(cpu_info.signature()); |
gayane | f550f50f | 2015-03-11 00:44:59 | [diff] [blame] | 295 | cpu->set_num_cores(base::SysInfo::NumberOfProcessors()); |
[email protected] | 5c8f89f69 | 2013-07-18 11:13:28 | [diff] [blame] | 296 | |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 297 | std::vector<ActiveGroupId> field_trial_ids; |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 298 | GetFieldTrialIds(&field_trial_ids); |
| 299 | WriteFieldTrials(field_trial_ids, system_profile); |
[email protected] | 6067756 | 2013-11-17 15:52:55 | [diff] [blame] | 300 | WriteFieldTrials(synthetic_trials, system_profile); |
[email protected] | f65859e | 2013-02-04 20:00:25 | [diff] [blame] | 301 | |
[email protected] | 85791b0b | 2014-05-20 15:18:58 | [diff] [blame] | 302 | for (size_t i = 0; i < metrics_providers.size(); ++i) |
| 303 | metrics_providers[i]->ProvideSystemProfileMetrics(system_profile); |
| 304 | |
holte | 1bf273c | 2017-02-23 00:22:28 | [diff] [blame] | 305 | EnvironmentRecorder recorder(local_state_); |
| 306 | return recorder.SerializeAndRecordEnvironmentToPrefs(*system_profile); |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 307 | } |
| 308 | |
manzagop | ea99d195 | 2016-09-08 23:40:05 | [diff] [blame] | 309 | bool MetricsLog::LoadSavedEnvironmentFromPrefs(std::string* app_version) { |
| 310 | DCHECK(app_version); |
| 311 | app_version->clear(); |
| 312 | |
[email protected] | 0f2f779 | 2013-11-28 16:09:14 | [diff] [blame] | 313 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
holte | 1bf273c | 2017-02-23 00:22:28 | [diff] [blame] | 314 | EnvironmentRecorder recorder(local_state_); |
| 315 | bool success = recorder.LoadEnvironmentFromPrefs(system_profile); |
manzagop | ea99d195 | 2016-09-08 23:40:05 | [diff] [blame] | 316 | if (success) |
| 317 | *app_version = system_profile->app_version(); |
| 318 | return success; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 319 | } |
| 320 | |
[email protected] | bfb77b5 | 2014-06-07 01:54:01 | [diff] [blame] | 321 | void MetricsLog::CloseLog() { |
| 322 | DCHECK(!closed_); |
| 323 | closed_ = true; |
| 324 | } |
| 325 | |
| 326 | void MetricsLog::GetEncodedLog(std::string* encoded_log) { |
| 327 | DCHECK(closed_); |
| 328 | uma_proto_.SerializeToString(encoded_log); |
| 329 | } |
asvitkine | cbd42073 | 2014-08-26 22:15:40 | [diff] [blame] | 330 | |
| 331 | } // namespace metrics |