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

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

Issue 794493002: Add UMA Histogram Manager to Cronet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed comments for Patch Set 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/metrics/histogram_encoder.h"
6
7 #include <string>
8
9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/metrics/histogram.h"
12 #include "base/metrics/histogram_samples.h"
13 #include "components/metrics/metrics_hashes.h"
14
15 using base::SampleCountIterator;
16
17 namespace metrics {
18
19 void RecordHistogramDelta(const std::string& histogram_name,
20 const base::HistogramSamples& snapshot,
21 ChromeUserMetricsExtension* uma_proto) {
22 DCHECK_NE(0, snapshot.TotalCount());
23
24 // We will ignore the MAX_INT/infinite value in the last element of range[].
25
26 HistogramEventProto* histogram_proto = uma_proto->add_histogram_event();
27 histogram_proto->set_name_hash(HashMetricName(histogram_name));
28 histogram_proto->set_sum(snapshot.sum());
29
30 for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); !it->Done();
31 it->Next()) {
32 base::Histogram::Sample min;
33 base::Histogram::Sample max;
34 base::Histogram::Count count;
35 it->Get(&min, &max, &count);
36 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket();
37 bucket->set_min(min);
38 bucket->set_max(max);
39 bucket->set_count(count);
40 }
41
42 // Omit fields to save space (see rules in histogram_event.proto comments).
43 for (int i = 0; i < histogram_proto->bucket_size(); ++i) {
44 HistogramEventProto::Bucket* bucket = histogram_proto->mutable_bucket(i);
45 if (i + 1 < histogram_proto->bucket_size() &&
46 bucket->max() == histogram_proto->bucket(i + 1).min()) {
47 bucket->clear_max();
48 } else if (bucket->max() == bucket->min() + 1) {
49 bucket->clear_min();
50 }
51 }
52 }
53
54 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698