Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: components/metrics/histogram_manager.cc

Issue 794493002: Add UMA Histogram Manager to Cronet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved histogram_manager_unittest to components/metrics Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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() {
+ // 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

Powered by Google App Engine
This is Rietveld 408576698