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.
5 #include "components/metrics/histogram_manager.h"
10 #include "base/lazy_instance.h"
11 #include "base/metrics/histogram.h"
12 #include "base/metrics/histogram_samples.h"
13 #include "components/metrics/histogram_encoder.h"
17 // TODO(rtenneti): move g_histogram_manager into java code.
18 static base::LazyInstance
<HistogramManager
>::Leaky
19 g_histogram_manager
= LAZY_INSTANCE_INITIALIZER
;
21 HistogramManager::HistogramManager() : histogram_snapshot_manager_(this) {
24 HistogramManager::~HistogramManager() {
28 HistogramManager
* HistogramManager::GetInstance() {
29 return g_histogram_manager
.Pointer();
32 void HistogramManager::RecordDelta(const base::HistogramBase
& histogram
,
33 const base::HistogramSamples
& snapshot
) {
34 EncodeHistogramDelta(histogram
.histogram_name(), snapshot
, &uma_proto_
);
37 void HistogramManager::InconsistencyDetected(
38 base::HistogramBase::Inconsistency problem
) {
39 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser.Cronet",
40 problem
, base::HistogramBase::NEVER_EXCEEDED_VALUE
);
43 void HistogramManager::UniqueInconsistencyDetected(
44 base::HistogramBase::Inconsistency problem
) {
45 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique.Cronet",
46 problem
, base::HistogramBase::NEVER_EXCEEDED_VALUE
);
49 void HistogramManager::InconsistencyDetectedInLoggedCount(int amount
) {
50 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser.Cronet",
54 bool HistogramManager::GetDeltas(std::vector
<uint8
>* data
) {
55 // Clear the protobuf between calls.
57 histogram_snapshot_manager_
.PrepareDeltas(
58 base::Histogram::kNoFlags
, base::Histogram::kUmaTargetedHistogramFlag
);
59 int32_t data_size
= uma_proto_
.ByteSize();
60 data
->resize(data_size
);
61 if (uma_proto_
.SerializeToArray(&(*data
)[0], data_size
))
67 } // namespace metrics