1// Copyright (C) 2023 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 {DatasetSliceTrack} from '../../components/tracks/dataset_slice_track'; 16import {JANK_COLOR} from './jank_colors'; 17import {getColorForSlice} from '../../components/colorizer'; 18import {ScrollJankV3DetailsPanel} from './scroll_jank_v3_details_panel'; 19import {SourceDataset} from '../../trace_processor/dataset'; 20import {LONG, NUM, STR} from '../../trace_processor/query_result'; 21import {Trace} from '../../public/trace'; 22 23const UNKNOWN_SLICE_NAME = 'Unknown'; 24const JANK_SLICE_NAME = ' Jank'; 25 26export function createScrollJankV3Track(trace: Trace, uri: string) { 27 return new DatasetSliceTrack({ 28 trace, 29 uri, 30 dataset: new SourceDataset({ 31 schema: { 32 id: NUM, 33 ts: LONG, 34 dur: LONG, 35 name: STR, 36 }, 37 src: ` 38 SELECT 39 IIF( 40 cause_of_jank IS NOT NULL, 41 cause_of_jank || IIF( 42 sub_cause_of_jank IS NOT NULL, "::" || sub_cause_of_jank, "" 43 ), "${UNKNOWN_SLICE_NAME}") || "${JANK_SLICE_NAME}" AS name, 44 id, 45 ts, 46 dur, 47 event_latency_id 48 FROM chrome_janky_frame_presentation_intervals 49 `, 50 }), 51 colorizer: (row) => { 52 let stage = row.name.substring(0, row.name.indexOf(JANK_SLICE_NAME)); 53 // Stage may include substage, in which case we use the substage for 54 // color selection. 55 const separator = '::'; 56 if (stage.indexOf(separator) != -1) { 57 stage = stage.substring(stage.indexOf(separator) + separator.length); 58 } 59 60 if (stage == UNKNOWN_SLICE_NAME) { 61 return JANK_COLOR; 62 } else { 63 return getColorForSlice(stage); 64 } 65 }, 66 detailsPanel: (row) => new ScrollJankV3DetailsPanel(trace, row.id), 67 }); 68} 69