Chromium Code Reviews| 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> | |
|
Alexei Svitkine (slow)
2014/12/10 15:19:31
Nit: Add a line after this.
ramant (doing other things)
2014/12/10 22:27:51
Done.
| |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "base/metrics/histogram_samples.h" | |
| 12 #include "components/metrics/metrics_log.h" | |
|
Alexei Svitkine (slow)
2014/12/10 15:19:31
This include shouldn't be needed - I think you jus
ramant (doing other things)
2014/12/10 22:27:51
This code was calling MetricsLog::Hash. Added a TO
| |
| 13 | |
| 14 using base::SampleCountIterator; | |
| 15 | |
| 16 namespace metrics { | |
| 17 | |
| 18 // extern | |
|
Alexei Svitkine (slow)
2014/12/10 15:19:31
Remove comment.
ramant (doing other things)
2014/12/10 22:27:51
Done.
| |
| 19 void RecordHistogramDelta(ChromeUserMetricsExtension& uma_proto, | |
|
Alexei Svitkine (slow)
2014/12/10 15:19:31
Nit: Pass by pointer, also modifiable params shoul
ramant (doing other things)
2014/12/10 22:27:51
Done.
| |
| 20 const std::string& histogram_name, | |
| 21 const base::HistogramSamples& snapshot) { | |
| 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(MetricsLog::Hash(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 | |
| OLD | NEW |