• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2025 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 {PerfettoPlugin} from '../../public/plugin';
17import {Trace} from '../../public/trace';
18import {TrackNode} from '../../public/workspace';
19import {SourceDataset} from '../../trace_processor/dataset';
20import {LONG, NUM, STR} from '../../trace_processor/query_result';
21
22export default class implements PerfettoPlugin {
23  static readonly id = 'com.android.TrustyTeeCpuTimeline';
24
25  async onTraceLoad(ctx: Trace): Promise<void> {
26    const title = 'Trusty Tee CPU Timeline';
27
28    const uri = `com.android.TrustyTeeCpuTimeline#TrustyTeeCpuTimeline`;
29    const query = `
30      SELECT
31        sched.id AS id,
32        ts,
33        dur,
34        cpu,
35        priority,
36        name,
37        utid,
38        thread.name AS threadName,
39        cpu AS depth
40      FROM sched
41      JOIN thread
42        USING (utid)
43      WHERE threadName GLOB 'trusty-nop*'
44    `;
45
46    ctx.tracks.registerTrack({
47      uri,
48      title,
49      track: new DatasetSliceTrack({
50        trace: ctx,
51        uri,
52        dataset: new SourceDataset({
53          src: query,
54          schema: {
55            id: NUM,
56            ts: LONG,
57            dur: LONG,
58            name: STR,
59            depth: NUM,
60          },
61        }),
62        // Blank details panel - overrides details panel that assumes slices are
63        // from the slice table.
64        detailsPanel: () => {
65          return {
66            render: () => undefined,
67          };
68        },
69      }),
70    });
71
72    const trackNode = new TrackNode({uri, title, sortOrder: -100});
73    ctx.workspace.addChildInOrder(trackNode);
74  }
75}
76