OLD | NEW |
---|---|
(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 | |
9 #include "base/android/jni_array.h" | |
10 #include "base/memory/singleton.h" | |
11 #include "base/metrics/histogram.h" | |
12 #include "base/metrics/histogram_samples.h" | |
13 | |
14 #include "jni/HistogramManager_jni.h" | |
15 | |
16 namespace cronet { | |
17 | |
18 // Explicitly register static JNI functions. | |
19 bool HistogramManagerRegisterJni(JNIEnv* env) { | |
20 return RegisterNativesImpl(env); | |
21 } | |
22 | |
23 HistogramManager::HistogramManager() : histogram_snapshot_manager_(this) { | |
24 } | |
25 | |
26 HistogramManager::~HistogramManager() { | |
27 } | |
28 | |
29 // static | |
30 HistogramManager* HistogramManager::GetInstance() { | |
31 return Singleton<HistogramManager>::get(); | |
32 } | |
33 | |
34 void HistogramManager::RecordDelta(const base::HistogramBase& histogram, | |
35 const base::HistogramSamples& snapshot) { | |
36 metrics::RecordHistogramDelta(histogram_name, snapshot, &uma_proto_); | |
37 } | |
38 | |
39 void HistogramManager::InconsistencyDetected( | |
40 base::HistogramBase::Inconsistency problem) { | |
41 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser.Cronet", | |
42 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); | |
43 } | |
44 | |
45 void HistogramManager::UniqueInconsistencyDetected( | |
46 base::HistogramBase::Inconsistency problem) { | |
47 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique.Cronet", | |
48 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); | |
49 } | |
50 | |
51 void HistogramManager::InconsistencyDetectedInLoggedCount(int amount) { | |
52 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser.Cronet", | |
53 std::abs(amount)); | |
54 } | |
55 | |
56 void HistogramManager::PrepareDeltas() { | |
57 // Clear the protobuf between calls. | |
58 uma_proto_.Clear(); | |
59 histogram_snapshot_manager_->PrepareDeltas( | |
60 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); | |
61 } | |
62 | |
63 static jbyteArray GetHistogramDeltas(JNIEnv* env, jobject jcaller) { | |
64 // TODO(mef): convert histogram_manager singleton to hang off java object. | |
65 HistogramManager* histogram_manager = HistogramManager::GetInstance(); | |
66 histogram_manager->PrepareDeltas(); | |
67 int data_size = histogram_manager->uma_proto().ByteSize(); | |
68 std::vector<uint8> data(data_size); | |
69 if (histogram_manager->uma_proto().SerializeToArray(&data[0], data_size)) { | |
Alexei Svitkine (slow)
2014/12/10 21:50:17
I suggest making a method of HistogramManager that
ramant (doing other things)
2014/12/10 22:27:51
Done. Will work with mef to write the unit test.
| |
70 return base::android::ToJavaByteArray(env, &data[0], data_size).Release(); | |
71 } | |
72 | |
73 return NULL; | |
74 } | |
75 | |
76 } // namespace cronet | |
OLD | NEW |