xref: /aosp_15_r20/external/perfetto/ui/src/plugins/dev.perfetto.Frames/expected_frames_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 {HSLColor} from '../../public/color';
16import {makeColorScheme} from '../../components/colorizer';
17import {
18  NAMED_ROW,
19  NamedRow,
20  NamedSliceTrack,
21} from '../../components/tracks/named_slice_track';
22import {SLICE_LAYOUT_FIT_CONTENT_DEFAULTS} from '../../components/tracks/slice_layout';
23import {Slice} from '../../public/track';
24import {Trace} from '../../public/trace';
25import {TrackEventDetails} from '../../public/selection';
26
27const GREEN = makeColorScheme(new HSLColor('#4CAF50')); // Green 500
28
29export class ExpectedFramesTrack extends NamedSliceTrack {
30  constructor(
31    trace: Trace,
32    maxDepth: number,
33    uri: string,
34    private trackIds: number[],
35  ) {
36    super(trace, uri);
37    this.sliceLayout = {
38      ...SLICE_LAYOUT_FIT_CONTENT_DEFAULTS,
39      depthGuess: maxDepth,
40    };
41  }
42
43  getSqlSource(): string {
44    return `
45      SELECT
46        ts,
47        dur,
48        layout_depth as depth,
49        name,
50        id
51      from experimental_slice_layout
52      where
53        filter_track_ids = '${this.trackIds.join(',')}'
54    `;
55  }
56
57  rowToSlice(row: NamedRow): Slice {
58    const baseSlice = this.rowToSliceBase(row);
59    return {...baseSlice, colorScheme: GREEN};
60  }
61
62  getRowSpec(): NamedRow {
63    return NAMED_ROW;
64  }
65
66  override async getSelectionDetails(
67    id: number,
68  ): Promise<TrackEventDetails | undefined> {
69    const baseDetails = await super.getSelectionDetails(id);
70    if (!baseDetails) return undefined;
71    return {
72      ...baseDetails,
73      tableName: 'slice',
74    };
75  }
76}
77