xref: /aosp_15_r20/external/perfetto/ui/src/components/details/thread_details_tab.ts (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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 m from 'mithril';
16import {Tab} from '../../public/tab';
17import {Utid} from '../sql_utils/core_types';
18import {DetailsShell} from '../../widgets/details_shell';
19import {GridLayout, GridLayoutColumn} from '../../widgets/grid_layout';
20import {Section} from '../../widgets/section';
21import {Details, DetailsSchema} from '../widgets/sql/details/details';
22import d = DetailsSchema;
23import {Trace} from '../../public/trace';
24
25export class ThreadDetailsTab implements Tab {
26  private data: Details;
27
28  // TODO(altimin): Ideally, we would not require the tid to be passed in, but
29  // fetch it from the underlying data instead. See comment in ProcessDetailsTab
30  // for more details.
31  constructor(private args: {trace: Trace; utid: Utid; tid?: number}) {
32    this.data = new Details(args.trace, 'thread', args.utid, {
33      'tid': d.Value('tid'),
34      'Name': d.Value('name'),
35      'Process': d.SqlIdRef('process', 'upid'),
36      'Is main thread': d.Boolean('is_main_thread'),
37      'Start time': d.Timestamp('start_ts', {skipIfNull: true}),
38      'End time': d.Timestamp('end_ts', {skipIfNull: true}),
39      'Machine id': d.Value('machine_id', {skipIfNull: true}),
40    });
41  }
42
43  render() {
44    return m(
45      DetailsShell,
46      {
47        title: this.getTitle(),
48      },
49      m(
50        GridLayout,
51        m(GridLayoutColumn, m(Section, {title: 'Details'}, this.data.render())),
52      ),
53    );
54  }
55
56  getTitle(): string {
57    if (this.args.tid !== undefined) {
58      return `Thread ${this.args.tid}`;
59    }
60    return `Thread utid:${this.args.utid}`;
61  }
62}
63