• 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  nofinish: boolean = false;
40  // distributed relation chain
41  ts: number | undefined;
42  pid: number | undefined;
43  traceId: string | undefined;
44  chainId: string | undefined;
45  chainName: string | undefined;
46  spanId: string | undefined;
47  parentSpanId: string | undefined;
48  chainFlag: string | undefined;
49  trace_level: string | undefined;
50  trace_tag: string | undefined;
51  custom_args: string | undefined;
52  category: string | undefined;
53
54  static draw(funcBeanStructCanvasCtx: CanvasRenderingContext2D, funcBeanStruct: FuncStruct): void {
55    if (funcBeanStruct.frame) {
56      if (
57        funcBeanStruct.dur === undefined ||
58        funcBeanStruct.dur === null ||
59        funcBeanStruct.dur === 0 ||
60        FuncStruct.isBinder(funcBeanStruct)
61      ) {
62      } else {
63        funcBeanStructCanvasCtx.fillStyle =
64          ColorUtils.FUNC_COLOR[funcBeanStruct.depth || 0 % ColorUtils.FUNC_COLOR.length];
65        let miniHeight = 20;
66        funcBeanStructCanvasCtx.fillRect(
67          funcBeanStruct.frame.x,
68          funcBeanStruct.frame.y,
69          funcBeanStruct.frame.width,
70          miniHeight - padding * 2
71        );
72        funcBeanStructCanvasCtx.fillStyle = '#fff';
73        drawString(funcBeanStructCanvasCtx, funcBeanStruct.funName || '', 5, funcBeanStruct.frame, funcBeanStruct);
74        if (FuncStruct.isSelected(funcBeanStruct)) {
75          funcBeanStructCanvasCtx.strokeStyle = '#000';
76          funcBeanStructCanvasCtx.lineWidth = 1;
77          funcBeanStructCanvasCtx.strokeRect(
78            funcBeanStruct.frame.x,
79            funcBeanStruct.frame.y,
80            funcBeanStruct.frame.width,
81            miniHeight - padding * 2
82          );
83        }
84      }
85    }
86  }
87
88  static isSelected(data: FuncStruct): boolean {
89    return (
90      FuncStruct.selectFuncStruct !== undefined &&
91      FuncStruct.selectFuncStruct.startTs === data.startTs &&
92      FuncStruct.selectFuncStruct.dur === data.dur &&
93      FuncStruct.selectFuncStruct.funName === data.funName
94    );
95  }
96
97  static isBinder(data: FuncStruct): boolean {
98    if (
99      data.funName &&
100      (data.funName.toLowerCase().startsWith('binder transaction') ||
101        data.funName.toLowerCase().startsWith('binder async') ||
102        data.funName.toLowerCase().startsWith('binder reply'))
103    ) {
104      return true;
105    } else {
106      return false;
107    }
108  }
109
110  static isBinderAsync(data: FuncStruct): boolean {
111    if (data.funName && data.funName.toLowerCase().includes('async')) {
112      return true;
113    } else {
114      return false;
115    }
116  }
117}
118
119const padding = 1;
120