1/*
2 * Copyright (C) 2019 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 *      http://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
17DROP VIEW IF EXISTS blocked_iowait_for_app_launches;
18
19CREATE VIEW blocked_iowait_for_app_launches AS
20WITH
21    block_launch_join AS (
22        SELECT *
23        FROM blocking_durations AS bd,
24             launch_durations_named AS ld
25        WHERE bd.block_timestamp >= ld.started_timestamp
26              AND bd.unblock_timestamp <= ld.finished_timestamp
27    ),
28    blocked_ui_threads AS (
29        SELECT *
30        FROM start_process_ui_threads AS sp,
31             block_launch_join AS blj
32        WHERE sp.atm_ui_thread_tid == unblock_pid
33              AND sp.process_name = blj.proc_name
34    ),
35    summed_raw AS (
36        SELECT SUM(unblock_timestamp-block_timestamp)*1000 AS sum_block_duration_ms,
37               *
38        FROM blocked_ui_threads
39        GROUP BY unblock_pid
40    ),
41    summed_neat AS (
42        SELECT sum_block_duration_ms AS blocked_iowait_duration_ms,
43               process_name,
44               (finished_timestamp - started_timestamp) * 1000 AS launching_duration_ms,
45               started_timestamp * 1000 AS launching_started_timestamp_ms,
46               finished_timestamp * 1000 AS launching_finished_timestamp_ms
47                -- filter out the rest because its just selecting 1 arbitrary row (due to the SUM aggregate).,
48        FROM summed_raw
49    )
50SELECT * FROM summed_neat;
51
52SELECT * FROM blocked_iowait_for_app_launches;
53