• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2024 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 {LONG, NUM, STR} from '../../trace_processor/query_result';
16import {DatasetSliceTrack} from '../../components/tracks/dataset_slice_track';
17import {PageLoadDetailsPanel} from './page_load_details_panel';
18import {StartupDetailsPanel} from './startup_details_panel';
19import {WebContentInteractionPanel} from './web_content_interaction_details_panel';
20import {GenericSliceDetailsTab} from './generic_slice_details_tab';
21import {SourceDataset} from '../../trace_processor/dataset';
22import {Trace} from '../../public/trace';
23
24export function createCriticalUserInteractionTrack(trace: Trace, uri: string) {
25  return new DatasetSliceTrack({
26    trace,
27    uri,
28    dataset: new SourceDataset({
29      schema: {
30        id: NUM,
31        ts: LONG,
32        dur: LONG,
33        name: STR,
34        scopedId: NUM,
35        type: STR,
36      },
37      // The scoped_id is not a unique identifier within the table; generate
38      // a unique id from type and scoped_id on the fly to use for slice
39      // selection.
40      src: `
41          SELECT
42            hash(type, scoped_id) AS id,
43            scoped_id AS scopedId,
44            name,
45            ts,
46            dur,
47            type
48          FROM chrome_interactions
49        `,
50    }),
51    detailsPanel: (row) => {
52      switch (row.type) {
53        case 'chrome_page_loads':
54          return new PageLoadDetailsPanel(trace, row.id);
55        case 'chrome_startups':
56          return new StartupDetailsPanel(trace, row.id);
57        case 'chrome_web_content_interactions':
58          return new WebContentInteractionPanel(trace, row.id);
59        default:
60          return new GenericSliceDetailsTab(
61            trace,
62            'chrome_interactions',
63            row.id,
64            'Chrome Interaction',
65          );
66      }
67    },
68  });
69}
70