xref: /aosp_15_r20/external/perfetto/ui/src/components/details/process_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 {Upid} 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 ProcessDetailsTab implements Tab {
26  private data: Details;
27
28  // TODO(altimin): Ideally, we would not require the pid to be passed in, but
29  // fetch it from the underlying data instead.
30  //
31  // However, the only place which creates `ProcessDetailsTab` currently is `renderProcessRef`,
32  // which already has `pid` available (note that Details is already fetching the data, including
33  // the `pid` from the trace processor, but it doesn't expose it for now).
34  constructor(private args: {trace: Trace; upid: Upid; pid?: number}) {
35    this.data = new Details(args.trace, 'process', args.upid, {
36      'pid': d.Value('pid'),
37      'Name': d.Value('name'),
38      'Start time': d.Timestamp('start_ts', {skipIfNull: true}),
39      'End time': d.Timestamp('end_ts', {skipIfNull: true}),
40      'Parent process': d.SqlIdRef('process', 'parent_upid', {
41        skipIfNull: true,
42      }),
43      'User ID': d.Value('uid', {skipIfNull: true}),
44      'Android app ID': d.Value('android_appid', {skipIfNull: true}),
45      'Command line': d.Value('cmdline', {skipIfNull: true}),
46      'Machine id': d.Value('machine_id', {skipIfNull: true}),
47      'Args': d.ArgSetId('arg_set_id'),
48    });
49  }
50
51  render() {
52    return m(
53      DetailsShell,
54      {
55        title: this.getTitle(),
56      },
57      m(
58        GridLayout,
59        m(GridLayoutColumn, m(Section, {title: 'Details'}, this.data.render())),
60      ),
61    );
62  }
63
64  getTitle(): string {
65    if (this.args.pid !== undefined) {
66      return `Process ${this.args.pid}`;
67    }
68    return `Process upid:${this.args.upid}`;
69  }
70}
71