OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package org.chromium.base; | 5 package org.chromium.base; |
6 | 6 |
7 import android.animation.Animator; | 7 import android.animation.Animator; |
8 import android.animation.Animator.AnimatorListener; | 8 import android.animation.Animator.AnimatorListener; |
9 import android.animation.AnimatorListenerAdapter; | 9 import android.animation.AnimatorListenerAdapter; |
10 import android.animation.TimeAnimator; | 10 import android.animation.TimeAnimator; |
11 import android.animation.TimeAnimator.TimeListener; | 11 import android.animation.TimeAnimator.TimeListener; |
| 12 import android.annotation.TargetApi; |
| 13 import android.os.Build; |
12 import android.util.Log; | 14 import android.util.Log; |
13 | 15 |
14 /** | 16 /** |
15 * Record Android animation frame rate and save it to UMA histogram. This is mai
nly for monitoring | 17 * Record Android animation frame rate and save it to UMA histogram. This is mai
nly for monitoring |
16 * any jankiness of short Chrome Android animations. It is limited to few second
s of recording. | 18 * any jankiness of short Chrome Android animations. It is limited to few second
s of recording. |
17 */ | 19 */ |
18 public class AnimationFrameTimeHistogram { | 20 public class AnimationFrameTimeHistogram { |
19 private static final String TAG = "AnimationFrameTimeHistogram"; | 21 private static final String TAG = "AnimationFrameTimeHistogram"; |
20 private static final int MAX_FRAME_TIME_NUM = 600; // 10 sec on 60 fps. | 22 private static final int MAX_FRAME_TIME_NUM = 600; // 10 sec on 60 fps. |
21 | 23 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 if (mRecorder.endRecording()) { | 75 if (mRecorder.endRecording()) { |
74 nativeSaveHistogram(mHistogramName, | 76 nativeSaveHistogram(mHistogramName, |
75 mRecorder.getFrameTimesMs(), mRecorder.getFrameTimesCount())
; | 77 mRecorder.getFrameTimesMs(), mRecorder.getFrameTimesCount())
; |
76 } | 78 } |
77 mRecorder.cleanUp(); | 79 mRecorder.cleanUp(); |
78 } | 80 } |
79 | 81 |
80 /** | 82 /** |
81 * Record Android animation frame rate and return the result. | 83 * Record Android animation frame rate and return the result. |
82 */ | 84 */ |
| 85 // Note: TimeAnimator was added to the Android public API in level 16, but h
as actually been |
| 86 // available since level 14. So, it's safe to use TimeAnimator here, even on
ICS. |
| 87 @TargetApi(Build.VERSION_CODES.JELLY_BEAN) |
83 private static class Recorder implements TimeListener { | 88 private static class Recorder implements TimeListener { |
84 // TODO(kkimlabs): If we can use in the future, migrate to Choreographer
for minimal | 89 // TODO(kkimlabs): If we can use in the future, migrate to Choreographer
for minimal |
85 // workload. | 90 // workload. |
86 private final TimeAnimator mAnimator = new TimeAnimator(); | 91 private final TimeAnimator mAnimator = new TimeAnimator(); |
87 private long[] mFrameTimesMs; | 92 private long[] mFrameTimesMs; |
88 private int mFrameTimesCount; | 93 private int mFrameTimesCount; |
89 | 94 |
90 private Recorder() { | 95 private Recorder() { |
91 mAnimator.setTimeListener(this); | 96 mAnimator.setTimeListener(this); |
92 } | 97 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 141 |
137 // deltaTime is 0 for the first frame. | 142 // deltaTime is 0 for the first frame. |
138 if (deltaTime > 0) { | 143 if (deltaTime > 0) { |
139 mFrameTimesMs[mFrameTimesCount++] = deltaTime; | 144 mFrameTimesMs[mFrameTimesCount++] = deltaTime; |
140 } | 145 } |
141 } | 146 } |
142 } | 147 } |
143 | 148 |
144 private native void nativeSaveHistogram(String histogramName, long[] frameTi
mesMs, int count); | 149 private native void nativeSaveHistogram(String histogramName, long[] frameTi
mesMs, int count); |
145 } | 150 } |
OLD | NEW |