• 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
17DROP VIEW IF EXISTS dma_heap_timeline;
18CREATE VIEW dma_heap_timeline AS
19SELECT
20  ts,
21  LEAD(ts, 1, (SELECT end_ts FROM trace_bounds))
22  OVER(PARTITION BY track_id ORDER BY ts) - ts AS dur,
23  track_id,
24  value
25FROM counter JOIN counter_track
26  ON counter.track_id = counter_track.id
27WHERE (name = 'mem.dma_heap');
28
29DROP VIEW IF EXISTS dma_heap_stats;
30CREATE VIEW dma_heap_stats AS
31SELECT
32  SUM(value * dur) / SUM(dur) AS avg_size,
33  MIN(value) AS min_size,
34  MAX(value) AS max_size
35FROM dma_heap_timeline;
36
37DROP VIEW IF EXISTS dma_heap_raw_allocs;
38CREATE VIEW dma_heap_raw_allocs AS
39SELECT
40  ts,
41  value AS instant_value,
42  SUM(value) OVER win AS value
43FROM counter c JOIN thread_counter_track t ON c.track_id = t.id
44WHERE (name = 'mem.dma_heap_change') AND value > 0
45WINDOW win AS (
46  PARTITION BY name ORDER BY ts
47  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
48);
49
50DROP VIEW IF EXISTS dma_heap_total_stats;
51CREATE VIEW dma_heap_total_stats AS
52SELECT
53  SUM(instant_value) AS total_alloc_size_bytes
54FROM dma_heap_raw_allocs;
55
56-- We need to group by ts here as we can have two ion events from
57-- different processes occurring at the same timestamp. We take the
58-- max as this will take both allocations into account at that
59-- timestamp.
60DROP VIEW IF EXISTS android_dma_heap_event;
61CREATE VIEW android_dma_heap_event AS
62SELECT
63  'counter' AS track_type,
64  printf('Buffers created from DMA-BUF heaps: ') AS track_name,
65  ts,
66  MAX(value) AS value
67FROM dma_heap_raw_allocs
68GROUP BY 1, 2, 3;
69
70DROP VIEW IF EXISTS android_dma_heap_output;
71CREATE VIEW android_dma_heap_output AS
72SELECT AndroidDmaHeapMetric(
73  'avg_size_bytes', avg_size,
74  'min_size_bytes', min_size,
75  'max_size_bytes', max_size,
76  'total_alloc_size_bytes', total_alloc_size_bytes
77  )
78FROM dma_heap_stats JOIN dma_heap_total_stats;
79