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