• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
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 */
15
16import { BaseStruct } from './BaseStruct';
17import { Rect } from '../component/trace/timer-shaft/Rect';
18import { ColorUtils } from '../component/trace/base/ColorUtils';
19import { drawString } from '../database/ui-worker/ProcedureWorkerCommon';
20
21export class FuncStruct extends BaseStruct {
22  static hoverFuncStruct: FuncStruct | undefined;
23  static selectFuncStruct: FuncStruct | undefined;
24  argsetid: number | undefined;
25  depth: number | undefined;
26  dur: number | undefined;
27  funName: string | undefined;
28  id: number | undefined;
29  callid: number | undefined;
30  is_main_thread: number | undefined;
31  parent_id: number | undefined;
32  startTs: number | undefined;
33  threadName: string | undefined;
34  tid: number | undefined;
35  itid: number | undefined;
36  ipid: number | undefined;
37  identify: number | undefined;
38  track_id: number | undefined;
39
40  static draw(funcBeanStructCanvasCtx: CanvasRenderingContext2D, funcBeanStruct: FuncStruct) {
41    if (funcBeanStruct.frame) {
42      if (
43        funcBeanStruct.dur == undefined ||
44        funcBeanStruct.dur == null ||
45        funcBeanStruct.dur == 0 ||
46        FuncStruct.isBinder(funcBeanStruct)
47      ) {
48      } else {
49        funcBeanStructCanvasCtx.fillStyle =
50          ColorUtils.FUNC_COLOR[funcBeanStruct.depth || 0 % ColorUtils.FUNC_COLOR.length];
51        let miniHeight = 20;
52        funcBeanStructCanvasCtx.fillRect(
53          funcBeanStruct.frame.x,
54          funcBeanStruct.frame.y,
55          funcBeanStruct.frame.width,
56          miniHeight - padding * 2
57        );
58        funcBeanStructCanvasCtx.fillStyle = '#fff';
59        drawString(funcBeanStructCanvasCtx, funcBeanStruct.funName || '', 5, funcBeanStruct.frame, funcBeanStruct);
60        if (FuncStruct.isSelected(funcBeanStruct)) {
61          funcBeanStructCanvasCtx.strokeStyle = '#000';
62          funcBeanStructCanvasCtx.lineWidth = 1;
63          funcBeanStructCanvasCtx.strokeRect(
64            funcBeanStruct.frame.x,
65            funcBeanStruct.frame.y,
66            funcBeanStruct.frame.width,
67            miniHeight - padding * 2
68          );
69        }
70      }
71    }
72  }
73
74  static isSelected(data: FuncStruct): boolean {
75    return (
76      FuncStruct.selectFuncStruct != undefined &&
77      FuncStruct.selectFuncStruct.startTs == data.startTs &&
78      FuncStruct.selectFuncStruct.dur == data.dur &&
79      FuncStruct.selectFuncStruct.funName == data.funName
80    );
81  }
82
83  static isBinder(data: FuncStruct): boolean {
84    if (
85      data.funName != null &&
86      (data.funName.toLowerCase().startsWith('binder transaction') ||
87        data.funName.toLowerCase().startsWith('binder async') ||
88        data.funName.toLowerCase().startsWith('binder reply'))
89    ) {
90      return true;
91    } else {
92      return false;
93    }
94  }
95
96  static isBinderAsync(data: FuncStruct): boolean {
97    if (data.funName != null && data.funName.toLowerCase().includes('async')) {
98      return true;
99    } else {
100      return false;
101    }
102  }
103}
104
105const padding = 1;
106