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 "base/android/jni_android.h" | |
6 #include "base/android/jni_string.h" | |
7 #include "base/android/record_histogram.h" | |
8 #include "base/metrics/histogram.h" | |
9 #include "base/metrics/statistics_recorder.h" | |
10 #include "jni/RecordHistogram_jni.h" | |
11 | |
12 namespace base { | |
13 namespace android { | |
14 | |
15 void RecordBooleanHistogram(JNIEnv* env, | |
16 jclass, | |
17 jstring j_histogram_name, | |
18 jboolean j_sample) { | |
19 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); | |
20 int sample = static_cast<int>(j_sample); | |
Ilya Sherman
2014/12/16 20:14:08
Why int rather than bool?
ppi
2014/12/17 13:15:31
Done.
| |
21 | |
22 BooleanHistogram::FactoryGet(histogram_name, | |
23 base::HistogramBase::kUmaTargetedHistogramFlag) | |
24 ->Add(sample); | |
Ilya Sherman
2014/12/16 20:14:08
nit: AddBoolean
ppi
2014/12/17 13:15:31
Done.
| |
25 } | |
26 | |
27 void RecordEnumeratedHistogram(JNIEnv* env, | |
28 jclass, | |
29 jstring j_histogram_name, | |
30 jint j_sample, | |
31 jint j_boundary) { | |
32 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); | |
33 int sample = static_cast<int>(j_sample); | |
34 int boundary = static_cast<int>(j_boundary); | |
35 | |
36 base::LinearHistogram::FactoryGet( | |
37 histogram_name, 1, boundary, boundary + 1, | |
38 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(sample); | |
39 } | |
40 | |
41 jint GetHistogramValueCount(JNIEnv* env, | |
42 jclass, | |
43 jstring histogram_name, | |
44 jint sample) { | |
45 base::HistogramBase* histogram = base::StatisticsRecorder::FindHistogram( | |
46 base::android::ConvertJavaStringToUTF8(env, histogram_name).c_str()); | |
Ilya Sherman
2014/12/16 20:14:08
nit: Do you need the .c_str() call?
ppi
2014/12/17 13:15:31
Done.
| |
47 if (histogram == NULL) { | |
Ilya Sherman
2014/12/16 20:14:08
nit: Either "if (!histogram)" or "if (histogram ==
ppi
2014/12/17 13:15:31
Done.
| |
48 // No samples have been recorded for this histogram (yet?). | |
49 return 0; | |
50 } | |
51 | |
52 scoped_ptr<base::HistogramSamples> samples = histogram->SnapshotSamples(); | |
53 return samples->GetCount(static_cast<int>(sample)); | |
54 } | |
Ilya Sherman
2014/12/16 20:14:08
What is this used for? If it's for tests only, th
ppi
2014/12/17 13:15:31
Yes, this is needed for the Java-side test util be
Ilya Sherman
2014/12/17 22:58:51
Thanks for the explanation. I think that with the
| |
55 | |
56 void Initialize(JNIEnv* env, jclass) { | |
57 StatisticsRecorder::Initialize(); | |
58 } | |
59 | |
60 bool RegisterRecordHistogram(JNIEnv* env) { | |
61 return RegisterNativesImpl(env); | |
62 } | |
63 | |
64 } // namespace android | |
65 | |
66 } // namespace base | |
OLD | NEW |