1 /* 2 * Copyright (C) 2017 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.tv.perf; 18 19 import static com.android.tv.perf.EventNames.EventName; 20 21 import android.content.Context; 22 import com.google.errorprone.annotations.CompileTimeConstant; 23 24 /** Measures Performance. */ 25 public interface PerformanceMonitor { 26 27 /** 28 * Starts monitoring application's lifecylce for interesting memory events, captures and records 29 * memory usage data whenever these events are fired. 30 */ startMemoryMonitor()31 void startMemoryMonitor(); 32 33 /** 34 * Collects and records memory usage for a specific custom event 35 * 36 * @param eventName to record 37 */ recordMemory(@ventName @ompileTimeConstant String eventName)38 void recordMemory(@EventName @CompileTimeConstant String eventName); 39 40 /** 41 * Starts a timer for a global event to allow measuring the event's latency across activities If 42 * multiple events with the same name are started, only the last event is retained. 43 * 44 * @param eventName for which the timer starts 45 */ startGlobalTimer(@ventName @ompileTimeConstant String eventName)46 void startGlobalTimer(@EventName @CompileTimeConstant String eventName); 47 48 /** 49 * Stops a cross activities timer for a specific eventName and records the timer duration. If no 50 * timer found for the event specified an error will be logged, and recording will be skipped. 51 * 52 * @param eventName for which the timer stops 53 */ stopGlobalTimer(@ventName @ompileTimeConstant String eventName)54 void stopGlobalTimer(@EventName @CompileTimeConstant String eventName); 55 56 /** 57 * Starts a timer to record latency of a specific scenario or event. Use this method to track 58 * latency in the same method/class 59 * 60 * @return TimerEvent object to be used for stopping/recording the timer for a specific event. 61 * If PerformanceMonitor is not initialized for any reason, an empty TimerEvent will be 62 * returned. 63 */ startTimer()64 TimerEvent startTimer(); 65 66 /** 67 * Stops timer for a specific event and records the timer duration. passing a null TimerEvent 68 * will cause this operation to be skipped. 69 * 70 * @param event that needs to be stopped 71 * @param eventName for which the timer stops. This must be constant with no PII. 72 */ stopTimer(TimerEvent event, @EventName @CompileTimeConstant String eventName)73 void stopTimer(TimerEvent event, @EventName @CompileTimeConstant String eventName); 74 75 /** 76 * Starts recording jank for a specific scenario or event. 77 * 78 * <p>If jank recording was started already for an event with the current name, but was never 79 * stopped, the previously recorded event will be skipped. 80 * 81 * @param eventName of the event for which tracking is started 82 */ startJankRecorder(@ventName @ompileTimeConstant String eventName)83 void startJankRecorder(@EventName @CompileTimeConstant String eventName); 84 85 /** 86 * Stops recording jank for a specific event and records the jank event. 87 * 88 * @param eventName of the event that needs to be stopped 89 */ stopJankRecorder(@ventName @ompileTimeConstant String eventName)90 void stopJankRecorder(@EventName @CompileTimeConstant String eventName); 91 92 /** 93 * Starts activity to display PerformanceMonitor events recorded in local database for debug 94 * purpose. 95 * 96 * @return true if the activity is available to start 97 */ startPerformanceMonitorEventDebugActivity(Context context)98 boolean startPerformanceMonitorEventDebugActivity(Context context); 99 100 /** 101 * Initialize crash monitoring for an app by wrapping the default {@link 102 * Thread.UncaughtExceptionHandler} with a handler that can report crashes to the performance 103 * montitor and then delegate the handling of the UncaughtException to the original default 104 * {@link Thread.UncaughtExceptionHandler}. 105 * 106 * <p>Note: This will override the current {@link Thread.UncaughtExceptionHandler}. 107 */ startCrashMonitor()108 void startCrashMonitor(); 109 } 110