Collect and analyze traces

This page describes how to use Wattson to record a Perfetto trace and view power estimates.

Quick start: Run Wattson in one command

To run Wattson in one command, use the CtsWattsonTestCases CTS module (cts/tests/wattson). The following command handles device preparation, Perfetto tracing, workload markers, and power calculation automatically:

atest CtsWattsonTestCases

CtsWattsonTestCases configures the device for repeatable measurements, runs the built-in workloads, records traces with wattson.cfg (plus DSU counters when supported), logs average CPU power and energy estimates, and saves the Perfetto traces so you can inspect them in the Perfetto UI.

Use the following command to customize iterations, duration, and settle time by passing iterations, test-time, or start-delay as Tradefed options:

atest CtsWattsonTestCases -- --test-arg com.android.compatibility.common.tradefed.testtype.JarHostTest:set-option:iterations:5

To measure your own app or workload, or on Android versions lower than Android 17 QPR2, use the manual workflow in the following sections.

Minimum build requirements

The following devices require a minimum build version for CPU power estimation. Other supported devices have no minimum build requirement for CPU estimation. For GPU support and minimum builds, see GPU power estimation.

Device Minimum build requirement: CPU estimation
Pixel Watch 3 Android 16
Pixel 9 series Android 16
Pixel 10 series Android 16

Step 1: Record a Perfetto trace

Use the Perfetto UI for quick interactive debugging, or the command line for repeatable benchmarks, GPU estimation, or app-package attribution.

Option A: Perfetto UI (recommended for getting started)

  1. Connect your device over USB, open Record new trace in the Perfetto UI, and connect your device on the Overview screen.
  2. Keep the Default preset. For workloads longer than 10 seconds, increase Max duration under Buffers and duration.

    Scheduling details and CPU frequency and idle states toggles

    Figure 1. Required CPU toggles in the Perfetto UI.

  3. Pixel 9 series and newer only: Under Advanced settings > Advanced ftrace config > Event groups, select devfreq:

    Enable Device frequency

    Figure 2. Enabling devfreq for Pixel 9 and newer devices.

  4. Click Start tracing, run your workload, and click Stop (or let the timer finish). The trace opens automatically—continue to Step 2: View power estimates.

Option B: Command line (adb)

Run these commands from your host machine using Android Debug Bridge (adb).

  1. Copy the complete wattson.cfg configuration to a local file named wattson.cfg, then push it to the device:

    adb push wattson.cfg /data/misc/perfetto-configs/wattson.cfg
    
  2. Start tracing:

    adb shell perfetto --txt -c /data/misc/perfetto-configs/wattson.cfg --background-wait -o /data/misc/perfetto-traces/trace
    
  3. Run your workload on the device.

  4. Stop tracing and pull the trace file to your host:

    adb shell killall -w perfetto
    adb pull /data/misc/perfetto-traces/trace my_perfetto_trace.pb
    
  5. Open my_perfetto_trace.pb in the Perfetto UI and continue to Step 2: View power estimates.

Step 2: View power estimates in the Perfetto UI

When you open a trace from a supported device, a Wattson track group appears automatically in the timeline.

View Wattson traces in Perfetto

Figure 3. Wattson track group in the Perfetto UI.

What appears in the details panel depends on which tracks you drag-select:

  • Select Wattson tracks (Cpu0 estimate through CpuN estimate, DSU/SCU estimate, GPU Estimate) to view hardware power and energy on the Wattson estimates tab.
  • Select all CPU Scheduling tracks (CPU 0 through CPU N) to attribute energy to software on the Wattson by thread, Wattson by process, and Wattson by package tabs.

Hardware rail breakdown

  1. Click Wattson to expand the power estimate tracks.
  2. Drag across the Wattson tracks for your time window, then open the Wattson estimates tab in the details panel.

CPU and DSU/SCU tracks share the same vertical scale for easy comparison. Click any column header in the details panel to sort, and read totals directly below the column headers.

Rail estimates

Figure 4. Per-rail power and energy estimates on the Wattson estimates tab.

Thread, process, and package attribution

Drag across all CPU Scheduling tracks (CPU 0 through CPU N) for your time window, then select Wattson by thread, Wattson by process, or Wattson by package in the details panel (do not use CPU by thread or CPU by process). Click any column header to sort.

Wattson by thread

Shows which individual threads consumed the most energy during your selection.

Thread level breakdowns

Figure 5. Thread-level breakdown.

