• 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 { ColorUtils } from "../component/trace/base/ColorUtils.js";
17import {BaseStruct} from "./BaseStruct.js";
18
19export class MemoryAbilityMonitorStruct extends BaseStruct {
20    static maxMemoryByte: number = 0
21    static maxMemoryByteName: string = "0 MB"
22    static hoverMemoryAbilityStruct: MemoryAbilityMonitorStruct | undefined;
23    static selectMemoryAbilityStruct: MemoryAbilityMonitorStruct | undefined;
24    cpu: number | undefined
25    value: number | undefined
26    startNS: number | undefined
27    dur: number | undefined
28
29    static draw(context2D: any, data: MemoryAbilityMonitorStruct) {
30        if (data.frame) {
31            let width = data.frame.width || 0;
32            let index = data.cpu || 0
33            index += 2
34            context2D.fillStyle = ColorUtils.colorForTid(index)
35            context2D.strokeStyle = ColorUtils.colorForTid(index)
36            if (data.startNS === MemoryAbilityMonitorStruct.hoverMemoryAbilityStruct?.startNS) {
37                context2D.lineWidth = 1;
38                context2D.globalAlpha = 0.6;
39                let drawHeight: number = Math.floor(((data.value || 0) * (data.frame.height || 0) * 1.0) / MemoryAbilityMonitorStruct.maxMemoryByte);
40                context2D.fillRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight)
41                context2D.beginPath()
42                context2D.arc(data.frame.x, data.frame.y + data.frame.height - drawHeight, 3, 0, 2 * Math.PI, true)
43                context2D.fill()
44                context2D.globalAlpha = 1.0;
45                context2D.stroke();
46                context2D.beginPath()
47                context2D.moveTo(data.frame.x + 3, data.frame.y + data.frame.height - drawHeight);
48                context2D.lineWidth = 3;
49                context2D.lineTo(data.frame.x + width, data.frame.y + data.frame.height - drawHeight)
50                context2D.stroke();
51            } else {
52                context2D.globalAlpha = 0.6;
53                context2D.lineWidth = 1;
54                let drawHeight: number = Math.floor(((data.value || 0) * (data.frame.height || 0)) / MemoryAbilityMonitorStruct.maxMemoryByte);
55                context2D.fillRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight)
56            }
57        }
58        context2D.globalAlpha = 1.0;
59        context2D.lineWidth = 1;
60    }
61}
62