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

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: disabled flaky HistogramBucketFields unittest 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
« no previous file with comments | « components/metrics/histogram_manager.h ('k') | components/metrics/histogram_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..dfa865b3fa1c1bf485dd5875fae681b95b0dae13
--- /dev/null
+++ b/components/metrics/histogram_manager.cc
@@ -0,0 +1,67 @@
+// 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/lazy_instance.h"
+#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_samples.h"
+#include "components/metrics/histogram_encoder.h"
+
+namespace metrics {
+
+// TODO(rtenneti): move g_histogram_manager into java code.
+static base::LazyInstance<HistogramManager>::Leaky
+ g_histogram_manager = LAZY_INSTANCE_INITIALIZER;
+
+HistogramManager::HistogramManager() : histogram_snapshot_manager_(this) {
+}
+
+HistogramManager::~HistogramManager() {
+}
+
+// static
+HistogramManager* HistogramManager::GetInstance() {
+ return g_histogram_manager.Pointer();
+}
+
+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));
+}
+
+bool HistogramManager::GetDeltas(std::vector<uint8>* data) {
+ // 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();
+ data->resize(data_size);
+ if (uma_proto_.SerializeToArray(&(*data)[0], data_size))
+ return true;
+ data->clear();
+ return false;
+}
+
+} // namespace metrics
« no previous file with comments | « components/metrics/histogram_manager.h ('k') | components/metrics/histogram_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698