• 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 {toNs} from '../../common/time';
19import {
20  ACTUAL_FRAMES_SLICE_TRACK_KIND,
21  Config
22} from '../../tracks/actual_frames/common';
23import {globals} from '../globals';
24
25import {AggregationController} from './aggregation_controller';
26
27export class FrameAggregationController extends AggregationController {
28  async createAggregateView(engine: Engine, area: Area) {
29    await engine.query(`drop view if exists ${this.kind};`);
30
31    const selectedSqlTrackIds = [];
32    for (const trackId of area.tracks) {
33      const track = globals.state.tracks[trackId];
34      // Track will be undefined for track groups.
35      if (track !== undefined &&
36          track.kind === ACTUAL_FRAMES_SLICE_TRACK_KIND) {
37        selectedSqlTrackIds.push((track.config as Config).trackIds);
38      }
39    }
40    if (selectedSqlTrackIds.length === 0) return false;
41
42    const query = `create view ${this.kind} as
43        SELECT
44        jank_type,
45        count(1) as occurrences,
46        MIN(dur) as minDur,
47        AVG(dur) as meanDur,
48        MAX(dur) as maxDur
49        FROM actual_frame_timeline_slice
50        WHERE track_id IN (${selectedSqlTrackIds}) AND
51        ts + dur > ${toNs(area.startSec)} AND
52        ts < ${toNs(area.endSec)} group by jank_type`;
53
54    await engine.query(query);
55    return true;
56  }
57
58  getTabName() {
59    return 'Frames';
60  }
61
62  async getExtra() {}
63
64  getDefaultSorting(): Sorting {
65    return {column: 'occurrences', direction: 'DESC'};
66  }
67
68  getColumnDefinitions(): ColumnDef[] {
69    return [
70      {
71        title: 'Jank Type',
72        kind: 'STRING',
73        columnConstructor: Uint16Array,
74        columnId: 'jank_type',
75      },
76      {
77        title: 'Min duration',
78        kind: 'NUMBER',
79        columnConstructor: Uint16Array,
80        columnId: 'minDur',
81      },
82      {
83        title: 'Max duration',
84        kind: 'NUMBER',
85        columnConstructor: Uint16Array,
86        columnId: 'maxDur',
87      },
88      {
89        title: 'Mean duration',
90        kind: 'NUMBER',
91        columnConstructor: Uint16Array,
92        columnId: 'meanDur',
93      },
94      {
95        title: 'Occurrences',
96        kind: 'NUMBER',
97        columnConstructor: Uint16Array,
98        columnId: 'occurrences',
99        sum: true
100      }
101    ];
102  }
103}
104