“How Long does it take?” Just Systrace and Perfetto it

Narendra Nath Chatterjee
3 min readMay 5, 2021

Figure out jank, time your Android processes and check your app performance using “Systrace” and “Perfetto”

Have you ever wondered how long does it take for that Nested Recycler View to Render after getting the data from the API? Or if your SplashScreen is staying visible for a longer time than you need it to?

In all these situations the calculation of time becomes very important. We can always use Log.d or System.nanoTime() to guage the time elasped but it does not show us what is going on behind the scenes.

Enter Systrace

According to the Android Documentation:

Systrace is a legacy platform-provided command-line tool that records device activity over a short period of time in a compressed text file. The tool produces a report that combines data from the Android kernel, such as the CPU scheduler, disk activity, and app threads.

Systrace comes pre packaged with android platform_tools and can be found in your SDK directory at \platform-tools\systrace\systrace.py

To get Systrace up and running there are a few prerequisites:

  • You need to have a Python 2.7 distribution installed in your system Download it at: https://www.python.org/downloads/release/python-2717/
  • Connect your physical android device and make sure that your adb(Android Debug Bridge) detects it.
  • Run Systrace from /platform-tools directory as the adb (Android Debug Bridge) is in /platform-tools directory like this:

/platform-tools$ python systrace/systrace.py

If you have followed the steps you should be greeted with a screen like this:

This is where you start interacting with your app and playing around with it. Once you’re satisfied press Enter
.

A HTML file would be generated in the specified location. On opening the generated HTML (use Google Chrome or Edge) it would give you a page like this.

Go to the Processes tab at the top and select the process you want to check and all the metrics you need related to your app would be available to you.

Yes you have all the data that you need but even at first glance it looks clunky and tough to navigate and measure.

Enter Perfetto

Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis.

Perfetto extends the functionality of the Syntrace and makes our work easier.

To set up Perfetto:

  • open https://ui.perfetto.dev/#!/
  • Select the Open Trace File from the left hand pane and navigate to your trace HTML file generated in the previous step with Systrace and click on Open.

A very detailed (and colourful) view of your previously obtained Systrace should now be visible to you.

On selecting the appropriate process you can see when your app started, what were the processes run which would help you determine how long it took due to the handy selection function which gives you a very accurate representation.

Phew!! So this is my first post in Medium. Hope this helps you. A clap would be……phenomenal.

Ref:

--

--