Chromium Code Reviews| Index: components/metrics/histogram_manager.cc |
| diff --git a/components/metrics/histogram_manager.cc b/components/metrics/histogram_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5821800618e10e588e85740e6402d4571cd29ac6 |
| --- /dev/null |
| +++ b/components/metrics/histogram_manager.cc |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/metrics/histogram_manager.h" |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/memory/singleton.h" |
| +#include "base/metrics/histogram.h" |
| +#include "base/metrics/histogram_samples.h" |
| +#include "components/metrics/histogram_encoder.h" |
| + |
| +namespace metrics { |
| + |
| +HistogramManager::HistogramManager() : histogram_snapshot_manager_(this) { |
| +} |
| + |
| +HistogramManager::~HistogramManager() { |
| +} |
| + |
| +// static |
| +HistogramManager* HistogramManager::GetInstance() { |
| + return Singleton<HistogramManager>::get(); |
| +} |
| + |
| +void HistogramManager::RecordDelta(const base::HistogramBase& histogram, |
| + const base::HistogramSamples& snapshot) { |
| + EncodeHistogramDelta(histogram.histogram_name(), snapshot, &uma_proto_); |
| +} |
| + |
| +void HistogramManager::InconsistencyDetected( |
| + base::HistogramBase::Inconsistency problem) { |
| + UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser.Cronet", |
| + problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
| +} |
| + |
| +void HistogramManager::UniqueInconsistencyDetected( |
| + base::HistogramBase::Inconsistency problem) { |
| + UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique.Cronet", |
| + problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
| +} |
| + |
| +void HistogramManager::InconsistencyDetectedInLoggedCount(int amount) { |
| + UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser.Cronet", |
| + std::abs(amount)); |
| +} |
| + |
| +std::vector<uint8> HistogramManager::GetDeltas() { |
|
mef
2014/12/11 23:11:41
should this be HistogramManager::GetDeltas(std::ve
ramant (doing other things)
2014/12/12 02:43:05
Done.
|
| + // Clear the protobuf between calls. |
| + uma_proto_.Clear(); |
| + histogram_snapshot_manager_.PrepareDeltas( |
| + base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); |
| + int32_t data_size = uma_proto_.ByteSize(); |
| + std::vector<uint8> data(data_size); |
| + if (!uma_proto_.SerializeToArray(&data[0], data_size)) { |
| + data.clear(); |
| + } |
| + return data; |
| +} |
| + |
| +} // namespace metrics |