OLD | NEW |
(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_log.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 // TODO(rtenneti): Move MetricsLog::Hash from metrics_log.h into |
| 28 // metrics_hash.h and rename it. |
| 29 histogram_proto->set_name_hash(MetricsLog::Hash(histogram_name)); |
| 30 histogram_proto->set_sum(snapshot.sum()); |
| 31 |
| 32 for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator(); !it->Done(); |
| 33 it->Next()) { |
| 34 base::Histogram::Sample min; |
| 35 base::Histogram::Sample max; |
| 36 base::Histogram::Count count; |
| 37 it->Get(&min, &max, &count); |
| 38 HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket(); |
| 39 bucket->set_min(min); |
| 40 bucket->set_max(max); |
| 41 bucket->set_count(count); |
| 42 } |
| 43 |
| 44 // Omit fields to save space (see rules in histogram_event.proto comments). |
| 45 for (int i = 0; i < histogram_proto->bucket_size(); ++i) { |
| 46 HistogramEventProto::Bucket* bucket = histogram_proto->mutable_bucket(i); |
| 47 if (i + 1 < histogram_proto->bucket_size() && |
| 48 bucket->max() == histogram_proto->bucket(i + 1).min()) { |
| 49 bucket->clear_max(); |
| 50 } else if (bucket->max() == bucket->min() + 1) { |
| 51 bucket->clear_min(); |
| 52 } |
| 53 } |
| 54 } |
| 55 |
| 56 } // namespace metrics |
OLD | NEW |