| OLD | NEW |
| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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 if (snapshot.sum() != 0) | 28 if (snapshot.sum() != 0) |
| 29 histogram_proto->set_sum(snapshot.sum()); | 29 histogram_proto->set_sum(snapshot.sum()); |
| 30 | 30 |
| 31 for (std::unique_ptr<SampleCountIterator> it = snapshot.Iterator(); | 31 for (std::unique_ptr<SampleCountIterator> it = snapshot.Iterator(); |
| 32 !it->Done(); it->Next()) { | 32 !it->Done(); it->Next()) { |
| 33 base::Histogram::Sample min; | 33 base::Histogram::Sample min; |
| 34 base::Histogram::Sample max; | 34 int64_t max; |
| 35 base::Histogram::Count count; | 35 base::Histogram::Count count; |
| 36 it->Get(&min, &max, &count); | 36 it->Get(&min, &max, &count); |
| 37 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket(); | 37 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket(); |
| 38 bucket->set_min(min); | 38 bucket->set_min(min); |
| 39 bucket->set_max(max); | 39 bucket->set_max(max); |
| 40 // Note: The default for count is 1 in the proto, so omit it in that case. | 40 // Note: The default for count is 1 in the proto, so omit it in that case. |
| 41 if (count != 1) | 41 if (count != 1) |
| 42 bucket->set_count(count); | 42 bucket->set_count(count); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Omit fields to save space (see rules in histogram_event.proto comments). | 45 // Omit fields to save space (see rules in histogram_event.proto comments). |
| 46 for (int i = 0; i < histogram_proto->bucket_size(); ++i) { | 46 for (int i = 0; i < histogram_proto->bucket_size(); ++i) { |
| 47 HistogramEventProto::Bucket* bucket = histogram_proto->mutable_bucket(i); | 47 HistogramEventProto::Bucket* bucket = histogram_proto->mutable_bucket(i); |
| 48 if (i + 1 < histogram_proto->bucket_size() && | 48 if (i + 1 < histogram_proto->bucket_size() && |
| 49 bucket->max() == histogram_proto->bucket(i + 1).min()) { | 49 bucket->max() == histogram_proto->bucket(i + 1).min()) { |
| 50 bucket->clear_max(); | 50 bucket->clear_max(); |
| 51 } else if (bucket->max() == bucket->min() + 1) { | 51 } else if (bucket->max() == bucket->min() + 1) { |
| 52 bucket->clear_min(); | 52 bucket->clear_min(); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace metrics | 57 } // namespace metrics |
| OLD | NEW |