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

Side by Side Diff: components/cronet/android/histogram_manager.cc

Issue 794493002: Add UMA Histogram Manager to Cronet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added end to end 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "components/cronet/android/histogram_manager.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/android/jni_array.h"
11 #include "base/memory/singleton.h"
12 #include "base/metrics/histogram.h"
13 #include "base/metrics/histogram_samples.h"
14 #include "components/metrics/histogram_encoder.h"
15
16 #include "jni/HistogramManager_jni.h"
17
18 namespace cronet {
19
20 // Explicitly register static JNI functions.
21 bool HistogramManagerRegisterJni(JNIEnv* env) {
22 return RegisterNativesImpl(env);
23 }
24
25 HistogramManager::HistogramManager() : histogram_snapshot_manager_(this) {
26 }
27
28 HistogramManager::~HistogramManager() {
29 }
30
31 // static
32 HistogramManager* HistogramManager::GetInstance() {
33 return Singleton<HistogramManager>::get();
34 }
35
36 void HistogramManager::RecordDelta(const base::HistogramBase& histogram,
37 const base::HistogramSamples& snapshot) {
38 metrics::RecordHistogramDelta(histogram.histogram_name(), snapshot,
39 &uma_proto_);
40 }
41
42 void HistogramManager::InconsistencyDetected(
43 base::HistogramBase::Inconsistency problem) {
44 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser.Cronet",
45 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE);
46 }
47
48 void HistogramManager::UniqueInconsistencyDetected(
49 base::HistogramBase::Inconsistency problem) {
50 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique.Cronet",
51 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE);
52 }
53
54 void HistogramManager::InconsistencyDetectedInLoggedCount(int amount) {
55 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser.Cronet",
56 std::abs(amount));
57 }
58
59 std::vector<uint8> HistogramManager::GetDeltas() {
60 // Clear the protobuf between calls.
61 uma_proto_.Clear();
62 histogram_snapshot_manager_.PrepareDeltas(
63 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag);
64 int32_t data_size = uma_proto_.ByteSize();
65 std::vector<uint8> data(data_size);
66 if (!uma_proto_.SerializeToArray(&data[0], data_size)) {
67 data.clear();
68 }
69 return data;
70 }
71
72 static jbyteArray GetHistogramDeltas(JNIEnv* env, jobject jcaller) {
73 // TODO(mef): convert histogram_manager singleton to hang off java object.
74 std::vector<uint8> data = HistogramManager::GetInstance()->GetDeltas();
75 if (!data.empty()) {
76 return base::android::ToJavaByteArray(env, &data[0], data.size()).Release();
77 }
78 return NULL;
79 }
80
81 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698