• 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.js';
17import { Rect } from '../component/trace/timer-shaft/Rect.js';
18import { ColorUtils } from '../component/trace/base/ColorUtils.js';
19import { drawString } from '../database/ui-worker/ProcedureWorkerCommon.js';
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  is_main_thread: number | undefined;
30  parent_id: number | undefined;
31  startTs: number | undefined;
32  threadName: string | undefined;
33  tid: number | undefined;
34  itid: number | undefined;
35  ipid: number | undefined;
36  identify: number | undefined;
37  track_id: number | undefined;
38
39  static draw(funcBeanStructCanvasCtx: CanvasRenderingContext2D, funcBeanStruct: FuncStruct) {
40    if (funcBeanStruct.frame) {
41      if (funcBeanStruct.dur == undefined || funcBeanStruct.dur == null || funcBeanStruct.dur == 0 || FuncStruct.isBinder(funcBeanStruct)) {
42      } else {
43        funcBeanStructCanvasCtx.fillStyle = ColorUtils.FUNC_COLOR[funcBeanStruct.depth || 0 % ColorUtils.FUNC_COLOR.length];
44        let miniHeight = 20;
45        funcBeanStructCanvasCtx.fillRect(funcBeanStruct.frame.x, funcBeanStruct.frame.y, funcBeanStruct.frame.width, miniHeight - padding * 2);
46        funcBeanStructCanvasCtx.fillStyle = '#fff';
47        drawString(funcBeanStructCanvasCtx, funcBeanStruct.funName || '', 5, funcBeanStruct.frame, funcBeanStruct);
48        if (FuncStruct.isSelected(funcBeanStruct)) {
49          funcBeanStructCanvasCtx.strokeStyle = '#000';
50          funcBeanStructCanvasCtx.lineWidth = 1;
51          funcBeanStructCanvasCtx.strokeRect(funcBeanStruct.frame.x, funcBeanStruct.frame.y, funcBeanStruct.frame.width, miniHeight - padding * 2);
52        }
53      }
54    }
55  }
56
57  static isSelected(data: FuncStruct): boolean {
58    return (
59      FuncStruct.selectFuncStruct != undefined &&
60      FuncStruct.selectFuncStruct.startTs == data.startTs &&
61      FuncStruct.selectFuncStruct.dur == data.dur &&
62      FuncStruct.selectFuncStruct.funName == data.funName
63    );
64  }
65
66  static isBinder(data: FuncStruct): boolean {
67    if (
68      data.funName != null &&
69      (data.funName.toLowerCase().startsWith('binder transaction') ||
70        data.funName.toLowerCase().startsWith('binder async') ||
71        data.funName.toLowerCase().startsWith('binder reply'))
72    ) {
73      return true;
74    } else {
75      return false;
76    }
77  }
78
79  static isBinderAsync(data: FuncStruct): boolean {
80    if (data.funName != null && data.funName.toLowerCase().includes('async')) {
81      return true;
82    } else {
83      return false;
84    }
85  }
86}
87
88const padding = 1;
89