• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 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--     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
17CREATE VIEW IF NOT EXISTS ion_timeline AS
18SELECT
19  ts,
20  LEAD(ts, 1, (SELECT end_ts FROM trace_bounds))
21    OVER(PARTITION BY track_id ORDER BY ts) - ts AS dur,
22  CASE name
23    WHEN 'mem.ion' THEN 'all'
24    ELSE SUBSTR(name, 9)
25  END AS heap_name,
26  track_id,
27  value
28FROM counter JOIN counter_track
29  ON counter.track_id = counter_track.id
30WHERE (name LIKE 'mem.ion.%' OR name = 'mem.ion');
31
32CREATE VIEW IF NOT EXISTS ion_heap_stats AS
33SELECT
34  heap_name,
35  SUM(value * dur) / SUM(dur) AS avg_size,
36  MIN(value) AS min_size,
37  MAX(value) AS max_size
38FROM ion_timeline
39GROUP BY 1;
40
41CREATE VIEW IF NOT EXISTS ion_raw_allocs AS
42SELECT
43  CASE name
44    WHEN 'mem.ion_change' THEN 'all'
45    ELSE SUBSTR(name, 16)
46  END AS heap_name,
47  ts,
48  value AS instant_value,
49  SUM(value) OVER win AS value
50FROM counter c JOIN thread_counter_track t ON c.track_id = t.id
51WHERE (name LIKE 'mem.ion_change.%' OR name = 'mem.ion_change') AND value > 0
52WINDOW win AS (
53  PARTITION BY name ORDER BY ts
54  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
55);
56
57CREATE VIEW IF NOT EXISTS ion_alloc_stats AS
58SELECT
59  heap_name,
60  SUM(instant_value) AS total_alloc_size_bytes
61FROM ion_raw_allocs
62GROUP BY 1;
63
64-- We need to group by ts here as we can have two ion events from
65-- different processes occurring at the same timestamp. We take the
66-- max as this will take both allocations into account at that
67-- timestamp.
68CREATE VIEW IF NOT EXISTS android_ion_annotations AS
69SELECT
70  'counter' AS track_type,
71  printf('ION allocations (heap: %s)', heap_name) AS track_name,
72  ts,
73  MAX(value) AS value
74FROM ion_raw_allocs
75GROUP BY 1, 2, 3;
76
77CREATE VIEW IF NOT EXISTS android_ion_output AS
78SELECT AndroidIonMetric(
79  'buffer', RepeatedField(
80    AndroidIonMetric_Buffer(
81      'name', heap_name,
82      'avg_size_bytes', avg_size,
83      'min_size_bytes', min_size,
84      'max_size_bytes', max_size,
85      'total_alloc_size_bytes', total_alloc_size_bytes
86    )
87  ))
88FROM ion_heap_stats JOIN ion_alloc_stats USING (heap_name);
89