Wattson by process

Groups thread energy estimates by process name.

By process breakdown

Figure 6. Process-level breakdown.

Wattson by package

Groups energy estimates by Android app package name. Requires android.packages_list, which is included when recording with Option B (wattson.cfg).

Package-level breakdown

Figure 7. Package-level breakdown.

GPU power estimation

On supported devices recorded with Option B (wattson.cfg), a GPU Estimate track appears under Wattson, and a Gpu row appears on the Wattson estimates tab when your selection includes the GPU Estimate track. To view per-app GPU energy attribution, select the GPU Work Period track and open the Wattson by package (GPU) tab.

Device Minimum build requirement: GPU estimation
Pixel 6 series Android 16
Pixel 10 series Android 17
Pixel 11 series Android 17 QPR2

GPU Power Estimation

Figure 8. GPU power estimation.

Optional: Mark exact workload boundaries

For repeatable command-line measurements without setup overhead, write one pair of markers around your workload while Perfetto is recording. Perfetto displays this window on a Wattson markers window track under Wattson.

Before your workload:

adb shell "echo 'I|0|wattson_start' > /sys/kernel/tracing/trace_marker"

After your workload:

adb shell "echo 'I|0|wattson_stop' > /sys/kernel/tracing/trace_marker"

Reference: wattson.cfg

Use this complete configuration with Option B. It enables CPU and GPU estimation, thread/process/package attribution, and workload markers out of the box. Perfetto ignores any event not supported by your device.

write_into_file: true
flush_period_ms: 30000
file_write_period_ms: 30000

buffers: {
  size_kb: 2048
  fill_policy: RING_BUFFER
}
buffers: {
  size_kb: 200000
  fill_policy: RING_BUFFER
}

# Process-level power attribution
data_sources: {
  config {
    name: "linux.process_stats"
    target_buffer: 0
    process_stats_config {
      scan_all_processes_on_start: true
    }
  }
}

# Package-level power attribution
data_sources: {
  config {
    name: "android.packages_list"
    target_buffer: 0
  }
}

# Initial CPU frequency and DSU devfreq state (polled once at trace start)
data_sources: {
  config {
    name: "linux.sys_stats"
    sys_stats_config {
      cpufreq_period_ms: 100000000
      devfreq_period_ms: 100000000
    }
  }
}

# Core power estimation, GPU estimation, markers, and thread/process attribution
data_sources: {
  config {
    name: "linux.ftrace"
    target_buffer: 1
    ftrace_config {
      # Required for CPU power estimation
      ftrace_events: "power/cpu_frequency"
      ftrace_events: "power/cpu_idle"
      ftrace_events: "power/suspend_resume"
      ftrace_events: "cpuhp/cpuhp_enter"
      ftrace_events: "cpuhp/cpuhp_exit"
      ftrace_events: "cpuhp/cpuhp_multi_enter"
      ftrace_events: "devfreq/devfreq_frequency"

      # GPU power estimation
      ftrace_events: "mali/gpu_power_state"
      ftrace_events: "power/gpu_power_state"
      ftrace_events: "power/gpu_frequency"
      ftrace_events: "power/gpu_work_period"  # Enables GPU package attribution

      # Wattson start/stop markers
      ftrace_events: "ftrace/print"

      # Thread-level attribution
      ftrace_events: "sched/sched_switch"

      # Process-level attribution
      ftrace_events: "sched/sched_process_free"
      ftrace_events: "task/task_newtask"
      ftrace_events: "task/task_rename"
    }
  }
}

Example traces

Explore sample Wattson traces in the Perfetto UI (Pixel 6 kernel config experiments):

FAQs

Is Wattson expected to match lab power measurement hardware output?

For most workloads, Wattson estimates closely track lab hardware measurements, but exact numerical agreement isn't guaranteed or the primary goal. Wattson is designed to validate power improvements and catch regressions without noise from ambient temperature, chip-to-chip leakage variation, or hardware calibration differences.

How is Wattson more useful than looking at CPU time or CPU cycles?

CPU time and cycles don't account for power differences across CPU frequencies and core types (little, mid, and big). Doubling CPU frequency doesn't double CPU power or performance.

How accurate is Wattson compared to hardware measurements?

Across workloads tested against lab power measurement hardware, Wattson has an average error of 1 percentage point and a standard deviation of 1.5 percentage points. This accuracy holds across tests ranging from 10 seconds to 4 hours, with no time-dependent drift.