• 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
20INCLUDE PERFETTO MODULE 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.
24CREATE OR REPLACE PERFETTO FUNCTION dur_of_process_running_concurrent_to_launch(
25  startup_id INT,
26  process_glob STRING
27)
28RETURNS INT AS
29SELECT IFNULL(SUM(sched.dur), 0)
30FROM sched
31JOIN thread USING (utid)
32JOIN process USING (upid)
33JOIN (
34  SELECT ts, ts_end
35  FROM android_startups
36  WHERE startup_id = $startup_id
37) launch
38WHERE
39  process.name GLOB $process_glob AND
40  sched.ts BETWEEN launch.ts AND launch.ts_end;
41
42-- Given a launch id and slice name glob, returns the number of slices with that
43-- name which start concurrent to that launch.
44CREATE OR REPLACE PERFETTO FUNCTION count_slices_concurrent_to_launch(startup_id INT, slice_glob STRING)
45RETURNS INT AS
46SELECT COUNT(1)
47FROM slice
48JOIN (
49  SELECT ts, ts_end
50  FROM android_startups
51  WHERE startup_id = $startup_id
52) launch
53WHERE
54  slice.name GLOB $slice_glob AND
55  slice.ts BETWEEN launch.ts AND launch.ts_end;
56