1fb726d48Sopenharmony_ci/*
2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License.
5fb726d48Sopenharmony_ci * You may obtain a copy of the License at
6fb726d48Sopenharmony_ci *
7fb726d48Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fb726d48Sopenharmony_ci *
9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and
13fb726d48Sopenharmony_ci * limitations under the License.
14fb726d48Sopenharmony_ci */
15fb726d48Sopenharmony_ci
16fb726d48Sopenharmony_ciimport { BaseStruct } from './BaseStruct';
17fb726d48Sopenharmony_ciimport { ColorUtils } from '../component/trace/base/ColorUtils';
18fb726d48Sopenharmony_ci
19fb726d48Sopenharmony_ciexport class ProcessMemStruct extends BaseStruct {
20fb726d48Sopenharmony_ci  static hoverProcessMemStruct: ProcessMemStruct | undefined;
21fb726d48Sopenharmony_ci  processName: string | undefined;
22fb726d48Sopenharmony_ci  pid: number | undefined;
23fb726d48Sopenharmony_ci  upid: number | undefined;
24fb726d48Sopenharmony_ci  trackName: string | undefined;
25fb726d48Sopenharmony_ci  type: string | undefined;
26fb726d48Sopenharmony_ci  track_id: string | undefined;
27fb726d48Sopenharmony_ci  value: number | undefined;
28fb726d48Sopenharmony_ci  startTime: number | undefined;
29fb726d48Sopenharmony_ci  duration: number | undefined;
30fb726d48Sopenharmony_ci  maxValue: number | undefined;
31fb726d48Sopenharmony_ci  delta: number | undefined;
32fb726d48Sopenharmony_ci
33fb726d48Sopenharmony_ci  static draw(pMemCtx: CanvasRenderingContext2D, pMemData: ProcessMemStruct): void {
34fb726d48Sopenharmony_ci    if (pMemData.frame) {
35fb726d48Sopenharmony_ci      let width = pMemData.frame.width || 0;
36fb726d48Sopenharmony_ci      if (pMemData.startTime === ProcessMemStruct.hoverProcessMemStruct?.startTime) {
37fb726d48Sopenharmony_ci        pMemCtx.lineWidth = 1;
38fb726d48Sopenharmony_ci        pMemCtx.globalAlpha = 0.6;
39fb726d48Sopenharmony_ci        let drawHeight: number = Math.floor(
40fb726d48Sopenharmony_ci          ((pMemData.value || 0) * (pMemData.frame.height || 0) * 1.0) / (pMemData.maxValue || 0)
41fb726d48Sopenharmony_ci        );
42fb726d48Sopenharmony_ci        pMemCtx.fillRect(pMemData.frame.x, pMemData.frame.y + pMemData.frame.height - drawHeight, width, drawHeight);
43fb726d48Sopenharmony_ci        pMemCtx.beginPath();
44fb726d48Sopenharmony_ci        pMemCtx.arc(pMemData.frame.x, pMemData.frame.y + pMemData.frame.height - drawHeight, 3, 0, 2 * Math.PI, true);
45fb726d48Sopenharmony_ci        pMemCtx.fill();
46fb726d48Sopenharmony_ci        pMemCtx.globalAlpha = 1.0;
47fb726d48Sopenharmony_ci        pMemCtx.stroke();
48fb726d48Sopenharmony_ci        pMemCtx.beginPath();
49fb726d48Sopenharmony_ci        pMemCtx.moveTo(pMemData.frame.x + 3, pMemData.frame.y + pMemData.frame.height - drawHeight);
50fb726d48Sopenharmony_ci        pMemCtx.lineWidth = 3;
51fb726d48Sopenharmony_ci        pMemCtx.lineTo(pMemData.frame.x + width, pMemData.frame.y + pMemData.frame.height - drawHeight);
52fb726d48Sopenharmony_ci        pMemCtx.stroke();
53fb726d48Sopenharmony_ci      } else {
54fb726d48Sopenharmony_ci        pMemCtx.fillStyle = ColorUtils.colorForTid(pMemData.maxValue || 0);
55fb726d48Sopenharmony_ci        pMemCtx.strokeStyle = ColorUtils.colorForTid(pMemData.maxValue || 0);
56fb726d48Sopenharmony_ci        pMemCtx.globalAlpha = 0.6;
57fb726d48Sopenharmony_ci        pMemCtx.lineWidth = 1;
58fb726d48Sopenharmony_ci        let drawHeight: number =
59fb726d48Sopenharmony_ci          ((pMemData.value || 0) * (pMemData.frame.height || 0) * 1.0) / (pMemData.maxValue || 1);
60fb726d48Sopenharmony_ci        pMemCtx.fillRect(pMemData.frame.x, pMemData.frame.y + pMemData.frame.height - drawHeight, width, drawHeight);
61fb726d48Sopenharmony_ci      }
62fb726d48Sopenharmony_ci    }
63fb726d48Sopenharmony_ci    pMemCtx.globalAlpha = 1.0;
64fb726d48Sopenharmony_ci    pMemCtx.lineWidth = 1;
65fb726d48Sopenharmony_ci  }
66fb726d48Sopenharmony_ci}
67