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 { 18 BaseStruct, 19 drawFlagLine, 20 drawLines, 21 drawLoading, 22 drawSelection, 23 HiPerfStruct, 24 hiPerf, 25 PerfRender, 26 RequestMessage, 27} from './ProcedureWorkerCommon.js'; 28import { TraceRow } from '../../component/trace/base/TraceRow.js'; 29import { HiPerfThreadStruct } from './ProcedureWorkerHiPerfThread.js'; 30 31export class HiperfCpuRender extends PerfRender { 32 renderMainThread(req: any, row: TraceRow<HiPerfCpuStruct>) { 33 let list = row.dataList; 34 let filter = row.dataListCache; 35 let groupBy10MS = req.scale > 30_000_000; 36 if (list && row.dataList2.length == 0) { 37 row.dataList2 = HiPerfCpuStruct.groupBy10MS(list, req.intervalPerf, req.maxCpu); 38 } 39 hiPerf( 40 list, 41 row.dataList2, 42 filter, 43 TraceRow.range?.startNS ?? 0, 44 TraceRow.range?.endNS ?? 0, 45 row.frame, 46 groupBy10MS, 47 req.useCache || (TraceRow.range?.refresh ?? false) 48 ); 49 req.context.beginPath(); 50 req.context.fillStyle = ColorUtils.FUNC_COLOR[0]; 51 req.context.strokeStyle = ColorUtils.FUNC_COLOR[0]; 52 let normalPath = new Path2D(); 53 let specPath = new Path2D(); 54 let find = false; 55 let offset = groupBy10MS ? 0 : 3; 56 for (let re of filter) { 57 if ( 58 row.isHover && 59 re.frame && 60 row.hoverX >= re.frame.x - offset && 61 row.hoverX <= re.frame.x + re.frame.width + offset 62 ) { 63 HiPerfCpuStruct.hoverStruct = re; 64 find = true; 65 } 66 HiPerfCpuStruct.draw(req.context, normalPath, specPath, re, groupBy10MS); 67 } 68 if (!find && row.isHover) HiPerfCpuStruct.hoverStruct = undefined; 69 if (groupBy10MS) { 70 req.context.fill(normalPath); 71 } else { 72 req.context.stroke(normalPath); 73 HiPerfStruct.drawSpecialPath(req.context, specPath); 74 } 75 req.context.closePath(); 76 } 77 78 render(hiPerfCpuRequest: RequestMessage, list: Array<any>, filter: Array<any>, dataList2: Array<any>) {} 79} 80 81export class HiPerfCpuStruct extends HiPerfStruct { 82 static hoverStruct: HiPerfCpuStruct | undefined; 83 static selectStruct: HiPerfCpuStruct | undefined; 84 85 cpu: number | undefined; 86} 87