• 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  minValue: number | undefined;
32  delta: number | undefined;
33
34  static draw(pMemCtx: CanvasRenderingContext2D, pMemData: ProcessMemStruct): void {
35    if (pMemData.frame) {
36      let width = pMemData.frame.width || 0;
37      if (pMemData.startTime === ProcessMemStruct.hoverProcessMemStruct?.startTime) {
38        pMemCtx.lineWidth = 1;
39        pMemCtx.globalAlpha = 0.6;
40        let drawHeight: number = Math.floor(
41          ((pMemData.value || 0) * (pMemData.frame.height || 0) * 1.0) / (pMemData.maxValue || 0)
42        );
43        pMemCtx.fillRect(pMemData.frame.x, pMemData.frame.y + pMemData.frame.height - drawHeight, width, drawHeight);
44        pMemCtx.beginPath();
45        pMemCtx.arc(pMemData.frame.x, pMemData.frame.y + pMemData.frame.height - drawHeight, 3, 0, 2 * Math.PI, true);
46        pMemCtx.fill();
47        pMemCtx.globalAlpha = 1.0;
48        pMemCtx.stroke();
49        pMemCtx.beginPath();
50        pMemCtx.moveTo(pMemData.frame.x + 3, pMemData.frame.y + pMemData.frame.height - drawHeight);
51        pMemCtx.lineWidth = 3;
52        pMemCtx.lineTo(pMemData.frame.x + width, pMemData.frame.y + pMemData.frame.height - drawHeight);
53        pMemCtx.stroke();
54      } else {
55        pMemCtx.fillStyle = ColorUtils.colorForTid(pMemData.maxValue || 0);
56        pMemCtx.strokeStyle = ColorUtils.colorForTid(pMemData.maxValue || 0);
57        pMemCtx.globalAlpha = 0.6;
58        pMemCtx.lineWidth = 1;
59        let drawHeight: number =
60          ((pMemData.value || 0) * (pMemData.frame.height || 0) * 1.0) / (pMemData.maxValue || 1);
61        pMemCtx.fillRect(pMemData.frame.x, pMemData.frame.y + pMemData.frame.height - drawHeight, width, drawHeight);
62      }
63    }
64    pMemCtx.globalAlpha = 1.0;
65    pMemCtx.lineWidth = 1;
66  }
67}
68