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

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

Issue 1744283002: Optimizations to histogram protobuf encoding. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | components/metrics/proto/histogram_event.proto » ('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 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/histogram_encoder.h" 5 #include "components/metrics/histogram_encoder.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/metrics/histogram_samples.h" 11 #include "base/metrics/histogram_samples.h"
12 #include "base/metrics/metrics_hashes.h" 12 #include "base/metrics/metrics_hashes.h"
13 13
14 using base::SampleCountIterator; 14 using base::SampleCountIterator;
15 15
16 namespace metrics { 16 namespace metrics {
17 17
18 void EncodeHistogramDelta(const std::string& histogram_name, 18 void EncodeHistogramDelta(const std::string& histogram_name,
19 const base::HistogramSamples& snapshot, 19 const base::HistogramSamples& snapshot,
20 ChromeUserMetricsExtension* uma_proto) { 20 ChromeUserMetricsExtension* uma_proto) {
21 DCHECK_NE(0, snapshot.TotalCount()); 21 DCHECK_NE(0, snapshot.TotalCount());
22 DCHECK(uma_proto); 22 DCHECK(uma_proto);
23 23
24 // We will ignore the MAX_INT/infinite value in the last element of range[]. 24 // We will ignore the MAX_INT/infinite value in the last element of range[].
25 25
26 HistogramEventProto* histogram_proto = uma_proto->add_histogram_event(); 26 HistogramEventProto* histogram_proto = uma_proto->add_histogram_event();
27 histogram_proto->set_name_hash(base::HashMetricName(histogram_name)); 27 histogram_proto->set_name_hash(base::HashMetricName(histogram_name));
28 histogram_proto->set_sum(snapshot.sum()); 28 if (snapshot.sum() != 0)
29 histogram_proto->set_sum(snapshot.sum());
29 30
30 for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); !it->Done(); 31 for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); !it->Done();
31 it->Next()) { 32 it->Next()) {
32 base::Histogram::Sample min; 33 base::Histogram::Sample min;
33 base::Histogram::Sample max; 34 base::Histogram::Sample max;
34 base::Histogram::Count count; 35 base::Histogram::Count count;
35 it->Get(&min, &max, &count); 36 it->Get(&min, &max, &count);
36 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket(); 37 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket();
37 bucket->set_min(min); 38 bucket->set_min(min);
38 bucket->set_max(max); 39 bucket->set_max(max);
39 bucket->set_count(count); 40 if (count != 1)
rkaplow 2016/02/29 22:46:44 Might just add a comment that 1 is the default in
Alexei Svitkine (slow) 2016/02/29 22:55:53 Done.
41 bucket->set_count(count);
40 } 42 }
41 43
42 // Omit fields to save space (see rules in histogram_event.proto comments). 44 // Omit fields to save space (see rules in histogram_event.proto comments).
43 for (int i = 0; i < histogram_proto->bucket_size(); ++i) { 45 for (int i = 0; i < histogram_proto->bucket_size(); ++i) {
44 HistogramEventProto::Bucket* bucket = histogram_proto->mutable_bucket(i); 46 HistogramEventProto::Bucket* bucket = histogram_proto->mutable_bucket(i);
45 if (i + 1 < histogram_proto->bucket_size() && 47 if (i + 1 < histogram_proto->bucket_size() &&
46 bucket->max() == histogram_proto->bucket(i + 1).min()) { 48 bucket->max() == histogram_proto->bucket(i + 1).min()) {
47 bucket->clear_max(); 49 bucket->clear_max();
48 } else if (bucket->max() == bucket->min() + 1) { 50 } else if (bucket->max() == bucket->min() + 1) {
49 bucket->clear_min(); 51 bucket->clear_min();
50 } 52 }
51 } 53 }
52 } 54 }
53 55
54 } // namespace metrics 56 } // namespace metrics
OLDNEW
« no previous file with comments | « no previous file | components/metrics/proto/histogram_event.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698