| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view; |
| 18 |
|
| 19 |
import static android.graphics.FrameInfo.FLAG_WINDOW_VISIBILITY_CHANGED; |
| 20 |
|
| 21 |
import android.annotation.IntDef; |
| 22 |
import android.compat.annotation.UnsupportedAppUsage; |
| 23 |
import android.os.Build; |
| 24 |
|
| 25 |
import java.lang.annotation.Retention; |
| 26 |
import java.lang.annotation.RetentionPolicy; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public final class FrameMetrics { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public static final int UNKNOWN_DELAY_DURATION = 0; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static final int INPUT_HANDLING_DURATION = 1; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public static final int ANIMATION_DURATION = 2; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public static final int LAYOUT_MEASURE_DURATION = 3; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public static final int DRAW_DURATION = 4; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public static final int SYNC_DURATION = 5; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public static final int COMMAND_ISSUE_DURATION = 6; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public static final int SWAP_BUFFERS_DURATION = 7; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public static final int TOTAL_DURATION = 8; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public static final int FIRST_DRAW_FRAME = 9; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
public static final int INTENDED_VSYNC_TIMESTAMP = 10; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
public static final int VSYNC_TIMESTAMP = 11; |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public static final int GPU_DURATION = 12; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public static final int DEADLINE = 13; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
@IntDef({ |
| 184 |
UNKNOWN_DELAY_DURATION, |
| 185 |
INPUT_HANDLING_DURATION, |
| 186 |
ANIMATION_DURATION, |
| 187 |
LAYOUT_MEASURE_DURATION, |
| 188 |
DRAW_DURATION, |
| 189 |
SYNC_DURATION, |
| 190 |
COMMAND_ISSUE_DURATION, |
| 191 |
SWAP_BUFFERS_DURATION, |
| 192 |
TOTAL_DURATION, |
| 193 |
FIRST_DRAW_FRAME, |
| 194 |
INTENDED_VSYNC_TIMESTAMP, |
| 195 |
VSYNC_TIMESTAMP, |
| 196 |
GPU_DURATION, |
| 197 |
DEADLINE, |
| 198 |
}) |
| 199 |
@Retention(RetentionPolicy.SOURCE) |
| 200 |
public @interface Metric {} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
@IntDef ({ |
| 212 |
Index.FLAGS, |
| 213 |
Index.FRAME_TIMELINE_VSYNC_ID, |
| 214 |
Index.INTENDED_VSYNC, |
| 215 |
Index.VSYNC, |
| 216 |
Index.INPUT_EVENT_ID, |
| 217 |
Index.HANDLE_INPUT_START, |
| 218 |
Index.ANIMATION_START, |
| 219 |
Index.PERFORM_TRAVERSALS_START, |
| 220 |
Index.DRAW_START, |
| 221 |
Index.FRAME_DEADLINE, |
| 222 |
Index.SYNC_QUEUED, |
| 223 |
Index.SYNC_START, |
| 224 |
Index.ISSUE_DRAW_COMMANDS_START, |
| 225 |
Index.SWAP_BUFFERS, |
| 226 |
Index.FRAME_COMPLETED, |
| 227 |
Index.DEQUEUE_BUFFER_DURATION, |
| 228 |
Index.QUEUE_BUFFER_DURATION, |
| 229 |
Index.GPU_COMPLETED, |
| 230 |
Index.SWAP_BUFFERS_COMPLETED, |
| 231 |
Index.DISPLAY_PRESENT_TIME, |
| 232 |
}) |
| 233 |
@Retention(RetentionPolicy.SOURCE) |
| 234 |
public @interface Index { |
| 235 |
int FLAGS = 0; |
| 236 |
int FRAME_TIMELINE_VSYNC_ID = 1; |
| 237 |
int INTENDED_VSYNC = 2; |
| 238 |
int VSYNC = 3; |
| 239 |
int INPUT_EVENT_ID = 4; |
| 240 |
int HANDLE_INPUT_START = 5; |
| 241 |
int ANIMATION_START = 6; |
| 242 |
int PERFORM_TRAVERSALS_START = 7; |
| 243 |
int DRAW_START = 8; |
| 244 |
int FRAME_DEADLINE = 9; |
| 245 |
int FRAME_START_TIME = 10; |
| 246 |
int FRAME_INTERVAL = 11; |
| 247 |
int SYNC_QUEUED = 12; |
| 248 |
int SYNC_START = 13; |
| 249 |
int ISSUE_DRAW_COMMANDS_START = 14; |
| 250 |
int SWAP_BUFFERS = 15; |
| 251 |
int FRAME_COMPLETED = 16; |
| 252 |
int DEQUEUE_BUFFER_DURATION = 17; |
| 253 |
int QUEUE_BUFFER_DURATION = 18; |
| 254 |
int GPU_COMPLETED = 19; |
| 255 |
int SWAP_BUFFERS_COMPLETED = 20; |
| 256 |
int DISPLAY_PRESENT_TIME = 21; |
| 257 |
int COMMAND_SUBMISSION_COMPLETED = 22; |
| 258 |
|
| 259 |
int FRAME_STATS_COUNT = 23; |
| 260 |
|
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
private static final int[] DURATIONS = new int[] { |
| 270 |
|
| 271 |
Index.INTENDED_VSYNC, Index.HANDLE_INPUT_START, |
| 272 |
|
| 273 |
Index.HANDLE_INPUT_START, Index.ANIMATION_START, |
| 274 |
|
| 275 |
Index.ANIMATION_START, Index.PERFORM_TRAVERSALS_START, |
| 276 |
|
| 277 |
Index.PERFORM_TRAVERSALS_START, Index.DRAW_START, |
| 278 |
|
| 279 |
Index.DRAW_START, Index.SYNC_QUEUED, |
| 280 |
|
| 281 |
Index.SYNC_START, Index.ISSUE_DRAW_COMMANDS_START, |
| 282 |
|
| 283 |
Index.ISSUE_DRAW_COMMANDS_START, Index.SWAP_BUFFERS, |
| 284 |
|
| 285 |
Index.SWAP_BUFFERS, Index.SWAP_BUFFERS_COMPLETED, |
| 286 |
|
| 287 |
Index.INTENDED_VSYNC, Index.FRAME_COMPLETED, |
| 288 |
|
| 289 |
0, 0, |
| 290 |
|
| 291 |
0, 0, |
| 292 |
|
| 293 |
0, 0, |
| 294 |
|
| 295 |
Index.COMMAND_SUBMISSION_COMPLETED, Index.GPU_COMPLETED, |
| 296 |
|
| 297 |
Index.INTENDED_VSYNC, Index.FRAME_DEADLINE, |
| 298 |
}; |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 304 |
public final long[] mTimingData; |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
public FrameMetrics(FrameMetrics other) { |
| 316 |
mTimingData = new long[Index.FRAME_STATS_COUNT]; |
| 317 |
System.arraycopy(other.mTimingData, 0, mTimingData, 0, mTimingData.length); |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
public FrameMetrics() { |
| 324 |
mTimingData = new long[Index.FRAME_STATS_COUNT]; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
public long getMetric(@Metric int id) { |
| 338 |
if (id < UNKNOWN_DELAY_DURATION || id > DEADLINE) { |
| 339 |
return -1; |
| 340 |
} |
| 341 |
|
| 342 |
if (mTimingData == null) { |
| 343 |
return -1; |
| 344 |
} |
| 345 |
|
| 346 |
if (id == FIRST_DRAW_FRAME) { |
| 347 |
return (mTimingData[Index.FLAGS] & FLAG_WINDOW_VISIBILITY_CHANGED) != 0 ? 1 : 0; |
| 348 |
} else if (id == INTENDED_VSYNC_TIMESTAMP) { |
| 349 |
return mTimingData[Index.INTENDED_VSYNC]; |
| 350 |
} else if (id == VSYNC_TIMESTAMP) { |
| 351 |
return mTimingData[Index.VSYNC]; |
| 352 |
} |
| 353 |
|
| 354 |
int durationsIdx = 2 * id; |
| 355 |
return mTimingData[DURATIONS[durationsIdx + 1]] |
| 356 |
- mTimingData[DURATIONS[durationsIdx]]; |
| 357 |
} |
| 358 |
} |
| 359 |
|