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