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, Sorting} from '../../public/aggregation'; 16import {AreaSelection} from '../../public/selection'; 17import {ACTUAL_FRAMES_SLICE_TRACK_KIND} from '../../public/track_kinds'; 18import {Engine} from '../../trace_processor/engine'; 19import {AreaSelectionAggregator} from '../../public/selection'; 20 21export class FrameSelectionAggregator implements AreaSelectionAggregator { 22 readonly id = 'frame_aggregation'; 23 24 async createAggregateView(engine: Engine, area: AreaSelection) { 25 const selectedSqlTrackIds: number[] = []; 26 for (const trackInfo of area.tracks) { 27 if (trackInfo?.tags?.kind === ACTUAL_FRAMES_SLICE_TRACK_KIND) { 28 trackInfo.tags.trackIds && 29 selectedSqlTrackIds.push(...trackInfo.tags.trackIds); 30 } 31 } 32 if (selectedSqlTrackIds.length === 0) return false; 33 34 await engine.query(` 35 create or replace perfetto table ${this.id} as 36 select 37 jank_type, 38 count(1) as occurrences, 39 min(dur) as minDur, 40 avg(dur) as meanDur, 41 max(dur) as maxDur 42 from actual_frame_timeline_slice 43 where track_id in (${selectedSqlTrackIds}) 44 AND ts + dur > ${area.start} 45 AND ts < ${area.end} 46 group by jank_type 47 `); 48 return true; 49 } 50 51 getTabName() { 52 return 'Frames'; 53 } 54 55 async getExtra() {} 56 57 getDefaultSorting(): Sorting { 58 return {column: 'occurrences', direction: 'DESC'}; 59 } 60 61 getColumnDefinitions(): ColumnDef[] { 62 return [ 63 { 64 title: 'Jank Type', 65 kind: 'STRING', 66 columnConstructor: Uint16Array, 67 columnId: 'jank_type', 68 }, 69 { 70 title: 'Min duration', 71 kind: 'NUMBER', 72 columnConstructor: Uint16Array, 73 columnId: 'minDur', 74 }, 75 { 76 title: 'Max duration', 77 kind: 'NUMBER', 78 columnConstructor: Uint16Array, 79 columnId: 'maxDur', 80 }, 81 { 82 title: 'Mean duration', 83 kind: 'NUMBER', 84 columnConstructor: Uint16Array, 85 columnId: 'meanDur', 86 }, 87 { 88 title: 'Occurrences', 89 kind: 'NUMBER', 90 columnConstructor: Uint16Array, 91 columnId: 'occurrences', 92 sum: true, 93 }, 94 ]; 95 } 96} 97