• 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 { ns2x } from '../component/trace/TimerShaftElement';
18import { Rect } from '../component/trace/timer-shaft/Rect';
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(
39          ((heapBeanData.heapsize || 0) * (heapBeanData.frame.height || 0)) / heapBeanData.maxHeapSize
40        );
41        heapBeanStructCanvasCtx.fillRect(
42          heapBeanData.frame.x,
43          heapBeanData.frame.y + heapBeanData.frame.height - drawHeight,
44          width,
45          drawHeight
46        );
47        heapBeanStructCanvasCtx.beginPath();
48        heapBeanStructCanvasCtx.arc(
49          heapBeanData.frame.x,
50          heapBeanData.frame.y + heapBeanData.frame.height - drawHeight,
51          3,
52          0,
53          2 * Math.PI,
54          true
55        );
56        heapBeanStructCanvasCtx.fill();
57        heapBeanStructCanvasCtx.globalAlpha = 1.0;
58        heapBeanStructCanvasCtx.stroke();
59        heapBeanStructCanvasCtx.beginPath();
60        heapBeanStructCanvasCtx.moveTo(
61          heapBeanData.frame.x + 3,
62          heapBeanData.frame.y + heapBeanData.frame.height - drawHeight
63        );
64        heapBeanStructCanvasCtx.lineWidth = 3;
65        heapBeanStructCanvasCtx.lineTo(
66          heapBeanData.frame.x + width,
67          heapBeanData.frame.y + heapBeanData.frame.height - drawHeight
68        );
69        heapBeanStructCanvasCtx.stroke();
70      } else {
71        heapBeanStructCanvasCtx.globalAlpha = 0.6;
72        heapBeanStructCanvasCtx.lineWidth = 1;
73        let drawHeight: number = Math.ceil(
74          ((heapBeanData.heapsize || 0) * (heapBeanData.frame.height || 0)) / heapBeanData.maxHeapSize
75        );
76        heapBeanStructCanvasCtx.fillRect(
77          heapBeanData.frame.x,
78          heapBeanData.frame.y + heapBeanData.frame.height - drawHeight,
79          width,
80          drawHeight
81        );
82      }
83    }
84    heapBeanStructCanvasCtx.globalAlpha = 1.0;
85    heapBeanStructCanvasCtx.lineWidth = 1;
86  }
87}
88