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