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 #include "components/metrics/histogram_encoder.h" |
| 14 |
| 15 #include "jni/HistogramManager_jni.h" |
| 16 |
| 17 namespace cronet { |
| 18 |
| 19 // Explicitly register static JNI functions. |
| 20 bool HistogramManagerRegisterJni(JNIEnv* env) { |
| 21 return RegisterNativesImpl(env); |
| 22 } |
| 23 |
| 24 HistogramManager::HistogramManager() : histogram_snapshot_manager_(this) { |
| 25 } |
| 26 |
| 27 HistogramManager::~HistogramManager() { |
| 28 } |
| 29 |
| 30 // static |
| 31 HistogramManager* HistogramManager::GetInstance() { |
| 32 return Singleton<HistogramManager>::get(); |
| 33 } |
| 34 |
| 35 void HistogramManager::RecordDelta(const base::HistogramBase& histogram, |
| 36 const base::HistogramSamples& snapshot) { |
| 37 std::string histogram_name("cronet"); |
| 38 metrics::RecordHistogramDelta(histogram_name, snapshot, &uma_proto_); |
| 39 } |
| 40 |
| 41 void HistogramManager::InconsistencyDetected( |
| 42 base::HistogramBase::Inconsistency problem) { |
| 43 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser.Cronet", |
| 44 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
| 45 } |
| 46 |
| 47 void HistogramManager::UniqueInconsistencyDetected( |
| 48 base::HistogramBase::Inconsistency problem) { |
| 49 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique.Cronet", |
| 50 problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
| 51 } |
| 52 |
| 53 void HistogramManager::InconsistencyDetectedInLoggedCount(int amount) { |
| 54 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser.Cronet", |
| 55 std::abs(amount)); |
| 56 } |
| 57 |
| 58 std::vector<uint8> HistogramManager::GetDeltas() { |
| 59 // Clear the protobuf between calls. |
| 60 uma_proto_.Clear(); |
| 61 histogram_snapshot_manager_.PrepareDeltas( |
| 62 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); |
| 63 int data_size = uma_proto_.ByteSize(); |
| 64 std::vector<uint8> data(data_size); |
| 65 if (!uma_proto_.SerializeToArray(&data[0], data_size)) { |
| 66 data.clear(); |
| 67 } |
| 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 |
| 79 return NULL; |
| 80 } |
| 81 |
| 82 } // namespace cronet |
OLD | NEW |