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 sched_switch_next_comm_pids;
18
19CREATE VIEW IF NOT EXISTS sched_switch_next_comm_pids AS
20
21-- TODO: switch to using sched_switches table.
22
23WITH
24    sched_switchs AS (
25        SELECT * FROM raw_ftrace_entries WHERE function = 'sched_switch' AND function_args LIKE '% next_pid=%' AND function_args NOT LIKE '% next_comm=main %'
26    ),
27    comm_and_pids_raws AS (
28        SELECT id,
29               SUBSTR(function_args, instr(function_args, "next_comm="), instr(function_args, "next_pid=") - instr(function_args, "next_comm=")) AS next_comm_raw,
30               SUBSTR(function_args, instr(function_args, "next_pid="), instr(function_args, "next_prio=") - instr(function_args, "next_pid=")) AS next_pid_raw
31        FROM sched_switchs
32    ),
33    comm_and_pids AS (
34        SELECT id,
35               id AS raw_ftrace_entry_id,
36               TRIM(SUBSTR(next_pid_raw, 10)) AS next_pid, -- len("next_pid=") is 10
37               TRIM(SUBSTR(next_comm_raw, 11)) AS next_comm -- len("next_comm=") is 11
38        FROM comm_and_pids_raws
39    )
40SELECT * from comm_and_pids;
41
42SELECT * from sched_switch_next_comm_pids;
43