xref: /aosp_15_r20/external/perfetto/ui/src/plugins/org.chromium.ChromeScrollJank/event_latency_track.ts (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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 {NamedRow} from '../../components/tracks/named_slice_track';
16import {Slice} from '../../public/track';
17import {
18  CustomSqlTableDefConfig,
19  CustomSqlTableSliceTrack,
20} from '../../components/tracks/custom_sql_table_slice_track';
21import {JANK_COLOR} from './jank_colors';
22import {TrackEventSelection} from '../../public/selection';
23import {EventLatencySliceDetailsPanel} from './event_latency_details_panel';
24import {Trace} from '../../public/trace';
25
26export const JANKY_LATENCY_NAME = 'Janky EventLatency';
27
28export class EventLatencyTrack extends CustomSqlTableSliceTrack {
29  constructor(
30    trace: Trace,
31    uri: string,
32    private baseTable: string,
33  ) {
34    super(trace, uri);
35  }
36
37  getSqlSource(): string {
38    return `SELECT * FROM ${this.baseTable}`;
39  }
40
41  getSqlDataSource(): CustomSqlTableDefConfig {
42    return {
43      sqlTableName: this.baseTable,
44    };
45  }
46
47  rowToSlice(row: NamedRow): Slice {
48    const baseSlice = super.rowToSlice(row);
49    if (baseSlice.title === JANKY_LATENCY_NAME) {
50      return {...baseSlice, colorScheme: JANK_COLOR};
51    } else {
52      return baseSlice;
53    }
54  }
55
56  override detailsPanel(sel: TrackEventSelection) {
57    return new EventLatencySliceDetailsPanel(this.trace, sel.eventId);
58  }
59}
60