Chromium Code Reviews| Index: components/cronet/android/histogram_manager.cc |
| diff --git a/components/cronet/android/histogram_manager.cc b/components/cronet/android/histogram_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c3390d77435d3bb3a715cb7750273e964942a13c |
| --- /dev/null |
| +++ b/components/cronet/android/histogram_manager.cc |
| @@ -0,0 +1,83 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/cronet/android/histogram_manager.h" |
| + |
| +#include <string> |
| + |
| +#include "base/android/jni_array.h" |
| +#include "base/memory/singleton.h" |
| +#include "base/metrics/histogram_delta_serialization.h" |
| +#include "base/metrics/histogram_samples.h" |
| +#include "base/metrics/histogram_snapshot_manager.h" |
| +#include "base/metrics/sample_map.h" |
| +#include "base/metrics/statistics_recorder.h" |
| +#include "components/metrics/metrics_hashes.h" |
| +#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.
|
| +#include "components/metrics/proto/histogram_event.pb.h" |
| + |
| +#include "jni/HistogramManager_jni.h" |
| + |
| +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.
|
| + |
| +namespace cronet { |
| + |
| +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.
|
| + |
| +// Explicitly register static JNI functions. |
| +bool HistogramManagerRegisterJni(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +HistogramManager::HistogramManager() : histogram_snapshot_manager_(this) { |
| +} |
| + |
| +HistogramManager::~HistogramManager() { |
| +} |
| + |
| +// static |
| +HistogramManager* HistogramManager::GetInstance() { |
| + return Singleton<HistogramManager>::get(); |
| +} |
| + |
| +void HistogramManager::RecordDelta(const base::HistogramBase& histogram, |
| + const base::HistogramSamples& snapshot) { |
| + metrics::RecordHistogramDelta(&uma_proto_, histogram_name, snapshot); |
| +} |
| + |
| +void HistogramManager::InconsistencyDetected( |
| + base::HistogramBase::Inconsistency problem) { |
| + UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser.Cronet", |
| + problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
| +} |
| + |
| +void HistogramManager::UniqueInconsistencyDetected( |
| + base::HistogramBase::Inconsistency problem) { |
| + UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique.Cronet", |
| + problem, base::HistogramBase::NEVER_EXCEEDED_VALUE); |
| +} |
| + |
| +void HistogramManager::InconsistencyDetectedInLoggedCount(int amount) { |
| + UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser.Cronet", |
| + std::abs(amount)); |
| +} |
| + |
| +void HistogramManager::PrepareDeltas() { |
| + histogram_snapshot_manager_->PrepareDeltas( |
| + base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag); |
| +} |
| + |
| +static jbyteArray GetHistogramDeltas(JNIEnv* env, jobject jcaller) { |
| + 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.
|
| + histogram_manager->PrepareDeltas(); |
| + 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.
|
| + std::vector<uint8> data(data_size); |
| + if (histogram_manager->uma_proto().SerializeToArray(&data[0], data_size)) { |
| + return base::android::ToJavaByteArray(env, &data[0], data_size).Release(); |
| + } |
| + |
| + return NULL; |
| +} |
| + |
| +} // namespace cronet |