Original address: medium.com/androiddeve…

Original post: medium.com/yi.yang

Published: 17 June 2020-5 minutes to read

In Android Studio 4.0, we have made sweeping improvements to the CPU Profiler UI to provide a more intuitive recording workflow. We continued to make improvements based on your feedback and added more features in 4.1.

In this article, we’ll focus on a new feature in Android Studio called System Tracing, which is an infrequently used but powerful CONFIGURATION for CPU logging. Unlike Java Method or C/C++ Function Traces, System Trace can collect device activities (such as CPU core scheduling) and Android System processes (such as SurfaceFlinger). In addition, you can detect your code with custom events by calling the Trace API in your application. In this way, your custom events will be collected along with system events. All of this data comes in handy when you’re investigating performance issues, such as UI jankiness or high power consumption.


Collect all threads at once

CPU records are now separated from the main profiler timeline for easier analysis. In this dedicated view, trace data is organized in various sections on the left side of the Profiler window.

System trace in Android Studio 4.1 Beta 1

You can move sections up and down to reorganize the list, or simply drag and drop to move individual items within a section.

We learned from you that it is cumbersome to select each thread to see its call graph (or trace events tracked by the system), so we combined all thread activity into one view, showing thread state and call graph at once. By default, threads are sorted by how busy they are, but you can drag and drop any individual thread to reorder.

Drag and drop threads to change list order

You can also collapse or expand each thread by clicking the triangle icon or double-clicking the thread name. Note that for Java method tracing or C/C++ function tracing, due to the deep call stack, we collapse all threads by default so that you can see all thread data at a glance up front.

The C/C++ function trace shows that threads are collapsed by default.

For system tracing, the color of the trace event is now unique for easy differentiation.

System trace events are color-coded by name

More intuitive navigation

The new tracking UI has a new timeline navigation scheme. We replaced the old horizontal scroll bar with a master detail view.

At the top, you can see a timeline that maps only to the duration of the trace, not the entire profiling session. Using the range selector, you can quickly narrow down to a specific time range. The following section shows the detailed data.

Use the range selector to focus on a small piece of the timeline.

From there you can perform more precise navigation operations.

  • Use Ctrl (or Cmd on Mac) + mouse wheel to zoom in/out.
  • Pan the view by dragging the mouse left and right while holding down the space bar.
  • Use the “WASD “key to zoom and pan the view, like the traditional SysTrace UI in Chrome (Chrome ://tracing).

Starting with Android Studio 4.1 Canary 9, you can drag the mouse in the thread section to perform a box selection. Box selection allows you to select a rectangular area precisely, which you can enlarge by clicking on the “Zoom to Select” button (the “M “key) in the upper right corner. You can even select across multiple threads. This is useful when you drag and drop similar threads next to each other and examine all threads at the same time. For example, you might want to analyze multiple worker threads (often found in games).

Box selection is combined with drag and drop and zoom.

Team.

Speaking of analytics, we’ll highlight the new analytics panel introduced in Android Studio 4.0, on the right-hand side of the Profiler window.

Here, you can find the analysis data exported from the record trace based on your choice. When you select a thread, stack frame, or trace event from the left-hand column, the analysis panel displays specific information about your selection. For example, when a thread is selected, its thread status and other useful information are displayed.

We want this analytics panel to be useful to you, so we’re always exploring ways to present useful analytics data. In addition to the Top Down, Flame Chart, and Bottom Up charts that already exist in the CPU Profiler, we added a Summary TAB in Android Studio 4.1 Canary 10 for thread state distribution, tracking event statistics, and more. For example, many times we want to learn more about a recurring trace event. The Summary TAB shows the basic statistics (count, minimum, maximum, and so on) as well as the maximum number of times the selected trace event was run. You can even navigate to another event by selecting a row from the table.

Track the statistics of events and the maximum number of occurrences

Stability and performance improvement

Last but not least, we are constantly improving the stability and performance of CPU records.

  • We fixed several errors that could cause recording failures.
  • We built system tracing on Android API Level 28 and later with Perfetto as the background, utilizing the latest Instrumentation technology of Android.
  • We also optimized the profiler code to significantly reduce memory consumption (up to 80%) when parsing traces of records, enabling you to open and analyze longer traces. Keep in mind that you can increase the maximum heap size of Android Studio, which helps with very long traces.

Download the latest Android Studio 4.1 preview to try out these features. As always, we appreciate your feedback.


Translated through (www.DeepL.com/Translator) (free version)