1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.wm.shell.common; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.Context; 22 import android.text.TextUtils; 23 import android.view.SurfaceControl; 24 import android.view.View; 25 26 import com.android.internal.jank.Cuj.CujType; 27 import com.android.internal.jank.InteractionJankMonitor; 28 29 /** Utils class for simplfy InteractionJank trancing call */ 30 public class InteractionJankMonitorUtils { 31 32 /** 33 * Begin a trace session. 34 * 35 * @param cujType the specific {@link CujType}. 36 * @param view the view to trace 37 * @param tag the tag to distinguish different flow of same type CUJ. 38 */ beginTracing(@ujType int cujType, @NonNull View view, @Nullable String tag)39 public static void beginTracing(@CujType int cujType, 40 @NonNull View view, @Nullable String tag) { 41 final InteractionJankMonitor.Configuration.Builder builder = 42 InteractionJankMonitor.Configuration.Builder.withView(cujType, view); 43 if (!TextUtils.isEmpty(tag)) { 44 builder.setTag(tag); 45 } 46 InteractionJankMonitor.getInstance().begin(builder); 47 } 48 49 /** 50 * Begin a trace session. 51 * 52 * @param cujType the specific {@link CujType}. 53 * @param context the context 54 * @param surface the surface to trace 55 * @param tag the tag to distinguish different flow of same type CUJ. 56 */ beginTracing(@ujType int cujType, @NonNull Context context, @NonNull SurfaceControl surface, @Nullable String tag)57 public static void beginTracing(@CujType int cujType, 58 @NonNull Context context, @NonNull SurfaceControl surface, @Nullable String tag) { 59 final InteractionJankMonitor.Configuration.Builder builder = 60 InteractionJankMonitor.Configuration.Builder.withSurface(cujType, context, surface); 61 if (!TextUtils.isEmpty(tag)) { 62 builder.setTag(tag); 63 } 64 InteractionJankMonitor.getInstance().begin(builder); 65 } 66 67 /** 68 * End a trace session. 69 * 70 * @param cujType the specific {@link CujType}. 71 */ endTracing(@ujType int cujType)72 public static void endTracing(@CujType int cujType) { 73 InteractionJankMonitor.getInstance().end(cujType); 74 } 75 76 /** 77 * Cancel the trace session. 78 * 79 * @param cujType the specific {@link CujType}. 80 */ cancelTracing(@ujType int cujType)81 public static void cancelTracing(@CujType int cujType) { 82 InteractionJankMonitor.getInstance().cancel(cujType); 83 } 84 } 85