• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2020 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-- Creates a span view for counters that may be global or associated with a
18-- process, assuming that in the latter case we don't actually care about the
19-- process (probably because it's always system_server). We may want to erase
20-- this distinction for example when merging system properties and atrace
21-- counters.
22--
23-- It also does another type of merging: it merges together temporally adjacent
24-- identical values.
25
26DROP VIEW IF EXISTS {{table_name}}_span;
27CREATE VIEW {{table_name}}_span AS
28SELECT
29  ts,
30  LEAD(ts, 1, (SELECT end_ts + 1 FROM trace_bounds))
31  OVER(ORDER BY ts) - ts AS dur,
32  CAST(value AS INT) AS {{table_name}}_val
33FROM (
34    SELECT ts, value, LAG(value) OVER (ORDER BY ts) AS lag_value
35    FROM counter c JOIN counter_track t
36      ON t.id = c.track_id
37    WHERE name = '{{counter_name}}'
38)
39WHERE value != lag_value OR lag_value IS NULL;
40