• 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 {CpuStruct} from "./CpuStruct.js";
18import {BaseStruct} from "./BaseStruct.js";
19
20const padding = 1;
21
22export class ProcessStruct extends BaseStruct {
23    cpu: number | undefined
24    dur: number | undefined
25    id: number | undefined
26    pid: number | undefined
27    process: string | undefined
28    startTime: number | undefined
29    state: string | undefined
30    thread: string | undefined
31    tid: number | undefined
32    ts: number | undefined
33    type: string | undefined
34    utid: number | undefined
35
36    static draw(ctx: CanvasRenderingContext2D, data: ProcessStruct) {
37        if (data.frame) {
38            let width = data.frame.width || 0;
39            ctx.fillStyle = ColorUtils.colorForTid(data.pid || 0)
40            let miniHeight = Math.round(data.frame.height / CpuStruct.cpuCount)
41            ctx.fillRect(data.frame.x, data.frame.y + (data.cpu || 0) * miniHeight + padding, data.frame.width, miniHeight - padding * 2)
42        }
43    }
44}