Android Performance

Android Perfetto Series 3: Familiarizing with the Perfetto View

Word count: 917Reading time: 5 min
2024/05/21
loading

This is the third article in the Perfetto series. After introducing what Perfetto is and how to capture traces, this article focuses on how to navigate the web interface and interpret the complex information presented after opening a trace.

Table of Contents

Paul Graham once said: “Either provide something most people want a little, or something a few people want a lot.“ Perfetto is exactly what a dedicated minority “wants a lot.” Let’s begin.

This series aims to provide a fresh perspective on Android system operation through Perfetto. It offers a unique angle to study App, Framework, and Linux internals. Through graphical tools like Perfetto, you may gain much deeper insights.

Perfetto Series Catalog

  1. Android Perfetto Series Catalog
  2. Android Perfetto Series 1: Introduction to Perfetto
  3. Android Perfetto Series 2: Capturing Perfetto Traces
  4. Android Perfetto Series 3: Familiarizing with the Perfetto View
  5. Android Perfetto Series 4: Opening Large Traces via Command Line
  6. Android Perfetto Series 5: Choreographer-based Rendering Flow
  7. Android Perfetto Series 6: Why 120Hz? Advantages and Challenges
  8. Android Perfetto Series 7: MainThread and RenderThread Deep Dive
  9. Android Perfetto Series 8: Understanding Vsync and Performance Analysis
  10. Android Perfetto Series 9: Interpreting CPU Information
  11. Video (Bilibili) - Android Perfetto Basics and Case Studies

The Perfetto Landing View

Once you’ve captured a trace, you typically open it at ui.perfetto.dev. (If you used the official capture script, it opens automatically).

Perfetto Landing View

You can click “Open trace file” or simply drag and drop your file into the white area.

The Trace Interface

After opening a trace, you’ll see the main analysis interface:

Trace Interface Map

The interface is divided into four main sections:

  1. Sidebar (Right): Contains high-frequency tools:
    • Show timeline: Returns to the main trace view.
    • Query: Where you write SQL to query the trace database.
    • Metrics: Ready-to-use analysis reports provided by the system.
    • Info and stats: Metadata about the trace and the target device.
  2. Timeline Header (Top): Primarily used for time-referencing.
  3. Content Area (Center): Where most analysis happens. Traces are grouped by function (CPU usage, Ftrace events) or by App Process (Threads, Input events, Binder calls, Memory, etc.).
  4. Info Panel (Bottom): Displays details for any selected slice, log, or event.

Basic Operations

Perfetto’s UI is incredibly smooth, handling multi-GB files far better than Systrace ever could.

The navigation shortcuts are similar to Systrace:

  • W / S: Zoom In / Zoom Out.
  • A / D: Pan Left / Pan Right.
  • Mouse Click: Select a slice or area.

Shortcuts Reference

Key Shortcuts to Master:

  • f: Zoom and center on the current selection.
  • m: Create a Temporary Mark area. Selecting another area and pressing m will remove the previous one. Press Esc to clear.
  • Shift + m: Create a Persistent Mark. These stay until manually removed, perfect for tagging every frame drop in a long trace.
  • q: Toggle the Info Panel. Perfetto is screen-intensive, so hiding the bottom panel when not needed is vital.
  • Flagging: Hover over the very top of the timeline and click to drop a flag at a specific timestamp.

Usage Tips and Tricks

Identifying Wakeup Sources

Understanding what woke up a thread is key to tracing App and Framework logic. Perfetto makes this much smoother than Systrace.

Method 1: Click the “Runnable” Slice

Click the Runnable (cyan) section before a Running slice. The Info Panel will show Related thread states, including the Waker thread.

Wakeup via Runnable

Method 2: Track via CPU Info

Click a Running slice and tap the arrow to jump to the CPU core view. Here you can see contiguous execution and follow the chain of wakeups across Different cores.

Wakeup Chain

Analyzing the Critical Path

The Critical Path visualizes all tasks your current selection depends on. If task E is waiting on D, D on C, and so on, Perfetto can highlight this the entire chain.

Click a Running slice and select Critical path in the bottom panel. This collapses dependent wakeups into a single view.

Critical Path View

Pinning Threads

Click the thumbtack icon on the far left of any thread name to pin it to the top. This is essential for keeping related threads (like an App’s MainThread and the System’s SurfaceFlinger) together for comparison.

Pinned Threads

Buffer Consumption Tracking

For apps, the consumer is SurfaceFlinger. By looking at the Actual Timeline in the App process, you can see exactly which SurfaceFlinger frame consumed a specific app buffer.

Detecting App Timeouts

Using the Expected and Actual Timeline tracks, you can see where an app exceeded its rendering budget. Red slices in the Actual Timeline indicate frames that took too long.

App Timeout

Interactive Logs and Events

In the Android Logs tab, hovering over a log line will draw a vertical line on the timeline, showing exactly when it happened. The same applies to the Ftrace events tab.

Running State Analysis

Click and drag to select a region on the CPU State track. The bottom panel will calculate the percentage of time the thread spent in Running, Runnable, Sleep, and Uninterruptible Sleep. This is invaluable for App Launch optimization.

Running State Analysis


Summary

This article covered the basic interface and navigation of Perfetto, along with several high-impact analysis tips. Google is actively adding new features to the web UI, so expect this tool to only get more powerful over time.

This concludes the Perfetto basics. In the next part of the series, we will dive into specific Android system flows and use SQL queries to solve real-world performance and power consumption issues.


“If you want to go fast, go alone. If you want to go far, go together.”

WeChat QR Code

CATALOG
  1. 1. Table of Contents
  • Perfetto Series Catalog
  • The Perfetto Landing View
  • The Trace Interface
  • Basic Operations
    1. 0.1. Key Shortcuts to Master:
  • Usage Tips and Tricks
    1. 1. Identifying Wakeup Sources
      1. 1.1. Method 1: Click the “Runnable” Slice
      2. 1.2. Method 2: Track via CPU Info
    2. 2. Analyzing the Critical Path
    3. 3. Pinning Threads
    4. 4. Buffer Consumption Tracking
    5. 5. Detecting App Timeouts
    6. 6. Interactive Logs and Events
    7. 7. Running State Analysis
  • Summary