• 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 { ns2x } from '../component/trace/TimerShaftElement.js';
18import { Rect } from '../component/trace/timer-shaft/Rect.js';
19
20export class HeapStruct extends BaseStruct {
21  static hoverHeapStruct: HeapStruct | undefined;
22  startTime: number | undefined;
23  endTime: number | undefined;
24  dur: number | undefined;
25  eventType: string | undefined;
26  heapsize: number | undefined;
27  density: number | undefined;
28  maxHeapSize: number = 0;
29  minHeapSize: number = 0;
30  static draw(heapBeanStructCanvasCtx: CanvasRenderingContext2D, heapBeanData: HeapStruct) {
31    if (heapBeanData.frame) {
32      let width = heapBeanData.frame.width || 0;
33      heapBeanStructCanvasCtx.fillStyle = '#2db3aa';
34      heapBeanStructCanvasCtx.strokeStyle = '#2db3aa';
35      if (heapBeanData.startTime === HeapStruct.hoverHeapStruct?.startTime) {
36        heapBeanStructCanvasCtx.lineWidth = 1;
37        heapBeanStructCanvasCtx.globalAlpha = 0.6;
38        let drawHeight: number = Math.ceil(((heapBeanData.heapsize || 0) * (heapBeanData.frame.height || 0)) / heapBeanData.maxHeapSize);
39        heapBeanStructCanvasCtx.fillRect(heapBeanData.frame.x, heapBeanData.frame.y + heapBeanData.frame.height - drawHeight, width, drawHeight);
40        heapBeanStructCanvasCtx.beginPath();
41        heapBeanStructCanvasCtx.arc(heapBeanData.frame.x, heapBeanData.frame.y + heapBeanData.frame.height - drawHeight, 3, 0, 2 * Math.PI, true);
42        heapBeanStructCanvasCtx.fill();
43        heapBeanStructCanvasCtx.globalAlpha = 1.0;
44        heapBeanStructCanvasCtx.stroke();
45        heapBeanStructCanvasCtx.beginPath();
46        heapBeanStructCanvasCtx.moveTo(heapBeanData.frame.x + 3, heapBeanData.frame.y + heapBeanData.frame.height - drawHeight);
47        heapBeanStructCanvasCtx.lineWidth = 3;
48        heapBeanStructCanvasCtx.lineTo(heapBeanData.frame.x + width, heapBeanData.frame.y + heapBeanData.frame.height - drawHeight);
49        heapBeanStructCanvasCtx.stroke();
50      } else {
51        heapBeanStructCanvasCtx.globalAlpha = 0.6;
52        heapBeanStructCanvasCtx.lineWidth = 1;
53        let drawHeight: number = Math.ceil(((heapBeanData.heapsize || 0) * (heapBeanData.frame.height || 0)) / heapBeanData.maxHeapSize);
54        heapBeanStructCanvasCtx.fillRect(heapBeanData.frame.x, heapBeanData.frame.y + heapBeanData.frame.height - drawHeight, width, drawHeight);
55      }
56    }
57    heapBeanStructCanvasCtx.globalAlpha = 1.0;
58    heapBeanStructCanvasCtx.lineWidth = 1;
59  }
60}
61