Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: base/android/record_histogram.cc

Issue 1312153003: jni_generator: Pass object parameters as JavaParamRef. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/android/path_service_android.cc ('k') | base/android/record_user_action.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <map> 7 #include <map>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 std::map<jint, HistogramBase*> histograms_; 167 std::map<jint, HistogramBase*> histograms_;
168 168
169 DISALLOW_COPY_AND_ASSIGN(HistogramCache); 169 DISALLOW_COPY_AND_ASSIGN(HistogramCache);
170 }; 170 };
171 171
172 base::LazyInstance<HistogramCache>::Leaky g_histograms; 172 base::LazyInstance<HistogramCache>::Leaky g_histograms;
173 173
174 } // namespace 174 } // namespace
175 175
176 void RecordBooleanHistogram(JNIEnv* env, 176 void RecordBooleanHistogram(JNIEnv* env,
177 jclass clazz, 177 const JavaParamRef<jclass>& clazz,
178 jstring j_histogram_name, 178 const JavaParamRef<jstring>& j_histogram_name,
179 jint j_histogram_key, 179 jint j_histogram_key,
180 jboolean j_sample) { 180 jboolean j_sample) {
181 bool sample = static_cast<bool>(j_sample); 181 bool sample = static_cast<bool>(j_sample);
182 g_histograms.Get() 182 g_histograms.Get()
183 .BooleanHistogram(env, j_histogram_name, j_histogram_key) 183 .BooleanHistogram(env, j_histogram_name, j_histogram_key)
184 ->AddBoolean(sample); 184 ->AddBoolean(sample);
185 } 185 }
186 186
187 void RecordEnumeratedHistogram(JNIEnv* env, 187 void RecordEnumeratedHistogram(JNIEnv* env,
188 jclass clazz, 188 const JavaParamRef<jclass>& clazz,
189 jstring j_histogram_name, 189 const JavaParamRef<jstring>& j_histogram_name,
190 jint j_histogram_key, 190 jint j_histogram_key,
191 jint j_sample, 191 jint j_sample,
192 jint j_boundary) { 192 jint j_boundary) {
193 int sample = static_cast<int>(j_sample); 193 int sample = static_cast<int>(j_sample);
194 194
195 g_histograms.Get() 195 g_histograms.Get()
196 .EnumeratedHistogram(env, j_histogram_name, j_histogram_key, j_boundary) 196 .EnumeratedHistogram(env, j_histogram_name, j_histogram_key, j_boundary)
197 ->Add(sample); 197 ->Add(sample);
198 } 198 }
199 199
200 void RecordCustomCountHistogram(JNIEnv* env, 200 void RecordCustomCountHistogram(JNIEnv* env,
201 jclass clazz, 201 const JavaParamRef<jclass>& clazz,
202 jstring j_histogram_name, 202 const JavaParamRef<jstring>& j_histogram_name,
203 jint j_histogram_key, 203 jint j_histogram_key,
204 jint j_sample, 204 jint j_sample,
205 jint j_min, 205 jint j_min,
206 jint j_max, 206 jint j_max,
207 jint j_num_buckets) { 207 jint j_num_buckets) {
208 int sample = static_cast<int>(j_sample); 208 int sample = static_cast<int>(j_sample);
209 209
210 g_histograms.Get() 210 g_histograms.Get()
211 .CustomCountHistogram(env, j_histogram_name, j_histogram_key, j_min, 211 .CustomCountHistogram(env, j_histogram_name, j_histogram_key, j_min,
212 j_max, j_num_buckets) 212 j_max, j_num_buckets)
213 ->Add(sample); 213 ->Add(sample);
214 } 214 }
215 215
216 void RecordLinearCountHistogram(JNIEnv* env, 216 void RecordLinearCountHistogram(JNIEnv* env,
217 jclass clazz, 217 const JavaParamRef<jclass>& clazz,
218 jstring j_histogram_name, 218 const JavaParamRef<jstring>& j_histogram_name,
219 jint j_histogram_key, 219 jint j_histogram_key,
220 jint j_sample, 220 jint j_sample,
221 jint j_min, 221 jint j_min,
222 jint j_max, 222 jint j_max,
223 jint j_num_buckets) { 223 jint j_num_buckets) {
224 int sample = static_cast<int>(j_sample); 224 int sample = static_cast<int>(j_sample);
225 225
226 g_histograms.Get() 226 g_histograms.Get()
227 .LinearCountHistogram(env, j_histogram_name, j_histogram_key, j_min, 227 .LinearCountHistogram(env, j_histogram_name, j_histogram_key, j_min,
228 j_max, j_num_buckets) 228 j_max, j_num_buckets)
229 ->Add(sample); 229 ->Add(sample);
230 } 230 }
231 231
232 void RecordSparseHistogram(JNIEnv* env, 232 void RecordSparseHistogram(JNIEnv* env,
233 jclass clazz, 233 const JavaParamRef<jclass>& clazz,
234 jstring j_histogram_name, 234 const JavaParamRef<jstring>& j_histogram_name,
235 jint j_histogram_key, 235 jint j_histogram_key,
236 jint j_sample) { 236 jint j_sample) {
237 int sample = static_cast<int>(j_sample); 237 int sample = static_cast<int>(j_sample);
238 g_histograms.Get() 238 g_histograms.Get()
239 .SparseHistogram(env, j_histogram_name, j_histogram_key) 239 .SparseHistogram(env, j_histogram_name, j_histogram_key)
240 ->Add(sample); 240 ->Add(sample);
241 } 241 }
242 242
243 void RecordCustomTimesHistogramMilliseconds(JNIEnv* env, 243 void RecordCustomTimesHistogramMilliseconds(
244 jclass clazz, 244 JNIEnv* env,
245 jstring j_histogram_name, 245 const JavaParamRef<jclass>& clazz,
246 jint j_histogram_key, 246 const JavaParamRef<jstring>& j_histogram_name,
247 jlong j_duration, 247 jint j_histogram_key,
248 jlong j_min, 248 jlong j_duration,
249 jlong j_max, 249 jlong j_min,
250 jint j_num_buckets) { 250 jlong j_max,
251 jint j_num_buckets) {
251 g_histograms.Get() 252 g_histograms.Get()
252 .CustomTimesHistogram(env, j_histogram_name, j_histogram_key, j_min, 253 .CustomTimesHistogram(env, j_histogram_name, j_histogram_key, j_min,
253 j_max, j_num_buckets) 254 j_max, j_num_buckets)
254 ->AddTime(TimeDelta::FromMilliseconds(static_cast<int64>(j_duration))); 255 ->AddTime(TimeDelta::FromMilliseconds(static_cast<int64>(j_duration)));
255 } 256 }
256 257
257 void Initialize(JNIEnv* env, jclass) { 258 void Initialize(JNIEnv* env, const JavaParamRef<jclass>&) {
258 StatisticsRecorder::Initialize(); 259 StatisticsRecorder::Initialize();
259 } 260 }
260 261
261 // This backs a Java test util for testing histograms - 262 // This backs a Java test util for testing histograms -
262 // MetricsUtils.HistogramDelta. It should live in a test-specific file, but we 263 // MetricsUtils.HistogramDelta. It should live in a test-specific file, but we
263 // currently can't have test-specific native code packaged in test-specific Java 264 // currently can't have test-specific native code packaged in test-specific Java
264 // targets - see http://crbug.com/415945. 265 // targets - see http://crbug.com/415945.
265 jint GetHistogramValueCountForTesting(JNIEnv* env, 266 jint GetHistogramValueCountForTesting(
266 jclass clazz, 267 JNIEnv* env,
267 jstring histogram_name, 268 const JavaParamRef<jclass>& clazz,
268 jint sample) { 269 const JavaParamRef<jstring>& histogram_name,
270 jint sample) {
269 HistogramBase* histogram = StatisticsRecorder::FindHistogram( 271 HistogramBase* histogram = StatisticsRecorder::FindHistogram(
270 android::ConvertJavaStringToUTF8(env, histogram_name)); 272 android::ConvertJavaStringToUTF8(env, histogram_name));
271 if (histogram == nullptr) { 273 if (histogram == nullptr) {
272 // No samples have been recorded for this histogram (yet?). 274 // No samples have been recorded for this histogram (yet?).
273 return 0; 275 return 0;
274 } 276 }
275 277
276 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples(); 278 scoped_ptr<HistogramSamples> samples = histogram->SnapshotSamples();
277 return samples->GetCount(static_cast<int>(sample)); 279 return samples->GetCount(static_cast<int>(sample));
278 } 280 }
279 281
280 bool RegisterRecordHistogram(JNIEnv* env) { 282 bool RegisterRecordHistogram(JNIEnv* env) {
281 return RegisterNativesImpl(env); 283 return RegisterNativesImpl(env);
282 } 284 }
283 285
284 } // namespace android 286 } // namespace android
285 } // namespace base 287 } // namespace base
OLDNEW
« no previous file with comments | « base/android/path_service_android.cc ('k') | base/android/record_user_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698