• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2023 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-- This module contains helpers for computing the thread-level parallelism counters,
17-- including how many threads were runnable at a given time and how many threads
18-- where running at a given point in time.
19
20INCLUDE PERFETTO MODULE intervals.overlap;
21
22-- The count of runnable threads over time.
23CREATE PERFETTO TABLE sched_runnable_thread_count (
24  -- Timestamp when the runnable thread count changed to the current value.
25  ts TIMESTAMP,
26  -- Number of runnable threads, covering the range from this timestamp to the
27  -- next row's timestamp.
28  runnable_thread_count LONG
29) AS
30WITH
31  runnable AS (
32    SELECT
33      ts,
34      dur
35    FROM thread_state
36    WHERE
37      state = 'R'
38  )
39SELECT
40  ts,
41  value AS runnable_thread_count
42FROM intervals_overlap_count!(runnable, ts, dur)
43ORDER BY
44  ts;
45
46-- The count of threads in uninterruptible sleep over time.
47CREATE PERFETTO TABLE sched_uninterruptible_sleep_thread_count (
48  -- Timestamp when the thread count changed to the current value.
49  ts TIMESTAMP,
50  -- Number of threads in uninterrutible sleep, covering the range from this timestamp to the
51  -- next row's timestamp.
52  uninterruptible_sleep_thread_count LONG
53) AS
54WITH
55  uninterruptible_sleep AS (
56    SELECT
57      ts,
58      dur
59    FROM thread_state
60    WHERE
61      state = 'D'
62  )
63SELECT
64  ts,
65  value AS uninterruptible_sleep_thread_count
66FROM intervals_overlap_count!(uninterruptible_sleep, ts, dur)
67ORDER BY
68  ts;
69
70-- The count of active CPUs over time.
71CREATE PERFETTO TABLE sched_active_cpu_count (
72  -- Timestamp when the number of active CPU changed.
73  ts TIMESTAMP,
74  -- Number of active CPUs, covering the range from this timestamp to the next
75  -- row's timestamp.
76  active_cpu_count LONG
77) AS
78WITH
79  -- Filter sched events corresponding to running tasks.
80  -- thread(s) with is_idle = 1 are the swapper threads / idle tasks.
81  tasks AS (
82    SELECT
83      ts,
84      dur
85    FROM sched
86    WHERE
87      NOT utid IN (
88        SELECT
89          utid
90        FROM thread
91        WHERE
92          is_idle
93      )
94  )
95SELECT
96  ts,
97  value AS active_cpu_count
98FROM intervals_overlap_count!(tasks, ts, dur)
99ORDER BY
100  ts;
101