Home | History | Annotate | Download | only in perf
      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 
     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      * Stops timer for a specific event and records the timer duration. passing a null TimerEvent
     67      * will cause this operation to be skipped.
     68      *
     69      * @param event that needs to be stopped
     70      * @param eventName for which the timer stops. This must be constant with no PII.
     71      */
     72     void stopTimer(TimerEvent event, @EventName String eventName);
     73 
     74     /**
     75      * Starts recording jank for a specific scenario or event.
     76      *
     77      * <p>If jank recording was started already for an event with the current name, but was never
     78      * stopped, the previously recorded event will be skipped.
     79      *
     80      * @param eventName of the event for which tracking is started
     81      */
     82     void startJankRecorder(@EventName String eventName);
     83 
     84     /**
     85      * Stops recording jank for a specific event and records the jank event.
     86      *
     87      * @param eventName of the event that needs to be stopped
     88      */
     89     void stopJankRecorder(@EventName String eventName);
     90 
     91     /**
     92      * Starts activity to display PerformanceMonitor events recorded in local database for debug
     93      * purpose.
     94      *
     95      * @return true if the activity is available to start
     96      */
     97     boolean startPerformanceMonitorEventDebugActivity(Context context);
     98 }
     99