• 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 {ColorUtils} from "../component/trace/base/ColorUtils.js";
18
19export class ProcessMemStruct extends BaseStruct {
20    static hoverProcessMemStruct: ProcessMemStruct | undefined;
21    trackId: number | undefined
22    processName: string | undefined
23    pid: number | undefined
24    upid: number | undefined
25    trackName: string | undefined
26    type: string | undefined
27    track_id: string | undefined
28    value: number | undefined
29    startTime: number | undefined
30    duration: number | undefined
31    maxValue: number | undefined
32    delta: number | undefined;
33
34    static draw(ctx: CanvasRenderingContext2D, data: ProcessMemStruct) {
35        if (data.frame) {
36            let width = data.frame.width || 0;
37            if (data.startTime === ProcessMemStruct.hoverProcessMemStruct?.startTime) {
38                ctx.lineWidth = 1;
39                ctx.globalAlpha = 0.6;
40                let drawHeight: number = Math.floor(((data.value || 0) * (data.frame.height || 0) * 1.0) / (data.maxValue || 0));
41                ctx.fillRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight)
42                ctx.beginPath()
43                ctx.arc(data.frame.x, data.frame.y + data.frame.height - drawHeight, 3, 0, 2 * Math.PI, true)
44                ctx.fill()
45                ctx.globalAlpha = 1.0;
46                ctx.stroke();
47                ctx.beginPath()
48                ctx.moveTo(data.frame.x + 3, data.frame.y + data.frame.height - drawHeight);
49                ctx.lineWidth = 3;
50                ctx.lineTo(data.frame.x + width, data.frame.y + data.frame.height - drawHeight)
51                ctx.stroke();
52            } else {
53                ctx.fillStyle = ColorUtils.colorForTid(data.maxValue || 0)
54                ctx.strokeStyle = ColorUtils.colorForTid(data.maxValue || 0)
55                ctx.globalAlpha = 0.6;
56                ctx.lineWidth = 1;
57                let drawHeight: number = ((data.value || 0) * (data.frame.height || 0) * 1.0) / (data.maxValue || 1);
58                ctx.fillRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight)
59            }
60        }
61        ctx.globalAlpha = 1.0;
62        ctx.lineWidth = 1;
63    }
64}