1// Copyright (C) 2019 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use size 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 * as m from 'mithril';
16
17import {translateState} from '../common/thread_state';
18import {timeToCode} from '../common/time';
19
20import {globals} from './globals';
21import {Panel, PanelSize} from './panel';
22
23interface ThreadStateDetailsAttr {
24  utid: number;
25  ts: number;
26  dur: number;
27  state: string;
28}
29
30export class ThreadStatePanel extends Panel<ThreadStateDetailsAttr> {
31  view({attrs}: m.CVnode<ThreadStateDetailsAttr>) {
32    const threadInfo = globals.threads.get(attrs.utid);
33    if (threadInfo) {
34      return m(
35          '.details-panel',
36          m('.details-panel-heading', 'Thread State'),
37          m('.details-table', [m('table', [
38              m('tr',
39                m('th', `Start time`),
40                m('td',
41                  `${
42                     timeToCode(attrs.ts - globals.state.traceTime.startSec)
43                   }`)),
44              m('tr', m('th', `Duration`), m('td', `${timeToCode(attrs.dur)}`)),
45              m('tr',
46                m('th', `State`),
47                m('td', `${translateState(attrs.state)}`)),
48              m('tr',
49                m('th', `Process`),
50                m('td', `${threadInfo.procName} [${threadInfo.pid}]`)),
51            ])]));
52    } else {
53      return m('.details-panel');
54    }
55  }
56
57  renderCanvas(_ctx: CanvasRenderingContext2D, _size: PanelSize) {}
58}
59