• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2024 The Android Open Source Project
3--
4-- Licensed under the Apache License, Version 2.0 (the "License");
5-- you may not use this file except in compliance with the License.
6-- You may obtain a copy of the License at
7--
8--     https://www.apache.org/licenses/LICENSE-2.0
9--
10-- Unless required by applicable law or agreed to in writing, software
11-- distributed under the License is distributed on an "AS IS" BASIS,
12-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-- See the License for the specific language governing permissions and
14-- limitations under the License.
15--
16
17-- Previous runnable slice on the same thread.
18-- For each "Running" thread state finds:
19-- - previous "Runnable" (or runnable preempted) state.
20-- - previous uninterrupted "Runnable" state with a valid waker thread.
21CREATE PERFETTO TABLE sched_previous_runnable_on_thread(
22    -- `thread_state.id` id.
23    id INT,
24    -- Previous runnable `thread_state.id`.
25    prev_runnable_id INT,
26    -- Previous runnable `thread_state.id` with valid waker
27    -- thread.
28    prev_wakeup_runnable_id INT
29) AS
30WITH running_and_runnable AS (
31  SELECT
32        id,
33        state,
34        MAX(id)
35          FILTER (WHERE state != 'Running')
36          OVER utid_part AS prev_runnable_id,
37        MAX(id)
38          FILTER (WHERE
39            waker_utid IS NOT NULL
40            AND (irq_context IS NULL OR irq_context != 1))
41          OVER utid_part AS prev_wakeup_runnable_id
42    FROM thread_state
43    -- Optimal operation for state IN (R, R+, Running)
44    WHERE state GLOB 'R*' AND dur != -1
45    WINDOW utid_part AS (PARTITION BY utid ORDER BY id)
46)
47SELECT
48  id,
49  prev_runnable_id,
50  prev_wakeup_runnable_id
51FROM running_and_runnable
52WHERE state = 'Running'
53ORDER BY id;