• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2022 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-- All thread slices with data about thread, thread track and process.
17-- Where possible, use available view functions which filter this view.
18--
19-- @column slice_id           Id of slice.
20-- @column slice_name         Name of slice.
21-- @column ts                 Timestamp of slice start.
22-- @column dur                Duration of slice.
23-- @column slice_depth        Depth of slice.
24-- @column arg_set_id         Slice arg set id.
25-- @column thread_track_id    Id of thread track.
26-- @column thread_track_name  Name of thread track.
27-- @column utid               Utid of thread with slice.
28-- @column thread_name        Name of thread with slice.
29-- @column upid               Upid of process with slice.
30-- @column process_name       Name of process with slice.
31CREATE VIEW thread_slice AS
32SELECT
33  slice.id AS slice_id,
34  slice.name AS slice_name,
35  ts,
36  dur,
37  slice.depth AS slice_depth,
38  slice.arg_set_id,
39  slice.track_id AS thread_track_id,
40  thread_track.name AS thread_track_name,
41  utid,
42  thread.name AS thread_name,
43  upid,
44  process.name AS process_name
45FROM slice
46JOIN thread_track ON slice.track_id = thread_track.id
47JOIN thread using (utid)
48LEFT JOIN process using (upid);
49
50-- All process slices with data about process track and process.
51-- Where possible, use available view functions which filter this view.
52--
53-- @column slice_id           Id of slice.
54-- @column slice_name         Name of slice.
55-- @column ts                 Timestamp of slice start.
56-- @column dur                Duration of slice.
57-- @column slice_depth        Depth of slice.
58-- @column arg_set_id         Slice arg set id.
59-- @column process_track_id   Id of process track.
60-- @column process_track_name Name of process track.
61-- @column upid               Upid of process with slice.
62-- @column process_name       Name of process with slice.
63CREATE VIEW process_slice AS
64SELECT
65  slice.id AS slice_id,
66  slice.name AS slice_name,
67  ts,
68  dur,
69  slice.depth AS slice_depth,
70  slice.arg_set_id,
71  process_track.id AS process_track_id,
72  process_track.name AS process_track_name,
73  upid,
74  process.name AS process_name
75FROM slice
76JOIN process_track ON slice.track_id = process_track.id
77JOIN process using (upid);
78
79-- Checks if slice has an ancestor with provided name.
80--
81-- @arg id INT              Id of the slice to check parents of.
82-- @arg parent_name STRING  Name of potential ancestor slice.
83-- @ret BOOL                Whether `parent_name` is a name of an ancestor slice.
84SELECT
85  CREATE_FUNCTION(
86    'HAS_PARENT_SLICE_WITH_NAME(id INT, parent_name STRING)',
87    'BOOL',
88    '
89    SELECT EXISTS(
90      SELECT 1
91      FROM ancestor_slice($id)
92      WHERE name = $parent_name
93      LIMIT 1
94    );
95  '
96);
97
98-- Count slices with specified name.
99--
100-- @arg slice_glob STRING Name of the slices to counted.
101-- @ret INT               Number of slices with the name.
102SELECT CREATE_FUNCTION(
103  'SLICE_COUNT(slice_glob STRING)',
104  'INT',
105  'SELECT COUNT(1) FROM slice WHERE name GLOB $slice_glob;'
106);
107