• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2021 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-- Marks the beginning of the trace and is equivalent to when the statsd launch
18-- logging begins.
19DROP VIEW IF EXISTS activity_intent_received;
20CREATE VIEW activity_intent_received AS
21SELECT ts FROM slice
22WHERE name = 'MetricsLogger:launchObserverNotifyIntentStarted';
23
24-- We partition the trace into spans based on posted activity intents.
25-- We will refine these progressively in the next steps to only encompass
26-- activity starts.
27DROP TABLE IF EXISTS activity_intent_recv_spans;
28CREATE TABLE activity_intent_recv_spans(id INT, ts BIG INT, dur BIG INT);
29
30INSERT INTO activity_intent_recv_spans
31SELECT
32  ROW_NUMBER()
33    OVER(ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS id,
34  ts,
35  LEAD(ts, 1, (SELECT end_ts FROM trace_bounds)) OVER(ORDER BY ts) - ts AS dur
36FROM activity_intent_received
37ORDER BY ts;
38
39-- Filter activity_intent_recv_spans, keeping only the ones that triggered
40-- a launch.
41DROP VIEW IF EXISTS launch_partitions;
42CREATE VIEW launch_partitions AS
43SELECT * FROM activity_intent_recv_spans AS spans
44WHERE 1 = (
45  SELECT COUNT(1)
46  FROM launching_events
47  WHERE launching_events.ts BETWEEN spans.ts AND spans.ts + spans.dur);
48
49-- Successful activity launch. The end of the 'launching' event is not related
50-- to whether it actually succeeded or not.
51DROP VIEW IF EXISTS activity_intent_launch_successful;
52CREATE VIEW activity_intent_launch_successful AS
53SELECT ts FROM slice
54WHERE name = 'MetricsLogger:launchObserverNotifyActivityLaunchFinished';
55
56-- Use the starting event package name. The finish event package name
57-- is not reliable in the case of failed launches.
58INSERT INTO launches(id, ts, ts_end, dur, package)
59SELECT
60  lpart.id AS id,
61  lpart.ts AS ts,
62  launching_events.ts_end AS ts_end,
63  launching_events.ts_end - lpart.ts AS dur,
64  package_name AS package
65FROM launch_partitions AS lpart
66JOIN launching_events ON
67  (launching_events.ts BETWEEN lpart.ts AND lpart.ts + lpart.dur) AND
68  (launching_events.ts_end BETWEEN lpart.ts AND lpart.ts + lpart.dur)
69WHERE (
70  SELECT COUNT(1)
71  FROM activity_intent_launch_successful AS successful
72  WHERE successful.ts BETWEEN lpart.ts AND lpart.ts + lpart.dur
73) > 0;
74