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_delta_serialization.h" | |
12 #include "base/metrics/histogram_samples.h" | |
13 #include "base/metrics/histogram_snapshot_manager.h" | |
14 #include "base/metrics/sample_map.h" | |
15 #include "base/metrics/statistics_recorder.h" | |
16 #include "components/metrics/metrics_hashes.h" | |
17 #include "components/metrics/metrics_log.h" | |
Alexei Svitkine (slow)
2014/12/10 15:19:31
This is no longer needed. Please check the other i
ramant (doing other things)
2014/12/10 22:27:51
Done.
| |
18 #include "components/metrics/proto/histogram_event.pb.h" | |
19 | |
20 #include "jni/HistogramManager_jni.h" | |
21 | |
22 using base::SampleCountIterator; | |
Alexei Svitkine (slow)
2014/12/10 15:19:31
This is no longer needed.
ramant (doing other things)
2014/12/10 22:27:51
Done.
| |
23 | |
24 namespace cronet { | |
25 | |
26 static const char kCronetHistogramName[] = "cronet"; | |
Alexei Svitkine (slow)
2014/12/10 15:19:31
This is not used.
ramant (doing other things)
2014/12/10 22:27:51
Done.
| |
27 | |
28 // Explicitly register static JNI functions. | |
29 bool HistogramManagerRegisterJni(JNIEnv* env) { | |
30 return RegisterNativesImpl(env); | |
31 } | |
32 | |
33 HistogramManager::HistogramManager() : histogram_snapshot_manager_(this) { | |
34 } | |
35 | |
36 HistogramManager::~HistogramManager() { | |
37 } | |
38 | |
39 // static | |
40 HistogramManager* HistogramManager::GetInstance() { | |
41 return Singleton<HistogramManager>::get(); | |
42 } | |
43 | |
44 void HistogramManager::RecordDelta(const base::HistogramBase& histogram, | |
45 const base::HistogramSamples& snapshot) { | |
46 metrics::RecordHistogramDelta(&uma_proto_, histogram_name, snapshot); | |
47 } | |
48 | |
49 void HistogramManager::InconsistencyDetected( | |
50 base::HistogramBase::Inconsistency problem) { | |
51 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser.Cronet", | |
52 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); | |
53 } | |
54 | |
55 void HistogramManager::UniqueInconsistencyDetected( | |
56 base::HistogramBase::Inconsistency problem) { | |
57 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique.Cronet", | |
58 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); | |
59 } | |
60 | |
61 void HistogramManager::InconsistencyDetectedInLoggedCount(int amount) { | |
62 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser.Cronet", | |
63 std::abs(amount)); | |
64 } | |
65 | |
66 void HistogramManager::PrepareDeltas() { | |
67 histogram_snapshot_manager_->PrepareDeltas( | |
68 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); | |
69 } | |
70 | |
71 static jbyteArray GetHistogramDeltas(JNIEnv* env, jobject jcaller) { | |
72 HistogramManager* histogram_manager = HistogramManager::GetInstance(); | |
mef
2014/12/10 15:06:52
I think having it as singleton for initial CL is O
Alexei Svitkine (slow)
2014/12/10 15:19:31
I agree, this is fine for now. Maybe add a TODO ab
ramant (doing other things)
2014/12/10 22:27:51
Acknowledged.
ramant (doing other things)
2014/12/10 22:27:51
Done.
| |
73 histogram_manager->PrepareDeltas(); | |
74 int data_size = histogram_manager->uma_proto().ByteSize(); | |
Alexei Svitkine (slow)
2014/12/10 15:19:31
|uma_proto| should be cleared between calls.
ramant (doing other things)
2014/12/10 22:27:51
Done.
| |
75 std::vector<uint8> data(data_size); | |
76 if (histogram_manager->uma_proto().SerializeToArray(&data[0], data_size)) { | |
77 return base::android::ToJavaByteArray(env, &data[0], data_size).Release(); | |
78 } | |
79 | |
80 return NULL; | |
81 } | |
82 | |
83 } // namespace cronet | |
OLD | NEW |