1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ci 16fb726d48Sopenharmony_ciimport { SpSystemTrace } from '../SpSystemTrace'; 17fb726d48Sopenharmony_ciimport { Utils } from '../trace/base/Utils'; 18fb726d48Sopenharmony_ciimport { info } from '../../../log/Log'; 19fb726d48Sopenharmony_ciimport { TraceRow } from '../trace/base/TraceRow'; 20fb726d48Sopenharmony_ciimport { ProcessRender, ProcessStruct } from '../../database/ui-worker/ProcedureWorkerProcess'; 21fb726d48Sopenharmony_ciimport { ThreadRender, ThreadStruct } from '../../database/ui-worker/ProcedureWorkerThread'; 22fb726d48Sopenharmony_ciimport { FuncRender, FuncStruct } from '../../database/ui-worker/ProcedureWorkerFunc'; 23fb726d48Sopenharmony_ciimport { MemRender, ProcessMemStruct } from '../../database/ui-worker/ProcedureWorkerMem'; 24fb726d48Sopenharmony_ciimport { folderSupplier, folderThreadHandler, getRowContext, rowThreadHandler, SpChartManager } from './SpChartManager'; 25fb726d48Sopenharmony_ciimport { JankRender, JankStruct } from '../../database/ui-worker/ProcedureWorkerJank'; 26fb726d48Sopenharmony_ciimport { isFrameContainPoint, ns2xByTimeShaft, PairPoint } from '../../database/ui-worker/ProcedureWorkerCommon'; 27fb726d48Sopenharmony_ciimport { AppStartupRender, AppStartupStruct } from '../../database/ui-worker/ProcedureWorkerAppStartup'; 28fb726d48Sopenharmony_ciimport { SoRender, SoStruct } from '../../database/ui-worker/ProcedureWorkerSoInit'; 29fb726d48Sopenharmony_ciimport { FlagsConfig } from '../SpFlags'; 30fb726d48Sopenharmony_ciimport { processDataSender } from '../../database/data-trafic/process/ProcessDataSender'; 31fb726d48Sopenharmony_ciimport { threadDataSender } from '../../database/data-trafic/process/ThreadDataSender'; 32fb726d48Sopenharmony_ciimport { funcDataSender } from '../../database/data-trafic/process/FuncDataSender'; 33fb726d48Sopenharmony_ciimport { processMemDataSender } from '../../database/data-trafic/process/ProcessMemDataSender'; 34fb726d48Sopenharmony_ciimport { processStartupDataSender } from '../../database/data-trafic/process/ProcessStartupDataSender'; 35fb726d48Sopenharmony_ciimport { processSoInitDataSender } from '../../database/data-trafic/process/ProcessSoInitDataSender'; 36fb726d48Sopenharmony_ciimport { processExpectedDataSender } from '../../database/data-trafic/process/ProcessExpectedDataSender'; 37fb726d48Sopenharmony_ciimport { processActualDataSender } from '../../database/data-trafic/process/ProcessActualDataSender'; 38fb726d48Sopenharmony_ciimport { processDeliverInputEventDataSender } from '../../database/data-trafic/process/ProcessDeliverInputEventDataSender'; 39fb726d48Sopenharmony_ciimport { processTouchEventDispatchDataSender } from '../../database/data-trafic/process/ProcessTouchEventDispatchDataSender'; 40fb726d48Sopenharmony_ciimport { getMaxDepthByTid, queryProcessAsyncFunc, queryProcessAsyncFuncCat } from '../../database/sql/Func.sql'; 41fb726d48Sopenharmony_ciimport { queryMemFilterIdMaxValue } from '../../database/sql/Memory.sql'; 42fb726d48Sopenharmony_ciimport { queryAllSoInitNames, queryAllSrcSlices, queryEventCountMap } from '../../database/sql/SqlLite.sql'; 43fb726d48Sopenharmony_ciimport { 44fb726d48Sopenharmony_ci queryProcessByTable, 45fb726d48Sopenharmony_ci queryProcessContentCount, 46fb726d48Sopenharmony_ci queryProcessMem, 47fb726d48Sopenharmony_ci queryProcessSoMaxDepth, 48fb726d48Sopenharmony_ci queryProcessThreadsByTable, 49fb726d48Sopenharmony_ci queryStartupPidArray, 50fb726d48Sopenharmony_ci queryRsProcess, 51fb726d48Sopenharmony_ci queryTaskPoolProcessIds, 52fb726d48Sopenharmony_ci queryDistributedRelationData, 53fb726d48Sopenharmony_ci} from '../../database/sql/ProcessThread.sql'; 54fb726d48Sopenharmony_ciimport { queryAllJankProcess } from '../../database/sql/Janks.sql'; 55fb726d48Sopenharmony_ciimport { BaseStruct } from '../../bean/BaseStruct'; 56fb726d48Sopenharmony_ciimport { promises } from 'dns'; 57fb726d48Sopenharmony_ciimport { HangStruct } from '../../database/ui-worker/ProcedureWorkerHang'; 58fb726d48Sopenharmony_ciimport { hangDataSender } from '../../database/data-trafic/HangDataSender'; 59fb726d48Sopenharmony_ciimport { SpHangChart } from './SpHangChart'; 60fb726d48Sopenharmony_ciimport { queryHangData } from '../../database/sql/Hang.sql'; 61fb726d48Sopenharmony_ciimport { EmptyRender } from '../../database/ui-worker/cpu/ProcedureWorkerCPU'; 62fb726d48Sopenharmony_ciimport { renders } from '../../database/ui-worker/ProcedureWorker'; 63fb726d48Sopenharmony_ci 64fb726d48Sopenharmony_ciconst FOLD_HEIGHT = 24; 65fb726d48Sopenharmony_ciexport class SpProcessChart { 66fb726d48Sopenharmony_ci private readonly trace: SpSystemTrace; 67fb726d48Sopenharmony_ci private processAsyncFuncMap: unknown = {}; 68fb726d48Sopenharmony_ci private processAsyncFuncArray: unknown[] = []; 69fb726d48Sopenharmony_ci private processAsyncFuncCatMap: unknown = {}; 70fb726d48Sopenharmony_ci private eventCountMap: unknown; 71fb726d48Sopenharmony_ci private processThreads: Array<ThreadStruct> = []; 72fb726d48Sopenharmony_ci private processMem: Array<unknown> = []; 73fb726d48Sopenharmony_ci private processThreadCountMap: Map<number, number> = new Map(); 74fb726d48Sopenharmony_ci private processThreadDataCountMap: Map<number, number> = new Map(); 75fb726d48Sopenharmony_ci private processFuncDataCountMap: Map<number, number> = new Map(); 76fb726d48Sopenharmony_ci private processMemDataCountMap: Map<number, number> = new Map(); 77fb726d48Sopenharmony_ci private threadFuncMaxDepthMap: Map<string, number> = new Map(); 78fb726d48Sopenharmony_ci private startupProcessArr: { pid: number }[] = []; 79fb726d48Sopenharmony_ci private processSoMaxDepth: { pid: number; maxDepth: number }[] = []; 80fb726d48Sopenharmony_ci private filterIdMaxValue: Map<number, number> = new Map(); 81fb726d48Sopenharmony_ci private soInitNameMap: Map<number, string> = new Map(); 82fb726d48Sopenharmony_ci private processSrcSliceMap: Map<number, string> = new Map(); 83fb726d48Sopenharmony_ci private distributedDataMap: Map< 84fb726d48Sopenharmony_ci string, 85fb726d48Sopenharmony_ci { 86fb726d48Sopenharmony_ci chainId: string; 87fb726d48Sopenharmony_ci spanId: string; 88fb726d48Sopenharmony_ci parentSpanId: string; 89fb726d48Sopenharmony_ci chainFlag: string; 90fb726d48Sopenharmony_ci traceId: string 91fb726d48Sopenharmony_ci } 92fb726d48Sopenharmony_ci > = new Map(); 93fb726d48Sopenharmony_ci private renderRow: TraceRow<BaseStruct> | null = null; 94fb726d48Sopenharmony_ci private loadAppStartup: boolean = false; 95fb726d48Sopenharmony_ci private isDistributed: boolean = false; 96fb726d48Sopenharmony_ci private traceId?: string | undefined; 97fb726d48Sopenharmony_ci private parentRow: TraceRow<BaseStruct> | undefined; 98fb726d48Sopenharmony_ci static asyncFuncCache: unknown[] = []; 99fb726d48Sopenharmony_ci static threadStateList: Map<string, unknown> = new Map(); 100fb726d48Sopenharmony_ci static processRowSortMap: Map<string, unknown> = new Map(); 101fb726d48Sopenharmony_ci private sameThreadFolder!: TraceRow<ProcessStruct>; 102fb726d48Sopenharmony_ci 103fb726d48Sopenharmony_ci private hangProcessSet: Set<number> = new Set(); 104fb726d48Sopenharmony_ci constructor(trace: SpSystemTrace) { 105fb726d48Sopenharmony_ci this.trace = trace; 106fb726d48Sopenharmony_ci } 107fb726d48Sopenharmony_ci 108fb726d48Sopenharmony_ci clearCache(): void { 109fb726d48Sopenharmony_ci this.processAsyncFuncArray = []; 110fb726d48Sopenharmony_ci this.processAsyncFuncMap = {}; 111fb726d48Sopenharmony_ci this.processAsyncFuncCatMap = {}; 112fb726d48Sopenharmony_ci this.eventCountMap = {}; 113fb726d48Sopenharmony_ci this.processThreads = []; 114fb726d48Sopenharmony_ci this.processMem = []; 115fb726d48Sopenharmony_ci this.processThreadCountMap.clear(); 116fb726d48Sopenharmony_ci this.processThreadDataCountMap.clear(); 117fb726d48Sopenharmony_ci this.processFuncDataCountMap.clear(); 118fb726d48Sopenharmony_ci this.processMemDataCountMap.clear(); 119fb726d48Sopenharmony_ci this.threadFuncMaxDepthMap.clear(); 120fb726d48Sopenharmony_ci this.startupProcessArr = []; 121fb726d48Sopenharmony_ci this.processSoMaxDepth = []; 122fb726d48Sopenharmony_ci this.filterIdMaxValue.clear(); 123fb726d48Sopenharmony_ci this.soInitNameMap.clear(); 124fb726d48Sopenharmony_ci this.processSrcSliceMap.clear(); 125fb726d48Sopenharmony_ci this.distributedDataMap.clear(); 126fb726d48Sopenharmony_ci this.renderRow = null; 127fb726d48Sopenharmony_ci SpProcessChart.asyncFuncCache = []; 128fb726d48Sopenharmony_ci if (this.parentRow) { 129fb726d48Sopenharmony_ci this.parentRow.clearMemory(); 130fb726d48Sopenharmony_ci this.parentRow = undefined; 131fb726d48Sopenharmony_ci } 132fb726d48Sopenharmony_ci } 133fb726d48Sopenharmony_ci 134fb726d48Sopenharmony_ci initAsyncFuncData = async (traceRange: { startTs: number; endTs: number }, traceId?: string): Promise<void> => { 135fb726d48Sopenharmony_ci let asyncFuncList: unknown[] = await queryProcessAsyncFunc(traceRange, traceId); 136fb726d48Sopenharmony_ci for (const func of asyncFuncList) { 137fb726d48Sopenharmony_ci //@ts-ignore 138fb726d48Sopenharmony_ci func.funName = this.traceId ? Utils.getInstance().getCallStatckMap().get(`${this.traceId}_${func.id}`) : Utils.getInstance().getCallStatckMap().get(func.id); //@ts-ignore 139fb726d48Sopenharmony_ci func.threadName = Utils.getInstance().getThreadMap(traceId).get(func.tid); 140fb726d48Sopenharmony_ci } 141fb726d48Sopenharmony_ci info('AsyncFuncData Count is: ', asyncFuncList!.length); 142fb726d48Sopenharmony_ci this.processAsyncFuncArray = asyncFuncList; 143fb726d48Sopenharmony_ci this.processAsyncFuncMap = Utils.groupBy(asyncFuncList, 'pid'); 144fb726d48Sopenharmony_ci 145fb726d48Sopenharmony_ci let asyncFuncCatList: unknown[] = await queryProcessAsyncFuncCat(traceRange); 146fb726d48Sopenharmony_ci info('AsyncFuncCatData Count is: ', asyncFuncCatList!.length); 147fb726d48Sopenharmony_ci this.processAsyncFuncCatMap = Utils.groupBy(asyncFuncCatList, 'pid'); 148fb726d48Sopenharmony_ci }; 149fb726d48Sopenharmony_ci 150fb726d48Sopenharmony_ci initDeliverInputEvent = async (): Promise<void> => { 151fb726d48Sopenharmony_ci let row = TraceRow.skeleton(); 152fb726d48Sopenharmony_ci row.rowId = 'DeliverInputEvent'; 153fb726d48Sopenharmony_ci row.index = 0; 154fb726d48Sopenharmony_ci row.rowType = TraceRow.ROW_TYPE_DELIVER_INPUT_EVENT; 155fb726d48Sopenharmony_ci row.rowParentId = ''; 156fb726d48Sopenharmony_ci row.folder = true; 157fb726d48Sopenharmony_ci row.style.height = '40px'; 158fb726d48Sopenharmony_ci row.name = 'DeliverInputEvent'; 159fb726d48Sopenharmony_ci // @ts-ignore 160fb726d48Sopenharmony_ci row.supplier = folderSupplier(); 161fb726d48Sopenharmony_ci row.onThreadHandler = folderThreadHandler(row, this.trace); 162fb726d48Sopenharmony_ci 163fb726d48Sopenharmony_ci let asyncFuncGroup = Utils.groupBy( 164fb726d48Sopenharmony_ci //@ts-ignore 165fb726d48Sopenharmony_ci this.processAsyncFuncArray.filter((it) => it.funName === 'deliverInputEvent'), 166fb726d48Sopenharmony_ci 'pid' 167fb726d48Sopenharmony_ci ); // @ts-ignore 168fb726d48Sopenharmony_ci if (Reflect.ownKeys(asyncFuncGroup).length > 0) { 169fb726d48Sopenharmony_ci this.trace.rowsEL?.appendChild(row); 170fb726d48Sopenharmony_ci } // @ts-ignore 171fb726d48Sopenharmony_ci Reflect.ownKeys(asyncFuncGroup).map((key: unknown) => { 172fb726d48Sopenharmony_ci // @ts-ignore 173fb726d48Sopenharmony_ci let asyncFuncGroups: Array<unknown> = asyncFuncGroup[key]; 174fb726d48Sopenharmony_ci if (asyncFuncGroups.length > 0) { 175fb726d48Sopenharmony_ci //@ts-ignore 176fb726d48Sopenharmony_ci row.addChildTraceRow(this.createDeliverInputEventRow(row, key, asyncFuncGroups)); 177fb726d48Sopenharmony_ci } 178fb726d48Sopenharmony_ci }); 179fb726d48Sopenharmony_ci }; 180fb726d48Sopenharmony_ci 181fb726d48Sopenharmony_ci private createDeliverInputEventRow( 182fb726d48Sopenharmony_ci //@ts-ignore 183fb726d48Sopenharmony_ci parentRow: TraceRow<unknown>, 184fb726d48Sopenharmony_ci key: number, 185fb726d48Sopenharmony_ci asyncFuncGroups: Array<unknown> 186fb726d48Sopenharmony_ci ): TraceRow<FuncStruct> { 187fb726d48Sopenharmony_ci let funcRow = TraceRow.skeleton<FuncStruct>(); 188fb726d48Sopenharmony_ci //@ts-ignore 189fb726d48Sopenharmony_ci funcRow.rowId = `${asyncFuncGroups[0].funName}-${key}`; //@ts-ignore 190fb726d48Sopenharmony_ci funcRow.asyncFuncName = asyncFuncGroups[0].funName; 191fb726d48Sopenharmony_ci funcRow.asyncFuncNamePID = key; 192fb726d48Sopenharmony_ci funcRow.rowType = TraceRow.ROW_TYPE_FUNC; 193fb726d48Sopenharmony_ci funcRow.enableCollapseChart(FOLD_HEIGHT, this.trace); //允许折叠泳道图 194fb726d48Sopenharmony_ci funcRow.rowParentId = `${parentRow.rowId}`; 195fb726d48Sopenharmony_ci funcRow.rowHidden = !parentRow.expansion; 196fb726d48Sopenharmony_ci funcRow.style.width = '100%'; 197fb726d48Sopenharmony_ci //@ts-ignore 198fb726d48Sopenharmony_ci funcRow.name = `${asyncFuncGroups[0].funName} ${key}`; 199fb726d48Sopenharmony_ci funcRow.setAttribute('children', ''); 200fb726d48Sopenharmony_ci funcRow.supplierFrame = async (): Promise<FuncStruct[]> => { 201fb726d48Sopenharmony_ci const res = await processDeliverInputEventDataSender(key, funcRow!); 202fb726d48Sopenharmony_ci this.deliverInputEventSendCallback(res, funcRow, asyncFuncGroups); 203fb726d48Sopenharmony_ci return res; 204fb726d48Sopenharmony_ci }; 205fb726d48Sopenharmony_ci funcRow.findHoverStruct = (): void => { 206fb726d48Sopenharmony_ci FuncStruct.hoverFuncStruct = funcRow.getHoverStruct(); 207fb726d48Sopenharmony_ci }; 208fb726d48Sopenharmony_ci funcRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 209fb726d48Sopenharmony_ci funcRow.selectChangeHandler = this.trace.selectChangeHandler; 210fb726d48Sopenharmony_ci funcRow.onThreadHandler = rowThreadHandler<FuncRender>( 211fb726d48Sopenharmony_ci 'func', 212fb726d48Sopenharmony_ci 'context', 213fb726d48Sopenharmony_ci { 214fb726d48Sopenharmony_ci //@ts-ignore 215fb726d48Sopenharmony_ci type: `func-${asyncFuncGroups[0].funName}-${key}`, 216fb726d48Sopenharmony_ci }, 217fb726d48Sopenharmony_ci funcRow, 218fb726d48Sopenharmony_ci this.trace 219fb726d48Sopenharmony_ci ); 220fb726d48Sopenharmony_ci return funcRow; 221fb726d48Sopenharmony_ci } 222fb726d48Sopenharmony_ci //@ts-ignore 223fb726d48Sopenharmony_ci private deliverInputEventSendCallback( 224fb726d48Sopenharmony_ci res: Array<unknown>, //@ts-ignore 225fb726d48Sopenharmony_ci funcRow: TraceRow<unknown>, 226fb726d48Sopenharmony_ci asyncFuncGroups: Array<unknown> 227fb726d48Sopenharmony_ci ): void { 228fb726d48Sopenharmony_ci let isIntersect = ( 229fb726d48Sopenharmony_ci left: unknown, 230fb726d48Sopenharmony_ci right: unknown 231fb726d48Sopenharmony_ci ): boolean => //@ts-ignore 232fb726d48Sopenharmony_ci Math.max(left.startTs + left.dur, right.startTs + right.dur) - Math.min(left.startTs, right.startTs) < 233fb726d48Sopenharmony_ci //@ts-ignore 234fb726d48Sopenharmony_ci left.dur + right.dur; 235fb726d48Sopenharmony_ci let depths: unknown = []; 236fb726d48Sopenharmony_ci let createDepth = (currentDepth: number, index: number): void => { 237fb726d48Sopenharmony_ci //@ts-ignore 238fb726d48Sopenharmony_ci if (depths[currentDepth] === undefined || !isIntersect(depths[currentDepth], res[index])) { 239fb726d48Sopenharmony_ci //@ts-ignore 240fb726d48Sopenharmony_ci res[index].depth = currentDepth; 241fb726d48Sopenharmony_ci //@ts-ignore 242fb726d48Sopenharmony_ci depths[currentDepth] = res[index]; 243fb726d48Sopenharmony_ci } else { 244fb726d48Sopenharmony_ci createDepth(++currentDepth, index); 245fb726d48Sopenharmony_ci } 246fb726d48Sopenharmony_ci }; 247fb726d48Sopenharmony_ci res.forEach((it, i): void => { 248fb726d48Sopenharmony_ci //@ts-ignore 249fb726d48Sopenharmony_ci res[i].funName = this.traceId ? Utils.getInstance().getCallStatckMap().get(`${this.traceId}_${res[i].id!}`) : Utils.getInstance().getCallStatckMap().get(res[i].id!); //@ts-ignore 250fb726d48Sopenharmony_ci res[i].threadName = Utils.getInstance().getThreadMap().get(res[i].tid!); 251fb726d48Sopenharmony_ci //@ts-ignore 252fb726d48Sopenharmony_ci if (it.dur === -1 || it.dur === null || it.dur === undefined) { 253fb726d48Sopenharmony_ci //@ts-ignore 254fb726d48Sopenharmony_ci it.dur = (TraceRow.range?.endNS || 0) - it.startTs; 255fb726d48Sopenharmony_ci //@ts-ignore 256fb726d48Sopenharmony_ci it.flag = 'Did not end'; 257fb726d48Sopenharmony_ci } 258fb726d48Sopenharmony_ci createDepth(0, i); 259fb726d48Sopenharmony_ci }); 260fb726d48Sopenharmony_ci if (funcRow && !funcRow.isComplete) { 261fb726d48Sopenharmony_ci //@ts-ignore 262fb726d48Sopenharmony_ci let max = Math.max(...asyncFuncGroups.map((it) => it.depth || 0)) + 1; 263fb726d48Sopenharmony_ci let maxHeight = max * 18 + 6; 264fb726d48Sopenharmony_ci funcRow.style.height = `${maxHeight}px`; 265fb726d48Sopenharmony_ci funcRow.setAttribute('height', `${maxHeight}`); 266fb726d48Sopenharmony_ci } 267fb726d48Sopenharmony_ci } 268fb726d48Sopenharmony_ci 269fb726d48Sopenharmony_ci initTouchEventDispatch = async (): Promise<void> => { 270fb726d48Sopenharmony_ci let row = TraceRow.skeleton() as TraceRow<ProcessStruct>; 271fb726d48Sopenharmony_ci row.rowId = 'TouchEventDispatch'; 272fb726d48Sopenharmony_ci row.index = 0; 273fb726d48Sopenharmony_ci row.rowType = TraceRow.ROW_TYPE_TOUCH_EVENT_DISPATCH; 274fb726d48Sopenharmony_ci row.rowParentId = ''; 275fb726d48Sopenharmony_ci row.folder = true; 276fb726d48Sopenharmony_ci row.style.height = '40px'; 277fb726d48Sopenharmony_ci row.name = 'TouchEventDispatch'; 278fb726d48Sopenharmony_ci //@ts-ignore 279fb726d48Sopenharmony_ci row.supplier = folderSupplier(); 280fb726d48Sopenharmony_ci row.onThreadHandler = folderThreadHandler(row, this.trace); 281fb726d48Sopenharmony_ci 282fb726d48Sopenharmony_ci let asyncFuncGroup = Utils.groupBy( 283fb726d48Sopenharmony_ci //@ts-ignore 284fb726d48Sopenharmony_ci this.processAsyncFuncArray.filter((it) => it.funName === 'H:touchEventDispatch' || it.funName === 'H:TouchEventDispatch'), 285fb726d48Sopenharmony_ci 'pid' 286fb726d48Sopenharmony_ci ); 287fb726d48Sopenharmony_ci //@ts-ignore 288fb726d48Sopenharmony_ci if (Reflect.ownKeys(asyncFuncGroup).length > 0) { 289fb726d48Sopenharmony_ci this.trace.rowsEL?.appendChild(row); 290fb726d48Sopenharmony_ci } 291fb726d48Sopenharmony_ci //@ts-ignore 292fb726d48Sopenharmony_ci Reflect.ownKeys(asyncFuncGroup).map((key: unknown) => { 293fb726d48Sopenharmony_ci //@ts-ignore 294fb726d48Sopenharmony_ci let asyncFuncGroups: Array<unknown> = asyncFuncGroup[key]; 295fb726d48Sopenharmony_ci if (asyncFuncGroups.length > 0) { 296fb726d48Sopenharmony_ci // @ts-ignore 297fb726d48Sopenharmony_ci row.addChildTraceRow(this.createTouchEventDispatchRow(row, key, asyncFuncGroups)); 298fb726d48Sopenharmony_ci } 299fb726d48Sopenharmony_ci }); 300fb726d48Sopenharmony_ci }; 301fb726d48Sopenharmony_ci 302fb726d48Sopenharmony_ci private createTouchEventDispatchRow( 303fb726d48Sopenharmony_ci parentRow: TraceRow<ProcessStruct>, 304fb726d48Sopenharmony_ci key: number, 305fb726d48Sopenharmony_ci asyncFuncGroups: Array<unknown> 306fb726d48Sopenharmony_ci ): TraceRow<FuncStruct> { 307fb726d48Sopenharmony_ci let funcRow = TraceRow.skeleton<FuncStruct>(); 308fb726d48Sopenharmony_ci // @ts-ignore 309fb726d48Sopenharmony_ci funcRow.rowId = `${asyncFuncGroups[0].funName}-${key}`; 310fb726d48Sopenharmony_ci // @ts-ignore 311fb726d48Sopenharmony_ci funcRow.asyncFuncName = asyncFuncGroups[0].funName; 312fb726d48Sopenharmony_ci funcRow.asyncFuncNamePID = key; 313fb726d48Sopenharmony_ci funcRow.rowType = TraceRow.ROW_TYPE_FUNC; 314fb726d48Sopenharmony_ci funcRow.enableCollapseChart(FOLD_HEIGHT, this.trace); //允许折叠泳道图 315fb726d48Sopenharmony_ci funcRow.rowParentId = `${parentRow.rowId}`; 316fb726d48Sopenharmony_ci funcRow.rowHidden = !parentRow.expansion; 317fb726d48Sopenharmony_ci funcRow.style.width = '100%'; 318fb726d48Sopenharmony_ci funcRow.style.height = '24px'; 319fb726d48Sopenharmony_ci //@ts-ignore 320fb726d48Sopenharmony_ci funcRow.name = `${asyncFuncGroups[0].funName} ${key}`; 321fb726d48Sopenharmony_ci funcRow.setAttribute('children', ''); 322fb726d48Sopenharmony_ci //@ts-ignore 323fb726d48Sopenharmony_ci funcRow.supplierFrame = (): Promise => { 324fb726d48Sopenharmony_ci return processTouchEventDispatchDataSender(key, funcRow!).then((res: Array<unknown>) => { 325fb726d48Sopenharmony_ci this.touchEventDispatchSendCallback(res, funcRow, asyncFuncGroups); 326fb726d48Sopenharmony_ci return res; 327fb726d48Sopenharmony_ci }); 328fb726d48Sopenharmony_ci }; 329fb726d48Sopenharmony_ci 330fb726d48Sopenharmony_ci funcRow.findHoverStruct = (): void => { 331fb726d48Sopenharmony_ci FuncStruct.hoverFuncStruct = funcRow.getHoverStruct(); 332fb726d48Sopenharmony_ci }; 333fb726d48Sopenharmony_ci funcRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 334fb726d48Sopenharmony_ci funcRow.selectChangeHandler = this.trace.selectChangeHandler; 335fb726d48Sopenharmony_ci funcRow.onThreadHandler = rowThreadHandler<FuncRender>( 336fb726d48Sopenharmony_ci 'func', 337fb726d48Sopenharmony_ci 'context', 338fb726d48Sopenharmony_ci { 339fb726d48Sopenharmony_ci // @ts-ignore 340fb726d48Sopenharmony_ci type: `func-${asyncFuncGroups[0].funName}-${key}`, 341fb726d48Sopenharmony_ci }, 342fb726d48Sopenharmony_ci funcRow, 343fb726d48Sopenharmony_ci this.trace 344fb726d48Sopenharmony_ci ); 345fb726d48Sopenharmony_ci return funcRow; 346fb726d48Sopenharmony_ci } 347fb726d48Sopenharmony_ci 348fb726d48Sopenharmony_ci // @ts-ignore 349fb726d48Sopenharmony_ci private touchEventDispatchSendCallback(res: Array<unknown>, funcRow: TraceRow<unknown>, asyncFuncGroups: Array<unknown>): void { 350fb726d48Sopenharmony_ci let isIntersect = (left: unknown, right: unknown): boolean => 351fb726d48Sopenharmony_ci // @ts-ignore 352fb726d48Sopenharmony_ci Math.max(left.startTs + left.dur, right.startTs + right.dur) - Math.min(left.startTs, right.startTs) < 353fb726d48Sopenharmony_ci // @ts-ignore 354fb726d48Sopenharmony_ci left.dur + right.dur; 355fb726d48Sopenharmony_ci let depths: unknown = []; 356fb726d48Sopenharmony_ci let createDepth = (currentDepth: number, index: number): void => { 357fb726d48Sopenharmony_ci // @ts-ignore 358fb726d48Sopenharmony_ci if (depths[currentDepth] === undefined || !isIntersect(depths[currentDepth], res[index])) { 359fb726d48Sopenharmony_ci //@ts-ignore 360fb726d48Sopenharmony_ci res[index].depth = currentDepth; 361fb726d48Sopenharmony_ci // @ts-ignore 362fb726d48Sopenharmony_ci depths[currentDepth] = res[index]; 363fb726d48Sopenharmony_ci } else { 364fb726d48Sopenharmony_ci createDepth(++currentDepth, index); 365fb726d48Sopenharmony_ci } 366fb726d48Sopenharmony_ci }; 367fb726d48Sopenharmony_ci res.forEach((it, i) => { 368fb726d48Sopenharmony_ci //@ts-ignore 369fb726d48Sopenharmony_ci res[i].funName = this.traceId ? Utils.getInstance().getCallStatckMap().get(`${this.traceId}_${res[i].id!}`) : Utils.getInstance().getCallStatckMap().get(res[i].id!); 370fb726d48Sopenharmony_ci //@ts-ignore 371fb726d48Sopenharmony_ci res[i].threadName = Utils.getInstance().getThreadMap().get(res[i].tid!); 372fb726d48Sopenharmony_ci //@ts-ignore 373fb726d48Sopenharmony_ci if (it.dur === -1 || it.dur === null || it.dur === undefined) { 374fb726d48Sopenharmony_ci //@ts-ignore 375fb726d48Sopenharmony_ci it.dur = (TraceRow.range?.endNS || 0) - it.startTs; 376fb726d48Sopenharmony_ci //@ts-ignore 377fb726d48Sopenharmony_ci it.flag = 'Did not end'; 378fb726d48Sopenharmony_ci } 379fb726d48Sopenharmony_ci createDepth(0, i); 380fb726d48Sopenharmony_ci }); 381fb726d48Sopenharmony_ci if (funcRow && !funcRow.isComplete) { 382fb726d48Sopenharmony_ci // @ts-ignore 383fb726d48Sopenharmony_ci let max = Math.max(...asyncFuncGroups.map((it) => it.depth || 0)) + 1; 384fb726d48Sopenharmony_ci let maxHeight = max * 18 + 6; 385fb726d48Sopenharmony_ci funcRow.style.height = `${maxHeight}px`; 386fb726d48Sopenharmony_ci funcRow.setAttribute('height', `${maxHeight}`); 387fb726d48Sopenharmony_ci } 388fb726d48Sopenharmony_ci } 389fb726d48Sopenharmony_ci 390fb726d48Sopenharmony_ci // @ts-ignore 391fb726d48Sopenharmony_ci async init(isDistributed: boolean, parentRow?: TraceRow<unknown>, traceId?: string): Promise<void> { 392fb726d48Sopenharmony_ci this.traceId = traceId; 393fb726d48Sopenharmony_ci // @ts-ignore 394fb726d48Sopenharmony_ci this.parentRow = parentRow; 395fb726d48Sopenharmony_ci this.isDistributed = isDistributed; 396fb726d48Sopenharmony_ci await this.prepareData(traceId); 397fb726d48Sopenharmony_ci if ( 398fb726d48Sopenharmony_ci //@ts-ignore 399fb726d48Sopenharmony_ci this.eventCountMap.print === 0 && //@ts-ignore 400fb726d48Sopenharmony_ci this.eventCountMap.tracing_mark_write === 0 && //@ts-ignore 401fb726d48Sopenharmony_ci this.eventCountMap.sched_switch === 0 402fb726d48Sopenharmony_ci ) { 403fb726d48Sopenharmony_ci return; 404fb726d48Sopenharmony_ci } 405fb726d48Sopenharmony_ci let time = new Date().getTime(); 406fb726d48Sopenharmony_ci let processSortArray = Array.from(SpProcessChart.processRowSortMap); 407fb726d48Sopenharmony_ci // @ts-ignore 408fb726d48Sopenharmony_ci processSortArray.sort((a: Array<unknown>, b: Array<unknown>) => 409fb726d48Sopenharmony_ci // @ts-ignore 410fb726d48Sopenharmony_ci b[1] - a[1] 411fb726d48Sopenharmony_ci ); 412fb726d48Sopenharmony_ci let processFromTable = await queryProcessByTable(traceId); 413fb726d48Sopenharmony_ci let processList = Utils.sortThreadRow(processSortArray, processFromTable, 'process'); 414fb726d48Sopenharmony_ci SpProcessChart.processRowSortMap.clear(); 415fb726d48Sopenharmony_ci let allJankProcess: Array<number> = []; 416fb726d48Sopenharmony_ci let allTaskPoolPid: Array<{ pid: number }> = []; 417fb726d48Sopenharmony_ci let renderServiceProcess: unknown[] = []; 418fb726d48Sopenharmony_ci if (!this.isDistributed) { 419fb726d48Sopenharmony_ci let allJankProcessData = await queryAllJankProcess(); 420fb726d48Sopenharmony_ci if (allJankProcessData.length > 0) { 421fb726d48Sopenharmony_ci allJankProcessData.forEach((name, index) => { 422fb726d48Sopenharmony_ci allJankProcess.push(name.pid!); 423fb726d48Sopenharmony_ci }); 424fb726d48Sopenharmony_ci } 425fb726d48Sopenharmony_ci if (FlagsConfig.getFlagsConfigEnableStatus('TaskPool')) { 426fb726d48Sopenharmony_ci allTaskPoolPid = await queryTaskPoolProcessIds(); 427fb726d48Sopenharmony_ci } 428fb726d48Sopenharmony_ci renderServiceProcess = await queryRsProcess(); 429fb726d48Sopenharmony_ci } 430fb726d48Sopenharmony_ci 431fb726d48Sopenharmony_ci // @ts-ignore 432fb726d48Sopenharmony_ci info('ProcessList Data size is: ', processList!.length); 433fb726d48Sopenharmony_ci 434fb726d48Sopenharmony_ci 435fb726d48Sopenharmony_ci this.hangProcessSet = new Set<number>((await queryHangData()).map(item => item.id)); 436fb726d48Sopenharmony_ci 437fb726d48Sopenharmony_ci // @ts-ignore 438fb726d48Sopenharmony_ci await this.initProcessRow(processList, allTaskPoolPid, allJankProcess, renderServiceProcess, traceId); 439fb726d48Sopenharmony_ci let durTime = new Date().getTime() - time; 440fb726d48Sopenharmony_ci info('The time to load the Process data is: ', durTime); 441fb726d48Sopenharmony_ci } 442fb726d48Sopenharmony_ci 443fb726d48Sopenharmony_ci private async prepareData(traceId?: string): Promise<void> { 444fb726d48Sopenharmony_ci if (!this.isDistributed) { 445fb726d48Sopenharmony_ci let maxValues = await queryMemFilterIdMaxValue(); 446fb726d48Sopenharmony_ci maxValues.forEach((it) => { 447fb726d48Sopenharmony_ci this.filterIdMaxValue.set(it.filterId, it.maxValue); 448fb726d48Sopenharmony_ci }); 449fb726d48Sopenharmony_ci let soInitNamesArray = await queryAllSoInitNames(); 450fb726d48Sopenharmony_ci soInitNamesArray.forEach((it) => { 451fb726d48Sopenharmony_ci // @ts-ignore 452fb726d48Sopenharmony_ci this.soInitNameMap.set(it.id, it.name); 453fb726d48Sopenharmony_ci }); 454fb726d48Sopenharmony_ci let processSrcSliceArray = await queryAllSrcSlices(); 455fb726d48Sopenharmony_ci processSrcSliceArray.forEach((it) => { 456fb726d48Sopenharmony_ci // @ts-ignore 457fb726d48Sopenharmony_ci this.processSrcSliceMap.set(it.id, it.src); 458fb726d48Sopenharmony_ci }); 459fb726d48Sopenharmony_ci this.processMem = await queryProcessMem(); 460fb726d48Sopenharmony_ci info('The amount of initialized process memory data is : ', this.processMem!.length); 461fb726d48Sopenharmony_ci this.loadAppStartup = FlagsConfig.getFlagsConfigEnableStatus('AppStartup'); 462fb726d48Sopenharmony_ci info('Prepare App startup data '); 463fb726d48Sopenharmony_ci if (this.loadAppStartup) { 464fb726d48Sopenharmony_ci this.startupProcessArr = await queryStartupPidArray(); 465fb726d48Sopenharmony_ci this.processSoMaxDepth = await queryProcessSoMaxDepth(); 466fb726d48Sopenharmony_ci } 467fb726d48Sopenharmony_ci } 468fb726d48Sopenharmony_ci let threadFuncMaxDepthArray = await getMaxDepthByTid(traceId); 469fb726d48Sopenharmony_ci info('Gets the maximum tier per thread , tid and maxDepth'); 470fb726d48Sopenharmony_ci threadFuncMaxDepthArray.forEach((it) => { 471fb726d48Sopenharmony_ci //@ts-ignore 472fb726d48Sopenharmony_ci this.threadFuncMaxDepthMap.set(`${it.ipid}-${it.tid}`, it.maxDepth); 473fb726d48Sopenharmony_ci }); 474fb726d48Sopenharmony_ci info('convert tid and maxDepth array to map'); 475fb726d48Sopenharmony_ci let pidCountArray = await queryProcessContentCount(traceId); 476fb726d48Sopenharmony_ci info('fetch per process pid,switch_count,thread_count,slice_count,mem_count'); 477fb726d48Sopenharmony_ci pidCountArray.forEach((it) => { 478fb726d48Sopenharmony_ci //@ts-ignore 479fb726d48Sopenharmony_ci this.processThreadDataCountMap.set(it.pid, it.switch_count); 480fb726d48Sopenharmony_ci //@ts-ignore 481fb726d48Sopenharmony_ci this.processThreadCountMap.set(it.pid, it.thread_count); 482fb726d48Sopenharmony_ci //@ts-ignore 483fb726d48Sopenharmony_ci this.processFuncDataCountMap.set(it.pid, it.slice_count); 484fb726d48Sopenharmony_ci //@ts-ignore 485fb726d48Sopenharmony_ci this.processMemDataCountMap.set(it.pid, it.mem_count); 486fb726d48Sopenharmony_ci }); 487fb726d48Sopenharmony_ci let eventCountList: Array<unknown> = await queryEventCountMap(traceId); 488fb726d48Sopenharmony_ci this.eventCountMap = eventCountList.reduce((pre, current) => { 489fb726d48Sopenharmony_ci //@ts-ignore 490fb726d48Sopenharmony_ci pre[`${current.eventName}`] = current.count; 491fb726d48Sopenharmony_ci return pre; 492fb726d48Sopenharmony_ci }, {}); 493fb726d48Sopenharmony_ci // threadStateList转数组 494fb726d48Sopenharmony_ci let threadArray = Array.from(SpProcessChart.threadStateList); 495fb726d48Sopenharmony_ci // @ts-ignore 排序 496fb726d48Sopenharmony_ci threadArray.sort((a: Array<unknown>, b: Array<unknown>) => 497fb726d48Sopenharmony_ci // @ts-ignore 498fb726d48Sopenharmony_ci b[1] - a[1]); 499fb726d48Sopenharmony_ci let queryProcessThreadsByTableResult = await queryProcessThreadsByTable(traceId); 500fb726d48Sopenharmony_ci // @ts-ignore 501fb726d48Sopenharmony_ci // 全量threads排序 502fb726d48Sopenharmony_ci // @ts-ignore 503fb726d48Sopenharmony_ci this.processThreads = Utils.sortThreadRow(threadArray, queryProcessThreadsByTableResult, 'thread'); 504fb726d48Sopenharmony_ci SpProcessChart.threadStateList.clear(); 505fb726d48Sopenharmony_ci let distributedDataLists = await queryDistributedRelationData(traceId); 506fb726d48Sopenharmony_ci distributedDataLists.forEach((item) => { 507fb726d48Sopenharmony_ci this.distributedDataMap.set(`${item.id}_${traceId}`, { 508fb726d48Sopenharmony_ci chainId: item.chainId, 509fb726d48Sopenharmony_ci spanId: item.spanId, 510fb726d48Sopenharmony_ci parentSpanId: item.parentSpanId, 511fb726d48Sopenharmony_ci chainFlag: item.chainFlag, 512fb726d48Sopenharmony_ci traceId: traceId!, 513fb726d48Sopenharmony_ci }); 514fb726d48Sopenharmony_ci }); 515fb726d48Sopenharmony_ci info('The amount of initialized process threads data is : ', this.processThreads!.length); 516fb726d48Sopenharmony_ci } 517fb726d48Sopenharmony_ci 518fb726d48Sopenharmony_ci private async initProcessRow( 519fb726d48Sopenharmony_ci pArr: Array<unknown>, 520fb726d48Sopenharmony_ci allTaskPoolPid: Array<{ pid: number }>, 521fb726d48Sopenharmony_ci jankArr: Array<number>, 522fb726d48Sopenharmony_ci rsProcess: Array<unknown>, 523fb726d48Sopenharmony_ci traceId?: string 524fb726d48Sopenharmony_ci ): Promise<void> { 525fb726d48Sopenharmony_ci for (let i = 0; i < pArr.length; i++) { 526fb726d48Sopenharmony_ci const it = pArr[i] as { 527fb726d48Sopenharmony_ci pid: number; 528fb726d48Sopenharmony_ci processName: string | null 529fb726d48Sopenharmony_ci }; 530fb726d48Sopenharmony_ci if ( 531fb726d48Sopenharmony_ci (this.processThreadDataCountMap.get(it.pid) || 0) === 0 && 532fb726d48Sopenharmony_ci (this.processThreadCountMap.get(it.pid) || 0) === 0 && 533fb726d48Sopenharmony_ci (this.processFuncDataCountMap.get(it.pid) || 0) === 0 && 534fb726d48Sopenharmony_ci (this.processMemDataCountMap.get(it.pid) || 0) === 0 535fb726d48Sopenharmony_ci ) { 536fb726d48Sopenharmony_ci continue; 537fb726d48Sopenharmony_ci } 538fb726d48Sopenharmony_ci let processRow = this.createProcessRow(i, it, allTaskPoolPid); 539fb726d48Sopenharmony_ci if (this.parentRow) { 540fb726d48Sopenharmony_ci this.parentRow.addChildTraceRow(processRow); 541fb726d48Sopenharmony_ci } else { 542fb726d48Sopenharmony_ci this.trace.rowsEL?.appendChild(processRow); 543fb726d48Sopenharmony_ci } 544fb726d48Sopenharmony_ci /* App Startup row*/ 545fb726d48Sopenharmony_ci let startupRow: TraceRow<AppStartupStruct> | undefined = undefined; 546fb726d48Sopenharmony_ci let soRow: TraceRow<SoStruct> | undefined = undefined; 547fb726d48Sopenharmony_ci let actualRow: TraceRow<JankStruct> | null = null; 548fb726d48Sopenharmony_ci let expectedRow: TraceRow<JankStruct> | null = null; 549fb726d48Sopenharmony_ci //@ts-ignore 550fb726d48Sopenharmony_ci let currentPid = it.pid; 551fb726d48Sopenharmony_ci if (!this.isDistributed) { 552fb726d48Sopenharmony_ci if (this.loadAppStartup) { 553fb726d48Sopenharmony_ci if (this.startupProcessArr.find((sp) => sp.pid === currentPid)) { 554fb726d48Sopenharmony_ci startupRow = this.addStartUpRow(processRow); 555fb726d48Sopenharmony_ci } 556fb726d48Sopenharmony_ci let maxSoDepth = this.processSoMaxDepth.find((md) => md.pid === currentPid); 557fb726d48Sopenharmony_ci if (maxSoDepth) { 558fb726d48Sopenharmony_ci soRow = this.addSoInitRow(processRow, maxSoDepth.maxDepth); 559fb726d48Sopenharmony_ci } 560fb726d48Sopenharmony_ci } 561fb726d48Sopenharmony_ci if (jankArr.indexOf(currentPid) > -1) { 562fb726d48Sopenharmony_ci expectedRow = this.addExpectedRow(it, processRow, rsProcess); 563fb726d48Sopenharmony_ci actualRow = this.addActualRow(it, processRow, rsProcess); 564fb726d48Sopenharmony_ci } 565fb726d48Sopenharmony_ci } 566fb726d48Sopenharmony_ci this.renderRow = null; 567fb726d48Sopenharmony_ci if (it.processName === 'render_service') { 568fb726d48Sopenharmony_ci //@ts-ignore 569fb726d48Sopenharmony_ci this.addThreadList(it, processRow, expectedRow, actualRow, soRow, startupRow, traceId); //@ts-ignore 570fb726d48Sopenharmony_ci this.addProcessMemInfo(it, processRow); //@ts-ignore 571fb726d48Sopenharmony_ci this.addAsyncFunction(it, processRow);//@ts-ignore 572fb726d48Sopenharmony_ci this.addAsyncCatFunction(it, processRow); 573fb726d48Sopenharmony_ci } else { 574fb726d48Sopenharmony_ci //@ts-ignore 575fb726d48Sopenharmony_ci this.addAsyncFunction(it, processRow); //@ts-ignore 576fb726d48Sopenharmony_ci this.addProcessMemInfo(it, processRow); //@ts-ignore 577fb726d48Sopenharmony_ci this.addThreadList(it, processRow, expectedRow, actualRow, soRow, startupRow, traceId);//@ts-ignore 578fb726d48Sopenharmony_ci this.addAsyncCatFunction(it, processRow); 579fb726d48Sopenharmony_ci } 580fb726d48Sopenharmony_ci this.addProcessRowListener(processRow, actualRow); 581fb726d48Sopenharmony_ci if (!this.isDistributed) { 582fb726d48Sopenharmony_ci //@ts-ignore 583fb726d48Sopenharmony_ci await this.trace.chartManager?.frameTimeChart.initAnimatedScenesChart(processRow, it, expectedRow!, actualRow!); 584fb726d48Sopenharmony_ci } 585fb726d48Sopenharmony_ci } 586fb726d48Sopenharmony_ci } 587fb726d48Sopenharmony_ci 588fb726d48Sopenharmony_ci private createProcessRow( 589fb726d48Sopenharmony_ci index: number, 590fb726d48Sopenharmony_ci process: unknown, 591fb726d48Sopenharmony_ci allTaskPoolPid: Array<{ pid: number }> 592fb726d48Sopenharmony_ci ): TraceRow<ProcessStruct> { 593fb726d48Sopenharmony_ci let processRow = TraceRow.skeleton<ProcessStruct>(this.traceId); //@ts-ignore 594fb726d48Sopenharmony_ci processRow.rowId = `${process.pid}`; 595fb726d48Sopenharmony_ci processRow.index = index; 596fb726d48Sopenharmony_ci processRow.rowType = TraceRow.ROW_TYPE_PROCESS; 597fb726d48Sopenharmony_ci processRow.rowParentId = ''; 598fb726d48Sopenharmony_ci processRow.style.height = '40px'; 599fb726d48Sopenharmony_ci processRow.folder = true; 600fb726d48Sopenharmony_ci if ( 601fb726d48Sopenharmony_ci //@ts-ignore 602fb726d48Sopenharmony_ci SpChartManager.APP_STARTUP_PID_ARR.find((pid) => pid === process.pid) !== undefined || //@ts-ignore 603fb726d48Sopenharmony_ci process.processName === 'render_service' 604fb726d48Sopenharmony_ci ) { 605fb726d48Sopenharmony_ci processRow.addTemplateTypes('AppStartup'); 606fb726d48Sopenharmony_ci } 607fb726d48Sopenharmony_ci if (allTaskPoolPid.find((process) => process.pid === process.pid) !== undefined) { 608fb726d48Sopenharmony_ci processRow.addTemplateTypes('TaskPool'); 609fb726d48Sopenharmony_ci } //@ts-ignore 610fb726d48Sopenharmony_ci processRow.name = `${process.processName || 'Process'} ${process.pid}`; //@ts-ignore 611fb726d48Sopenharmony_ci processRow.supplierFrame = (): Promise<Array<unknown>> => { 612fb726d48Sopenharmony_ci //@ts-ignore 613fb726d48Sopenharmony_ci return processDataSender(process.pid || -1, processRow, this.traceId); 614fb726d48Sopenharmony_ci }; 615fb726d48Sopenharmony_ci processRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 616fb726d48Sopenharmony_ci processRow.selectChangeHandler = this.trace.selectChangeHandler; 617fb726d48Sopenharmony_ci processRow.onThreadHandler = rowThreadHandler<ProcessRender>( 618fb726d48Sopenharmony_ci 'process', 619fb726d48Sopenharmony_ci 'context', 620fb726d48Sopenharmony_ci { 621fb726d48Sopenharmony_ci //@ts-ignore 622fb726d48Sopenharmony_ci pid: process.pid, //@ts-ignore 623fb726d48Sopenharmony_ci type: `process ${processRow.index} ${process.processName}`, 624fb726d48Sopenharmony_ci }, 625fb726d48Sopenharmony_ci processRow, 626fb726d48Sopenharmony_ci this.trace 627fb726d48Sopenharmony_ci ); 628fb726d48Sopenharmony_ci return processRow; 629fb726d48Sopenharmony_ci } 630fb726d48Sopenharmony_ci 631fb726d48Sopenharmony_ci addProcessRowListener(processRow: TraceRow<ProcessStruct>, actualRow: TraceRow<JankStruct> | null): void { 632fb726d48Sopenharmony_ci let offsetYTimeOut: unknown = undefined; 633fb726d48Sopenharmony_ci processRow.addEventListener('expansion-change', (e: unknown) => { 634fb726d48Sopenharmony_ci JankStruct.delJankLineFlag = false; 635fb726d48Sopenharmony_ci if (offsetYTimeOut) { 636fb726d48Sopenharmony_ci //@ts-ignore 637fb726d48Sopenharmony_ci clearTimeout(offsetYTimeOut); 638fb726d48Sopenharmony_ci } 639fb726d48Sopenharmony_ci if (JankStruct.selectJankStruct !== null && JankStruct.selectJankStruct !== undefined) { 640fb726d48Sopenharmony_ci //@ts-ignore 641fb726d48Sopenharmony_ci if (e.detail.expansion) { 642fb726d48Sopenharmony_ci offsetYTimeOut = setTimeout(() => { 643fb726d48Sopenharmony_ci this.trace.linkNodes.forEach((linkNodeItem) => this.handler1(e, linkNodeItem, actualRow)); 644fb726d48Sopenharmony_ci }, 300); 645fb726d48Sopenharmony_ci } else { 646fb726d48Sopenharmony_ci if (JankStruct!.selectJankStruct) { 647fb726d48Sopenharmony_ci JankStruct.selectJankStructList?.push(<JankStruct>JankStruct!.selectJankStruct); 648fb726d48Sopenharmony_ci } 649fb726d48Sopenharmony_ci offsetYTimeOut = setTimeout(() => { 650fb726d48Sopenharmony_ci this.trace.linkNodes?.forEach((linkProcessItem) => this.handler2(e, linkProcessItem, processRow)); 651fb726d48Sopenharmony_ci }, 300); 652fb726d48Sopenharmony_ci } 653fb726d48Sopenharmony_ci } else if (FuncStruct.selectFuncStruct) { //@ts-ignore 654fb726d48Sopenharmony_ci if (e.detail.expansion) { 655fb726d48Sopenharmony_ci offsetYTimeOut = setTimeout(() => { 656fb726d48Sopenharmony_ci this.trace.linkNodes.forEach((linkNodeItem) => this.handler3(e, linkNodeItem)); 657fb726d48Sopenharmony_ci }, 300); 658fb726d48Sopenharmony_ci } else { 659fb726d48Sopenharmony_ci offsetYTimeOut = setTimeout(() => { 660fb726d48Sopenharmony_ci this.trace.linkNodes?.forEach((linkProcessItem) => { 661fb726d48Sopenharmony_ci this.handler4(e, linkProcessItem, processRow); 662fb726d48Sopenharmony_ci JankStruct.selectJankStructList = []; 663fb726d48Sopenharmony_ci }); 664fb726d48Sopenharmony_ci }, 300); 665fb726d48Sopenharmony_ci } 666fb726d48Sopenharmony_ci this.trace.resetDistributedLine(); 667fb726d48Sopenharmony_ci 668fb726d48Sopenharmony_ci } else { 669fb726d48Sopenharmony_ci //@ts-ignore 670fb726d48Sopenharmony_ci if (e.detail.expansion) { 671fb726d48Sopenharmony_ci offsetYTimeOut = setTimeout(() => { 672fb726d48Sopenharmony_ci this.trace.linkNodes.forEach((linkNodeItem) => this.handler3(e, linkNodeItem)); 673fb726d48Sopenharmony_ci }, 300); 674fb726d48Sopenharmony_ci } else { 675fb726d48Sopenharmony_ci if (ThreadStruct!.selectThreadStruct) { 676fb726d48Sopenharmony_ci ThreadStruct.selectThreadStructList?.push(<ThreadStruct>ThreadStruct!.selectThreadStruct); 677fb726d48Sopenharmony_ci } 678fb726d48Sopenharmony_ci offsetYTimeOut = setTimeout(() => { 679fb726d48Sopenharmony_ci this.trace.linkNodes?.forEach((linkProcessItem) => { 680fb726d48Sopenharmony_ci this.handler4(e, linkProcessItem, processRow); 681fb726d48Sopenharmony_ci JankStruct.selectJankStructList = []; 682fb726d48Sopenharmony_ci }); 683fb726d48Sopenharmony_ci }, 300); 684fb726d48Sopenharmony_ci } 685fb726d48Sopenharmony_ci } 686fb726d48Sopenharmony_ci let refreshTimeOut = setTimeout(() => { 687fb726d48Sopenharmony_ci this.trace.refreshCanvas(true); 688fb726d48Sopenharmony_ci clearTimeout(refreshTimeOut); 689fb726d48Sopenharmony_ci }, 360); 690fb726d48Sopenharmony_ci }); 691fb726d48Sopenharmony_ci } 692fb726d48Sopenharmony_ci 693fb726d48Sopenharmony_ci handler1(e: unknown, linkItem: PairPoint[], actualRow: TraceRow<JankStruct> | null): void { 694fb726d48Sopenharmony_ci JankStruct.selectJankStructList?.forEach((selectProcessStruct: unknown) => { 695fb726d48Sopenharmony_ci //@ts-ignore 696fb726d48Sopenharmony_ci if (e.detail.rowId === selectProcessStruct.pid) { 697fb726d48Sopenharmony_ci //@ts-ignore 698fb726d48Sopenharmony_ci JankStruct.selectJankStruct = selectProcessStruct; //@ts-ignore 699fb726d48Sopenharmony_ci JankStruct.hoverJankStruct = selectProcessStruct; 700fb726d48Sopenharmony_ci } 701fb726d48Sopenharmony_ci }); 702fb726d48Sopenharmony_ci this.updatePairPointTranslateY(linkItem[0]); 703fb726d48Sopenharmony_ci linkItem[0].y = linkItem[0].rowEL!.translateY! + linkItem[0].offsetY; 704fb726d48Sopenharmony_ci this.updatePairPointTranslateY(linkItem[1]); 705fb726d48Sopenharmony_ci linkItem[1].y = linkItem[1].rowEL!.translateY! + linkItem[1].offsetY; 706fb726d48Sopenharmony_ci if (actualRow) { 707fb726d48Sopenharmony_ci //@ts-ignore 708fb726d48Sopenharmony_ci if (linkItem[0].rowEL.rowId === e.detail.rowId) { 709fb726d48Sopenharmony_ci linkItem[0].x = ns2xByTimeShaft(linkItem[0].ns, this.trace.timerShaftEL!); 710fb726d48Sopenharmony_ci linkItem[0].y = actualRow!.translateY! + linkItem[0].offsetY * 2; 711fb726d48Sopenharmony_ci linkItem[0].offsetY = linkItem[0].offsetY * 2; 712fb726d48Sopenharmony_ci //@ts-ignore 713fb726d48Sopenharmony_ci linkItem[0].rowEL = actualRow!; 714fb726d48Sopenharmony_ci //@ts-ignore 715fb726d48Sopenharmony_ci } else if (linkItem[1].rowEL.rowId === e.detail.rowId) { 716fb726d48Sopenharmony_ci linkItem[1].x = ns2xByTimeShaft(linkItem[1].ns, this.trace.timerShaftEL!); 717fb726d48Sopenharmony_ci linkItem[1].y = actualRow!.translateY! + linkItem[1].offsetY * 2; 718fb726d48Sopenharmony_ci linkItem[1].offsetY = linkItem[1].offsetY * 2; 719fb726d48Sopenharmony_ci //@ts-ignore 720fb726d48Sopenharmony_ci linkItem[1].rowEL = actualRow!; 721fb726d48Sopenharmony_ci } 722fb726d48Sopenharmony_ci } 723fb726d48Sopenharmony_ci } 724fb726d48Sopenharmony_ci 725fb726d48Sopenharmony_ci handler2(e: unknown, linkItem: PairPoint[], processRow: TraceRow<ProcessStruct>): void { 726fb726d48Sopenharmony_ci this.updatePairPointTranslateY(linkItem[0]); 727fb726d48Sopenharmony_ci linkItem[0].y = linkItem[0].rowEL!.translateY! + linkItem[0].offsetY; 728fb726d48Sopenharmony_ci this.updatePairPointTranslateY(linkItem[1]); 729fb726d48Sopenharmony_ci linkItem[1].y = linkItem[1].rowEL!.translateY! + linkItem[1].offsetY; //@ts-ignore 730fb726d48Sopenharmony_ci if (linkItem[0].rowEL.rowParentId === e.detail.rowId) { 731fb726d48Sopenharmony_ci this.updatePairPoint(linkItem[0], processRow); //@ts-ignore 732fb726d48Sopenharmony_ci } else if (linkItem[1].rowEL.rowParentId === e.detail.rowId) { 733fb726d48Sopenharmony_ci this.updatePairPoint(linkItem[1], processRow); 734fb726d48Sopenharmony_ci } 735fb726d48Sopenharmony_ci } 736fb726d48Sopenharmony_ci 737fb726d48Sopenharmony_ci handler3(e: unknown, linkItem: PairPoint[]): void { 738fb726d48Sopenharmony_ci ThreadStruct.selectThreadStructList?.forEach((selectProcessStruct: unknown) => { 739fb726d48Sopenharmony_ci //@ts-ignore 740fb726d48Sopenharmony_ci if (e.detail.rowId === selectProcessStruct.pid) { 741fb726d48Sopenharmony_ci //@ts-ignore 742fb726d48Sopenharmony_ci ThreadStruct.selectThreadStruct = selectProcessStruct; //@ts-ignore 743fb726d48Sopenharmony_ci ThreadStruct.hoverThreadStruct = selectProcessStruct; 744fb726d48Sopenharmony_ci } 745fb726d48Sopenharmony_ci }); 746fb726d48Sopenharmony_ci if (linkItem[0].rowEL.expansion && linkItem[0].backrowEL) { 747fb726d48Sopenharmony_ci this.updatePairPointTranslateY(linkItem[0]); 748fb726d48Sopenharmony_ci linkItem[0].x = ns2xByTimeShaft(linkItem[0].ns, this.trace.timerShaftEL!); 749fb726d48Sopenharmony_ci linkItem[0].y = linkItem[0].rowEL.translateY + linkItem[0].offsetY; 750fb726d48Sopenharmony_ci linkItem[0].offsetY = linkItem[0].offsetY * 2; 751fb726d48Sopenharmony_ci linkItem[0].rowEL = linkItem[0].backrowEL; 752fb726d48Sopenharmony_ci } 753fb726d48Sopenharmony_ci if (linkItem[1].rowEL.expansion && linkItem[1].backrowEL) { 754fb726d48Sopenharmony_ci this.updatePairPointTranslateY(linkItem[1]); 755fb726d48Sopenharmony_ci linkItem[1].x = ns2xByTimeShaft(linkItem[1].ns, this.trace.timerShaftEL!); 756fb726d48Sopenharmony_ci linkItem[1].y = linkItem[1].rowEL!.translateY! + linkItem[1].offsetY; 757fb726d48Sopenharmony_ci linkItem[1].offsetY = linkItem[1].offsetY * 2; 758fb726d48Sopenharmony_ci linkItem[1].rowEL = linkItem[1].backrowEL; 759fb726d48Sopenharmony_ci } 760fb726d48Sopenharmony_ci } 761fb726d48Sopenharmony_ci 762fb726d48Sopenharmony_ci handler4(e: unknown, linkItem: PairPoint[], processRow: TraceRow<ProcessStruct>): void { 763fb726d48Sopenharmony_ci this.updatePairPointTranslateY(linkItem[0]); 764fb726d48Sopenharmony_ci linkItem[0].y = processRow!.translateY + linkItem[0].offsetY; 765fb726d48Sopenharmony_ci this.updatePairPointTranslateY(linkItem[1]); 766fb726d48Sopenharmony_ci linkItem[1].y = linkItem[1].rowEL!.translateY + linkItem[1].offsetY; //@ts-ignore 767fb726d48Sopenharmony_ci if (linkItem[0].rowEL.rowParentId === e.detail.rowId) { 768fb726d48Sopenharmony_ci //@ts-ignore 769fb726d48Sopenharmony_ci this.updatePairPoint(linkItem[0], processRow); 770fb726d48Sopenharmony_ci } //@ts-ignore 771fb726d48Sopenharmony_ci if (linkItem[1].rowEL.rowParentId === e.detail.rowId) { 772fb726d48Sopenharmony_ci this.updatePairPoint(linkItem[1], processRow); 773fb726d48Sopenharmony_ci } 774fb726d48Sopenharmony_ci } 775fb726d48Sopenharmony_ci 776fb726d48Sopenharmony_ci updatePairPointTranslateY(pair: PairPoint): void { 777fb726d48Sopenharmony_ci if (pair.rowEL.collect) { 778fb726d48Sopenharmony_ci pair.rowEL.translateY = pair.rowEL.getBoundingClientRect().top - 195; 779fb726d48Sopenharmony_ci } else { 780fb726d48Sopenharmony_ci pair.rowEL.translateY = pair.rowEL.offsetTop - this.trace.rowsPaneEL!.scrollTop; 781fb726d48Sopenharmony_ci } 782fb726d48Sopenharmony_ci } 783fb726d48Sopenharmony_ci 784fb726d48Sopenharmony_ci updatePairPoint(pair: PairPoint, processRow: TraceRow<ProcessStruct>): void { 785fb726d48Sopenharmony_ci if (!pair.rowEL.collect) { 786fb726d48Sopenharmony_ci pair.x = ns2xByTimeShaft(pair.ns, this.trace.timerShaftEL!); 787fb726d48Sopenharmony_ci pair.y = processRow!.translateY! + pair.offsetY / 2; 788fb726d48Sopenharmony_ci pair.offsetY = pair.offsetY / 2; 789fb726d48Sopenharmony_ci pair.rowEL = processRow!; 790fb726d48Sopenharmony_ci } 791fb726d48Sopenharmony_ci } 792fb726d48Sopenharmony_ci 793fb726d48Sopenharmony_ci /* Janks Frames */ 794fb726d48Sopenharmony_ci //@ts-ignore 795fb726d48Sopenharmony_ci addExpectedRow( 796fb726d48Sopenharmony_ci process: unknown, //@ts-ignore 797fb726d48Sopenharmony_ci processRow: TraceRow<unknown>, 798fb726d48Sopenharmony_ci renderServiceProcess: Array<unknown> 799fb726d48Sopenharmony_ci ): TraceRow<JankStruct> { 800fb726d48Sopenharmony_ci let expectedRow = TraceRow.skeleton<JankStruct>(); //@ts-ignore 801fb726d48Sopenharmony_ci expectedRow.asyncFuncName = process.processName; //@ts-ignore 802fb726d48Sopenharmony_ci expectedRow.asyncFuncNamePID = process.pid; 803fb726d48Sopenharmony_ci expectedRow.rowType = TraceRow.ROW_TYPE_JANK; //@ts-ignore 804fb726d48Sopenharmony_ci expectedRow.rowParentId = `${process.pid}`; 805fb726d48Sopenharmony_ci expectedRow.rowHidden = !processRow.expansion; 806fb726d48Sopenharmony_ci expectedRow.style.width = '100%'; 807fb726d48Sopenharmony_ci expectedRow.name = 'Expected Timeline'; 808fb726d48Sopenharmony_ci expectedRow.addTemplateTypes('FrameTimeline'); 809fb726d48Sopenharmony_ci expectedRow.setAttribute('children', ''); 810fb726d48Sopenharmony_ci expectedRow.supplierFrame = async (): Promise<JankStruct[]> => { 811fb726d48Sopenharmony_ci //@ts-ignore 812fb726d48Sopenharmony_ci let res = await processExpectedDataSender(process.pid, expectedRow!); 813fb726d48Sopenharmony_ci this.jankSenderCallback(res, 'expected', process, expectedRow, renderServiceProcess); 814fb726d48Sopenharmony_ci return res; 815fb726d48Sopenharmony_ci }; 816fb726d48Sopenharmony_ci expectedRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 817fb726d48Sopenharmony_ci expectedRow.selectChangeHandler = this.trace.selectChangeHandler; 818fb726d48Sopenharmony_ci expectedRow.onThreadHandler = rowThreadHandler<JankRender>( 819fb726d48Sopenharmony_ci 'jank', 820fb726d48Sopenharmony_ci 'context', 821fb726d48Sopenharmony_ci { 822fb726d48Sopenharmony_ci type: 'expected_frame_timeline_slice', 823fb726d48Sopenharmony_ci }, 824fb726d48Sopenharmony_ci expectedRow, 825fb726d48Sopenharmony_ci this.trace 826fb726d48Sopenharmony_ci ); 827fb726d48Sopenharmony_ci if (this.renderRow) { 828fb726d48Sopenharmony_ci processRow.addChildTraceRowBefore(expectedRow, this.renderRow); 829fb726d48Sopenharmony_ci } else { 830fb726d48Sopenharmony_ci processRow.addChildTraceRow(expectedRow); 831fb726d48Sopenharmony_ci } 832fb726d48Sopenharmony_ci return expectedRow; 833fb726d48Sopenharmony_ci } 834fb726d48Sopenharmony_ci 835fb726d48Sopenharmony_ci //@ts-ignore 836fb726d48Sopenharmony_ci addActualRow( 837fb726d48Sopenharmony_ci process: unknown, //@ts-ignore 838fb726d48Sopenharmony_ci processRow: TraceRow<unknown>, 839fb726d48Sopenharmony_ci renderServiceProcess: Array<unknown> 840fb726d48Sopenharmony_ci ): TraceRow<JankStruct> { 841fb726d48Sopenharmony_ci let actualRow = TraceRow.skeleton<JankStruct>(); 842fb726d48Sopenharmony_ci actualRow.rowType = TraceRow.ROW_TYPE_JANK; //@ts-ignore 843fb726d48Sopenharmony_ci actualRow.rowParentId = `${process.pid}`; 844fb726d48Sopenharmony_ci actualRow.rowHidden = !processRow.expansion; 845fb726d48Sopenharmony_ci actualRow.style.width = '100%'; 846fb726d48Sopenharmony_ci actualRow.name = 'Actual Timeline'; 847fb726d48Sopenharmony_ci actualRow.addTemplateTypes('FrameTimeline'); 848fb726d48Sopenharmony_ci actualRow.setAttribute('children', ''); 849fb726d48Sopenharmony_ci actualRow.supplierFrame = async (): Promise<JankStruct[]> => { 850fb726d48Sopenharmony_ci //@ts-ignore 851fb726d48Sopenharmony_ci let res = await processActualDataSender(process.pid, actualRow!); 852fb726d48Sopenharmony_ci this.jankSenderCallback(res, 'actual', process, actualRow, renderServiceProcess); 853fb726d48Sopenharmony_ci return res; 854fb726d48Sopenharmony_ci }; 855fb726d48Sopenharmony_ci actualRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 856fb726d48Sopenharmony_ci actualRow.selectChangeHandler = this.trace.selectChangeHandler; 857fb726d48Sopenharmony_ci actualRow.onThreadHandler = rowThreadHandler<JankRender>( 858fb726d48Sopenharmony_ci 'jank', 859fb726d48Sopenharmony_ci 'context', 860fb726d48Sopenharmony_ci { 861fb726d48Sopenharmony_ci type: 'actual_frame_timeline_slice', 862fb726d48Sopenharmony_ci }, 863fb726d48Sopenharmony_ci actualRow, 864fb726d48Sopenharmony_ci this.trace 865fb726d48Sopenharmony_ci ); 866fb726d48Sopenharmony_ci if (this.renderRow) { 867fb726d48Sopenharmony_ci processRow.addChildTraceRowBefore(actualRow, this.renderRow); 868fb726d48Sopenharmony_ci } else { 869fb726d48Sopenharmony_ci processRow.addChildTraceRow(actualRow); 870fb726d48Sopenharmony_ci } 871fb726d48Sopenharmony_ci return actualRow; 872fb726d48Sopenharmony_ci } 873fb726d48Sopenharmony_ci 874fb726d48Sopenharmony_ci //@ts-ignore 875fb726d48Sopenharmony_ci addHangRow( 876fb726d48Sopenharmony_ci data: { 877fb726d48Sopenharmony_ci pid: number | null; 878fb726d48Sopenharmony_ci processName: string | null; 879fb726d48Sopenharmony_ci }, 880fb726d48Sopenharmony_ci processRow: TraceRow<ProcessStruct>, 881fb726d48Sopenharmony_ci funcRow: TraceRow<FuncStruct>, 882fb726d48Sopenharmony_ci thread: unknown 883fb726d48Sopenharmony_ci ): void { 884fb726d48Sopenharmony_ci if (this.hangProcessSet.has(data.pid!) && FlagsConfig.getFlagsConfigEnableStatus('Hangs Detection')) { 885fb726d48Sopenharmony_ci //@ts-ignore 886fb726d48Sopenharmony_ci if (data.pid === thread.tid) { 887fb726d48Sopenharmony_ci let hangsRow = TraceRow.skeleton<HangStruct>(); 888fb726d48Sopenharmony_ci hangsRow.rowType = TraceRow.ROW_TYPE_HANG_INNER; 889fb726d48Sopenharmony_ci hangsRow.rowId = `${data.processName ?? 'Process'} ${data.pid}`; 890fb726d48Sopenharmony_ci hangsRow.rowParentId = `${data.pid}`; 891fb726d48Sopenharmony_ci hangsRow.rowHidden = !processRow.expansion; 892fb726d48Sopenharmony_ci hangsRow.style.width = '100%'; 893fb726d48Sopenharmony_ci hangsRow.name = 'Hangs'; 894fb726d48Sopenharmony_ci hangsRow.addTemplateTypes('FrameTimeline'); 895fb726d48Sopenharmony_ci hangsRow.setAttribute('children', ''); 896fb726d48Sopenharmony_ci hangsRow.supplierFrame = async (): Promise<HangStruct[]> => { 897fb726d48Sopenharmony_ci let promiseData = hangDataSender(data.pid!, hangsRow); 898fb726d48Sopenharmony_ci if (promiseData === null) { 899fb726d48Sopenharmony_ci return new Promise<Array<HangStruct>>((resolve) => resolve([])); 900fb726d48Sopenharmony_ci } else { 901fb726d48Sopenharmony_ci return promiseData.then((resultHang: Array<HangStruct>) => 902fb726d48Sopenharmony_ci resultHang.map(hangItem => ({ 903fb726d48Sopenharmony_ci ...hangItem, 904fb726d48Sopenharmony_ci pname: data.processName ?? 'process', 905fb726d48Sopenharmony_ci type: SpHangChart.calculateHangType(hangItem.dur!), 906fb726d48Sopenharmony_ci content: SpHangChart.funcNameMap.get(hangItem.id!) 907fb726d48Sopenharmony_ci })) 908fb726d48Sopenharmony_ci ); 909fb726d48Sopenharmony_ci } 910fb726d48Sopenharmony_ci }; 911fb726d48Sopenharmony_ci hangsRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 912fb726d48Sopenharmony_ci hangsRow.selectChangeHandler = this.trace.selectChangeHandler; 913fb726d48Sopenharmony_ci hangsRow.findHoverStruct = (): void => { 914fb726d48Sopenharmony_ci HangStruct.hoverHangStruct = hangsRow.getHoverStruct(); 915fb726d48Sopenharmony_ci }; 916fb726d48Sopenharmony_ci hangsRow.onThreadHandler = rowThreadHandler<HangStruct>( 917fb726d48Sopenharmony_ci 'hang', 918fb726d48Sopenharmony_ci 'context', 919fb726d48Sopenharmony_ci { 920fb726d48Sopenharmony_ci type: 'hangs_frame_timeline_slice', 921fb726d48Sopenharmony_ci }, 922fb726d48Sopenharmony_ci hangsRow, 923fb726d48Sopenharmony_ci this.trace 924fb726d48Sopenharmony_ci ); 925fb726d48Sopenharmony_ci processRow.addChildTraceRowAfter(hangsRow, funcRow); 926fb726d48Sopenharmony_ci } 927fb726d48Sopenharmony_ci } 928fb726d48Sopenharmony_ci } 929fb726d48Sopenharmony_ci 930fb726d48Sopenharmony_ci jankSenderCallback( 931fb726d48Sopenharmony_ci res: JankStruct[], 932fb726d48Sopenharmony_ci type: string, 933fb726d48Sopenharmony_ci process: unknown, 934fb726d48Sopenharmony_ci row: TraceRow<JankStruct>, 935fb726d48Sopenharmony_ci renderServiceProcess: Array<unknown>, 936fb726d48Sopenharmony_ci ): void { 937fb726d48Sopenharmony_ci let maxDepth: number = 1; 938fb726d48Sopenharmony_ci let unitHeight: number = 20; 939fb726d48Sopenharmony_ci for (let j = 0; j < res.length; j++) { 940fb726d48Sopenharmony_ci let struct = res[j]; 941fb726d48Sopenharmony_ci if (struct.depth! >= maxDepth) { 942fb726d48Sopenharmony_ci maxDepth = struct.depth! + 1; 943fb726d48Sopenharmony_ci } 944fb726d48Sopenharmony_ci if (type === 'actual') { 945fb726d48Sopenharmony_ci struct.src_slice = this.processSrcSliceMap.get(res[j].id!); 946fb726d48Sopenharmony_ci } 947fb726d48Sopenharmony_ci struct.cmdline = Utils.getInstance().getProcessMap().get(res[j].pid!); //@ts-ignore 948fb726d48Sopenharmony_ci if (res[j].pid! === renderServiceProcess[0].pid) { 949fb726d48Sopenharmony_ci struct.cmdline = 'render_service'; 950fb726d48Sopenharmony_ci struct.frameType = struct.cmdline; 951fb726d48Sopenharmony_ci } else { 952fb726d48Sopenharmony_ci struct.frameType = 'app'; 953fb726d48Sopenharmony_ci } 954fb726d48Sopenharmony_ci } 955fb726d48Sopenharmony_ci if (row && !row.isComplete && res.length > 0) { 956fb726d48Sopenharmony_ci let maxHeight: number = maxDepth * unitHeight; 957fb726d48Sopenharmony_ci row.style.height = `${maxHeight}px`; 958fb726d48Sopenharmony_ci row.setAttribute('height', `${maxHeight}`); 959fb726d48Sopenharmony_ci if (res[0]) { 960fb726d48Sopenharmony_ci let timeLineType = res[0].type; //@ts-ignore 961fb726d48Sopenharmony_ci row.rowId = `${timeLineType}-${process.pid}`; 962fb726d48Sopenharmony_ci row.setAttribute('frame_type', res[0].frameType || ''); 963fb726d48Sopenharmony_ci if (type === 'actual') { 964fb726d48Sopenharmony_ci row.dataList = res; 965fb726d48Sopenharmony_ci } 966fb726d48Sopenharmony_ci } 967fb726d48Sopenharmony_ci } 968fb726d48Sopenharmony_ci } 969fb726d48Sopenharmony_ci 970fb726d48Sopenharmony_ci addStartUpRow(processRow: TraceRow<ProcessStruct>): TraceRow<AppStartupStruct> { 971fb726d48Sopenharmony_ci processRow.setAttribute('hasStartup', 'true'); 972fb726d48Sopenharmony_ci let startupRow: TraceRow<AppStartupStruct> = TraceRow.skeleton<AppStartupStruct>(); 973fb726d48Sopenharmony_ci startupRow.rowId = `app-start-${processRow.rowId}`; 974fb726d48Sopenharmony_ci startupRow.rowType = TraceRow.ROW_TYPE_APP_STARTUP; 975fb726d48Sopenharmony_ci startupRow.rowParentId = `${processRow.rowId}`; 976fb726d48Sopenharmony_ci startupRow.rowHidden = !processRow.expansion; 977fb726d48Sopenharmony_ci startupRow.index = 0; 978fb726d48Sopenharmony_ci startupRow.style.height = '30px'; 979fb726d48Sopenharmony_ci startupRow.style.width = '100%'; 980fb726d48Sopenharmony_ci startupRow.name = 'App Startups'; 981fb726d48Sopenharmony_ci startupRow.findHoverStruct = (): void => { 982fb726d48Sopenharmony_ci AppStartupStruct.hoverStartupStruct = startupRow.getHoverStruct(); 983fb726d48Sopenharmony_ci }; 984fb726d48Sopenharmony_ci startupRow.setAttribute('children', ''); 985fb726d48Sopenharmony_ci startupRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 986fb726d48Sopenharmony_ci startupRow.selectChangeHandler = this.trace.selectChangeHandler; 987fb726d48Sopenharmony_ci startupRow.supplierFrame = (): Promise<Array<AppStartupStruct>> => 988fb726d48Sopenharmony_ci processStartupDataSender(parseInt(processRow.rowId!), startupRow).then((res) => { 989fb726d48Sopenharmony_ci if (res.length <= 0) { 990fb726d48Sopenharmony_ci this.trace.refreshCanvas(true); 991fb726d48Sopenharmony_ci } 992fb726d48Sopenharmony_ci for (let i = 0; i < res.length; i++) { 993fb726d48Sopenharmony_ci if (res[i].startName! < 6 && i < res.length - 1) { 994fb726d48Sopenharmony_ci res[i].endItid = res[i + 1].itid; 995fb726d48Sopenharmony_ci } 996fb726d48Sopenharmony_ci } 997fb726d48Sopenharmony_ci return res; 998fb726d48Sopenharmony_ci }); 999fb726d48Sopenharmony_ci startupRow.onThreadHandler = rowThreadHandler<AppStartupRender>( 1000fb726d48Sopenharmony_ci 'app-start-up', 1001fb726d48Sopenharmony_ci 'appStartupContext', 1002fb726d48Sopenharmony_ci { 1003fb726d48Sopenharmony_ci type: `app-startup ${processRow.rowId}`, 1004fb726d48Sopenharmony_ci }, 1005fb726d48Sopenharmony_ci startupRow, 1006fb726d48Sopenharmony_ci this.trace 1007fb726d48Sopenharmony_ci ); 1008fb726d48Sopenharmony_ci processRow.addChildTraceRow(startupRow); 1009fb726d48Sopenharmony_ci return startupRow; 1010fb726d48Sopenharmony_ci } 1011fb726d48Sopenharmony_ci 1012fb726d48Sopenharmony_ci addSoInitRow(processRow: TraceRow<ProcessStruct>, maxDepth: number): TraceRow<SoStruct> { 1013fb726d48Sopenharmony_ci processRow.setAttribute('hasStaticInit', 'true'); 1014fb726d48Sopenharmony_ci let maxHeight = (maxDepth + 1) * 20; 1015fb726d48Sopenharmony_ci let soRow: TraceRow<SoStruct> = TraceRow.skeleton<SoStruct>(); 1016fb726d48Sopenharmony_ci soRow.rowId = `app-start-${processRow.rowId}`; 1017fb726d48Sopenharmony_ci soRow.rowType = TraceRow.ROW_TYPE_STATIC_INIT; 1018fb726d48Sopenharmony_ci soRow.rowParentId = `${processRow.rowId}`; 1019fb726d48Sopenharmony_ci soRow.rowHidden = !processRow.expansion; 1020fb726d48Sopenharmony_ci soRow.index = 0; 1021fb726d48Sopenharmony_ci soRow.style.height = `${maxHeight}px`; 1022fb726d48Sopenharmony_ci soRow.style.width = '100%'; 1023fb726d48Sopenharmony_ci soRow.name = 'Static Initialization'; 1024fb726d48Sopenharmony_ci soRow.setAttribute('children', ''); 1025fb726d48Sopenharmony_ci soRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 1026fb726d48Sopenharmony_ci soRow.selectChangeHandler = this.trace.selectChangeHandler; 1027fb726d48Sopenharmony_ci soRow.findHoverStruct = (): void => { 1028fb726d48Sopenharmony_ci SoStruct.hoverSoStruct = soRow.getHoverStruct(); 1029fb726d48Sopenharmony_ci }; 1030fb726d48Sopenharmony_ci soRow.supplierFrame = (): Promise<Array<SoStruct>> => 1031fb726d48Sopenharmony_ci processSoInitDataSender(parseInt(processRow.rowId!), soRow).then((res) => { 1032fb726d48Sopenharmony_ci if (res.length <= 0) { 1033fb726d48Sopenharmony_ci this.trace.refreshCanvas(true); 1034fb726d48Sopenharmony_ci } 1035fb726d48Sopenharmony_ci res.forEach((so, index) => { 1036fb726d48Sopenharmony_ci let soName = this.soInitNameMap.get(res[index].id!); 1037fb726d48Sopenharmony_ci if (soName) { 1038fb726d48Sopenharmony_ci so.soName = soName.replace('dlopen: ', ''); 1039fb726d48Sopenharmony_ci } 1040fb726d48Sopenharmony_ci }); 1041fb726d48Sopenharmony_ci return res; 1042fb726d48Sopenharmony_ci }); 1043fb726d48Sopenharmony_ci soRow.onThreadHandler = rowThreadHandler<SoRender>( 1044fb726d48Sopenharmony_ci 'app-so-init', 1045fb726d48Sopenharmony_ci 'context', 1046fb726d48Sopenharmony_ci { 1047fb726d48Sopenharmony_ci type: `static-init ${processRow.rowId}`, 1048fb726d48Sopenharmony_ci }, 1049fb726d48Sopenharmony_ci soRow, 1050fb726d48Sopenharmony_ci this.trace 1051fb726d48Sopenharmony_ci ); 1052fb726d48Sopenharmony_ci processRow.addChildTraceRow(soRow); 1053fb726d48Sopenharmony_ci return soRow; 1054fb726d48Sopenharmony_ci } 1055fb726d48Sopenharmony_ci 1056fb726d48Sopenharmony_ci insertAfter(newEl: HTMLElement, targetEl: HTMLElement): void { 1057fb726d48Sopenharmony_ci let parentEl = targetEl.parentNode; 1058fb726d48Sopenharmony_ci if (parentEl!.lastChild === targetEl) { 1059fb726d48Sopenharmony_ci parentEl!.appendChild(newEl); 1060fb726d48Sopenharmony_ci } else { 1061fb726d48Sopenharmony_ci parentEl!.insertBefore(newEl, targetEl.nextSibling); 1062fb726d48Sopenharmony_ci } 1063fb726d48Sopenharmony_ci } 1064fb726d48Sopenharmony_ci 1065fb726d48Sopenharmony_ci //add thread list 1066fb726d48Sopenharmony_ci async addThreadList( 1067fb726d48Sopenharmony_ci it: { pid: number | null; processName: string | null }, 1068fb726d48Sopenharmony_ci pRow: TraceRow<ProcessStruct>, 1069fb726d48Sopenharmony_ci expectedRow: TraceRow<JankStruct> | null, 1070fb726d48Sopenharmony_ci actualRow: TraceRow<JankStruct> | null, 1071fb726d48Sopenharmony_ci soRow: TraceRow<SoStruct> | undefined, 1072fb726d48Sopenharmony_ci startupRow: TraceRow<AppStartupStruct> | undefined, 1073fb726d48Sopenharmony_ci traceId?: string 1074fb726d48Sopenharmony_ci ): Promise<void> { 1075fb726d48Sopenharmony_ci let threads = this.processThreads.filter((thread) => thread.pid === it.pid && thread.tid !== 0); 1076fb726d48Sopenharmony_ci const sameThreadCounts: Record<string, number> = {}; //同名thread添加子进程 1077fb726d48Sopenharmony_ci const sameThreadList: any[] = []; 1078fb726d48Sopenharmony_ci const differentThreadList: any[] = []; 1079fb726d48Sopenharmony_ci threads.forEach(item => { 1080fb726d48Sopenharmony_ci const sameThread = item.threadName; 1081fb726d48Sopenharmony_ci if (sameThread !== undefined) { 1082fb726d48Sopenharmony_ci if (sameThread in sameThreadCounts) { 1083fb726d48Sopenharmony_ci sameThreadCounts[sameThread]++; 1084fb726d48Sopenharmony_ci } else { 1085fb726d48Sopenharmony_ci sameThreadCounts[sameThread] = 1; 1086fb726d48Sopenharmony_ci } 1087fb726d48Sopenharmony_ci } 1088fb726d48Sopenharmony_ci }); 1089fb726d48Sopenharmony_ci 1090fb726d48Sopenharmony_ci threads.forEach((item) => { 1091fb726d48Sopenharmony_ci const sameThread = item.threadName; 1092fb726d48Sopenharmony_ci if (sameThreadCounts[sameThread!] > 128) { 1093fb726d48Sopenharmony_ci sameThreadList.push(item); 1094fb726d48Sopenharmony_ci } else { 1095fb726d48Sopenharmony_ci differentThreadList.push(item); 1096fb726d48Sopenharmony_ci } 1097fb726d48Sopenharmony_ci }); 1098fb726d48Sopenharmony_ci 1099fb726d48Sopenharmony_ci differentThreadList.length && this.addDifferentThread(it, pRow, expectedRow, actualRow, soRow, startupRow, differentThreadList, traceId!); 1100fb726d48Sopenharmony_ci if (sameThreadList.length) { 1101fb726d48Sopenharmony_ci let sameThreadFolder = await this.initSameThreadFolder(it, pRow, sameThreadList, traceId!); 1102fb726d48Sopenharmony_ci if (sameThreadFolder) { 1103fb726d48Sopenharmony_ci pRow.addChildTraceRow(this.sameThreadFolder); 1104fb726d48Sopenharmony_ci } 1105fb726d48Sopenharmony_ci await this.initSameThreadData(sameThreadFolder, it, expectedRow, actualRow, soRow, startupRow, sameThreadList, traceId); 1106fb726d48Sopenharmony_ci } 1107fb726d48Sopenharmony_ci } 1108fb726d48Sopenharmony_ci 1109fb726d48Sopenharmony_ci initSameThreadFolder(it: { pid: number | null; processName: string | null }, pRow: TraceRow<ProcessStruct>, list: Array<any>, traceId?: string) { 1110fb726d48Sopenharmony_ci let sameThreadRow = TraceRow.skeleton<ProcessStruct>(); 1111fb726d48Sopenharmony_ci sameThreadRow.rowId = 'sameThreadProcess'; 1112fb726d48Sopenharmony_ci sameThreadRow.rowParentId = `${it.pid}`; 1113fb726d48Sopenharmony_ci sameThreadRow.rowHidden = !pRow.expansion; 1114fb726d48Sopenharmony_ci sameThreadRow.rowType = TraceRow.ROW_TYPE_THREAD_NAME; 1115fb726d48Sopenharmony_ci sameThreadRow.folder = true; 1116fb726d48Sopenharmony_ci sameThreadRow.name = list[0].threadName; 1117fb726d48Sopenharmony_ci sameThreadRow.folderPaddingLeft = 20; 1118fb726d48Sopenharmony_ci sameThreadRow.style.height = '40px'; 1119fb726d48Sopenharmony_ci sameThreadRow.style.width = '100%'; 1120fb726d48Sopenharmony_ci sameThreadRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 1121fb726d48Sopenharmony_ci sameThreadRow.selectChangeHandler = this.trace.selectChangeHandler; 1122fb726d48Sopenharmony_ci sameThreadRow.supplierFrame = (): Promise<Array<ProcessStruct>> => 1123fb726d48Sopenharmony_ci new Promise<Array<ProcessStruct>>((resolve) => resolve([])); 1124fb726d48Sopenharmony_ci sameThreadRow.onThreadHandler = (useCache): void => { 1125fb726d48Sopenharmony_ci let context: CanvasRenderingContext2D; 1126fb726d48Sopenharmony_ci if (sameThreadRow.currentContext) { 1127fb726d48Sopenharmony_ci context = sameThreadRow.currentContext; 1128fb726d48Sopenharmony_ci } else { 1129fb726d48Sopenharmony_ci context = sameThreadRow.collect ? this.trace.canvasFavoritePanelCtx! : this.trace.canvasPanelCtx!; 1130fb726d48Sopenharmony_ci } 1131fb726d48Sopenharmony_ci sameThreadRow.canvasSave(context); 1132fb726d48Sopenharmony_ci if (sameThreadRow.expansion) { 1133fb726d48Sopenharmony_ci // @ts-ignore 1134fb726d48Sopenharmony_ci context?.clearRect(0, 0, sameThreadRow.frame.width, sameThreadRow.frame.height); 1135fb726d48Sopenharmony_ci } else { 1136fb726d48Sopenharmony_ci (renders.empty as EmptyRender).renderMainThread( 1137fb726d48Sopenharmony_ci { 1138fb726d48Sopenharmony_ci context: context, 1139fb726d48Sopenharmony_ci useCache: useCache, 1140fb726d48Sopenharmony_ci type: '', 1141fb726d48Sopenharmony_ci }, 1142fb726d48Sopenharmony_ci sameThreadRow 1143fb726d48Sopenharmony_ci ); 1144fb726d48Sopenharmony_ci } 1145fb726d48Sopenharmony_ci sameThreadRow.canvasRestore(context, this.trace); 1146fb726d48Sopenharmony_ci }; 1147fb726d48Sopenharmony_ci this.sameThreadFolder = sameThreadRow; 1148fb726d48Sopenharmony_ci return this.sameThreadFolder; 1149fb726d48Sopenharmony_ci } 1150fb726d48Sopenharmony_ci 1151fb726d48Sopenharmony_ci async initSameThreadData(sameThreadFolder: TraceRow<ProcessStruct>, it: { pid: number | null; processName: string | null }, 1152fb726d48Sopenharmony_ci expectedRow: TraceRow<JankStruct> | null, 1153fb726d48Sopenharmony_ci actualRow: TraceRow<JankStruct> | null, 1154fb726d48Sopenharmony_ci soRow: TraceRow<SoStruct> | undefined, 1155fb726d48Sopenharmony_ci startupRow: TraceRow<AppStartupStruct> | undefined, sameThreadList: Array<any>, traceId?: string): Promise<void> { 1156fb726d48Sopenharmony_ci let tRowArr: Array<TraceRow<BaseStruct>> = []; 1157fb726d48Sopenharmony_ci for (let j = 0; j < sameThreadList.length; j++) { 1158fb726d48Sopenharmony_ci let thread = sameThreadList[j]; 1159fb726d48Sopenharmony_ci let tRow = TraceRow.skeleton<ThreadStruct>(this.traceId); 1160fb726d48Sopenharmony_ci tRow.rowId = `${thread.tid}`; 1161fb726d48Sopenharmony_ci tRow.rowType = TraceRow.ROW_TYPE_THREAD; 1162fb726d48Sopenharmony_ci tRow.rowParentId = sameThreadFolder.rowId; 1163fb726d48Sopenharmony_ci tRow.rowHidden = !sameThreadFolder.expansion; 1164fb726d48Sopenharmony_ci tRow.index = j; 1165fb726d48Sopenharmony_ci tRow.style.height = '18px'; 1166fb726d48Sopenharmony_ci tRow.style.width = '100%'; 1167fb726d48Sopenharmony_ci tRow.name = `${thread.threadName || 'Thread'} ${thread.tid}`; 1168fb726d48Sopenharmony_ci tRow.namePrefix = `${thread.threadName || 'Thread'}`; 1169fb726d48Sopenharmony_ci tRow.setAttribute('children', ''); 1170fb726d48Sopenharmony_ci tRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 1171fb726d48Sopenharmony_ci tRow.selectChangeHandler = this.trace.selectChangeHandler; 1172fb726d48Sopenharmony_ci tRow.findHoverStruct = (): void => this.threadRowFindHoverStruct(tRow); 1173fb726d48Sopenharmony_ci tRow.supplierFrame = async (): Promise<Array<ThreadStruct>> => { 1174fb726d48Sopenharmony_ci const res = await threadDataSender(thread.tid || 0, it.pid || 0, tRow, this.traceId); 1175fb726d48Sopenharmony_ci if (res === true) { 1176fb726d48Sopenharmony_ci return []; 1177fb726d48Sopenharmony_ci } 1178fb726d48Sopenharmony_ci let rs = res as ThreadStruct[]; 1179fb726d48Sopenharmony_ci if (rs.length <= 0 && !tRow.isComplete) { 1180fb726d48Sopenharmony_ci this.trace.refreshCanvas(true); 1181fb726d48Sopenharmony_ci } 1182fb726d48Sopenharmony_ci return rs; 1183fb726d48Sopenharmony_ci }; 1184fb726d48Sopenharmony_ci tRow.onThreadHandler = rowThreadHandler<ThreadRender>( 1185fb726d48Sopenharmony_ci 'thread', 1186fb726d48Sopenharmony_ci 'context', 1187fb726d48Sopenharmony_ci { 1188fb726d48Sopenharmony_ci type: `thread ${thread.tid} ${thread.threadName}`, 1189fb726d48Sopenharmony_ci translateY: tRow.translateY, 1190fb726d48Sopenharmony_ci }, 1191fb726d48Sopenharmony_ci tRow, 1192fb726d48Sopenharmony_ci this.trace 1193fb726d48Sopenharmony_ci ); 1194fb726d48Sopenharmony_ci this.insertRowToDoc(it, j, thread, sameThreadFolder, tRow, sameThreadList, tRowArr, actualRow, expectedRow, startupRow, soRow); 1195fb726d48Sopenharmony_ci this.addFuncStackRow(it, thread, j, sameThreadList, tRowArr, tRow, sameThreadFolder, sameThreadFolder.rowId!); 1196fb726d48Sopenharmony_ci if ((thread.switchCount || 0) === 0) { 1197fb726d48Sopenharmony_ci tRow.rowDiscard = true; 1198fb726d48Sopenharmony_ci } 1199fb726d48Sopenharmony_ci sameThreadFolder.addChildTraceRow(tRow); 1200fb726d48Sopenharmony_ci } 1201fb726d48Sopenharmony_ci } 1202fb726d48Sopenharmony_ci 1203fb726d48Sopenharmony_ci addDifferentThread(it: { pid: number | null; processName: string | null }, 1204fb726d48Sopenharmony_ci pRow: TraceRow<ProcessStruct>, 1205fb726d48Sopenharmony_ci expectedRow: TraceRow<JankStruct> | null, 1206fb726d48Sopenharmony_ci actualRow: TraceRow<JankStruct> | null, 1207fb726d48Sopenharmony_ci soRow: TraceRow<SoStruct> | undefined, 1208fb726d48Sopenharmony_ci startupRow: TraceRow<AppStartupStruct> | undefined, 1209fb726d48Sopenharmony_ci list: Array<any>, traceId?: string) { 1210fb726d48Sopenharmony_ci let tRowArr: Array<TraceRow<BaseStruct>> = []; 1211fb726d48Sopenharmony_ci for (let j = 0; j < list.length; j++) { 1212fb726d48Sopenharmony_ci let thread = list[j]; 1213fb726d48Sopenharmony_ci let tRow = TraceRow.skeleton<ThreadStruct>(this.traceId); 1214fb726d48Sopenharmony_ci tRow.rowId = `${thread.tid}`; 1215fb726d48Sopenharmony_ci tRow.rowType = TraceRow.ROW_TYPE_THREAD; 1216fb726d48Sopenharmony_ci tRow.rowParentId = `${it.pid}`; 1217fb726d48Sopenharmony_ci tRow.rowHidden = !pRow.expansion; 1218fb726d48Sopenharmony_ci tRow.index = j; 1219fb726d48Sopenharmony_ci tRow.style.height = '18px'; 1220fb726d48Sopenharmony_ci tRow.style.width = '100%'; 1221fb726d48Sopenharmony_ci tRow.name = `${thread.threadName || 'Thread'} ${thread.tid}`; 1222fb726d48Sopenharmony_ci tRow.namePrefix = `${thread.threadName || 'Thread'}`; 1223fb726d48Sopenharmony_ci tRow.setAttribute('children', ''); 1224fb726d48Sopenharmony_ci tRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 1225fb726d48Sopenharmony_ci tRow.selectChangeHandler = this.trace.selectChangeHandler; 1226fb726d48Sopenharmony_ci tRow.findHoverStruct = (): void => this.threadRowFindHoverStruct(tRow); 1227fb726d48Sopenharmony_ci tRow.supplierFrame = async (): Promise<Array<ThreadStruct>> => { 1228fb726d48Sopenharmony_ci const res = await threadDataSender(thread.tid || 0, it.pid || 0, tRow, this.traceId); 1229fb726d48Sopenharmony_ci if (res === true) { 1230fb726d48Sopenharmony_ci return []; 1231fb726d48Sopenharmony_ci } 1232fb726d48Sopenharmony_ci let rs = res as ThreadStruct[]; 1233fb726d48Sopenharmony_ci if (rs.length <= 0 && !tRow.isComplete) { 1234fb726d48Sopenharmony_ci this.trace.refreshCanvas(true); 1235fb726d48Sopenharmony_ci } 1236fb726d48Sopenharmony_ci return rs; 1237fb726d48Sopenharmony_ci }; 1238fb726d48Sopenharmony_ci tRow.onThreadHandler = rowThreadHandler<ThreadRender>( 1239fb726d48Sopenharmony_ci 'thread', 1240fb726d48Sopenharmony_ci 'context', 1241fb726d48Sopenharmony_ci { 1242fb726d48Sopenharmony_ci type: `thread ${thread.tid} ${thread.threadName}`, 1243fb726d48Sopenharmony_ci translateY: tRow.translateY, 1244fb726d48Sopenharmony_ci }, 1245fb726d48Sopenharmony_ci tRow, 1246fb726d48Sopenharmony_ci this.trace 1247fb726d48Sopenharmony_ci ); 1248fb726d48Sopenharmony_ci this.insertRowToDoc(it, j, thread, pRow, tRow, list, tRowArr, actualRow, expectedRow, startupRow, soRow); 1249fb726d48Sopenharmony_ci this.addFuncStackRow(it, thread, j, list, tRowArr, tRow, pRow); 1250fb726d48Sopenharmony_ci if ((thread.switchCount || 0) === 0) { 1251fb726d48Sopenharmony_ci tRow.rowDiscard = true; 1252fb726d48Sopenharmony_ci } 1253fb726d48Sopenharmony_ci } 1254fb726d48Sopenharmony_ci } 1255fb726d48Sopenharmony_ci 1256fb726d48Sopenharmony_ci threadRowFindHoverStruct(threadRow: TraceRow<ThreadStruct>): void { 1257fb726d48Sopenharmony_ci let arr = threadRow.dataListCache.filter( 1258fb726d48Sopenharmony_ci (re) => re.frame && isFrameContainPoint(re.frame, threadRow.hoverX, threadRow.hoverY, true, false) 1259fb726d48Sopenharmony_ci ); 1260fb726d48Sopenharmony_ci let runItem = arr.find((it) => it.state === 'Running'); 1261fb726d48Sopenharmony_ci if (runItem) { 1262fb726d48Sopenharmony_ci ThreadStruct.hoverThreadStruct = runItem; 1263fb726d48Sopenharmony_ci } else { 1264fb726d48Sopenharmony_ci let otherItem = arr.find((it) => it.state !== 'S'); 1265fb726d48Sopenharmony_ci if (otherItem) { 1266fb726d48Sopenharmony_ci ThreadStruct.hoverThreadStruct = otherItem; 1267fb726d48Sopenharmony_ci } else { 1268fb726d48Sopenharmony_ci ThreadStruct.hoverThreadStruct = arr[0]; 1269fb726d48Sopenharmony_ci } 1270fb726d48Sopenharmony_ci } 1271fb726d48Sopenharmony_ci } 1272fb726d48Sopenharmony_ci 1273fb726d48Sopenharmony_ci insertRowToDoc( 1274fb726d48Sopenharmony_ci it: unknown, 1275fb726d48Sopenharmony_ci index: number, 1276fb726d48Sopenharmony_ci thread: ThreadStruct, 1277fb726d48Sopenharmony_ci processRow: TraceRow<ProcessStruct>, 1278fb726d48Sopenharmony_ci threadRow: TraceRow<ThreadStruct>, 1279fb726d48Sopenharmony_ci threads: ThreadStruct[], 1280fb726d48Sopenharmony_ci //@ts-ignore 1281fb726d48Sopenharmony_ci threadRowArr: TraceRow<unknown>[], 1282fb726d48Sopenharmony_ci //@ts-ignore 1283fb726d48Sopenharmony_ci actualRow: TraceRow<unknown> | null, 1284fb726d48Sopenharmony_ci //@ts-ignore 1285fb726d48Sopenharmony_ci expectedRow: TraceRow<unknown> | null, 1286fb726d48Sopenharmony_ci startupRow: TraceRow<AppStartupStruct> | null | undefined, 1287fb726d48Sopenharmony_ci soRow: TraceRow<SoStruct> | null | undefined 1288fb726d48Sopenharmony_ci ): void { 1289fb726d48Sopenharmony_ci //@ts-ignore 1290fb726d48Sopenharmony_ci if (it.processName === 'render_service') { 1291fb726d48Sopenharmony_ci //@ts-ignore 1292fb726d48Sopenharmony_ci if (threadRow.name === `${it.processName} ${it.pid}`) { 1293fb726d48Sopenharmony_ci this.renderRow = threadRow; 1294fb726d48Sopenharmony_ci } 1295fb726d48Sopenharmony_ci let flag = threads.length === index + 1 && !this.threadFuncMaxDepthMap.has(`${thread.upid}-${thread.tid}`); 1296fb726d48Sopenharmony_ci //@ts-ignore 1297fb726d48Sopenharmony_ci processRow.sortRenderServiceData(threadRow, threadRow, threadRowArr, flag); 1298fb726d48Sopenharmony_ci } else { 1299fb726d48Sopenharmony_ci if (threadRow.rowId === threadRow.rowParentId) { 1300fb726d48Sopenharmony_ci if (actualRow !== null) { 1301fb726d48Sopenharmony_ci processRow.addChildTraceRowAfter(threadRow, actualRow); 1302fb726d48Sopenharmony_ci } else if (expectedRow !== null) { 1303fb726d48Sopenharmony_ci processRow.addChildTraceRowAfter(threadRow, expectedRow); 1304fb726d48Sopenharmony_ci } else if (soRow) { 1305fb726d48Sopenharmony_ci processRow.addChildTraceRowAfter(threadRow, soRow); 1306fb726d48Sopenharmony_ci } else if (startupRow) { 1307fb726d48Sopenharmony_ci processRow.addChildTraceRowAfter(threadRow, startupRow); 1308fb726d48Sopenharmony_ci } else { 1309fb726d48Sopenharmony_ci processRow.addChildTraceRowSpecifyLocation(threadRow, 0); 1310fb726d48Sopenharmony_ci } 1311fb726d48Sopenharmony_ci } else { 1312fb726d48Sopenharmony_ci processRow.addChildTraceRow(threadRow); 1313fb726d48Sopenharmony_ci } 1314fb726d48Sopenharmony_ci } 1315fb726d48Sopenharmony_ci } 1316fb726d48Sopenharmony_ci 1317fb726d48Sopenharmony_ci addFuncStackRow( 1318fb726d48Sopenharmony_ci process: { pid: number | null; processName: string | null }, 1319fb726d48Sopenharmony_ci thread: unknown, 1320fb726d48Sopenharmony_ci index: number, 1321fb726d48Sopenharmony_ci threads: Array<unknown>, 1322fb726d48Sopenharmony_ci threadRowArr: Array<unknown>, 1323fb726d48Sopenharmony_ci threadRow: TraceRow<ThreadStruct>, 1324fb726d48Sopenharmony_ci processRow: TraceRow<ProcessStruct>, 1325fb726d48Sopenharmony_ci parentId?: string 1326fb726d48Sopenharmony_ci ): void { 1327fb726d48Sopenharmony_ci //@ts-ignore 1328fb726d48Sopenharmony_ci if (this.threadFuncMaxDepthMap.get(`${thread.upid}-${thread.tid}`) !== undefined) { 1329fb726d48Sopenharmony_ci //@ts-ignore 1330fb726d48Sopenharmony_ci let max = this.threadFuncMaxDepthMap.get(`${thread.upid}-${thread.tid}`) || 1; 1331fb726d48Sopenharmony_ci let maxHeight = max * 18 + 6; 1332fb726d48Sopenharmony_ci let funcRow = TraceRow.skeleton<FuncStruct>(this.traceId); 1333fb726d48Sopenharmony_ci //@ts-ignore 1334fb726d48Sopenharmony_ci funcRow.rowId = `${thread.tid}`; 1335fb726d48Sopenharmony_ci funcRow.rowType = TraceRow.ROW_TYPE_FUNC; 1336fb726d48Sopenharmony_ci funcRow.enableCollapseChart(FOLD_HEIGHT, this.trace); //允许折叠泳道图 1337fb726d48Sopenharmony_ci //@ts-ignore 1338fb726d48Sopenharmony_ci funcRow.rowParentId = parentId ? parentId : `${process.pid}`; 1339fb726d48Sopenharmony_ci funcRow.rowHidden = !processRow.expansion; 1340fb726d48Sopenharmony_ci funcRow.checkType = threadRow.checkType; 1341fb726d48Sopenharmony_ci funcRow.style.width = '100%'; 1342fb726d48Sopenharmony_ci funcRow.style.height = `${maxHeight}px`; 1343fb726d48Sopenharmony_ci //@ts-ignore 1344fb726d48Sopenharmony_ci funcRow.name = `${thread.threadName || 'Thread'} ${thread.tid}`; 1345fb726d48Sopenharmony_ci //@ts-ignore 1346fb726d48Sopenharmony_ci funcRow.namePrefix = `${thread.threadName || 'Thread'}`; 1347fb726d48Sopenharmony_ci funcRow.setAttribute('children', ''); 1348fb726d48Sopenharmony_ci funcRow.supplierFrame = async (): Promise<Array<FuncStruct>> => { 1349fb726d48Sopenharmony_ci //@ts-ignore 1350fb726d48Sopenharmony_ci const rs = await funcDataSender(thread.tid || 0, thread.upid || 0, funcRow, this.traceId); 1351fb726d48Sopenharmony_ci //@ts-ignore 1352fb726d48Sopenharmony_ci return this.funDataSenderCallback(rs, funcRow, thread); 1353fb726d48Sopenharmony_ci }; 1354fb726d48Sopenharmony_ci funcRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 1355fb726d48Sopenharmony_ci funcRow.selectChangeHandler = this.trace.selectChangeHandler; 1356fb726d48Sopenharmony_ci funcRow.findHoverStruct = (): void => { 1357fb726d48Sopenharmony_ci FuncStruct.hoverFuncStruct = funcRow.getHoverStruct(); 1358fb726d48Sopenharmony_ci }; 1359fb726d48Sopenharmony_ci funcRow.onThreadHandler = rowThreadHandler<FuncRender>( 1360fb726d48Sopenharmony_ci 'func', 1361fb726d48Sopenharmony_ci 'context', 1362fb726d48Sopenharmony_ci { 1363fb726d48Sopenharmony_ci //@ts-ignore 1364fb726d48Sopenharmony_ci type: `func${thread.tid}${thread.threadName}`, 1365fb726d48Sopenharmony_ci }, 1366fb726d48Sopenharmony_ci funcRow, 1367fb726d48Sopenharmony_ci this.trace 1368fb726d48Sopenharmony_ci ); //@ts-ignore 1369fb726d48Sopenharmony_ci if (process.processName === 'render_service') { 1370fb726d48Sopenharmony_ci let flag = threads.length === index + 1; 1371fb726d48Sopenharmony_ci //@ts-ignore 1372fb726d48Sopenharmony_ci processRow.sortRenderServiceData(funcRow, threadRow, threadRowArr, flag); 1373fb726d48Sopenharmony_ci } else { 1374fb726d48Sopenharmony_ci processRow.addChildTraceRowAfter(funcRow, threadRow); 1375fb726d48Sopenharmony_ci } 1376fb726d48Sopenharmony_ci this.addHangRow(process, processRow, funcRow, thread); 1377fb726d48Sopenharmony_ci } 1378fb726d48Sopenharmony_ci } 1379fb726d48Sopenharmony_ci 1380fb726d48Sopenharmony_ci funDataSenderCallback( 1381fb726d48Sopenharmony_ci rs: Array<unknown> | boolean, 1382fb726d48Sopenharmony_ci funcRow: TraceRow<FuncStruct>, 1383fb726d48Sopenharmony_ci thread: ThreadStruct 1384fb726d48Sopenharmony_ci ): FuncStruct[] { 1385fb726d48Sopenharmony_ci if (rs === true) { 1386fb726d48Sopenharmony_ci funcRow.rowDiscard = true; 1387fb726d48Sopenharmony_ci return []; 1388fb726d48Sopenharmony_ci } else { 1389fb726d48Sopenharmony_ci let funs = rs as FuncStruct[]; 1390fb726d48Sopenharmony_ci if (funs.length > 0) { 1391fb726d48Sopenharmony_ci funs.forEach((fun, index) => { 1392fb726d48Sopenharmony_ci funs[index].itid = thread.utid; 1393fb726d48Sopenharmony_ci funs[index].ipid = thread.upid; 1394fb726d48Sopenharmony_ci funs[index].tid = thread.tid; 1395fb726d48Sopenharmony_ci funs[index].pid = thread.pid; 1396fb726d48Sopenharmony_ci funs[index].funName = this.traceId ? Utils.getInstance().getCallStatckMap().get(`${this.traceId}_${funs[index].id}`) : Utils.getInstance().getCallStatckMap().get(funs[index].id!); 1397fb726d48Sopenharmony_ci if (Utils.isBinder(fun)) { 1398fb726d48Sopenharmony_ci } else { 1399fb726d48Sopenharmony_ci if (fun.nofinish) { 1400fb726d48Sopenharmony_ci fun.flag = 'Did not end'; 1401fb726d48Sopenharmony_ci } 1402fb726d48Sopenharmony_ci } 1403fb726d48Sopenharmony_ci if (fun.id && this.distributedDataMap.has(`${fun.id}_${this.traceId}`)) { 1404fb726d48Sopenharmony_ci let distributedData = this.distributedDataMap.get(`${fun.id}_${this.traceId}`); 1405fb726d48Sopenharmony_ci funs[index].chainId = distributedData!.chainId; 1406fb726d48Sopenharmony_ci funs[index].spanId = distributedData!.spanId; 1407fb726d48Sopenharmony_ci funs[index].parentSpanId = distributedData!.parentSpanId; 1408fb726d48Sopenharmony_ci funs[index].chainFlag = distributedData!.chainFlag; 1409fb726d48Sopenharmony_ci funs[index].traceId = this.traceId; 1410fb726d48Sopenharmony_ci } 1411fb726d48Sopenharmony_ci }); 1412fb726d48Sopenharmony_ci } else { 1413fb726d48Sopenharmony_ci this.trace.refreshCanvas(true); 1414fb726d48Sopenharmony_ci } 1415fb726d48Sopenharmony_ci return funs; 1416fb726d48Sopenharmony_ci } 1417fb726d48Sopenharmony_ci } 1418fb726d48Sopenharmony_ci 1419fb726d48Sopenharmony_ci //进程内存信息 1420fb726d48Sopenharmony_ci addProcessMemInfo(it: { pid: number | null; processName: string | null }, processRow: TraceRow<ProcessStruct>): void { 1421fb726d48Sopenharmony_ci //@ts-ignore 1422fb726d48Sopenharmony_ci let processMem = this.processMem.filter((mem) => mem.pid === it.pid); 1423fb726d48Sopenharmony_ci processMem.forEach((mem) => { 1424fb726d48Sopenharmony_ci let row = TraceRow.skeleton<ProcessMemStruct>(); 1425fb726d48Sopenharmony_ci //@ts-ignore 1426fb726d48Sopenharmony_ci row.rowId = `${mem.trackId}`; 1427fb726d48Sopenharmony_ci row.rowType = TraceRow.ROW_TYPE_MEM; 1428fb726d48Sopenharmony_ci row.rowParentId = `${it.pid}`; 1429fb726d48Sopenharmony_ci row.rowHidden = !processRow.expansion; 1430fb726d48Sopenharmony_ci row.style.height = '40px'; 1431fb726d48Sopenharmony_ci row.style.width = '100%'; 1432fb726d48Sopenharmony_ci //@ts-ignore 1433fb726d48Sopenharmony_ci row.name = `${mem.trackName}`; 1434fb726d48Sopenharmony_ci row.setAttribute('children', ''); 1435fb726d48Sopenharmony_ci row.favoriteChangeHandler = this.trace.favoriteChangeHandler; 1436fb726d48Sopenharmony_ci row.selectChangeHandler = this.trace.selectChangeHandler; 1437fb726d48Sopenharmony_ci row.focusHandler = (): void => { 1438fb726d48Sopenharmony_ci this.trace.displayTip( 1439fb726d48Sopenharmony_ci row, 1440fb726d48Sopenharmony_ci ProcessMemStruct.hoverProcessMemStruct, 1441fb726d48Sopenharmony_ci `<span>${ProcessMemStruct.hoverProcessMemStruct?.value || '0'}</span>` 1442fb726d48Sopenharmony_ci ); 1443fb726d48Sopenharmony_ci }; 1444fb726d48Sopenharmony_ci row.findHoverStruct = (): void => { 1445fb726d48Sopenharmony_ci ProcessMemStruct.hoverProcessMemStruct = row.getHoverStruct(false); 1446fb726d48Sopenharmony_ci }; 1447fb726d48Sopenharmony_ci row.supplierFrame = (): Promise<Array<ProcessMemStruct>> => 1448fb726d48Sopenharmony_ci //@ts-ignore 1449fb726d48Sopenharmony_ci processMemDataSender(mem.trackId, row).then((resultProcess) => { 1450fb726d48Sopenharmony_ci //@ts-ignore 1451fb726d48Sopenharmony_ci let maxValue = this.filterIdMaxValue.get(mem.trackId) || 0; 1452fb726d48Sopenharmony_ci for (let j = 0; j < resultProcess.length; j++) { 1453fb726d48Sopenharmony_ci resultProcess[j].maxValue = maxValue; 1454fb726d48Sopenharmony_ci if (j === resultProcess.length - 1) { 1455fb726d48Sopenharmony_ci resultProcess[j].duration = (TraceRow.range?.totalNS || 0) - (resultProcess[j].startTime || 0); 1456fb726d48Sopenharmony_ci } else { 1457fb726d48Sopenharmony_ci resultProcess[j].duration = (resultProcess[j + 1].startTime || 0) - (resultProcess[j].startTime || 0); 1458fb726d48Sopenharmony_ci } 1459fb726d48Sopenharmony_ci if (j > 0) { 1460fb726d48Sopenharmony_ci resultProcess[j].delta = (resultProcess[j].value || 0) - (resultProcess[j - 1].value || 0); 1461fb726d48Sopenharmony_ci } else { 1462fb726d48Sopenharmony_ci resultProcess[j].delta = 0; 1463fb726d48Sopenharmony_ci } 1464fb726d48Sopenharmony_ci } 1465fb726d48Sopenharmony_ci return resultProcess; 1466fb726d48Sopenharmony_ci }); 1467fb726d48Sopenharmony_ci row.onThreadHandler = rowThreadHandler<MemRender>( 1468fb726d48Sopenharmony_ci 'mem', 1469fb726d48Sopenharmony_ci 'context', 1470fb726d48Sopenharmony_ci { 1471fb726d48Sopenharmony_ci //@ts-ignore 1472fb726d48Sopenharmony_ci type: `mem ${mem.trackId} ${mem.trackName}`, 1473fb726d48Sopenharmony_ci }, 1474fb726d48Sopenharmony_ci row, 1475fb726d48Sopenharmony_ci this.trace 1476fb726d48Sopenharmony_ci ); 1477fb726d48Sopenharmony_ci if (this.renderRow && row.name === 'H:PreferredFrameRate') { 1478fb726d48Sopenharmony_ci processRow.addChildTraceRowBefore(row, this.renderRow); 1479fb726d48Sopenharmony_ci } else { 1480fb726d48Sopenharmony_ci processRow.addChildTraceRow(row); 1481fb726d48Sopenharmony_ci } 1482fb726d48Sopenharmony_ci }); 1483fb726d48Sopenharmony_ci } 1484fb726d48Sopenharmony_ci private calMaxHeight(asyncFunctions: unknown[]): number { 1485fb726d48Sopenharmony_ci let max = 0; 1486fb726d48Sopenharmony_ci asyncFunctions.forEach((it) => { 1487fb726d48Sopenharmony_ci //@ts-ignore 1488fb726d48Sopenharmony_ci const depth = it.depth || 0; 1489fb726d48Sopenharmony_ci if (depth > max) { 1490fb726d48Sopenharmony_ci max = depth; 1491fb726d48Sopenharmony_ci } 1492fb726d48Sopenharmony_ci }); 1493fb726d48Sopenharmony_ci max += 1; 1494fb726d48Sopenharmony_ci return max * 18 + 6; 1495fb726d48Sopenharmony_ci } 1496fb726d48Sopenharmony_ci //处理缓存数据的'startTs'字段统一成'startTime' 1497fb726d48Sopenharmony_ci private toAsyncFuncCache(object: unknown, name: string): void { 1498fb726d48Sopenharmony_ci // @ts-ignore 1499fb726d48Sopenharmony_ci let modifiedObject = { ...object }; 1500fb726d48Sopenharmony_ci modifiedObject.startTime = modifiedObject.startTs; 1501fb726d48Sopenharmony_ci Reflect.deleteProperty(modifiedObject, 'startTs'); 1502fb726d48Sopenharmony_ci modifiedObject.rowId = name; 1503fb726d48Sopenharmony_ci modifiedObject.type = 'func'; 1504fb726d48Sopenharmony_ci SpProcessChart.asyncFuncCache.push({ ...modifiedObject }); 1505fb726d48Sopenharmony_ci } 1506fb726d48Sopenharmony_ci //Async Function 1507fb726d48Sopenharmony_ci addAsyncFunction(it: { pid: number; processName: string | null }, processRow: TraceRow<ProcessStruct>): void { 1508fb726d48Sopenharmony_ci let isCategoryAsyncfunc: boolean = FlagsConfig.getFlagsConfigEnableStatus('Start&Finish Trace Category'); 1509fb726d48Sopenharmony_ci let asyncRemoveCatArr: unknown[]; 1510fb726d48Sopenharmony_ci let asyncCat: unknown; 1511fb726d48Sopenharmony_ci let setArrayLenThanOne: unknown; 1512fb726d48Sopenharmony_ci let setArrayLenOnlyOne: unknown; 1513fb726d48Sopenharmony_ci //@ts-ignore 1514fb726d48Sopenharmony_ci let asyncFuncList = this.processAsyncFuncMap[it.pid] || []; 1515fb726d48Sopenharmony_ci if (!asyncFuncList.length) { 1516fb726d48Sopenharmony_ci return; 1517fb726d48Sopenharmony_ci } 1518fb726d48Sopenharmony_ci let flag = FlagsConfig.getSecondarySelectValue('catValue') === 'business'; 1519fb726d48Sopenharmony_ci if (isCategoryAsyncfunc) {//聚合异步trace 1520fb726d48Sopenharmony_ci ({ asyncRemoveCatArr, asyncCat } = this.hanldCatFunc(asyncFuncList, flag));//处理是否cat 1521fb726d48Sopenharmony_ci ({ setArrayLenThanOne, setArrayLenOnlyOne } = this.hanldAsyncFunc(it, asyncRemoveCatArr));//len等于0和大于0的分类 1522fb726d48Sopenharmony_ci //@ts-ignore 1523fb726d48Sopenharmony_ci let aggregateData = {...setArrayLenThanOne, ...setArrayLenOnlyOne }; 1524fb726d48Sopenharmony_ci Reflect.ownKeys(aggregateData).map((key: unknown) => { 1525fb726d48Sopenharmony_ci let param: Array<unknown> = aggregateData[key]; 1526fb726d48Sopenharmony_ci //@ts-ignore 1527fb726d48Sopenharmony_ci this.makeAddAsyncFunction(param, it, processRow, key); 1528fb726d48Sopenharmony_ci }); 1529fb726d48Sopenharmony_ci //@ts-ignore 1530fb726d48Sopenharmony_ci Reflect.ownKeys(asyncCat).map((key: unknown) => { 1531fb726d48Sopenharmony_ci //@ts-ignore 1532fb726d48Sopenharmony_ci let param: Array<unknown> = asyncCat[key]; 1533fb726d48Sopenharmony_ci if (flag) {//处理business 1534fb726d48Sopenharmony_ci //@ts-ignore 1535fb726d48Sopenharmony_ci this.makeAddAsyncFunction(param, it, processRow, key); 1536fb726d48Sopenharmony_ci } else {//处理thread 1537fb726d48Sopenharmony_ci //@ts-ignore 1538fb726d48Sopenharmony_ci this.makeAddAsyncFunction(param, it, processRow, key, param[0].tid); 1539fb726d48Sopenharmony_ci } 1540fb726d48Sopenharmony_ci }); 1541fb726d48Sopenharmony_ci } else { 1542fb726d48Sopenharmony_ci //不聚合异步trace 1543fb726d48Sopenharmony_ci let asyncFuncGroup = Utils.groupBy(asyncFuncList, 'funName'); 1544fb726d48Sopenharmony_ci //@ts-ignore 1545fb726d48Sopenharmony_ci Reflect.ownKeys(asyncFuncGroup).map((key: unknown) => { 1546fb726d48Sopenharmony_ci //@ts-ignore 1547fb726d48Sopenharmony_ci let asyncFunctions: Array<unknown> = asyncFuncGroup[key]; 1548fb726d48Sopenharmony_ci if (asyncFunctions.length > 0) { 1549fb726d48Sopenharmony_ci let isIntersect = (a: unknown, b: unknown): boolean => 1550fb726d48Sopenharmony_ci // @ts-ignore 1551fb726d48Sopenharmony_ci Math.max(a.startTs + a.dur, b.startTs + b.dur) - Math.min(a.startTs, b.startTs) < a.dur + b.dur; 1552fb726d48Sopenharmony_ci let depthArray: unknown = []; 1553fb726d48Sopenharmony_ci asyncFunctions.forEach((it, i) => { 1554fb726d48Sopenharmony_ci // @ts-ignore 1555fb726d48Sopenharmony_ci if (it.dur === -1 || it.dur === null || it.dur === undefined) { 1556fb726d48Sopenharmony_ci // @ts-ignore 1557fb726d48Sopenharmony_ci it.dur = (TraceRow.range?.endNS || 0) - it.startTs; 1558fb726d48Sopenharmony_ci // @ts-ignore 1559fb726d48Sopenharmony_ci it.flag = 'Did not end'; 1560fb726d48Sopenharmony_ci } 1561fb726d48Sopenharmony_ci let currentDepth = 0; 1562fb726d48Sopenharmony_ci let index = i; 1563fb726d48Sopenharmony_ci while ( 1564fb726d48Sopenharmony_ci // @ts-ignore 1565fb726d48Sopenharmony_ci depthArray[currentDepth] !== undefined && 1566fb726d48Sopenharmony_ci // @ts-ignore 1567fb726d48Sopenharmony_ci isIntersect(depthArray[currentDepth], asyncFunctions[index]) 1568fb726d48Sopenharmony_ci ) { 1569fb726d48Sopenharmony_ci currentDepth++; 1570fb726d48Sopenharmony_ci } 1571fb726d48Sopenharmony_ci // @ts-ignore 1572fb726d48Sopenharmony_ci asyncFunctions[index].depth = currentDepth; 1573fb726d48Sopenharmony_ci // @ts-ignore 1574fb726d48Sopenharmony_ci depthArray[currentDepth] = asyncFunctions[index]; 1575fb726d48Sopenharmony_ci // @ts-ignore 1576fb726d48Sopenharmony_ci //处理缓存的异步trace数据缺失的字段 1577fb726d48Sopenharmony_ci this.toAsyncFuncCache(asyncFunctions[index], `${asyncFunctions[i].funName}-${it.pid}`); 1578fb726d48Sopenharmony_ci }); 1579fb726d48Sopenharmony_ci } 1580fb726d48Sopenharmony_ci //@ts-ignore 1581fb726d48Sopenharmony_ci this.lanesConfig(asyncFunctions, it, processRow, `${asyncFunctions[0].funName}`); 1582fb726d48Sopenharmony_ci }); 1583fb726d48Sopenharmony_ci } 1584fb726d48Sopenharmony_ci } 1585fb726d48Sopenharmony_ci //处理CategoryAsyncFunc 1586fb726d48Sopenharmony_ci hanldCatFunc( 1587fb726d48Sopenharmony_ci asyncFuncList: Array<unknown>, 1588fb726d48Sopenharmony_ci flag: boolean 1589fb726d48Sopenharmony_ci ): { asyncRemoveCatArr: Array<unknown>, asyncCat: unknown } { 1590fb726d48Sopenharmony_ci let asyncCat; 1591fb726d48Sopenharmony_ci let asyncCatArr = new Array(); 1592fb726d48Sopenharmony_ci let asyncCatMap: Map<string, unknown> = new Map<string, unknown>(); 1593fb726d48Sopenharmony_ci let asyncRemoveCatArr = new Array(); 1594fb726d48Sopenharmony_ci //取出cat字段(category)不为null的数据 1595fb726d48Sopenharmony_ci for (let i = 0; i < asyncFuncList.length; i++) { 1596fb726d48Sopenharmony_ci const el = asyncFuncList[i]; 1597fb726d48Sopenharmony_ci // @ts-ignore 1598fb726d48Sopenharmony_ci if (el.cat !== null) { 1599fb726d48Sopenharmony_ci if (flag) {//business first 1600fb726d48Sopenharmony_ci asyncCatArr.push(el); 1601fb726d48Sopenharmony_ci } else {//thread first 1602fb726d48Sopenharmony_ci //@ts-ignore 1603fb726d48Sopenharmony_ci if (asyncCatMap.has(`${el.cat}:${el.threadName} ${el.tid}`)) { 1604fb726d48Sopenharmony_ci //@ts-ignore 1605fb726d48Sopenharmony_ci let item: Array<unknown> = asyncCatMap.get(`${el.cat}:${el.threadName} ${el.tid}`); 1606fb726d48Sopenharmony_ci item.push(el); 1607fb726d48Sopenharmony_ci } else { 1608fb726d48Sopenharmony_ci //@ts-ignore 1609fb726d48Sopenharmony_ci asyncCatMap.set(`${el.cat}:${el.threadName} ${el.tid}`, [el]); 1610fb726d48Sopenharmony_ci } 1611fb726d48Sopenharmony_ci } 1612fb726d48Sopenharmony_ci } else { 1613fb726d48Sopenharmony_ci //取cat字段为null的数据 1614fb726d48Sopenharmony_ci asyncRemoveCatArr.push(el); 1615fb726d48Sopenharmony_ci } 1616fb726d48Sopenharmony_ci } 1617fb726d48Sopenharmony_ci asyncCat = flag ? Utils.groupBy(asyncCatArr, 'cat') : Object.fromEntries(asyncCatMap); 1618fb726d48Sopenharmony_ci return { asyncRemoveCatArr, asyncCat }; 1619fb726d48Sopenharmony_ci } 1620fb726d48Sopenharmony_ci //处理cat字段为null的数据,按funname分类,分别按len>1和=1去处理 1621fb726d48Sopenharmony_ci hanldAsyncFunc( 1622fb726d48Sopenharmony_ci it: { pid: number; processName: string | null }, 1623fb726d48Sopenharmony_ci asyncRemoveCatList: Array<unknown> 1624fb726d48Sopenharmony_ci ): { setArrayLenThanOne: unknown, setArrayLenOnlyOne: unknown } { 1625fb726d48Sopenharmony_ci let asyncFuncGroup = Utils.groupBy(asyncRemoveCatList, 'funName'); 1626fb726d48Sopenharmony_ci let funcArr: unknown[] = []; 1627fb726d48Sopenharmony_ci let setArrayLenThanOne: unknown = {}; 1628fb726d48Sopenharmony_ci let setArrayLenOnlyOne: unknown = {}; 1629fb726d48Sopenharmony_ci //@ts-ignore 1630fb726d48Sopenharmony_ci Reflect.ownKeys(asyncFuncGroup).map((key: unknown) => { 1631fb726d48Sopenharmony_ci //@ts-ignore 1632fb726d48Sopenharmony_ci let asyncFunctions: Array<unknown> = asyncFuncGroup[key]; 1633fb726d48Sopenharmony_ci if (asyncFunctions.length > 1) { 1634fb726d48Sopenharmony_ci //@ts-ignore 1635fb726d48Sopenharmony_ci setArrayLenThanOne[key] = asyncFunctions; 1636fb726d48Sopenharmony_ci } else if (asyncFunctions.length === 1) { 1637fb726d48Sopenharmony_ci funcArr.push(...asyncFunctions); 1638fb726d48Sopenharmony_ci } 1639fb726d48Sopenharmony_ci }); 1640fb726d48Sopenharmony_ci //len=1的数据继续按tid分类 1641fb726d48Sopenharmony_ci let asyncFuncTidGroup = Utils.groupBy(funcArr, 'tid'); 1642fb726d48Sopenharmony_ci //@ts-ignore 1643fb726d48Sopenharmony_ci Reflect.ownKeys(asyncFuncTidGroup).map((key: unknown) => { 1644fb726d48Sopenharmony_ci //@ts-ignore 1645fb726d48Sopenharmony_ci let asyncTidFunc: Array<unknown> = asyncFuncTidGroup[key]; 1646fb726d48Sopenharmony_ci //@ts-ignore 1647fb726d48Sopenharmony_ci setArrayLenOnlyOne[`H:${asyncTidFunc[0].threadName} ${asyncTidFunc[0].tid}`] = asyncTidFunc; 1648fb726d48Sopenharmony_ci }); 1649fb726d48Sopenharmony_ci return { setArrayLenThanOne, setArrayLenOnlyOne }; 1650fb726d48Sopenharmony_ci } 1651fb726d48Sopenharmony_ci makeAddAsyncFunction( 1652fb726d48Sopenharmony_ci asyncFunctions: unknown[], 1653fb726d48Sopenharmony_ci it: { pid: number; processName: string | null }, 1654fb726d48Sopenharmony_ci processRow: TraceRow<ProcessStruct>, 1655fb726d48Sopenharmony_ci key: string, 1656fb726d48Sopenharmony_ci rowSingleTid?: number 1657fb726d48Sopenharmony_ci ): void { 1658fb726d48Sopenharmony_ci let maxDepth: number = -1; 1659fb726d48Sopenharmony_ci let i = 0; 1660fb726d48Sopenharmony_ci let mapDepth = new Map(); 1661fb726d48Sopenharmony_ci let noEndData = new Array(); 1662fb726d48Sopenharmony_ci let normalData = new Array(); 1663fb726d48Sopenharmony_ci if (asyncFunctions.length) { 1664fb726d48Sopenharmony_ci while (i < asyncFunctions.length) { 1665fb726d48Sopenharmony_ci let param = asyncFunctions[i]; 1666fb726d48Sopenharmony_ci // @ts-ignore 1667fb726d48Sopenharmony_ci if (param.dur !== null) { 1668fb726d48Sopenharmony_ci // @ts-ignore 1669fb726d48Sopenharmony_ci let itemEndTime = param.startTs + param.dur; 1670fb726d48Sopenharmony_ci let flag = false; 1671fb726d48Sopenharmony_ci for (let [key, val] of mapDepth.entries()) { 1672fb726d48Sopenharmony_ci // @ts-ignore 1673fb726d48Sopenharmony_ci if (val.et < param.startTs) { 1674fb726d48Sopenharmony_ci flag = true; 1675fb726d48Sopenharmony_ci //更新endts 1676fb726d48Sopenharmony_ci val.et = itemEndTime; 1677fb726d48Sopenharmony_ci // @ts-ignore 1678fb726d48Sopenharmony_ci param.depth = Number(key); 1679fb726d48Sopenharmony_ci break; 1680fb726d48Sopenharmony_ci } 1681fb726d48Sopenharmony_ci } 1682fb726d48Sopenharmony_ci if (!flag) { 1683fb726d48Sopenharmony_ci //depth增加 1684fb726d48Sopenharmony_ci maxDepth++; 1685fb726d48Sopenharmony_ci mapDepth.set(`${maxDepth}`, { et: itemEndTime }); 1686fb726d48Sopenharmony_ci // @ts-ignore 1687fb726d48Sopenharmony_ci param.depth = maxDepth; 1688fb726d48Sopenharmony_ci } 1689fb726d48Sopenharmony_ci this.toAsyncFuncCache(param, `${key}-${it.pid}`); 1690fb726d48Sopenharmony_ci normalData.push(param); 1691fb726d48Sopenharmony_ci } else { 1692fb726d48Sopenharmony_ci noEndData.push(param); 1693fb726d48Sopenharmony_ci } 1694fb726d48Sopenharmony_ci i++; 1695fb726d48Sopenharmony_ci } 1696fb726d48Sopenharmony_ci if (noEndData.length) { 1697fb726d48Sopenharmony_ci noEndData.forEach((it: unknown, i: unknown) => { 1698fb726d48Sopenharmony_ci // @ts-ignore 1699fb726d48Sopenharmony_ci if (it.dur === -1 || it.dur === null || it.dur === undefined) { 1700fb726d48Sopenharmony_ci // @ts-ignore 1701fb726d48Sopenharmony_ci it.dur = (TraceRow.range?.endNS || 0) - it.startTs; 1702fb726d48Sopenharmony_ci // @ts-ignore 1703fb726d48Sopenharmony_ci it.nofinish = true; 1704fb726d48Sopenharmony_ci // @ts-ignore 1705fb726d48Sopenharmony_ci it.flag = 'Did not end'; 1706fb726d48Sopenharmony_ci } 1707fb726d48Sopenharmony_ci let index = i; 1708fb726d48Sopenharmony_ci maxDepth++; 1709fb726d48Sopenharmony_ci // @ts-ignore 1710fb726d48Sopenharmony_ci noEndData[index].depth = maxDepth; 1711fb726d48Sopenharmony_ci //@ts-ignore 1712fb726d48Sopenharmony_ci this.toAsyncFuncCache(noEndData[index], `${key}-${it.pid}`); 1713fb726d48Sopenharmony_ci }); 1714fb726d48Sopenharmony_ci } 1715fb726d48Sopenharmony_ci this.lanesConfig([...normalData, ...noEndData], it, processRow, key, rowSingleTid); 1716fb726d48Sopenharmony_ci } 1717fb726d48Sopenharmony_ci } 1718fb726d48Sopenharmony_ci //初始化异步泳道信息 1719fb726d48Sopenharmony_ci lanesConfig( 1720fb726d48Sopenharmony_ci asyncFunctions: unknown[], 1721fb726d48Sopenharmony_ci it: { pid: number; processName: string | null }, 1722fb726d48Sopenharmony_ci processRow: TraceRow<ProcessStruct>, 1723fb726d48Sopenharmony_ci key: string, 1724fb726d48Sopenharmony_ci rowSingleTid?: number 1725fb726d48Sopenharmony_ci ): void { 1726fb726d48Sopenharmony_ci const maxHeight = this.calMaxHeight(asyncFunctions); 1727fb726d48Sopenharmony_ci // @ts-ignore 1728fb726d48Sopenharmony_ci const namesSet = new Set(asyncFunctions.map((item) => item.funName)); 1729fb726d48Sopenharmony_ci const asyncFuncName = Array.from(namesSet); 1730fb726d48Sopenharmony_ci let funcRow = TraceRow.skeleton<FuncStruct>(); 1731fb726d48Sopenharmony_ci funcRow.rowId = `${key}-${it.pid}`; 1732fb726d48Sopenharmony_ci funcRow.asyncFuncName = asyncFuncName; 1733fb726d48Sopenharmony_ci funcRow.asyncFuncNamePID = it.pid; 1734fb726d48Sopenharmony_ci funcRow.asyncFuncStartTID = rowSingleTid ? rowSingleTid : undefined; 1735fb726d48Sopenharmony_ci funcRow.rowType = TraceRow.ROW_TYPE_FUNC; 1736fb726d48Sopenharmony_ci funcRow.enableCollapseChart(FOLD_HEIGHT, this.trace); //允许折叠泳道图 1737fb726d48Sopenharmony_ci funcRow.rowParentId = `${it.pid}`; 1738fb726d48Sopenharmony_ci funcRow.rowHidden = !processRow.expansion; 1739fb726d48Sopenharmony_ci funcRow.style.width = '100%'; 1740fb726d48Sopenharmony_ci funcRow.style.height = `${maxHeight}px`; 1741fb726d48Sopenharmony_ci funcRow.setAttribute('height', `${maxHeight}`); 1742fb726d48Sopenharmony_ci funcRow.name = key; 1743fb726d48Sopenharmony_ci funcRow.setAttribute('children', ''); 1744fb726d48Sopenharmony_ci funcRow.findHoverStruct = (): void => { 1745fb726d48Sopenharmony_ci FuncStruct.hoverFuncStruct = funcRow.getHoverStruct(); 1746fb726d48Sopenharmony_ci }; 1747fb726d48Sopenharmony_ci // @ts-ignore 1748fb726d48Sopenharmony_ci funcRow.supplier = (): Promise<unknown> => new Promise((resolve) => resolve(asyncFunctions)); 1749fb726d48Sopenharmony_ci funcRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 1750fb726d48Sopenharmony_ci funcRow.selectChangeHandler = this.trace.selectChangeHandler; 1751fb726d48Sopenharmony_ci funcRow.onThreadHandler = rowThreadHandler<FuncRender>( 1752fb726d48Sopenharmony_ci 'func', 1753fb726d48Sopenharmony_ci 'context', 1754fb726d48Sopenharmony_ci { 1755fb726d48Sopenharmony_ci type: `func-${funcRow.rowId}`, 1756fb726d48Sopenharmony_ci }, 1757fb726d48Sopenharmony_ci funcRow, 1758fb726d48Sopenharmony_ci this.trace 1759fb726d48Sopenharmony_ci ); 1760fb726d48Sopenharmony_ci processRow.addChildTraceRow(funcRow); 1761fb726d48Sopenharmony_ci } 1762fb726d48Sopenharmony_ci 1763fb726d48Sopenharmony_ci addAsyncCatFunction(it: { pid: number; processName: string | null }, processRow: TraceRow<ProcessStruct>): void { 1764fb726d48Sopenharmony_ci //@ts-ignore 1765fb726d48Sopenharmony_ci let asyncFuncCatList = this.processAsyncFuncCatMap[it.pid] || []; 1766fb726d48Sopenharmony_ci let asyncFuncGroup: unknown = Utils.groupBy(asyncFuncCatList, 'threadName'); 1767fb726d48Sopenharmony_ci //@ts-ignore 1768fb726d48Sopenharmony_ci Reflect.ownKeys(asyncFuncGroup).map((key: unknown) => { 1769fb726d48Sopenharmony_ci //@ts-ignore 1770fb726d48Sopenharmony_ci let asyncFunctions: Array<unknown> = asyncFuncGroup[key]; 1771fb726d48Sopenharmony_ci if (asyncFunctions.length > 0) { 1772fb726d48Sopenharmony_ci let isIntersect = (a: unknown, b: unknown): boolean => 1773fb726d48Sopenharmony_ci //@ts-ignore 1774fb726d48Sopenharmony_ci Math.max(a.startTs + a.dur, b.startTs + b.dur) - Math.min(a.startTs, b.startTs) < a.dur + b.dur; 1775fb726d48Sopenharmony_ci let depthArray: unknown = []; 1776fb726d48Sopenharmony_ci asyncFunctions.forEach((it, i) => { 1777fb726d48Sopenharmony_ci //@ts-ignore 1778fb726d48Sopenharmony_ci if (it.dur === -1 || it.dur === null || it.dur === undefined) { 1779fb726d48Sopenharmony_ci //@ts-ignore 1780fb726d48Sopenharmony_ci it.dur = (TraceRow.range?.endNS || 0) - it.startTs; 1781fb726d48Sopenharmony_ci //@ts-ignore 1782fb726d48Sopenharmony_ci it.flag = 'Did not end'; 1783fb726d48Sopenharmony_ci //@ts-ignore 1784fb726d48Sopenharmony_ci it.nofinish = true; 1785fb726d48Sopenharmony_ci } 1786fb726d48Sopenharmony_ci let currentDepth = 0; 1787fb726d48Sopenharmony_ci let index = i; 1788fb726d48Sopenharmony_ci //@ts-ignore 1789fb726d48Sopenharmony_ci while (depthArray[currentDepth] !== undefined && isIntersect(depthArray[currentDepth], asyncFunctions[index])) { 1790fb726d48Sopenharmony_ci currentDepth++; 1791fb726d48Sopenharmony_ci }//@ts-ignore 1792fb726d48Sopenharmony_ci asyncFunctions[index].depth = currentDepth; 1793fb726d48Sopenharmony_ci //@ts-ignore 1794fb726d48Sopenharmony_ci depthArray[currentDepth] = asyncFunctions[index]; 1795fb726d48Sopenharmony_ci //@ts-ignore 1796fb726d48Sopenharmony_ci this.toAsyncFuncCache(asyncFunctions[index], `${asyncFunctions[0].threadName}`); 1797fb726d48Sopenharmony_ci }); 1798fb726d48Sopenharmony_ci const maxHeight = this.calMaxHeight(asyncFunctions); 1799fb726d48Sopenharmony_ci let funcRow = TraceRow.skeleton<FuncStruct>(); 1800fb726d48Sopenharmony_ci //@ts-ignore 1801fb726d48Sopenharmony_ci funcRow.rowId = `${asyncFunctions[0].threadName}`; 1802fb726d48Sopenharmony_ci //@ts-ignore 1803fb726d48Sopenharmony_ci funcRow.asyncFuncThreadName = asyncFunctions[0].threadName; 1804fb726d48Sopenharmony_ci funcRow.asyncFuncNamePID = it.pid; 1805fb726d48Sopenharmony_ci funcRow.rowType = TraceRow.ROW_TYPE_FUNC; 1806fb726d48Sopenharmony_ci funcRow.enableCollapseChart(FOLD_HEIGHT, this.trace); 1807fb726d48Sopenharmony_ci //允许折叠泳道图 1808fb726d48Sopenharmony_ci funcRow.rowParentId = `${it.pid}`; 1809fb726d48Sopenharmony_ci funcRow.rowHidden = !processRow.expansion; 1810fb726d48Sopenharmony_ci funcRow.style.width = '100%'; 1811fb726d48Sopenharmony_ci funcRow.style.height = `${maxHeight}px`; 1812fb726d48Sopenharmony_ci funcRow.setAttribute('height', `${maxHeight}`); 1813fb726d48Sopenharmony_ci //@ts-ignore 1814fb726d48Sopenharmony_ci funcRow.name = `${asyncFunctions[0].threadName}`; 1815fb726d48Sopenharmony_ci funcRow.setAttribute('children', ''); 1816fb726d48Sopenharmony_ci funcRow.findHoverStruct = (): void => { 1817fb726d48Sopenharmony_ci FuncStruct.hoverFuncStruct = funcRow.getHoverStruct(); 1818fb726d48Sopenharmony_ci }; 1819fb726d48Sopenharmony_ci //@ts-ignore 1820fb726d48Sopenharmony_ci funcRow.supplier = (): Promise<unknown> => new Promise((resolve) => resolve(asyncFunctions)); 1821fb726d48Sopenharmony_ci funcRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; 1822fb726d48Sopenharmony_ci funcRow.selectChangeHandler = this.trace.selectChangeHandler; 1823fb726d48Sopenharmony_ci funcRow.onThreadHandler = rowThreadHandler<FuncRender>('func', 'context', { 1824fb726d48Sopenharmony_ci //@ts-ignore 1825fb726d48Sopenharmony_ci type: `func-${asyncFunctions[0].threadName}-${it.pid}`, 1826fb726d48Sopenharmony_ci }, funcRow, this.trace); 1827fb726d48Sopenharmony_ci processRow.addChildTraceRow(funcRow); 1828fb726d48Sopenharmony_ci } 1829fb726d48Sopenharmony_ci }); 1830fb726d48Sopenharmony_ci } 1831fb726d48Sopenharmony_ci} 1832