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

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

Issue 2657083003: Populate a basic SystemProfileProto in UKM. (Closed)
Patch Set: remove stale TODO Created 3 years, 10 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/metrics/metrics_log_unittest.cc ('k') | no next file » | 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/time/time.h" 17 #include "base/time/time.h"
18 #include "components/metrics/metrics_log.h"
18 #include "components/metrics/metrics_log_uploader.h" 19 #include "components/metrics/metrics_log_uploader.h"
19 #include "components/metrics/metrics_service_client.h" 20 #include "components/metrics/metrics_service_client.h"
20 #include "components/metrics/proto/ukm/report.pb.h" 21 #include "components/metrics/proto/ukm/report.pb.h"
21 #include "components/metrics/proto/ukm/source.pb.h" 22 #include "components/metrics/proto/ukm/source.pb.h"
22 #include "components/prefs/pref_registry_simple.h" 23 #include "components/prefs/pref_registry_simple.h"
23 #include "components/prefs/pref_service.h" 24 #include "components/prefs/pref_service.h"
24 #include "components/ukm/metrics_reporting_scheduler.h" 25 #include "components/ukm/metrics_reporting_scheduler.h"
25 #include "components/ukm/persisted_logs_metrics_impl.h" 26 #include "components/ukm/persisted_logs_metrics_impl.h"
26 #include "components/ukm/ukm_pref_names.h" 27 #include "components/ukm/ukm_pref_names.h"
27 #include "components/ukm/ukm_source.h" 28 #include "components/ukm/ukm_source.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 prefs::kUkmPersistedLogs, 94 prefs::kUkmPersistedLogs,
94 kMinPersistedLogs, 95 kMinPersistedLogs,
95 kMinPersistedBytes, 96 kMinPersistedBytes,
96 kMaxLogRetransmitSize), 97 kMaxLogRetransmitSize),
97 initialize_started_(false), 98 initialize_started_(false),
98 initialize_complete_(false), 99 initialize_complete_(false),
99 log_upload_in_progress_(false), 100 log_upload_in_progress_(false),
100 self_ptr_factory_(this) { 101 self_ptr_factory_(this) {
101 DCHECK(pref_service_); 102 DCHECK(pref_service_);
102 DCHECK(client_); 103 DCHECK(client_);
104 DVLOG(1) << "UkmService::Constructor";
103 105
104 persisted_logs_.DeserializeLogs(); 106 persisted_logs_.DeserializeLogs();
105 107
106 base::Closure rotate_callback = 108 base::Closure rotate_callback =
107 base::Bind(&UkmService::RotateLog, self_ptr_factory_.GetWeakPtr()); 109 base::Bind(&UkmService::RotateLog, self_ptr_factory_.GetWeakPtr());
108 // MetricsServiceClient outlives UkmService, and 110 // MetricsServiceClient outlives UkmService, and
109 // MetricsReportingScheduler is tied to the lifetime of |this|. 111 // MetricsReportingScheduler is tied to the lifetime of |this|.
110 const base::Callback<base::TimeDelta(void)>& get_upload_interval_callback = 112 const base::Callback<base::TimeDelta(void)>& get_upload_interval_callback =
111 base::Bind(&metrics::MetricsServiceClient::GetStandardUploadInterval, 113 base::Bind(&metrics::MetricsServiceClient::GetStandardUploadInterval,
112 base::Unretained(client_)); 114 base::Unretained(client_));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 BuildAndStoreLog(); 187 BuildAndStoreLog();
186 } 188 }
187 StartScheduledUpload(); 189 StartScheduledUpload();
188 } 190 }
189 191
190 void UkmService::BuildAndStoreLog() { 192 void UkmService::BuildAndStoreLog() {
191 DCHECK(thread_checker_.CalledOnValidThread()); 193 DCHECK(thread_checker_.CalledOnValidThread());
192 DVLOG(1) << "UkmService::BuildAndStoreLog"; 194 DVLOG(1) << "UkmService::BuildAndStoreLog";
193 Report report; 195 Report report;
194 report.set_client_id(client_id_); 196 report.set_client_id(client_id_);
195 // TODO(holte): Populate system_profile.
196 197
197 for (const auto& source : sources_) { 198 for (const auto& source : sources_) {
198 Source* proto_source = report.add_sources(); 199 Source* proto_source = report.add_sources();
199 source->PopulateProto(proto_source); 200 source->PopulateProto(proto_source);
200 } 201 }
201 UMA_HISTOGRAM_COUNTS_1000("UKM.Sources.SerializedCount", sources_.size()); 202 UMA_HISTOGRAM_COUNTS_1000("UKM.Sources.SerializedCount", sources_.size());
202 sources_.clear(); 203 sources_.clear();
203 204
205 metrics::MetricsLog::RecordCoreSystemProfile(client_,
206 report.mutable_system_profile());
207 // TODO(rkaplow): Populate network information.
204 std::string serialized_log; 208 std::string serialized_log;
205 report.SerializeToString(&serialized_log); 209 report.SerializeToString(&serialized_log);
206 persisted_logs_.StoreLog(serialized_log); 210 persisted_logs_.StoreLog(serialized_log);
207 } 211 }
208 212
209 void UkmService::StartScheduledUpload() { 213 void UkmService::StartScheduledUpload() {
210 DCHECK(thread_checker_.CalledOnValidThread()); 214 DCHECK(thread_checker_.CalledOnValidThread());
211 DCHECK(!log_upload_in_progress_); 215 DCHECK(!log_upload_in_progress_);
212 if (!persisted_logs_.has_staged_log()) 216 if (!persisted_logs_.has_staged_log())
213 persisted_logs_.StageLog(); 217 persisted_logs_.StageLog();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 void UkmService::RecordSource(std::unique_ptr<UkmSource> source) { 264 void UkmService::RecordSource(std::unique_ptr<UkmSource> source) {
261 if (sources_.size() >= kMaxSources) { 265 if (sources_.size() >= kMaxSources) {
262 UMA_HISTOGRAM_BOOLEAN("UKM.Sources.MaxSourcesHit", true); 266 UMA_HISTOGRAM_BOOLEAN("UKM.Sources.MaxSourcesHit", true);
263 return; 267 return;
264 } 268 }
265 269
266 sources_.push_back(std::move(source)); 270 sources_.push_back(std::move(source));
267 } 271 }
268 272
269 } // namespace ukm 273 } // namespace ukm
OLDNEW
« no previous file with comments | « components/metrics/metrics_log_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698