Skip to content

Commit

Permalink
Merge "stdlib: Add sched.latency module" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
aMayzner authored and Gerrit Code Review committed Nov 18, 2024
2 parents 95ab755 + aae882e commit 82bfdd5
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 4 deletions.
1 change: 1 addition & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -13654,6 +13654,7 @@ genrule {
"src/trace_processor/perfetto_sql/stdlib/prelude/after_eof/views.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/before_eof/tables.sql",
"src/trace_processor/perfetto_sql/stdlib/prelude/before_eof/trace_bounds.sql",
"src/trace_processor/perfetto_sql/stdlib/sched/latency.sql",
"src/trace_processor/perfetto_sql/stdlib/sched/runnable.sql",
"src/trace_processor/perfetto_sql/stdlib/sched/states.sql",
"src/trace_processor/perfetto_sql/stdlib/sched/thread_executing_span.sql",
Expand Down
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3167,6 +3167,7 @@ perfetto_filegroup(
perfetto_filegroup(
name = "src_trace_processor_perfetto_sql_stdlib_sched_sched",
srcs = [
"src/trace_processor/perfetto_sql/stdlib/sched/latency.sql",
"src/trace_processor/perfetto_sql/stdlib/sched/runnable.sql",
"src/trace_processor/perfetto_sql/stdlib/sched/states.sql",
"src/trace_processor/perfetto_sql/stdlib/sched/thread_executing_span.sql",
Expand Down
1 change: 1 addition & 0 deletions src/trace_processor/perfetto_sql/stdlib/sched/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import("../../../../../gn/perfetto_sql.gni")

perfetto_sql_source_set("sched") {
sources = [
"latency.sql",
"runnable.sql",
"states.sql",
"thread_executing_span.sql",
Expand Down
51 changes: 51 additions & 0 deletions src/trace_processor/perfetto_sql/stdlib/sched/latency.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--
-- Copyright 2024 The Android Open Source Project
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

INCLUDE PERFETTO MODULE sched.runnable;

CREATE PERFETTO VIEW _sched_with_thread_state_join AS
SELECT
thread_state.id AS thread_state_id,
sched.id AS sched_id
FROM sched
JOIN thread_state USING (utid, ts, dur);

-- Scheduling latency of running thread states.
-- For each time the thread was running, returns the duration of the runnable
-- state directly before.
CREATE PERFETTO TABLE sched_latency_for_running_interval(
-- Running state of the thread. Alias of `thread_state.id`.
thread_state_id INT,
-- Id of a corresponding slice in a `sched` table. Alias of `sched.id`.
sched_id INT,
-- Thread with running state. Alias of `thread.id`.
utid INT,
-- Runnable state before thread is "running". Duration of this thread state
-- is `latency_dur`. One of `thread_state.id`.
runnable_latency_id INT,
-- Scheduling latency of thread state. Duration of thread state with
-- `runnable_latency_id`.
latency_dur INT
) AS
SELECT
r.id AS thread_state_id,
sched_id,
utid,
prev_runnable_id AS runnable_latency_id,
dur AS latency_dur
FROM sched_previous_runnable_on_thread r
JOIN thread_state prev_ts ON prev_runnable_id = prev_ts.id
JOIN _sched_with_thread_state_join ON thread_state_id = r.id

8 changes: 4 additions & 4 deletions src/trace_processor/perfetto_sql/stdlib/sched/runnable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
-- - previous "Runnable" (or runnable preempted) state.
-- - previous uninterrupted "Runnable" state with a valid waker thread.
CREATE PERFETTO TABLE sched_previous_runnable_on_thread(
-- `thread_state.id` id.
-- Alias of `thread_state.id`.
id INT,
-- Previous runnable `thread_state.id`.
-- Previous runnable thread state. Alias of `thread_state.id`.
prev_runnable_id INT,
-- Previous runnable `thread_state.id` with valid waker
-- thread.
-- Previous runnable thread state with valid waker thread. Alias of
-- `thread_state.id`.
prev_wakeup_runnable_id INT
) AS
WITH running_and_runnable AS (
Expand Down
30 changes: 30 additions & 0 deletions test/trace_processor/diff_tests/stdlib/sched/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,33 @@ def test_sched_previous_runnable_on_thread(self):
538177,537492,537492
538175,538174,524613
"""))

def test_sched_latency(self):
return DiffTestBlueprint(
trace=DataPath('android_boot.pftrace'),
query="""
INCLUDE PERFETTO MODULE sched.latency;
SELECT
thread_state_id,
sched_id,
utid,
runnable_latency_id,
latency_dur
FROM sched_latency_for_running_interval
ORDER BY thread_state_id DESC
LIMIT 10;
""",
out=Csv("""
"thread_state_id","sched_id","utid","runnable_latency_id","latency_dur"
538199,269427,2,538191,91919
538197,269425,2,538191,91919
538195,269423,2,538191,91919
538190,269422,1330,538136,1437215
538188,269420,2,538088,826823
538184,269419,91,538176,131388
538181,269418,319,538178,4883
538179,269417,1022,524619,469849
538177,269416,319,537492,670736
538175,269415,91,538174,12532
"""))

0 comments on commit 82bfdd5

Please sign in to comment.