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