Running Systrace for android
Measuring time taken by app to launch
Go to verbose of logacat in Android monitor
Select no filters
Search for Displayed
Run your app
Time taken for every Activity to draw and display will be provoded in ms
1. Method Tracing
To run Method Tracing do following -
1. Pre requisite -
Tools > Android > Enable ADB Integration
- Android Device Monitor can’t be running. (Android Monitor is different thing , don't mix up)
- set your app debuggable in build.gradle file (app)
- 2. Now use Android Monitor as -
- View > Tool Windows > Android Monitor.
- Go to monitor Tab - to shift between the log and monitor tab , see on the right top, a icon is present that allows you to do so as given here - https://developer.android.com/images/tools/am-imaxlogcat.png
- Connect your device
- Click a clock to start method tracing just after starting your app. Click clock again to stop method tracing, You will get Result in the editor tab (where tabs of xml/java files are present). Click the tab and in bottom section you will find all the methods along with their inclusive and exclusive time. Click inclusive tab to sort them by highest or lowest time.
- Thus you can see the methods taking most of your time.
2. Systrace Tool
Pre - You must have systrace enabled in your android device - go to Settings -> Dev Options -> Monitoring -> Profile GPU rendering - in adb.....
->Enable opengl traces - systrace
To run this - You should have pip installed - So I installed pip and using pip installed
sudo easy_install pip
pip install pyserial
- Using Command Line After this - Run the following command -
cd Users/sachinaggarwal/Library/Android/sdk/platform-tools/systrace
python systrace.py --time=10 -o mynewtrace.html sched gfx view wmIf you get error that Is adb on your path - You need to add adb to your environment variables as -
echo "export PATH=\$PATH:/Users/${USER}/Library/Android/sdk/platform-tools/" >> ~/.bash_profile
In place of
${USER} enter your username
After this you need to quit the terminal and reopen it to see the effect.
Open Terminal, Connect your device and reenter the following commands
cd Users/sachinaggarwal/Library/Android/sdk/platform-tools/systracepython systrace.py --time=10 -o mynewtrace1.html sched gfx view wmYour inline trace will be saved in mynewtrace.html. Open it and analyze
2nd Option - Run in Android Studio in Android Device Monitor -
Additional prereq - For ADM to run, you must have ADB integration disabled. (disabled by defualt so no problem)
Prob - You may find that you are enable to run your project (it will ask you to enable adb integration). This is because instant run requires adb integration. SO -> Go to Settings and disable instant run -> You will be now able to run your app as well as ADM.
In ADM, open devices tab and select your device and on it select systrace icon to start taking systrace.
Analysing trace file -
To analyse the trace file you can click any of red part in trace but the easiest way is to Go to Right -> Choose alerts tab -> you will see all the problems by choosing any alert and also get video links or android doc suggestions about your problem - thats how easy it is
You may look at traceview in future - https://developer.android.com/studio/profile/traceview.html