Trace search

Use SQL to find specific states in Winscope Perfetto traces. Use the global Search viewer in the Winscope UI to run queries and visualize tabulated results:

search viewer tab

Figure 1. Search viewer tab.

The Search viewer lets you write and run custom SQL queries on Perfetto traces, and access recent and saved queries. Winscope provides specialized SQL views to aid with searching SurfaceFlinger and Transactions traces.

Use the following conventions for all views:

  • For property and flat_property columns:

    • Property names are in snake case, for example visible_region from LayerProto.
    • A dot notation is used to represent nested properties, for example, visible_region.rect.

    • Repeated fields in property are distinguished with square brackets:

      For example, within two instances of repeated field visible_region.rect, the top field is represented by visible_region.rect[0].top and visible_region.rect[1].top.

    • Repeated fields in flat_property are indistinguishable:

      For example, within two instances of repeated field visible_region.rect, the top field is represented by visible_region.rect.top in both the instances.

  • For value and previous_value columns:

    • Boolean values are represented by '0' (False) or '1' (True).

SurfaceFlinger SQL views

SurfaceFlinger proto data uses these formats:

To search layer data, use the sf_layer_search view. This view includes these columns:

Column Description
state_id Unique ID of the entry that the layer belongs to
ts Timestamp of the entry that the layer belongs to
layer_id Layer id
parent_id Layer ID of the parent
layer_name Layer name
property Property name accounting for repeated fields
flat_property Property name not accounting for repeated fields
value Property value in string format
previous_value Property value from the previous entry in string format

To search hierarchy root data, use the sf_hierarchy_root_search view. This view includes these columns:

Column Description
state_id Unique ID of the entry
ts Timestamp of the entry
property Property name accounting for repeated fields
flat_property Property name not accounting for repeated fields
value Property value in string format
previous_value Property value from the previous entry in string format

Example queries

  • Find all frames where the IME layer has valid screen bounds:

    SELECT ts, value, previous_value FROM sf_layer_search
      WHERE layer_name like 'IME%'
      AND property='screen_bounds.bottom'
      AND value<='24000'
    
  • Find all frames where the Taskbar layer color.a (alpha) changes:

    SELECT ts, value, previous_value FROM sf_layer_search
      WHERE layer_name like 'Taskbar%'
      AND property='color.a'
      AND value!=previous_value
    
  • Find all frames where the Wallpaper bottom bound is less than or equal to 2400:

    SELECT ts, value, previous_value FROM sf_layer_search
      WHERE layer_name LIKE 'Wallpaper%'
      AND property='bounds.bottom'
      AND cast_int!(value) <= 2400
    
  • List all properties for displays with a valid layer stack:

    SELECT STATE.* FROM sf_hierarchy_root_search STATE_WITH_DISPLAY_ON
    INNER JOIN sf_hierarchy_root_search STATE
      ON STATE.state_id = STATE_WITH_DISPLAY_ON.state_id
      AND STATE_WITH_DISPLAY_ON.flat_property='displays.layer_stack'
      AND STATE_WITH_DISPLAY_ON.value!='4294967295'
      AND STATE.property LIKE CONCAT(
        SUBSTRING(
            STATE_WITH_DISPLAY_ON.property,
            0,
            instr(STATE_WITH_DISPLAY_ON.property, ']')
        ),
        '%'
      )
    

Transactions SQL view

The transactions proto data uses the TransactionTraceEntry format.

To search transactions data, use the transactions_search view. This view includes these columns:

Column Description
state_id Unique ID of the entry that the proto property belongs to
ts Timestamp of the entry that the proto property belongs to
transaction_id Transaction ID if available
property Property name accounting for repeated fields
flat_property Property name not accounting for repeated fields
value Property value in string format

Example queries

  • Find the frame where a transaction was applied to change layer x position to -54.0:

    SELECT ts, transaction_id, value FROM transactions_search
      WHERE flat_property='transactions.layer_changes.x'
      AND value='-54.0'
    
  • Find the frame where the ImeContainer layer was added:

    SELECT ts FROM transactions_search
      WHERE flat_property='added_layers.name'
      AND value='ImeContainer'
    

Transitions SQL view

The transitions proto data uses the ShellTransition format.

To search transitions data, use the transitions_search view. This view includes these columns:

Column Description
ts Dispatch time - falls back to the send time if available, else 0
transition_id Transition id
property Property name accounting for repeated fields
flat_property Property name not accounting for repeated fields
value Property value in string format

Example queries

Find properties of transitions handled by the DefaultMixedHandler:

  SELECT
    PROPS.ts,
    PROPS.transition_id,
    PROPS.property,
    PROPS.value
  FROM transitions_search HANDLER_MATCH
  INNER JOIN transitions_search PROPS
    ON HANDLER_MATCH.transition_id = PROPS.transition_id
  WHERE HANDLER_MATCH.property = 'handler'
    AND HANDLER_MATCH.value LIKE "%DefaultMixedHandler"
  ORDER BY PROPS.transition_id, PROPS.property

ViewCapture SQL view

The ViewCapture proto data uses the View format.

To search ViewCapture data, use the viewcapture_search view. This view includes these columns:

Column Description
state_id Unique ID of the state that the view belongs to
ts Timestamp of the state that the view belongs to
package_name Package name
window_name Window name
class_name View class name
property Property name accounting for repeated fields
flat_property Property name not accounting for repeated fields
value Property value in string format
previous_value Property value from the previous state in string format

Example queries

Find all states when SearchContainerView moved in the y-direction:

  SELECT * FROM viewcapture_search
  WHERE class_name LIKE '%SearchContainerView'
    AND flat_property='translation_y'
    AND value!=previous_value

ProtoLog SQL table

The ProtoLog proto data uses the ProtoLogMessage format. This view includes these columns:

Column Description
ts Timestamp of the log
level Log level
tag Logging group tag
message Log message
stacktrace Stacktrace (if available)
location Code location from which message originates

Example queries

  • Find all logs with a message containing transition:

    SELECT ts, message, location FROM protolog
      WHERE message LIKE '%transition%'
    
  • Find all logs that contain valid transaction IDs:

    CREATE PERFETTO VIEW valid_tx_ids AS
      SELECT DISTINCT transaction_id FROM transactions_search
      WHERE transaction_id IS NOT NULL AND transaction_id != '0';
    
    SELECT TRANS.transaction_id, message FROM valid_tx_ids TRANS
    INNER JOIN protolog LOGS
      ON LOGS.message LIKE CONCAT('%', TRANS.transaction_id, '%');
    

Run queries

When you use the left panel, trace search starts. This takes a few seconds. While it starts, the timeline isn't available.

After trace search has initialized, write a query in the search box and click Run Search Query or press Enter on your keyboard to run it.

When finished, the table of results shows in the middle panel. Your query appears below the search box, with a field to save the query between sessions.

You can access saved queries by clicking the Saved tab in the left panel, and access recently run queries by clicking the Recent tab:

search viewer left panel

Figure 2. Search viewer left panel.

Results

All queries return tabulated results, shown in a scrollable view with interactive behavior similar to the log-based trace viewers, such as Transactions and ProtoLog:

search viewer results

Figure 3. Search viewer results.

If the resulting table contains a ts column, the values in that column are interpreted as timestamps and added to the timeline overlay as a new row of entries. Click this row and use your left and right arrow keys to navigate between entries:

search timeline

Figure 4. Search timeline.