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

Side by Side Diff: components/metrics/metrics_log.cc

Issue 794493002: Add UMA Histogram Manager to Cronet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: disabled flaky HistogramBucketFields unittest Created 6 years 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
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/build_time.h" 13 #include "base/build_time.h"
14 #include "base/cpu.h" 14 #include "base/cpu.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/metrics/histogram_samples.h" 17 #include "base/metrics/histogram_samples.h"
18 #include "base/prefs/pref_registry_simple.h" 18 #include "base/prefs/pref_registry_simple.h"
19 #include "base/prefs/pref_service.h" 19 #include "base/prefs/pref_service.h"
20 #include "base/sha1.h" 20 #include "base/sha1.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "base/sys_info.h" 24 #include "base/sys_info.h"
25 #include "base/time/time.h" 25 #include "base/time/time.h"
26 #include "components/metrics/histogram_encoder.h"
26 #include "components/metrics/metrics_hashes.h" 27 #include "components/metrics/metrics_hashes.h"
27 #include "components/metrics/metrics_pref_names.h" 28 #include "components/metrics/metrics_pref_names.h"
28 #include "components/metrics/metrics_provider.h" 29 #include "components/metrics/metrics_provider.h"
29 #include "components/metrics/metrics_service_client.h" 30 #include "components/metrics/metrics_service_client.h"
30 #include "components/metrics/proto/histogram_event.pb.h" 31 #include "components/metrics/proto/histogram_event.pb.h"
31 #include "components/metrics/proto/system_profile.pb.h" 32 #include "components/metrics/proto/system_profile.pb.h"
32 #include "components/metrics/proto/user_action_event.pb.h" 33 #include "components/metrics/proto/user_action_event.pb.h"
33 #include "components/variations/active_field_trials.h" 34 #include "components/variations/active_field_trials.h"
34 35
35 #if defined(OS_ANDROID) 36 #if defined(OS_ANDROID)
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 DCHECK(!closed_); 172 DCHECK(!closed_);
172 173
173 UserActionEventProto* user_action = uma_proto_.add_user_action_event(); 174 UserActionEventProto* user_action = uma_proto_.add_user_action_event();
174 user_action->set_name_hash(Hash(key)); 175 user_action->set_name_hash(Hash(key));
175 user_action->set_time(GetCurrentTime()); 176 user_action->set_time(GetCurrentTime());
176 } 177 }
177 178
178 void MetricsLog::RecordHistogramDelta(const std::string& histogram_name, 179 void MetricsLog::RecordHistogramDelta(const std::string& histogram_name,
179 const base::HistogramSamples& snapshot) { 180 const base::HistogramSamples& snapshot) {
180 DCHECK(!closed_); 181 DCHECK(!closed_);
181 DCHECK_NE(0, snapshot.TotalCount()); 182 EncodeHistogramDelta(histogram_name, snapshot, &uma_proto_);
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 } 183 }
212 184
213 void MetricsLog::RecordStabilityMetrics( 185 void MetricsLog::RecordStabilityMetrics(
214 const std::vector<MetricsProvider*>& metrics_providers, 186 const std::vector<MetricsProvider*>& metrics_providers,
215 base::TimeDelta incremental_uptime, 187 base::TimeDelta incremental_uptime,
216 base::TimeDelta uptime) { 188 base::TimeDelta uptime) {
217 DCHECK(!closed_); 189 DCHECK(!closed_);
218 DCHECK(HasEnvironment()); 190 DCHECK(HasEnvironment());
219 DCHECK(!HasStabilityMetrics()); 191 DCHECK(!HasStabilityMetrics());
220 192
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 DCHECK(!closed_); 399 DCHECK(!closed_);
428 closed_ = true; 400 closed_ = true;
429 } 401 }
430 402
431 void MetricsLog::GetEncodedLog(std::string* encoded_log) { 403 void MetricsLog::GetEncodedLog(std::string* encoded_log) {
432 DCHECK(closed_); 404 DCHECK(closed_);
433 uma_proto_.SerializeToString(encoded_log); 405 uma_proto_.SerializeToString(encoded_log);
434 } 406 }
435 407
436 } // namespace metrics 408 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/histogram_manager_unittest.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698