• 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 {
17  BaseStruct,
18  dataFilterHandler,
19  isFrameContainPoint,
20  Rect,
21  Render,
22  drawString,
23} from './ProcedureWorkerCommon.js';
24import { TraceRow } from '../../component/trace/base/TraceRow.js';
25import { ColorUtils } from '../../component/trace/base/ColorUtils.js';
26
27export class IrqRender extends Render {
28  renderMainThread(
29    irqReq: {
30      context: CanvasRenderingContext2D;
31      useCache: boolean;
32      type: string;
33      index: number;
34    },
35    row: TraceRow<IrqStruct>
36  ) {
37    IrqStruct.index = irqReq.index;
38    let irqList = row.dataList;
39    let irqFilter = row.dataListCache;
40    dataFilterHandler(irqList, irqFilter, {
41      startKey: 'startNS',
42      durKey: 'dur',
43      startNS: TraceRow.range?.startNS ?? 0,
44      endNS: TraceRow.range?.endNS ?? 0,
45      totalNS: TraceRow.range?.totalNS ?? 0,
46      frame: row.frame,
47      paddingTop: 5,
48      useCache: irqReq.useCache || !(TraceRow.range?.refresh ?? false),
49    });
50    irqReq.context.beginPath();
51    let find = false;
52    for (let re of irqFilter) {
53      IrqStruct.draw(irqReq.context, re, row.isHover);
54      if (row.isHover && re.frame && isFrameContainPoint(re.frame, row.hoverX, row.hoverY)) {
55        IrqStruct.hoverIrqStruct = re;
56        find = true;
57      }
58    }
59    if (!find && row.isHover) IrqStruct.hoverIrqStruct = undefined;
60    irqReq.context.closePath();
61    irqReq.context.globalAlpha = 0.8;
62    irqReq.context.fillStyle = '#f0f0f0';
63    irqReq.context.globalAlpha = 1;
64    irqReq.context.fillStyle = '#333';
65    irqReq.context.textBaseline = 'middle';
66  }
67}
68
69const padding = 3;
70export class IrqStruct extends BaseStruct {
71  static maxValue: number = 0;
72  static maxName: string = '';
73  static hoverIrqStruct: IrqStruct | undefined;
74  static selectIrqStruct: IrqStruct | undefined;
75  static index = 0;
76  id: number | undefined;
77  startNS: number | undefined;
78  name: string | undefined;
79  dur: number | undefined; //自补充,数据库没有返回
80  textMetricsWidth: number | undefined; //自补充
81  argSetId: number | undefined;
82
83  static draw(ctx: CanvasRenderingContext2D, data: IrqStruct, isHover: boolean) {
84    if (data.frame) {
85      ctx.fillStyle = ColorUtils.colorForName(data.name || '');
86      ctx.strokeStyle = '#232c5d';
87      if ((data === IrqStruct.hoverIrqStruct && isHover) || data === IrqStruct.selectIrqStruct) {
88        ctx.lineWidth = 1;
89        ctx.globalAlpha = 0.6;
90        ctx.fillRect(data.frame.x, data.frame.y + padding, data.frame.width, data.frame.height - padding * 2);
91        ctx.lineWidth = 2;
92        ctx.strokeRect(data.frame.x, data.frame.y + padding, data.frame.width - 2, data.frame.height - padding * 2);
93      } else {
94        ctx.globalAlpha = 0.6;
95        ctx.lineWidth = 1;
96        ctx.fillRect(data.frame.x, data.frame.y + padding, data.frame.width, data.frame.height - padding * 2);
97      }
98      ctx.globalAlpha = 1.0;
99      ctx.lineWidth = 1;
100      ctx.fillStyle = '#fff';
101      ctx.textBaseline = 'middle';
102      ctx.font = '8px sans-serif';
103      data.frame.width > 7 && drawString(ctx, data.name || '', 2, data.frame, data);
104    }
105  }
106}
107