OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/android/record_histogram.h" | 5 #include "base/android/record_histogram.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <map> | 9 #include <map> |
8 | 10 |
9 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
11 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/macros.h" |
12 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
13 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
14 #include "base/metrics/statistics_recorder.h" | 17 #include "base/metrics/statistics_recorder.h" |
15 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
16 #include "base/time/time.h" | 19 #include "base/time/time.h" |
17 #include "jni/RecordHistogram_jni.h" | 20 #include "jni/RecordHistogram_jni.h" |
18 | 21 |
19 namespace base { | 22 namespace base { |
20 namespace android { | 23 namespace android { |
21 namespace { | 24 namespace { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 65 } |
63 | 66 |
64 HistogramBase* CustomCountHistogram(JNIEnv* env, | 67 HistogramBase* CustomCountHistogram(JNIEnv* env, |
65 jstring j_histogram_name, | 68 jstring j_histogram_name, |
66 jint j_histogram_key, | 69 jint j_histogram_key, |
67 jint j_min, | 70 jint j_min, |
68 jint j_max, | 71 jint j_max, |
69 jint j_num_buckets) { | 72 jint j_num_buckets) { |
70 DCHECK(j_histogram_name); | 73 DCHECK(j_histogram_name); |
71 DCHECK(j_histogram_key); | 74 DCHECK(j_histogram_key); |
72 int64 min = static_cast<int64>(j_min); | 75 int64_t min = static_cast<int64_t>(j_min); |
73 int64 max = static_cast<int64>(j_max); | 76 int64_t max = static_cast<int64_t>(j_max); |
74 int num_buckets = static_cast<int>(j_num_buckets); | 77 int num_buckets = static_cast<int>(j_num_buckets); |
75 HistogramBase* histogram = FindLocked(j_histogram_key); | 78 HistogramBase* histogram = FindLocked(j_histogram_key); |
76 if (histogram) { | 79 if (histogram) { |
77 DCHECK(histogram->HasConstructionArguments(min, max, num_buckets)); | 80 DCHECK(histogram->HasConstructionArguments(min, max, num_buckets)); |
78 return histogram; | 81 return histogram; |
79 } | 82 } |
80 | 83 |
81 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); | 84 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); |
82 histogram = | 85 histogram = |
83 Histogram::FactoryGet(histogram_name, min, max, num_buckets, | 86 Histogram::FactoryGet(histogram_name, min, max, num_buckets, |
84 HistogramBase::kUmaTargetedHistogramFlag); | 87 HistogramBase::kUmaTargetedHistogramFlag); |
85 return InsertLocked(j_histogram_key, histogram); | 88 return InsertLocked(j_histogram_key, histogram); |
86 } | 89 } |
87 | 90 |
88 HistogramBase* LinearCountHistogram(JNIEnv* env, | 91 HistogramBase* LinearCountHistogram(JNIEnv* env, |
89 jstring j_histogram_name, | 92 jstring j_histogram_name, |
90 jint j_histogram_key, | 93 jint j_histogram_key, |
91 jint j_min, | 94 jint j_min, |
92 jint j_max, | 95 jint j_max, |
93 jint j_num_buckets) { | 96 jint j_num_buckets) { |
94 DCHECK(j_histogram_name); | 97 DCHECK(j_histogram_name); |
95 DCHECK(j_histogram_key); | 98 DCHECK(j_histogram_key); |
96 int64 min = static_cast<int64>(j_min); | 99 int64_t min = static_cast<int64_t>(j_min); |
97 int64 max = static_cast<int64>(j_max); | 100 int64_t max = static_cast<int64_t>(j_max); |
98 int num_buckets = static_cast<int>(j_num_buckets); | 101 int num_buckets = static_cast<int>(j_num_buckets); |
99 HistogramBase* histogram = FindLocked(j_histogram_key); | 102 HistogramBase* histogram = FindLocked(j_histogram_key); |
100 if (histogram) { | 103 if (histogram) { |
101 DCHECK(histogram->HasConstructionArguments(min, max, num_buckets)); | 104 DCHECK(histogram->HasConstructionArguments(min, max, num_buckets)); |
102 return histogram; | 105 return histogram; |
103 } | 106 } |
104 | 107 |
105 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); | 108 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); |
106 histogram = | 109 histogram = |
107 LinearHistogram::FactoryGet(histogram_name, min, max, num_buckets, | 110 LinearHistogram::FactoryGet(histogram_name, min, max, num_buckets, |
(...skipping 18 matching lines...) Expand all Loading... |
126 | 129 |
127 HistogramBase* CustomTimesHistogram(JNIEnv* env, | 130 HistogramBase* CustomTimesHistogram(JNIEnv* env, |
128 jstring j_histogram_name, | 131 jstring j_histogram_name, |
129 jint j_histogram_key, | 132 jint j_histogram_key, |
130 jlong j_min, | 133 jlong j_min, |
131 jlong j_max, | 134 jlong j_max, |
132 jint j_bucket_count) { | 135 jint j_bucket_count) { |
133 DCHECK(j_histogram_name); | 136 DCHECK(j_histogram_name); |
134 DCHECK(j_histogram_key); | 137 DCHECK(j_histogram_key); |
135 HistogramBase* histogram = FindLocked(j_histogram_key); | 138 HistogramBase* histogram = FindLocked(j_histogram_key); |
136 int64 min = static_cast<int64>(j_min); | 139 int64_t min = static_cast<int64_t>(j_min); |
137 int64 max = static_cast<int64>(j_max); | 140 int64_t max = static_cast<int64_t>(j_max); |
138 int bucket_count = static_cast<int>(j_bucket_count); | 141 int bucket_count = static_cast<int>(j_bucket_count); |
139 if (histogram) { | 142 if (histogram) { |
140 DCHECK(histogram->HasConstructionArguments(min, max, bucket_count)); | 143 DCHECK(histogram->HasConstructionArguments(min, max, bucket_count)); |
141 return histogram; | 144 return histogram; |
142 } | 145 } |
143 | 146 |
144 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); | 147 std::string histogram_name = ConvertJavaStringToUTF8(env, j_histogram_name); |
145 // This intentionally uses FactoryGet and not FactoryTimeGet. FactoryTimeGet | 148 // This intentionally uses FactoryGet and not FactoryTimeGet. FactoryTimeGet |
146 // is just a convenience for constructing the underlying Histogram with | 149 // is just a convenience for constructing the underlying Histogram with |
147 // TimeDelta arguments. | 150 // TimeDelta arguments. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 const JavaParamRef<jclass>& clazz, | 248 const JavaParamRef<jclass>& clazz, |
246 const JavaParamRef<jstring>& j_histogram_name, | 249 const JavaParamRef<jstring>& j_histogram_name, |
247 jint j_histogram_key, | 250 jint j_histogram_key, |
248 jlong j_duration, | 251 jlong j_duration, |
249 jlong j_min, | 252 jlong j_min, |
250 jlong j_max, | 253 jlong j_max, |
251 jint j_num_buckets) { | 254 jint j_num_buckets) { |
252 g_histograms.Get() | 255 g_histograms.Get() |
253 .CustomTimesHistogram(env, j_histogram_name, j_histogram_key, j_min, | 256 .CustomTimesHistogram(env, j_histogram_name, j_histogram_key, j_min, |
254 j_max, j_num_buckets) | 257 j_max, j_num_buckets) |
255 ->AddTime(TimeDelta::FromMilliseconds(static_cast<int64>(j_duration))); | 258 ->AddTime(TimeDelta::FromMilliseconds(static_cast<int64_t>(j_duration))); |
256 } | 259 } |
257 | 260 |
258 void Initialize(JNIEnv* env, const JavaParamRef<jclass>&) { | 261 void Initialize(JNIEnv* env, const JavaParamRef<jclass>&) { |
259 StatisticsRecorder::Initialize(); | 262 StatisticsRecorder::Initialize(); |
260 } | 263 } |
261 | 264 |
262 // This backs a Java test util for testing histograms - | 265 // This backs a Java test util for testing histograms - |
263 // MetricsUtils.HistogramDelta. It should live in a test-specific file, but we | 266 // MetricsUtils.HistogramDelta. It should live in a test-specific file, but we |
264 // currently can't have test-specific native code packaged in test-specific Java | 267 // currently can't have test-specific native code packaged in test-specific Java |
265 // targets - see http://crbug.com/415945. | 268 // targets - see http://crbug.com/415945. |
(...skipping 12 matching lines...) Expand all Loading... |
278 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); | 281 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); |
279 return samples->GetCount(static_cast<int>(sample)); | 282 return samples->GetCount(static_cast<int>(sample)); |
280 } | 283 } |
281 | 284 |
282 bool RegisterRecordHistogram(JNIEnv* env) { | 285 bool RegisterRecordHistogram(JNIEnv* env) { |
283 return RegisterNativesImpl(env); | 286 return RegisterNativesImpl(env); |
284 } | 287 } |
285 | 288 |
286 } // namespace android | 289 } // namespace android |
287 } // namespace base | 290 } // namespace base |
OLD | NEW |