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'; 17import { PerfRender, RequestMessage, hiPerf2, drawLoadingFrame, HiPerfStruct } from '../ProcedureWorkerCommon'; 18import { TraceRow } from '../../../component/trace/base/TraceRow'; 19 20export class HiperfCpuRender2 extends PerfRender { 21 renderMainThread(req: any, row: TraceRow<HiPerfCpuStruct>): void { 22 let hiperfCpu2Filter = row.dataListCache; 23 let groupBy10MS = req.scale > 30_000_000; 24 let textMetrics; 25 if (!groupBy10MS) { 26 req.context.font = 'normal 12px Arial'; 27 textMetrics = req.context.measureText(''); 28 } 29 hiPerf2(hiperfCpu2Filter, TraceRow.range?.startNS ?? 0, TraceRow.range?.endNS ?? 0, row.frame); 30 drawLoadingFrame(req.context, hiperfCpu2Filter, row); 31 req.context.beginPath(); 32 req.context.fillStyle = ColorUtils.FUNC_COLOR[0]; 33 req.context.strokeStyle = ColorUtils.FUNC_COLOR[0]; 34 let normalPath = new Path2D(); 35 let find = false; 36 let offset = groupBy10MS ? 0 : 3; 37 for (let re of hiperfCpu2Filter) { 38 if ( 39 row.isHover && 40 re.frame && 41 row.hoverX >= re.frame.x - offset && 42 row.hoverX <= re.frame.x + re.frame.width + offset 43 ) { 44 HiPerfCpuStruct.hoverStruct = re; 45 find = true; 46 } 47 HiPerfCpuStruct.draw(req.context, normalPath, normalPath, re, groupBy10MS, textMetrics); 48 } 49 if (!find && row.isHover) HiPerfCpuStruct.hoverStruct = undefined; 50 if (groupBy10MS) { 51 req.context.fill(normalPath); 52 } else { 53 req.context.stroke(normalPath); 54 HiPerfStruct.drawSpecialPath(req.context, normalPath); 55 } 56 req.context.closePath(); 57 } 58 59 render(hiPerfCpuRequest: RequestMessage, list: Array<any>, filter: Array<any>, dataList2: Array<any>): void {} 60} 61 62export class HiPerfCpuStruct extends HiPerfStruct { 63 static hoverStruct: HiPerfCpuStruct | undefined; 64 static selectStruct: HiPerfCpuStruct | undefined; 65 66 cpu: number | undefined; 67} 68