• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2021 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import {ColumnDef} from '../../common/aggregation_data';
16import {Engine} from '../../common/engine';
17import {Area, Sorting} from '../../common/state';
18import {globals} from '../../frontend/globals';
19import {
20  ACTUAL_FRAMES_SLICE_TRACK_KIND,
21  Config,
22} from '../../tracks/actual_frames';
23
24import {AggregationController} from './aggregation_controller';
25
26export class FrameAggregationController extends AggregationController {
27  async createAggregateView(engine: Engine, area: Area) {
28    await engine.query(`drop view if exists ${this.kind};`);
29
30    const selectedSqlTrackIds = [];
31    for (const trackId of area.tracks) {
32      const track = globals.state.tracks[trackId];
33      // Track will be undefined for track groups.
34      if (track !== undefined &&
35          track.kind === ACTUAL_FRAMES_SLICE_TRACK_KIND) {
36        selectedSqlTrackIds.push((track.config as Config).trackIds);
37      }
38    }
39    if (selectedSqlTrackIds.length === 0) return false;
40
41    const query = `create view ${this.kind} as
42        SELECT
43        jank_type,
44        count(1) as occurrences,
45        MIN(dur) as minDur,
46        AVG(dur) as meanDur,
47        MAX(dur) as maxDur
48        FROM actual_frame_timeline_slice
49        WHERE track_id IN (${selectedSqlTrackIds}) AND
50        ts + dur > ${area.start} AND
51        ts < ${area.end} group by jank_type`;
52
53    await engine.query(query);
54    return true;
55  }
56
57  getTabName() {
58    return 'Frames';
59  }
60
61  async getExtra() {}
62
63  getDefaultSorting(): Sorting {
64    return {column: 'occurrences', direction: 'DESC'};
65  }
66
67  getColumnDefinitions(): ColumnDef[] {
68    return [
69      {
70        title: 'Jank Type',
71        kind: 'STRING',
72        columnConstructor: Uint16Array,
73        columnId: 'jank_type',
74      },
75      {
76        title: 'Min duration',
77        kind: 'NUMBER',
78        columnConstructor: Uint16Array,
79        columnId: 'minDur',
80      },
81      {
82        title: 'Max duration',
83        kind: 'NUMBER',
84        columnConstructor: Uint16Array,
85        columnId: 'maxDur',
86      },
87      {
88        title: 'Mean duration',
89        kind: 'NUMBER',
90        columnConstructor: Uint16Array,
91        columnId: 'meanDur',
92      },
93      {
94        title: 'Occurrences',
95        kind: 'NUMBER',
96        columnConstructor: Uint16Array,
97        columnId: 'occurrences',
98        sum: true,
99      },
100    ];
101  }
102}
103