Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: components/ukm/ukm_service.cc

Issue 2657083003: Populate a basic SystemProfileProto in UKM. (Closed)
Patch Set: small fixes Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/ukm/ukm_service.h ('k') | components/ukm/ukm_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/ukm/ukm_service.h" 5 #include "components/ukm/ukm_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/rand_util.h" 15 #include "base/rand_util.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/sys_info.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "components/metrics/metrics_log.h"
18 #include "components/metrics/metrics_log_uploader.h" 20 #include "components/metrics/metrics_log_uploader.h"
19 #include "components/metrics/metrics_service_client.h" 21 #include "components/metrics/metrics_service_client.h"
20 #include "components/metrics/proto/ukm/report.pb.h" 22 #include "components/metrics/proto/ukm/report.pb.h"
21 #include "components/prefs/pref_registry_simple.h" 23 #include "components/prefs/pref_registry_simple.h"
22 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
23 #include "components/ukm/metrics_reporting_scheduler.h" 25 #include "components/ukm/metrics_reporting_scheduler.h"
24 #include "components/ukm/persisted_logs_metrics_impl.h" 26 #include "components/ukm/persisted_logs_metrics_impl.h"
25 #include "components/ukm/ukm_pref_names.h" 27 #include "components/ukm/ukm_pref_names.h"
26 #include "components/variations/variations_associated_data.h" 28 #include "components/variations/variations_associated_data.h"
27 29
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 prefs::kUkmPersistedLogs, 89 prefs::kUkmPersistedLogs,
88 kMinPersistedLogs, 90 kMinPersistedLogs,
89 kMinPersistedBytes, 91 kMinPersistedBytes,
90 kMaxLogRetransmitSize), 92 kMaxLogRetransmitSize),
91 initialize_started_(false), 93 initialize_started_(false),
92 initialize_complete_(false), 94 initialize_complete_(false),
93 log_upload_in_progress_(false), 95 log_upload_in_progress_(false),
94 self_ptr_factory_(this) { 96 self_ptr_factory_(this) {
95 DCHECK(pref_service_); 97 DCHECK(pref_service_);
96 DCHECK(client_); 98 DCHECK(client_);
99 DVLOG(1) << "UkmService::Constructor";
97 100
98 persisted_logs_.DeserializeLogs(); 101 persisted_logs_.DeserializeLogs();
99 102
100 base::Closure rotate_callback = 103 base::Closure rotate_callback =
101 base::Bind(&UkmService::RotateLog, self_ptr_factory_.GetWeakPtr()); 104 base::Bind(&UkmService::RotateLog, self_ptr_factory_.GetWeakPtr());
102 // MetricsServiceClient outlives UkmService, and 105 // MetricsServiceClient outlives UkmService, and
103 // MetricsReportingScheduler is tied to the lifetime of |this|. 106 // MetricsReportingScheduler is tied to the lifetime of |this|.
104 const base::Callback<base::TimeDelta(void)>& get_upload_interval_callback = 107 const base::Callback<base::TimeDelta(void)>& get_upload_interval_callback =
105 base::Bind(&metrics::MetricsServiceClient::GetStandardUploadInterval, 108 base::Bind(&metrics::MetricsServiceClient::GetStandardUploadInterval,
106 base::Unretained(client_)); 109 base::Unretained(client_));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 BuildAndStoreLog(); 185 BuildAndStoreLog();
183 } 186 }
184 StartScheduledUpload(); 187 StartScheduledUpload();
185 } 188 }
186 189
187 void UkmService::BuildAndStoreLog() { 190 void UkmService::BuildAndStoreLog() {
188 DCHECK(thread_checker_.CalledOnValidThread()); 191 DCHECK(thread_checker_.CalledOnValidThread());
189 DVLOG(1) << "UkmService::BuildAndStoreLog"; 192 DVLOG(1) << "UkmService::BuildAndStoreLog";
190 Report report; 193 Report report;
191 report.set_client_id(client_id_); 194 report.set_client_id(client_id_);
192 // TODO(holte): Populate system_profile. 195 PopulateSystemProfile(&report);
196 // TODO(rkaplow): Populate network information.
193 // TODO(oystein): Populate sources. 197 // TODO(oystein): Populate sources.
194 std::string serialized_log; 198 std::string serialized_log;
195 report.SerializeToString(&serialized_log); 199 report.SerializeToString(&serialized_log);
196 persisted_logs_.StoreLog(serialized_log); 200 persisted_logs_.StoreLog(serialized_log);
197 } 201 }
198 202
199 void UkmService::StartScheduledUpload() { 203 void UkmService::StartScheduledUpload() {
200 DCHECK(thread_checker_.CalledOnValidThread()); 204 DCHECK(thread_checker_.CalledOnValidThread());
201 DCHECK(!log_upload_in_progress_); 205 DCHECK(!log_upload_in_progress_);
202 if (!persisted_logs_.has_staged_log()) 206 if (!persisted_logs_.has_staged_log())
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // Store the updated list to disk now that the removed log is uploaded. 244 // Store the updated list to disk now that the removed log is uploaded.
241 persisted_logs_.SerializeLogs(); 245 persisted_logs_.SerializeLogs();
242 } 246 }
243 247
244 // Error 400 indicates a problem with the log, not with the server, so 248 // Error 400 indicates a problem with the log, not with the server, so
245 // don't consider that a sign that the server is in trouble. 249 // don't consider that a sign that the server is in trouble.
246 bool server_is_healthy = upload_succeeded || response_code == 400; 250 bool server_is_healthy = upload_succeeded || response_code == 400;
247 scheduler_->UploadFinished(server_is_healthy, !persisted_logs_.empty()); 251 scheduler_->UploadFinished(server_is_healthy, !persisted_logs_.empty());
248 } 252 }
249 253
254 void UkmService::PopulateSystemProfile(Report* report) {
255 // Currently just store the most important system information.
256 metrics::SystemProfileProto* system_profile =
257 report->mutable_system_profile();
258
259 system_profile->set_build_timestamp(metrics::MetricsLog::GetBuildTime());
260 system_profile->set_app_version(client_->GetVersionString());
261 system_profile->set_channel(client_->GetChannel());
262 system_profile->set_application_locale(client_->GetApplicationLocale());
263
264 metrics::SystemProfileProto::OS* os = system_profile->mutable_os();
265 os->set_name(base::SysInfo::OperatingSystemName());
266 os->set_version(base::SysInfo::OperatingSystemVersion());
267
268 metrics::SystemProfileProto::Hardware* hardware =
269 system_profile->mutable_hardware();
270 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
271 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
272 hardware->set_hardware_class(base::SysInfo::HardwareModelName());
273 }
Alexei Svitkine (slow) 2017/01/27 17:32:25 Can we share code with UMA? I suggest we refactor
274
250 } // namespace ukm 275 } // namespace ukm
OLDNEW
« no previous file with comments | « components/ukm/ukm_service.h ('k') | components/ukm/ukm_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698