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 {Engine} from '../../trace_processor/engine'; 18import {AreaSelectionAggregator} from '../../public/selection'; 19import {LONG, STR} from '../../trace_processor/query_result'; 20import {Dataset} from '../../trace_processor/dataset'; 21 22export const ACTUAL_FRAMES_SLICE_TRACK_KIND = 'ActualFramesSliceTrack'; 23 24export class FrameSelectionAggregator implements AreaSelectionAggregator { 25 readonly id = 'frame_aggregation'; 26 readonly schema = { 27 ts: LONG, 28 dur: LONG, 29 jank_type: STR, 30 } as const; 31 readonly trackKind = ACTUAL_FRAMES_SLICE_TRACK_KIND; 32 33 async createAggregateView( 34 engine: Engine, 35 area: AreaSelection, 36 dataset?: Dataset, 37 ) { 38 if (!dataset) return false; 39 40 await engine.query(` 41 create or replace perfetto table ${this.id} 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 (${dataset.query()}) 49 where ts + dur > ${area.start} 50 AND ts < ${area.end} 51 group by jank_type 52 `); 53 return true; 54 } 55 56 getTabName() { 57 return 'Frames'; 58 } 59 60 async getExtra() {} 61 62 getDefaultSorting(): Sorting { 63 return {column: 'occurrences', direction: 'DESC'}; 64 } 65 66 getColumnDefinitions(): ColumnDef[] { 67 return [ 68 { 69 title: 'Jank Type', 70 kind: 'STRING', 71 columnConstructor: Uint16Array, 72 columnId: 'jank_type', 73 }, 74 { 75 title: 'Min duration', 76 kind: 'NUMBER', 77 columnConstructor: Uint16Array, 78 columnId: 'minDur', 79 }, 80 { 81 title: 'Max duration', 82 kind: 'NUMBER', 83 columnConstructor: Uint16Array, 84 columnId: 'maxDur', 85 }, 86 { 87 title: 'Mean duration', 88 kind: 'NUMBER', 89 columnConstructor: Uint16Array, 90 columnId: 'meanDur', 91 }, 92 { 93 title: 'Occurrences', 94 kind: 'NUMBER', 95 columnConstructor: Uint16Array, 96 columnId: 'occurrences', 97 sum: true, 98 }, 99 ]; 100 } 101} 102