blob: 8764a739fcd6af29cff51e3f6f6022fd16bcbe2b [file] [log] [blame]
[email protected]91b1d912014-06-05 10:52:081// Copyright 2014 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]91b1d912014-06-05 10:52:085#include "components/metrics/metrics_log.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]76869ff2013-01-15 16:13:477#include <algorithm>
[email protected]1eeb5e02010-07-20 23:02:118#include <string>
9#include <vector>
10
[email protected]0f2f7792013-11-28 16:09:1411#include "base/base64.h"
[email protected]d1be67b2008-11-19 20:28:3812#include "base/basictypes.h"
sebmarchand2f4ed502014-10-31 15:28:1913#include "base/build_time.h"
[email protected]5c8f89f692013-07-18 11:13:2814#include "base/cpu.h"
[email protected]3b63f8f42011-03-28 01:54:1515#include "base/memory/scoped_ptr.h"
[email protected]bfb77b52014-06-07 01:54:0116#include "base/metrics/histogram.h"
17#include "base/metrics/histogram_samples.h"
[email protected]3853a4c2013-02-11 17:15:5718#include "base/prefs/pref_registry_simple.h"
19#include "base/prefs/pref_service.h"
[email protected]0f2f7792013-11-28 16:09:1420#include "base/sha1.h"
[email protected]3ea1b182013-02-08 22:38:4121#include "base/strings/string_number_conversions.h"
[email protected]f9b294362013-06-10 20:22:3122#include "base/strings/string_util.h"
[email protected]112158af2013-06-07 23:46:1823#include "base/strings/utf_string_conversions.h"
[email protected]fadf97f2008-09-18 12:18:1424#include "base/sys_info.h"
[email protected]84813472013-06-28 00:25:1925#include "base/time/time.h"
[email protected]bfb77b52014-06-07 01:54:0126#include "components/metrics/metrics_hashes.h"
[email protected]91b1d912014-06-05 10:52:0827#include "components/metrics/metrics_pref_names.h"
[email protected]85791b0b2014-05-20 15:18:5828#include "components/metrics/metrics_provider.h"
[email protected]09dee82d2014-05-22 14:00:5329#include "components/metrics/metrics_service_client.h"
[email protected]bfb77b52014-06-07 01:54:0130#include "components/metrics/proto/histogram_event.pb.h"
[email protected]064107e2014-05-02 00:59:0631#include "components/metrics/proto/system_profile.pb.h"
[email protected]bfb77b52014-06-07 01:54:0132#include "components/metrics/proto/user_action_event.pb.h"
[email protected]b3610d42014-05-19 18:07:2333#include "components/variations/active_field_trials.h"
initial.commit09911bf2008-07-26 23:55:2934
[email protected]5106b3a2012-10-03 20:10:4435#if defined(OS_ANDROID)
36#include "base/android/build_info.h"
37#endif
38
[email protected]d1be67b2008-11-19 20:28:3839#if defined(OS_WIN)
[email protected]1bb25e02012-08-03 22:39:3940#include "base/win/metro.h"
41
42// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
[email protected]d1be67b2008-11-19 20:28:3843extern "C" IMAGE_DOS_HEADER __ImageBase;
44#endif
45
[email protected]bfb77b52014-06-07 01:54:0146using base::SampleCountIterator;
[email protected]b3610d42014-05-19 18:07:2347typedef variations::ActiveGroupId ActiveGroupId;
[email protected]79078df2012-02-16 01:22:3248
asvitkinecbd420732014-08-26 22:15:4049namespace metrics {
50
[email protected]1df44b72012-01-19 05:20:3451namespace {
52
[email protected]bfb77b52014-06-07 01:54:0153// Any id less than 16 bytes is considered to be a testing id.
54bool IsTestingID(const std::string& id) {
55 return id.size() < 16;
56}
57
[email protected]1df44b72012-01-19 05:20:3458// Returns the date at which the current metrics client ID was created as
[email protected]ca5ac4b2012-12-14 07:46:4059// a string containing seconds since the epoch, or "0" if none was found.
[email protected]cc5d7f42012-10-30 00:30:0960std::string GetMetricsEnabledDate(PrefService* pref) {
[email protected]767c9d92012-03-02 16:04:3461 if (!pref) {
[email protected]1df44b72012-01-19 05:20:3462 NOTREACHED();
63 return "0";
64 }
[email protected]767c9d92012-03-02 16:04:3465
asvitkine4c1d1ef2014-09-29 20:57:3266 return pref->GetString(prefs::kMetricsReportingEnabledTimestamp);
[email protected]1df44b72012-01-19 05:20:3467}
68
[email protected]0f2f7792013-11-28 16:09:1469// Computes a SHA-1 hash of |data| and returns it as a hex string.
70std::string ComputeSHA1(const std::string& data) {
71 const std::string sha1 = base::SHA1HashString(data);
72 return base::HexEncode(sha1.data(), sha1.size());
73}
74
[email protected]0c8b7ad2012-11-06 07:08:1475void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids,
[email protected]767c9d92012-03-02 16:04:3476 SystemProfileProto* system_profile) {
[email protected]0c8b7ad2012-11-06 07:08:1477 for (std::vector<ActiveGroupId>::const_iterator it =
[email protected]ad2461c2012-04-27 21:11:0378 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
[email protected]767c9d92012-03-02 16:04:3479 SystemProfileProto::FieldTrial* field_trial =
80 system_profile->add_field_trial();
81 field_trial->set_name_id(it->name);
82 field_trial->set_group_id(it->group);
83 }
84}
85
[email protected]86573d12013-07-11 19:48:3286// Round a timestamp measured in seconds since epoch to one with a granularity
87// of an hour. This can be used before uploaded potentially sensitive
88// timestamps.
89int64 RoundSecondsToHour(int64 time_in_seconds) {
90 return 3600 * (time_in_seconds / 3600);
91}
92
[email protected]1df44b72012-01-19 05:20:3493} // namespace
94
[email protected]9eae4032014-04-09 19:15:1995MetricsLog::MetricsLog(const std::string& client_id,
96 int session_id,
[email protected]09dee82d2014-05-22 14:00:5397 LogType log_type,
asvitkine4c1d1ef2014-09-29 20:57:3298 MetricsServiceClient* client,
[email protected]24f81ca2014-05-26 15:59:3499 PrefService* local_state)
[email protected]bfb77b52014-06-07 01:54:01100 : closed_(false),
101 log_type_(log_type),
[email protected]09dee82d2014-05-22 14:00:53102 client_(client),
[email protected]24f81ca2014-05-26 15:59:34103 creation_time_(base::TimeTicks::Now()),
104 local_state_(local_state) {
[email protected]bfb77b52014-06-07 01:54:01105 if (IsTestingID(client_id))
106 uma_proto_.set_client_id(0);
107 else
108 uma_proto_.set_client_id(Hash(client_id));
109
110 uma_proto_.set_session_id(session_id);
111
asvitkine4c1d1ef2014-09-29 20:57:32112 const int32 product = client_->GetProduct();
113 // Only set the product if it differs from the default value.
114 if (product != uma_proto_.product())
115 uma_proto_.set_product(product);
116
[email protected]bfb77b52014-06-07 01:54:01117 SystemProfileProto* system_profile = uma_proto_.mutable_system_profile();
118 system_profile->set_build_timestamp(GetBuildTime());
119 system_profile->set_app_version(client_->GetVersionString());
120 system_profile->set_channel(client_->GetChannel());
[email protected]afc03f02013-10-11 06:01:35121}
[email protected]5ed7d4572009-12-23 17:42:41122
[email protected]bfb77b52014-06-07 01:54:01123MetricsLog::~MetricsLog() {
124}
initial.commit09911bf2008-07-26 23:55:29125
[email protected]91b1d912014-06-05 10:52:08126// static
127void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) {
asvitkine4c1d1ef2014-09-29 20:57:32128 registry->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0);
129 registry->RegisterIntegerPref(prefs::kStabilityCrashCount, 0);
130 registry->RegisterIntegerPref(prefs::kStabilityIncompleteSessionEndCount, 0);
131 registry->RegisterIntegerPref(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]91b1d912014-06-05 10:52:08132 registry->RegisterIntegerPref(
asvitkine4c1d1ef2014-09-29 20:57:32133 prefs::kStabilityBreakpadRegistrationSuccess, 0);
134 registry->RegisterIntegerPref(prefs::kStabilityDebuggerPresent, 0);
135 registry->RegisterIntegerPref(prefs::kStabilityDebuggerNotPresent, 0);
136 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfile,
[email protected]91b1d912014-06-05 10:52:08137 std::string());
asvitkine4c1d1ef2014-09-29 20:57:32138 registry->RegisterStringPref(prefs::kStabilitySavedSystemProfileHash,
[email protected]91b1d912014-06-05 10:52:08139 std::string());
140}
141
[email protected]bfb77b52014-06-07 01:54:01142// static
143uint64 MetricsLog::Hash(const std::string& value) {
asvitkine4c1d1ef2014-09-29 20:57:32144 uint64 hash = HashMetricName(value);
[email protected]bfb77b52014-06-07 01:54:01145
146 // The following log is VERY helpful when folks add some named histogram into
147 // the code, but forgot to update the descriptive list of histograms. When
148 // that happens, all we get to see (server side) is a hash of the histogram
149 // name. We can then use this logging to find out what histogram name was
150 // being hashed to a given MD5 value by just running the version of Chromium
151 // in question with --enable-logging.
152 DVLOG(1) << "Metrics: Hash numeric [" << value << "]=[" << hash << "]";
153
154 return hash;
155}
156
157// static
158int64 MetricsLog::GetBuildTime() {
159 static int64 integral_build_time = 0;
sebmarchand2f4ed502014-10-31 15:28:19160 if (!integral_build_time)
161 integral_build_time = static_cast<int64>(base::GetBuildTime().ToTimeT());
[email protected]bfb77b52014-06-07 01:54:01162 return integral_build_time;
163}
164
165// static
166int64 MetricsLog::GetCurrentTime() {
167 return (base::TimeTicks::Now() - base::TimeTicks()).InSeconds();
168}
169
170void MetricsLog::RecordUserAction(const std::string& key) {
171 DCHECK(!closed_);
172
173 UserActionEventProto* user_action = uma_proto_.add_user_action_event();
174 user_action->set_name_hash(Hash(key));
175 user_action->set_time(GetCurrentTime());
176}
177
178void MetricsLog::RecordHistogramDelta(const std::string& histogram_name,
179 const base::HistogramSamples& snapshot) {
180 DCHECK(!closed_);
181 DCHECK_NE(0, snapshot.TotalCount());
182
183 // We will ignore the MAX_INT/infinite value in the last element of range[].
184
185 HistogramEventProto* histogram_proto = uma_proto_.add_histogram_event();
186 histogram_proto->set_name_hash(Hash(histogram_name));
187 histogram_proto->set_sum(snapshot.sum());
188
189 for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); !it->Done();
190 it->Next()) {
191 base::Histogram::Sample min;
192 base::Histogram::Sample max;
193 base::Histogram::Count count;
194 it->Get(&min, &max, &count);
195 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket();
196 bucket->set_min(min);
197 bucket->set_max(max);
198 bucket->set_count(count);
199 }
200
201 // Omit fields to save space (see rules in histogram_event.proto comments).
202 for (int i = 0; i < histogram_proto->bucket_size(); ++i) {
203 HistogramEventProto::Bucket* bucket = histogram_proto->mutable_bucket(i);
204 if (i + 1 < histogram_proto->bucket_size() &&
205 bucket->max() == histogram_proto->bucket(i + 1).min()) {
206 bucket->clear_max();
207 } else if (bucket->max() == bucket->min() + 1) {
208 bucket->clear_min();
209 }
210 }
211}
212
[email protected]85791b0b2014-05-20 15:18:58213void MetricsLog::RecordStabilityMetrics(
asvitkine4c1d1ef2014-09-29 20:57:32214 const std::vector<MetricsProvider*>& metrics_providers,
[email protected]85791b0b2014-05-20 15:18:58215 base::TimeDelta incremental_uptime,
216 base::TimeDelta uptime) {
[email protected]bfb77b52014-06-07 01:54:01217 DCHECK(!closed_);
[email protected]0f2f7792013-11-28 16:09:14218 DCHECK(HasEnvironment());
219 DCHECK(!HasStabilityMetrics());
[email protected]0b33f80b2008-12-17 21:34:36220
[email protected]24f81ca2014-05-26 15:59:34221 PrefService* pref = local_state_;
[email protected]0b33f80b2008-12-17 21:34:36222 DCHECK(pref);
223
initial.commit09911bf2008-07-26 23:55:29224 // Get stability attributes out of Local State, zeroing out stored values.
225 // NOTE: This could lead to some data loss if this report isn't successfully
226 // sent, but that's true for all the metrics.
227
[email protected]147bbc0b2009-01-06 19:37:40228 WriteRequiredStabilityAttributes(pref);
[email protected]0edf8762013-11-21 18:33:30229
230 // Record recent delta for critical stability metrics. We can't wait for a
231 // restart to gather these, as that delay biases our observation away from
232 // users that run happily for a looooong time. We send increments with each
233 // uma log upload, just as we send histogram data.
[email protected]076961c2014-03-12 22:23:56234 WriteRealtimeStabilityAttributes(pref, incremental_uptime, uptime);
initial.commit09911bf2008-07-26 23:55:29235
[email protected]48ff2c7f2014-05-23 09:57:45236 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]85791b0b2014-05-20 15:18:58237 for (size_t i = 0; i < metrics_providers.size(); ++i)
[email protected]48ff2c7f2014-05-23 09:57:45238 metrics_providers[i]->ProvideStabilityMetrics(system_profile);
[email protected]85791b0b2014-05-20 15:18:58239
[email protected]0edf8762013-11-21 18:33:30240 // Omit some stats unless this is the initial stability log.
[email protected]9eae4032014-04-09 19:15:19241 if (log_type() != INITIAL_STABILITY_LOG)
[email protected]0edf8762013-11-21 18:33:30242 return;
243
[email protected]fe58acc22012-02-29 01:29:58244 int incomplete_shutdown_count =
asvitkine4c1d1ef2014-09-29 20:57:32245 pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount);
246 pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0);
[email protected]fe58acc22012-02-29 01:29:58247 int breakpad_registration_success_count =
asvitkine4c1d1ef2014-09-29 20:57:32248 pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess);
249 pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0);
[email protected]fe58acc22012-02-29 01:29:58250 int breakpad_registration_failure_count =
asvitkine4c1d1ef2014-09-29 20:57:32251 pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail);
252 pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0);
[email protected]fe58acc22012-02-29 01:29:58253 int debugger_present_count =
asvitkine4c1d1ef2014-09-29 20:57:32254 pref->GetInteger(prefs::kStabilityDebuggerPresent);
255 pref->SetInteger(prefs::kStabilityDebuggerPresent, 0);
[email protected]fe58acc22012-02-29 01:29:58256 int debugger_not_present_count =
asvitkine4c1d1ef2014-09-29 20:57:32257 pref->GetInteger(prefs::kStabilityDebuggerNotPresent);
258 pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0);
[email protected]b2a4812d2012-02-28 05:31:31259
[email protected]fe58acc22012-02-29 01:29:58260 // TODO(jar): The following are all optional, so we *could* optimize them for
261 // values of zero (and not include them).
[email protected]48ff2c7f2014-05-23 09:57:45262 SystemProfileProto::Stability* stability =
263 system_profile->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58264 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
265 stability->set_breakpad_registration_success_count(
266 breakpad_registration_success_count);
267 stability->set_breakpad_registration_failure_count(
268 breakpad_registration_failure_count);
269 stability->set_debugger_present_count(debugger_present_count);
270 stability->set_debugger_not_present_count(debugger_not_present_count);
[email protected]0edf8762013-11-21 18:33:30271}
[email protected]fe58acc22012-02-29 01:29:58272
[email protected]85791b0b2014-05-20 15:18:58273void MetricsLog::RecordGeneralMetrics(
asvitkine4c1d1ef2014-09-29 20:57:32274 const std::vector<MetricsProvider*>& metrics_providers) {
[email protected]85791b0b2014-05-20 15:18:58275 for (size_t i = 0; i < metrics_providers.size(); ++i)
276 metrics_providers[i]->ProvideGeneralMetrics(uma_proto());
277}
278
[email protected]0edf8762013-11-21 18:33:30279void MetricsLog::GetFieldTrialIds(
280 std::vector<ActiveGroupId>* field_trial_ids) const {
[email protected]b3610d42014-05-19 18:07:23281 variations::GetFieldTrialActiveGroupIds(field_trial_ids);
[email protected]147bbc0b2009-01-06 19:37:40282}
283
[email protected]0f2f7792013-11-28 16:09:14284bool MetricsLog::HasEnvironment() const {
285 return uma_proto()->system_profile().has_uma_enabled_date();
286}
287
288bool MetricsLog::HasStabilityMetrics() const {
289 return uma_proto()->system_profile().stability().has_launch_count();
290}
291
[email protected]fe58acc22012-02-29 01:29:58292// The server refuses data that doesn't have certain values. crashcount and
293// launchcount are currently "required" in the "stability" group.
294// TODO(isherman): Stop writing these attributes specially once the migration to
295// protobufs is complete.
[email protected]147bbc0b2009-01-06 19:37:40296void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) {
asvitkine4c1d1ef2014-09-29 20:57:32297 int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount);
298 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
299 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
300 pref->SetInteger(prefs::kStabilityCrashCount, 0);
[email protected]fe58acc22012-02-29 01:29:58301
[email protected]fe58acc22012-02-29 01:29:58302 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34303 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]fe58acc22012-02-29 01:29:58304 stability->set_launch_count(launch_count);
305 stability->set_crash_count(crash_count);
[email protected]0b33f80b2008-12-17 21:34:36306}
307
[email protected]c68a2b9b2013-10-09 18:16:36308void MetricsLog::WriteRealtimeStabilityAttributes(
309 PrefService* pref,
[email protected]076961c2014-03-12 22:23:56310 base::TimeDelta incremental_uptime,
311 base::TimeDelta uptime) {
[email protected]0b33f80b2008-12-17 21:34:36312 // Update the stats which are critical for real-time stability monitoring.
313 // Since these are "optional," only list ones that are non-zero, as the counts
[email protected]250f7b662013-11-23 02:36:51314 // are aggregated (summed) server side.
[email protected]0b33f80b2008-12-17 21:34:36315
[email protected]fe58acc22012-02-29 01:29:58316 SystemProfileProto::Stability* stability =
[email protected]767c9d92012-03-02 16:04:34317 uma_proto()->mutable_system_profile()->mutable_stability();
[email protected]0b33f80b2008-12-17 21:34:36318
[email protected]076961c2014-03-12 22:23:56319 const uint64 incremental_uptime_sec = incremental_uptime.InSeconds();
320 if (incremental_uptime_sec)
321 stability->set_incremental_uptime_sec(incremental_uptime_sec);
322 const uint64 uptime_sec = uptime.InSeconds();
[email protected]c68a2b9b2013-10-09 18:16:36323 if (uptime_sec)
324 stability->set_uptime_sec(uptime_sec);
[email protected]0b33f80b2008-12-17 21:34:36325}
326
initial.commit09911bf2008-07-26 23:55:29327void MetricsLog::RecordEnvironment(
asvitkine4c1d1ef2014-09-29 20:57:32328 const std::vector<MetricsProvider*>& metrics_providers,
[email protected]65801452014-07-09 05:42:41329 const std::vector<variations::ActiveGroupId>& synthetic_trials,
330 int64 install_date) {
[email protected]0f2f7792013-11-28 16:09:14331 DCHECK(!HasEnvironment());
332
[email protected]bc66d532012-03-23 01:57:05333 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
[email protected]24b9bb392013-01-29 20:29:29334
335 std::string brand_code;
[email protected]09dee82d2014-05-22 14:00:53336 if (client_->GetBrand(&brand_code))
[email protected]24b9bb392013-01-29 20:29:29337 system_profile->set_brand_code(brand_code);
338
[email protected]cc5d7f42012-10-30 00:30:09339 int enabled_date;
[email protected]24f81ca2014-05-26 15:59:34340 bool success =
341 base::StringToInt(GetMetricsEnabledDate(local_state_), &enabled_date);
[email protected]bc66d532012-03-23 01:57:05342 DCHECK(success);
[email protected]86573d12013-07-11 19:48:32343
344 // Reduce granularity of the enabled_date field to nearest hour.
345 system_profile->set_uma_enabled_date(RoundSecondsToHour(enabled_date));
346
[email protected]86573d12013-07-11 19:48:32347 // Reduce granularity of the install_date field to nearest hour.
348 system_profile->set_install_date(RoundSecondsToHour(install_date));
[email protected]bc66d532012-03-23 01:57:05349
[email protected]09dee82d2014-05-22 14:00:53350 system_profile->set_application_locale(client_->GetApplicationLocale());
[email protected]bc66d532012-03-23 01:57:05351
352 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
[email protected]51994b22014-05-30 13:24:21353
354 // By default, the hardware class is empty (i.e., unknown).
355 hardware->set_hardware_class(std::string());
356
[email protected]0b6a4fb2012-10-16 01:58:21357 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
[email protected]bc66d532012-03-23 01:57:05358 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
359#if defined(OS_WIN)
360 hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase));
361#endif
362
363 SystemProfileProto::OS* os = system_profile->mutable_os();
[email protected]1bb25e02012-08-03 22:39:39364 std::string os_name = base::SysInfo::OperatingSystemName();
365#if defined(OS_WIN)
366 // TODO(mad): This only checks whether the main process is a Metro process at
367 // upload time; not whether the collected metrics were all gathered from
368 // Metro. This is ok as an approximation for now, since users will rarely be
369 // switching from Metro to Desktop mode; but we should re-evaluate whether we
370 // can distinguish metrics more cleanly in the future: http://crbug.com/140568
371 if (base::win::IsMetroProcess())
372 os_name += " (Metro)";
373#endif
374 os->set_name(os_name);
[email protected]bc66d532012-03-23 01:57:05375 os->set_version(base::SysInfo::OperatingSystemVersion());
[email protected]5106b3a2012-10-03 20:10:44376#if defined(OS_ANDROID)
377 os->set_fingerprint(
378 base::android::BuildInfo::GetInstance()->android_build_fp());
379#endif
[email protected]bc66d532012-03-23 01:57:05380
[email protected]5c8f89f692013-07-18 11:13:28381 base::CPU cpu_info;
382 SystemProfileProto::Hardware::CPU* cpu = hardware->mutable_cpu();
383 cpu->set_vendor_name(cpu_info.vendor_name());
384 cpu->set_signature(cpu_info.signature());
385
[email protected]0c8b7ad2012-11-06 07:08:14386 std::vector<ActiveGroupId> field_trial_ids;
[email protected]767c9d92012-03-02 16:04:34387 GetFieldTrialIds(&field_trial_ids);
388 WriteFieldTrials(field_trial_ids, system_profile);
[email protected]60677562013-11-17 15:52:55389 WriteFieldTrials(synthetic_trials, system_profile);
[email protected]f65859e2013-02-04 20:00:25390
[email protected]85791b0b2014-05-20 15:18:58391 for (size_t i = 0; i < metrics_providers.size(); ++i)
392 metrics_providers[i]->ProvideSystemProfileMetrics(system_profile);
393
[email protected]0f2f7792013-11-28 16:09:14394 std::string serialied_system_profile;
395 std::string base64_system_profile;
[email protected]33fca122013-12-11 01:48:50396 if (system_profile->SerializeToString(&serialied_system_profile)) {
397 base::Base64Encode(serialied_system_profile, &base64_system_profile);
[email protected]24f81ca2014-05-26 15:59:34398 PrefService* local_state = local_state_;
asvitkine4c1d1ef2014-09-29 20:57:32399 local_state->SetString(prefs::kStabilitySavedSystemProfile,
[email protected]0f2f7792013-11-28 16:09:14400 base64_system_profile);
asvitkine4c1d1ef2014-09-29 20:57:32401 local_state->SetString(prefs::kStabilitySavedSystemProfileHash,
[email protected]0f2f7792013-11-28 16:09:14402 ComputeSHA1(serialied_system_profile));
403 }
404}
405
406bool MetricsLog::LoadSavedEnvironmentFromPrefs() {
[email protected]24f81ca2014-05-26 15:59:34407 PrefService* local_state = local_state_;
[email protected]0f2f7792013-11-28 16:09:14408 const std::string base64_system_profile =
asvitkine4c1d1ef2014-09-29 20:57:32409 local_state->GetString(prefs::kStabilitySavedSystemProfile);
[email protected]0f2f7792013-11-28 16:09:14410 if (base64_system_profile.empty())
411 return false;
412
413 const std::string system_profile_hash =
asvitkine4c1d1ef2014-09-29 20:57:32414 local_state->GetString(prefs::kStabilitySavedSystemProfileHash);
415 local_state->ClearPref(prefs::kStabilitySavedSystemProfile);
416 local_state->ClearPref(prefs::kStabilitySavedSystemProfileHash);
[email protected]0f2f7792013-11-28 16:09:14417
418 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
419 std::string serialied_system_profile;
420 return base::Base64Decode(base64_system_profile, &serialied_system_profile) &&
421 ComputeSHA1(serialied_system_profile) == system_profile_hash &&
422 system_profile->ParseFromString(serialied_system_profile);
initial.commit09911bf2008-07-26 23:55:29423}
424
[email protected]bfb77b52014-06-07 01:54:01425void MetricsLog::CloseLog() {
426 DCHECK(!closed_);
427 closed_ = true;
428}
429
430void MetricsLog::GetEncodedLog(std::string* encoded_log) {
431 DCHECK(closed_);
432 uma_proto_.SerializeToString(encoded_log);
433}
asvitkinecbd420732014-08-26 22:15:40434
435} // namespace metrics