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 std::vector<uint8> HistogramManager::GetDeltas() { |
| 57 // Clear the protobuf between calls. |
| 58 uma_proto_.Clear(); |
| 59 histogram_snapshot_manager_->PrepareDeltas( |
| 60 base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); |
| 61 int data_size = uma_proto_.ByteSize(); |
| 62 std::vector<uint8> data(data_size); |
| 63 if (!uma_proto_.SerializeToArray(&data[0], data_size)) { |
| 64 data.clear(); |
| 65 } |
| 66 |
| 67 return data; |
| 68 } |
| 69 |
| 70 static jbyteArray GetHistogramDeltas(JNIEnv* env, jobject jcaller) { |
| 71 // TODO(mef): convert histogram_manager singleton to hang off java object. |
| 72 std::vector<uint8> data = HistogramManager::GetInstance()->GetDeltas(); |
| 73 if (!data.empty()) { |
| 74 return base::android::ToJavaByteArray(env, &data[0], data_size).Release(); |
| 75 } |
| 76 |
| 77 return NULL; |
| 78 } |
| 79 |
| 80 } // namespace cronet |
OLD | NEW |