• 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
17-- Functions useful for filling the SystemState proto which gives
18-- context to what was happening on the system during a startup.
19
20SELECT IMPORT('android.startup.startups');
21
22-- Given a launch id and process name glob, returns the sched.dur if a process with
23-- that name was running on a CPU concurrent to that launch.
24SELECT CREATE_FUNCTION(
25  'DUR_OF_PROCESS_RUNNING_CONCURRENT_TO_LAUNCH(startup_id INT, process_glob STRING)',
26  'INT',
27  '
28      SELECT IFNULL(SUM(sched.dur), 0)
29      FROM sched
30      JOIN thread USING (utid)
31      JOIN process USING (upid)
32      JOIN (
33        SELECT ts, ts_end
34        FROM android_startups
35        WHERE startup_id = $startup_id
36      ) launch
37      WHERE
38        process.name GLOB $process_glob AND
39        sched.ts BETWEEN launch.ts AND launch.ts_end
40  '
41);
42
43-- Given a launch id and slice name glob, returns the number of slices with that
44-- name which start concurrent to that launch.
45SELECT CREATE_FUNCTION(
46  'COUNT_SLICES_CONCURRENT_TO_LAUNCH(startup_id INT, slice_glob STRING)',
47  'INT',
48  '
49    SELECT COUNT(1)
50    FROM slice
51    JOIN (
52      SELECT ts, ts_end
53      FROM android_startups
54      WHERE startup_id = $startup_id
55    ) launch
56    WHERE
57      slice.name GLOB $slice_glob AND
58      slice.ts BETWEEN launch.ts AND launch.ts_end
59  '
60);
61