• 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, dataFilterHandler, drawLoadingFrame, isFrameContainPoint, Render } from './ProcedureWorkerCommon';
17import { TraceRow } from '../../component/trace/base/TraceRow';
18import { ColorUtils } from '../../component/trace/base/ColorUtils';
19import {SpSystemTrace} from "../../component/SpSystemTrace";
20
21export class ClockRender extends Render {
22  renderMainThread(
23    clockReq: {
24      context: CanvasRenderingContext2D;
25      useCache: boolean;
26      type: string;
27      maxValue: number;
28      index: number;
29      maxName: string;
30    },
31    row: TraceRow<ClockStruct>
32  ) {
33    ClockStruct.index = clockReq.index;
34    let clockList = row.dataList;
35    let clockFilter = row.dataListCache;
36    dataFilterHandler(clockList, clockFilter, {
37      startKey: 'startNS',
38      durKey: 'dur',
39      startNS: TraceRow.range?.startNS ?? 0,
40      endNS: TraceRow.range?.endNS ?? 0,
41      totalNS: TraceRow.range?.totalNS ?? 0,
42      frame: row.frame,
43      paddingTop: 5,
44      useCache: clockReq.useCache || !(TraceRow.range?.refresh ?? false),
45    });
46    drawLoadingFrame(clockReq.context, clockFilter, row);
47    clockReq.context.beginPath();
48    let find = false;
49    for (let re of clockFilter) {
50      ClockStruct.draw(clockReq.context, re, clockReq.maxValue);
51      if (row.isHover && re.frame && isFrameContainPoint(re.frame, row.hoverX, row.hoverY)) {
52        ClockStruct.hoverClockStruct = re;
53        find = true;
54      }
55    }
56    if (!find && row.isHover) ClockStruct.hoverClockStruct = undefined;
57    clockReq.context.closePath();
58    let s = clockReq.maxName;
59    let textMetrics = clockReq.context.measureText(s);
60    clockReq.context.globalAlpha = 0.8;
61    clockReq.context.fillStyle = '#f0f0f0';
62    clockReq.context.fillRect(0, 5, textMetrics.width + 8, 18);
63    clockReq.context.globalAlpha = 1;
64    clockReq.context.fillStyle = '#333';
65    clockReq.context.textBaseline = 'middle';
66    clockReq.context.fillText(s, 4, 5 + 9);
67  }
68}
69export function ClockStructOnClick(clickRowType: string, sp: SpSystemTrace) {
70  return new Promise((resolve, reject) => {
71    if (clickRowType === TraceRow.ROW_TYPE_CLOCK && ClockStruct.hoverClockStruct) {
72      ClockStruct.selectClockStruct = ClockStruct.hoverClockStruct;
73      sp.traceSheetEL?.displayClockData(ClockStruct.selectClockStruct);
74      sp.timerShaftEL?.modifyFlagList(undefined);
75      reject();
76    }else{
77      resolve(null);
78    }
79  });
80
81}
82export class ClockStruct extends BaseStruct {
83  static maxValue: number = 0;
84  static maxName: string = '';
85  static hoverClockStruct: ClockStruct | undefined;
86  static selectClockStruct: ClockStruct | undefined;
87  static index = 0;
88  filterId: number | undefined;
89  value: number | undefined;
90  startNS: number | undefined;
91  dur: number | undefined; //自补充,数据库没有返回
92  delta: number | undefined; //自补充,数据库没有返回
93
94  static draw(clockContext: CanvasRenderingContext2D, data: ClockStruct, maxValue: number) {
95    if (data.frame) {
96      let width = data.frame.width || 0;
97      clockContext.fillStyle = ColorUtils.colorForTid(ClockStruct.index);
98      clockContext.strokeStyle = ColorUtils.colorForTid(ClockStruct.index);
99      let drawHeight: number = Math.floor(((data.value || 0) * (data.frame.height || 0) * 1.0) / maxValue);
100      if (drawHeight === 0) {
101        drawHeight = 1;
102      }
103      if (ClockStruct.isHover(data)) {
104        clockContext.lineWidth = 1;
105        clockContext.globalAlpha = 0.6;
106        clockContext.fillRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight);
107        clockContext.beginPath();
108        clockContext.arc(data.frame.x, data.frame.y + data.frame.height - drawHeight, 3, 0, 2 * Math.PI, true);
109        clockContext.fill();
110        clockContext.globalAlpha = 1.0;
111        clockContext.stroke();
112        clockContext.beginPath();
113        clockContext.moveTo(data.frame.x + 3, data.frame.y + data.frame.height - drawHeight);
114        clockContext.lineWidth = 3;
115        clockContext.lineTo(data.frame.x + width, data.frame.y + data.frame.height - drawHeight);
116        clockContext.stroke();
117      } else {
118        clockContext.lineWidth = 1;
119        clockContext.globalAlpha = 1.0;
120        clockContext.strokeRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight);
121        clockContext.globalAlpha = 0.6;
122        clockContext.fillRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight);
123      }
124    }
125    clockContext.globalAlpha = 1.0;
126    clockContext.lineWidth = 1;
127  }
128
129  static isHover(clock: ClockStruct) {
130    return clock === ClockStruct.hoverClockStruct || clock === ClockStruct.selectClockStruct;
131  }
132}
133