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