Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/Histogram.h" | 5 #include "platform/Histogram.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
| 9 #include "base/metrics/statistics_recorder.h" | |
| 9 | 10 |
| 10 namespace blink { | 11 namespace blink { |
| 11 | 12 |
| 12 CustomCountHistogram::CustomCountHistogram(const char* name, base::HistogramBase ::Sample min, base::HistogramBase::Sample max, int32_t bucketCount) | 13 CustomCountHistogram::CustomCountHistogram(const char* name, base::HistogramBase ::Sample min, base::HistogramBase::Sample max, int32_t bucketCount) |
| 13 { | 14 { |
| 14 m_histogram = base::Histogram::FactoryGet(name, min, max, bucketCount, base: :HistogramBase::kUmaTargetedHistogramFlag); | 15 m_histogram = base::Histogram::FactoryGet(name, min, max, bucketCount, base: :HistogramBase::kUmaTargetedHistogramFlag); |
| 15 } | 16 } |
| 16 | 17 |
| 17 CustomCountHistogram::CustomCountHistogram(base::HistogramBase* histogram) | 18 CustomCountHistogram::CustomCountHistogram(base::HistogramBase* histogram) |
| 18 : m_histogram(histogram) | 19 : m_histogram(histogram) |
| 19 { | 20 { |
| 20 } | 21 } |
| 21 | 22 |
| 22 void CustomCountHistogram::count(base::HistogramBase::Sample sample) | 23 void CustomCountHistogram::count(base::HistogramBase::Sample sample) |
| 23 { | 24 { |
| 24 m_histogram->Add(sample); | 25 m_histogram->Add(sample); |
| 25 } | 26 } |
| 26 | 27 |
| 27 BooleanHistogram::BooleanHistogram(const char* name) | 28 BooleanHistogram::BooleanHistogram(const char* name) |
| 28 : CustomCountHistogram(base::BooleanHistogram::FactoryGet(name, base::Histog ramBase::kUmaTargetedHistogramFlag)) | 29 : CustomCountHistogram(base::BooleanHistogram::FactoryGet(name, base::Histog ramBase::kUmaTargetedHistogramFlag)) |
| 29 { | 30 { |
| 30 } | 31 } |
| 31 | 32 |
| 32 EnumerationHistogram::EnumerationHistogram(const char* name, base::HistogramBase ::Sample boundaryValue) | 33 EnumerationHistogram::EnumerationHistogram(const char* name, base::HistogramBase ::Sample boundaryValue) |
| 33 : CustomCountHistogram(base::LinearHistogram::FactoryGet(name, 1, boundaryVa lue, boundaryValue + 1, base::HistogramBase::kUmaTargetedHistogramFlag)) | 34 : CustomCountHistogram(base::LinearHistogram::FactoryGet(name, 1, boundaryVa lue, boundaryValue + 1, base::HistogramBase::kUmaTargetedHistogramFlag)) |
| 34 { | 35 { |
| 35 } | 36 } |
| 36 | 37 |
| 38 bool EnumerationHistogram::GetHistogramCount(const char* name, base::HistogramBa se::Sample bucket, int32_t* count) | |
| 39 { | |
| 40 base::HistogramBase* histogram = base::StatisticsRecorder::FindHistogram(nam e); | |
| 41 if (!histogram) | |
| 42 return false; | |
| 43 | |
| 44 std::unique_ptr<base::HistogramSamples> samples( | |
| 45 histogram->SnapshotSamples()); | |
|
Ilya Sherman
2016/07/11 18:52:31
How do you guarantee that this call only includes
| |
| 46 | |
| 47 *count = samples->GetCount(bucket); | |
| 48 return true; | |
| 49 } | |
| 50 | |
| 37 SparseHistogram::SparseHistogram(const char* name) | 51 SparseHistogram::SparseHistogram(const char* name) |
| 38 { | 52 { |
| 39 m_histogram = base::SparseHistogram::FactoryGet(name, base::HistogramBase::k UmaTargetedHistogramFlag); | 53 m_histogram = base::SparseHistogram::FactoryGet(name, base::HistogramBase::k UmaTargetedHistogramFlag); |
| 40 } | 54 } |
| 41 | 55 |
| 42 void SparseHistogram::sample(base::HistogramBase::Sample sample) | 56 void SparseHistogram::sample(base::HistogramBase::Sample sample) |
| 43 { | 57 { |
| 44 m_histogram->Add(sample); | 58 m_histogram->Add(sample); |
| 45 } | 59 } |
| 46 | 60 |
| 47 } // namespace blink | 61 } // namespace blink |
| OLD | NEW |