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 android.content.Context; 20 21 import static com.android.tv.perf.EventNames.EventName; 22 23 /** Measures Performance. */ 24 public interface PerformanceMonitor { 25 26 /** 27 * Starts monitoring application's lifecylce for interesting memory events, captures and records 28 * memory usage data whenever these events are fired. 29 */ 30 void startMemoryMonitor(); 31 32 /** 33 * Collects and records memory usage for a specific custom event 34 * 35 * @param eventName to record 36 */ 37 void recordMemory(@EventName String eventName); 38 39 /** 40 * Starts a timer for a global event to allow measuring the event's latency across activities If 41 * multiple events with the same name are started, only the last event is retained. 42 * 43 * @param eventName for which the timer starts 44 */ 45 void startGlobalTimer(@EventName String eventName); 46 47 /** 48 * Stops a cross activities timer for a specific eventName and records the timer duration. If no 49 * timer found for the event specified an error will be logged, and recording will be skipped. 50 * 51 * @param eventName for which the timer stops 52 */ 53 void stopGlobalTimer(@EventName String eventName); 54 55 /** 56 * Starts a timer to record latency of a specific scenario or event. Use this method to track 57 * latency in the same method/class 58 * 59 * @return TimerEvent object to be used for stopping/recording the timer for a specific event. 60 * If PerformanceMonitor is not initialized for any reason, an empty TimerEvent will be 61 * returned. 62 */ 63 TimerEvent startTimer(); 64 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 */ 73 void stopTimer(TimerEvent event, @EventName 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 */ 83 void startJankRecorder(@EventName 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 */ 90 void stopJankRecorder(@EventName 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 */ 98 boolean startPerformanceMonitorEventDebugActivity(Context context); 99 } 100