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 { SpHiPerf } from './SpHiPerf'; 18fb726d48Sopenharmony_ciimport { SpCpuChart } from './SpCpuChart'; 19fb726d48Sopenharmony_ciimport { SpFreqChart } from './SpFreqChart'; 20fb726d48Sopenharmony_ciimport { SpFpsChart } from './SpFpsChart'; 21fb726d48Sopenharmony_ciimport { info } from '../../../log/Log'; 22fb726d48Sopenharmony_ciimport { SpNativeMemoryChart } from './SpNativeMemoryChart'; 23fb726d48Sopenharmony_ciimport { SpAbilityMonitorChart } from './SpAbilityMonitorChart'; 24fb726d48Sopenharmony_ciimport { SpProcessChart } from './SpProcessChart'; 25fb726d48Sopenharmony_ciimport { perfDataQuery } from './PerfDataQuery'; 26fb726d48Sopenharmony_ciimport { SpVirtualMemChart } from './SpVirtualMemChart'; 27fb726d48Sopenharmony_ciimport { SpEBPFChart } from './SpEBPFChart'; 28fb726d48Sopenharmony_ciimport { SpSdkChart } from './SpSdkChart'; 29fb726d48Sopenharmony_ciimport { SpHiSysEnergyChart } from './SpHiSysEnergyChart'; 30fb726d48Sopenharmony_ciimport { VmTrackerChart } from './SpVmTrackerChart'; 31fb726d48Sopenharmony_ciimport { SpClockChart } from './SpClockChart'; 32fb726d48Sopenharmony_ciimport { SpXpowerChart } from './SpXpowerChart'; 33fb726d48Sopenharmony_ciimport { SpIrqChart } from './SpIrqChart'; 34fb726d48Sopenharmony_ciimport { renders } from '../../database/ui-worker/ProcedureWorker'; 35fb726d48Sopenharmony_ciimport { EmptyRender } from '../../database/ui-worker/cpu/ProcedureWorkerCPU'; 36fb726d48Sopenharmony_ciimport { TraceRow } from '../trace/base/TraceRow'; 37fb726d48Sopenharmony_ciimport { SpFrameTimeChart } from './SpFrameTimeChart'; 38fb726d48Sopenharmony_ciimport { Utils } from '../trace/base/Utils'; 39fb726d48Sopenharmony_ciimport { SpArkTsChart } from './SpArkTsChart'; 40fb726d48Sopenharmony_ciimport { MemoryConfig } from '../../bean/MemoryConfig'; 41fb726d48Sopenharmony_ciimport { FlagsConfig } from '../SpFlags'; 42fb726d48Sopenharmony_ciimport { SpLogChart } from './SpLogChart'; 43fb726d48Sopenharmony_ciimport { SpHiSysEventChart } from './SpHiSysEventChart'; 44fb726d48Sopenharmony_ciimport { SpAllAppStartupsChart } from './SpAllAppStartups'; 45fb726d48Sopenharmony_ciimport { procedurePool } from '../../database/Procedure'; 46fb726d48Sopenharmony_ciimport { SpSegmentationChart } from './SpSegmentationChart'; 47fb726d48Sopenharmony_ciimport { SpHangChart } from './SpHangChart'; 48fb726d48Sopenharmony_ciimport { SpPerfOutputDataChart } from './SpPerfOutputDataChart'; 49fb726d48Sopenharmony_ciimport { 50fb726d48Sopenharmony_ci queryAppStartupProcessIds, 51fb726d48Sopenharmony_ci queryDataDICT, 52fb726d48Sopenharmony_ci queryThreadAndProcessName, 53fb726d48Sopenharmony_ci} from '../../database/sql/ProcessThread.sql'; 54fb726d48Sopenharmony_ciimport { queryTaskPoolCallStack, queryTotalTime } from '../../database/sql/SqlLite.sql'; 55fb726d48Sopenharmony_ciimport { queryMemoryConfig } from '../../database/sql/Memory.sql'; 56fb726d48Sopenharmony_ciimport { SpLtpoChart } from './SpLTPO'; 57fb726d48Sopenharmony_ciimport { SpBpftraceChart } from './SpBpftraceChart'; 58fb726d48Sopenharmony_ciimport { sliceSender } from '../../database/data-trafic/SliceSender'; 59fb726d48Sopenharmony_ciimport { BaseStruct } from '../../bean/BaseStruct'; 60fb726d48Sopenharmony_ciimport { SpGpuCounterChart } from './SpGpuCounterChart'; 61fb726d48Sopenharmony_ciimport { SpUserFileChart } from './SpUserPluginChart'; 62fb726d48Sopenharmony_ciimport { SpImportUserPluginsChart } from './SpImportUserPluginsChart'; 63fb726d48Sopenharmony_ciimport { queryDmaFenceIdAndCat } from '../../database/sql/dmaFence.sql'; 64fb726d48Sopenharmony_ciimport { queryAllFuncNames } from '../../database/sql/Func.sql'; 65fb726d48Sopenharmony_ci 66fb726d48Sopenharmony_ciexport class SpChartManager { 67fb726d48Sopenharmony_ci static APP_STARTUP_PID_ARR: Array<number> = []; 68fb726d48Sopenharmony_ci 69fb726d48Sopenharmony_ci private trace: SpSystemTrace; 70fb726d48Sopenharmony_ci public perf: SpHiPerf; 71fb726d48Sopenharmony_ci private cpu: SpCpuChart; 72fb726d48Sopenharmony_ci private freq: SpFreqChart; 73fb726d48Sopenharmony_ci private virtualMemChart: SpVirtualMemChart; 74fb726d48Sopenharmony_ci private fps: SpFpsChart; 75fb726d48Sopenharmony_ci private nativeMemory: SpNativeMemoryChart; 76fb726d48Sopenharmony_ci private abilityMonitor: SpAbilityMonitorChart; 77fb726d48Sopenharmony_ci private process: SpProcessChart; 78fb726d48Sopenharmony_ci private process2?: SpProcessChart; 79fb726d48Sopenharmony_ci private fileSystem: SpEBPFChart; 80fb726d48Sopenharmony_ci private sdkChart: SpSdkChart; 81fb726d48Sopenharmony_ci private hiSyseventChart: SpHiSysEnergyChart; 82fb726d48Sopenharmony_ci private smapsChart: VmTrackerChart; 83fb726d48Sopenharmony_ci private clockChart: SpClockChart; 84fb726d48Sopenharmony_ci private xpowerChart: SpXpowerChart; 85fb726d48Sopenharmony_ci private irqChart: SpIrqChart; 86fb726d48Sopenharmony_ci private spAllAppStartupsChart!: SpAllAppStartupsChart; 87fb726d48Sopenharmony_ci private SpLtpoChart!: SpLtpoChart; 88fb726d48Sopenharmony_ci frameTimeChart: SpFrameTimeChart; 89fb726d48Sopenharmony_ci public arkTsChart: SpArkTsChart; 90fb726d48Sopenharmony_ci private logChart: SpLogChart; 91fb726d48Sopenharmony_ci private spHiSysEvent: SpHiSysEventChart; 92fb726d48Sopenharmony_ci private spSegmentationChart: SpSegmentationChart; 93fb726d48Sopenharmony_ci private hangChart: SpHangChart; 94fb726d48Sopenharmony_ci private spBpftraceChart: SpBpftraceChart; 95fb726d48Sopenharmony_ci private spPerfOutputDataChart: SpPerfOutputDataChart; 96fb726d48Sopenharmony_ci private spGpuCounterChart: SpGpuCounterChart; 97fb726d48Sopenharmony_ci private spUserFileChart: SpUserFileChart; 98fb726d48Sopenharmony_ci private spImportUserPluginsChart: SpImportUserPluginsChart; 99fb726d48Sopenharmony_ci 100fb726d48Sopenharmony_ci constructor(trace: SpSystemTrace) { 101fb726d48Sopenharmony_ci this.trace = trace; 102fb726d48Sopenharmony_ci this.perf = new SpHiPerf(trace); 103fb726d48Sopenharmony_ci this.fileSystem = new SpEBPFChart(trace); 104fb726d48Sopenharmony_ci this.cpu = new SpCpuChart(trace); 105fb726d48Sopenharmony_ci this.freq = new SpFreqChart(trace); 106fb726d48Sopenharmony_ci this.virtualMemChart = new SpVirtualMemChart(trace); 107fb726d48Sopenharmony_ci this.fps = new SpFpsChart(trace); 108fb726d48Sopenharmony_ci this.nativeMemory = new SpNativeMemoryChart(trace); 109fb726d48Sopenharmony_ci this.abilityMonitor = new SpAbilityMonitorChart(trace); 110fb726d48Sopenharmony_ci this.process = new SpProcessChart(trace); 111fb726d48Sopenharmony_ci this.sdkChart = new SpSdkChart(trace); 112fb726d48Sopenharmony_ci this.hiSyseventChart = new SpHiSysEnergyChart(trace); 113fb726d48Sopenharmony_ci this.smapsChart = new VmTrackerChart(trace); 114fb726d48Sopenharmony_ci this.clockChart = new SpClockChart(trace); 115fb726d48Sopenharmony_ci this.irqChart = new SpIrqChart(trace); 116fb726d48Sopenharmony_ci this.frameTimeChart = new SpFrameTimeChart(trace); 117fb726d48Sopenharmony_ci this.arkTsChart = new SpArkTsChart(trace); 118fb726d48Sopenharmony_ci this.logChart = new SpLogChart(trace); 119fb726d48Sopenharmony_ci this.spHiSysEvent = new SpHiSysEventChart(trace); 120fb726d48Sopenharmony_ci this.spAllAppStartupsChart = new SpAllAppStartupsChart(trace); 121fb726d48Sopenharmony_ci this.SpLtpoChart = new SpLtpoChart(trace); 122fb726d48Sopenharmony_ci this.spSegmentationChart = new SpSegmentationChart(trace); 123fb726d48Sopenharmony_ci this.hangChart = new SpHangChart(trace); 124fb726d48Sopenharmony_ci this.spBpftraceChart = new SpBpftraceChart(trace); 125fb726d48Sopenharmony_ci this.spPerfOutputDataChart = new SpPerfOutputDataChart(trace); 126fb726d48Sopenharmony_ci this.spGpuCounterChart = new SpGpuCounterChart(trace); 127fb726d48Sopenharmony_ci this.spUserFileChart = new SpUserFileChart(trace); 128fb726d48Sopenharmony_ci this.spImportUserPluginsChart = new SpImportUserPluginsChart(trace); 129fb726d48Sopenharmony_ci this.xpowerChart = new SpXpowerChart(trace); 130fb726d48Sopenharmony_ci } 131fb726d48Sopenharmony_ci async initPreprocessData(progress: Function): Promise<void> { 132fb726d48Sopenharmony_ci progress('load data dict', 50); 133fb726d48Sopenharmony_ci this.process2 = undefined; 134fb726d48Sopenharmony_ci SpSystemTrace.DATA_DICT.clear(); 135fb726d48Sopenharmony_ci SpChartManager.APP_STARTUP_PID_ARR = []; 136fb726d48Sopenharmony_ci let dict = await queryDataDICT(); 137fb726d48Sopenharmony_ci if (FlagsConfig.getFlagsConfigEnableStatus('AppStartup')) { 138fb726d48Sopenharmony_ci let appStartUpPids = await queryAppStartupProcessIds(); 139fb726d48Sopenharmony_ci appStartUpPids.forEach((it) => SpChartManager.APP_STARTUP_PID_ARR.push(it.pid)); 140fb726d48Sopenharmony_ci } 141fb726d48Sopenharmony_ci await this.initTraceConfig(); //@ts-ignore 142fb726d48Sopenharmony_ci dict.map((d) => SpSystemTrace.DATA_DICT.set(d.id, d.data)); 143fb726d48Sopenharmony_ci await this.cacheDataDictToWorker(); 144fb726d48Sopenharmony_ci SpSystemTrace.DATA_TASK_POOL_CALLSTACK.clear(); 145fb726d48Sopenharmony_ci let taskPoolCallStack = await queryTaskPoolCallStack(); 146fb726d48Sopenharmony_ci taskPoolCallStack.map((d) => SpSystemTrace.DATA_TASK_POOL_CALLSTACK.set(d.id, d)); 147fb726d48Sopenharmony_ci progress('time range', 65); 148fb726d48Sopenharmony_ci await this.initTotalTime(); 149fb726d48Sopenharmony_ci let ptArr = await queryThreadAndProcessName(); //@ts-ignore 150fb726d48Sopenharmony_ci this.handleProcessThread(ptArr); 151fb726d48Sopenharmony_ci info('initData timerShaftEL Data initialized'); 152fb726d48Sopenharmony_ci let funArr = await queryAllFuncNames(); 153fb726d48Sopenharmony_ci this.handleFuncName(funArr); 154fb726d48Sopenharmony_ci } 155fb726d48Sopenharmony_ci 156fb726d48Sopenharmony_ci async initCpu(progress: Function): Promise<void> { 157fb726d48Sopenharmony_ci progress('cpu', 70); 158fb726d48Sopenharmony_ci let result = await sliceSender(); 159fb726d48Sopenharmony_ci // @ts-ignore 160fb726d48Sopenharmony_ci SpProcessChart.threadStateList = result.threadMap; 161fb726d48Sopenharmony_ci // @ts-ignore 162fb726d48Sopenharmony_ci SpProcessChart.processRowSortMap = result.processRowSortMap; 163fb726d48Sopenharmony_ci //@ts-ignore 164fb726d48Sopenharmony_ci await this.cpu.init(result.count.cpu); 165fb726d48Sopenharmony_ci info('initData cpu Data initialized'); 166fb726d48Sopenharmony_ci if (FlagsConfig.getFlagsConfigEnableStatus('Bpftrace')) { 167fb726d48Sopenharmony_ci await this.spBpftraceChart.init(null); 168fb726d48Sopenharmony_ci } 169fb726d48Sopenharmony_ci if (FlagsConfig.getFlagsConfigEnableStatus('UserPluginsRow')) { 170fb726d48Sopenharmony_ci await this.spUserFileChart.init(null) 171fb726d48Sopenharmony_ci await this.spImportUserPluginsChart.init(); 172fb726d48Sopenharmony_ci } 173fb726d48Sopenharmony_ci if (FlagsConfig.getFlagsConfigEnableStatus('GpuCounter')) { 174fb726d48Sopenharmony_ci await this.spGpuCounterChart.init([]); 175fb726d48Sopenharmony_ci } 176fb726d48Sopenharmony_ci if (FlagsConfig.getFlagsConfigEnableStatus('SchedulingAnalysis')) { 177fb726d48Sopenharmony_ci await this.cpu.initCpuIdle0Data(progress); 178fb726d48Sopenharmony_ci await this.cpu.initSchedulingPTData(progress); 179fb726d48Sopenharmony_ci await this.cpu.initSchedulingFreqData(progress); 180fb726d48Sopenharmony_ci } 181fb726d48Sopenharmony_ci info('initData ProcessThreadState Data initialized'); 182fb726d48Sopenharmony_ci progress('cpu rate', 75); 183fb726d48Sopenharmony_ci //@ts-ignore 184fb726d48Sopenharmony_ci await this.initCpuRate(result.cpuUtiliRateArray); 185fb726d48Sopenharmony_ci info('initData Cpu Rate Data initialized'); 186fb726d48Sopenharmony_ci progress('cpu freq', 80); 187fb726d48Sopenharmony_ci await this.freq.init(); 188fb726d48Sopenharmony_ci info('initData Cpu Freq Data initialized'); 189fb726d48Sopenharmony_ci } 190fb726d48Sopenharmony_ci 191fb726d48Sopenharmony_ci async init(progress: Function): Promise<void> { 192fb726d48Sopenharmony_ci info('initData data parse end '); 193fb726d48Sopenharmony_ci await this.initPreprocessData(progress); 194fb726d48Sopenharmony_ci await this.initCpu(progress); 195fb726d48Sopenharmony_ci await this.logChart.init(); 196fb726d48Sopenharmony_ci await this.spHiSysEvent.init(); 197fb726d48Sopenharmony_ci let idAndNameArr = await queryDmaFenceIdAndCat(); 198fb726d48Sopenharmony_ci this.handleDmaFenceName(idAndNameArr as { id: number; cat: string; seqno: number; driver: string; context: string }[]); 199fb726d48Sopenharmony_ci if (FlagsConfig.getFlagsConfigEnableStatus('Hangs Detection')) { 200fb726d48Sopenharmony_ci progress('Hang init', 80); 201fb726d48Sopenharmony_ci await this.hangChart.init(); 202fb726d48Sopenharmony_ci } 203fb726d48Sopenharmony_ci progress('Clock init', 82); 204fb726d48Sopenharmony_ci await this.clockChart.init(); 205fb726d48Sopenharmony_ci progress('Xpower init', 83); 206fb726d48Sopenharmony_ci await this.xpowerChart.init(); 207fb726d48Sopenharmony_ci progress('Irq init', 84); 208fb726d48Sopenharmony_ci await this.irqChart.init(); 209fb726d48Sopenharmony_ci progress('SpSegmentationChart inin', 84.5); 210fb726d48Sopenharmony_ci await this.spSegmentationChart.init(); 211fb726d48Sopenharmony_ci await this.virtualMemChart.init(); 212fb726d48Sopenharmony_ci progress('fps', 85); 213fb726d48Sopenharmony_ci await this.fps.init(); 214fb726d48Sopenharmony_ci progress('native memory', 87); 215fb726d48Sopenharmony_ci await this.nativeMemory.initChart(); 216fb726d48Sopenharmony_ci progress('ability monitor', 88); 217fb726d48Sopenharmony_ci await this.abilityMonitor.init(); 218fb726d48Sopenharmony_ci progress('hiSysevent', 88.2); 219fb726d48Sopenharmony_ci await this.hiSyseventChart.init(); 220fb726d48Sopenharmony_ci progress('vm tracker', 88.4); 221fb726d48Sopenharmony_ci await this.smapsChart.init(); 222fb726d48Sopenharmony_ci progress('sdk', 88.6); 223fb726d48Sopenharmony_ci await this.sdkChart.init(); 224fb726d48Sopenharmony_ci progress('perf', 88.8); 225fb726d48Sopenharmony_ci await this.perf!.init(); 226fb726d48Sopenharmony_ci await perfDataQuery.initPerfCache(); 227fb726d48Sopenharmony_ci progress('file system', 89); 228fb726d48Sopenharmony_ci await this.fileSystem!.init(); 229fb726d48Sopenharmony_ci progress('ark ts', 90); 230fb726d48Sopenharmony_ci await this.arkTsChart.initFolder(); 231fb726d48Sopenharmony_ci await this.spAllAppStartupsChart.init(); 232fb726d48Sopenharmony_ci await this.SpLtpoChart.init(); 233fb726d48Sopenharmony_ci await this.frameTimeChart.init(); 234fb726d48Sopenharmony_ci await this.spPerfOutputDataChart.init(); 235fb726d48Sopenharmony_ci progress('process', 92); 236fb726d48Sopenharmony_ci this.process.clearCache(); 237fb726d48Sopenharmony_ci this.process2?.clearCache(); 238fb726d48Sopenharmony_ci this.process2 = undefined; 239fb726d48Sopenharmony_ci await this.process.initAsyncFuncData({ 240fb726d48Sopenharmony_ci startTs: Utils.getInstance().getRecordStartNS(), 241fb726d48Sopenharmony_ci endTs: Utils.getInstance().getRecordEndNS(), 242fb726d48Sopenharmony_ci }); 243fb726d48Sopenharmony_ci await this.process.initDeliverInputEvent(); 244fb726d48Sopenharmony_ci await this.process.initTouchEventDispatch(); 245fb726d48Sopenharmony_ci await this.process.init(false); 246fb726d48Sopenharmony_ci progress('display', 95); 247fb726d48Sopenharmony_ci } 248fb726d48Sopenharmony_ci 249fb726d48Sopenharmony_ci async initDistributedChart(progress: Function, file1: string, file2: string): Promise<void> { 250fb726d48Sopenharmony_ci let funArr1 = await queryAllFuncNames('1'); 251fb726d48Sopenharmony_ci let funArr2 = await queryAllFuncNames('2'); 252fb726d48Sopenharmony_ci this.handleFuncName(funArr1, '1'); 253fb726d48Sopenharmony_ci this.handleFuncName(funArr2, '2'); 254fb726d48Sopenharmony_ci progress('load data dict', 50); 255fb726d48Sopenharmony_ci SpSystemTrace.DATA_DICT.clear(); 256fb726d48Sopenharmony_ci SpChartManager.APP_STARTUP_PID_ARR = []; 257fb726d48Sopenharmony_ci SpSystemTrace.DATA_TASK_POOL_CALLSTACK.clear(); 258fb726d48Sopenharmony_ci this.process.clearCache(); 259fb726d48Sopenharmony_ci this.process2?.clearCache(); 260fb726d48Sopenharmony_ci let trace1Folder = this.createFolderRow('trace-1', 'trace-1', file1); 261fb726d48Sopenharmony_ci let trace2Folder = this.createFolderRow('trace-2', 'trace-2', file2); 262fb726d48Sopenharmony_ci this.trace.rowsEL!.appendChild(trace1Folder); 263fb726d48Sopenharmony_ci this.trace.rowsEL!.appendChild(trace2Folder); 264fb726d48Sopenharmony_ci await this.initTotalTime(true); 265fb726d48Sopenharmony_ci await this.initDistributedTraceRow('1', trace1Folder, progress); 266fb726d48Sopenharmony_ci info(`trace 1 load completed`); 267fb726d48Sopenharmony_ci await this.initDistributedTraceRow('2', trace2Folder, progress); 268fb726d48Sopenharmony_ci info(`trace 2 load completed`); 269fb726d48Sopenharmony_ci } 270fb726d48Sopenharmony_ci 271fb726d48Sopenharmony_ci // @ts-ignore 272fb726d48Sopenharmony_ci async initDistributedTraceRow(traceId: string, traceFolder: TraceRow<unknown>, progress: Function): Promise<void> { 273fb726d48Sopenharmony_ci let ptArr = await queryThreadAndProcessName(traceId); 274fb726d48Sopenharmony_ci // @ts-ignore 275fb726d48Sopenharmony_ci this.handleProcessThread(ptArr, traceId); 276fb726d48Sopenharmony_ci info(`initData trace ${traceId} timerShaftEL Data initialized`); 277fb726d48Sopenharmony_ci progress(`trace ${traceId} cpu`, 70); 278fb726d48Sopenharmony_ci let count = await sliceSender(traceId); 279fb726d48Sopenharmony_ci // @ts-ignore 280fb726d48Sopenharmony_ci await this.cpu.init(count.count.cpu, traceFolder, traceId); 281fb726d48Sopenharmony_ci info(`initData trace ${traceId} cpu Data initialized`); 282fb726d48Sopenharmony_ci progress(`trace ${traceId} cpu freq`, 75); 283fb726d48Sopenharmony_ci // @ts-ignore 284fb726d48Sopenharmony_ci await this.freq.init(traceFolder, traceId); 285fb726d48Sopenharmony_ci info(`initData trace ${traceId} cpu freq Data initialized`); 286fb726d48Sopenharmony_ci progress(`trace ${traceId} clock`, 80); 287fb726d48Sopenharmony_ci // @ts-ignore 288fb726d48Sopenharmony_ci await this.clockChart.init(traceFolder, traceId); 289fb726d48Sopenharmony_ci info(`initData trace ${traceId} clock Data initialized`); 290fb726d48Sopenharmony_ci progress(`trace ${traceId} Irq`, 85); 291fb726d48Sopenharmony_ci // @ts-ignore 292fb726d48Sopenharmony_ci await this.irqChart.init(traceFolder, traceId); 293fb726d48Sopenharmony_ci info(`initData trace ${traceId} irq Data initialized`); 294fb726d48Sopenharmony_ci progress(`trace ${traceId} process`, 92); 295fb726d48Sopenharmony_ci if (traceId === '2') { 296fb726d48Sopenharmony_ci if (!this.process2) { 297fb726d48Sopenharmony_ci this.process2 = new SpProcessChart(this.trace); 298fb726d48Sopenharmony_ci } 299fb726d48Sopenharmony_ci await this.process2.initAsyncFuncData( 300fb726d48Sopenharmony_ci { 301fb726d48Sopenharmony_ci startTs: Utils.getInstance().getRecordStartNS('2'), 302fb726d48Sopenharmony_ci endTs: Utils.getInstance().getRecordEndNS('2'), 303fb726d48Sopenharmony_ci }, 304fb726d48Sopenharmony_ci traceId 305fb726d48Sopenharmony_ci ); 306fb726d48Sopenharmony_ci await this.process2.init(true, traceFolder, traceId); 307fb726d48Sopenharmony_ci } else { 308fb726d48Sopenharmony_ci await this.process.initAsyncFuncData( 309fb726d48Sopenharmony_ci { 310fb726d48Sopenharmony_ci startTs: Utils.getInstance().getRecordStartNS('1'), 311fb726d48Sopenharmony_ci endTs: Utils.getInstance().getRecordEndNS('1'), 312fb726d48Sopenharmony_ci }, 313fb726d48Sopenharmony_ci traceId 314fb726d48Sopenharmony_ci ); 315fb726d48Sopenharmony_ci await this.process.init(true, traceFolder, traceId); 316fb726d48Sopenharmony_ci } 317fb726d48Sopenharmony_ci } 318fb726d48Sopenharmony_ci 319fb726d48Sopenharmony_ci async initSample(ev: File) { 320fb726d48Sopenharmony_ci await this.initSampleTime(ev, 'bpftrace'); 321fb726d48Sopenharmony_ci await this.spBpftraceChart.init(ev); 322fb726d48Sopenharmony_ci } 323fb726d48Sopenharmony_ci 324fb726d48Sopenharmony_ci async initGpuCounter(ev: File): Promise<void> { 325fb726d48Sopenharmony_ci const res = await this.initSampleTime(ev, 'gpucounter'); 326fb726d48Sopenharmony_ci //@ts-ignore 327fb726d48Sopenharmony_ci await this.spGpuCounterChart.init(res); 328fb726d48Sopenharmony_ci } 329fb726d48Sopenharmony_ci 330fb726d48Sopenharmony_ci async importSoFileUpdate(): Promise<void> { 331fb726d48Sopenharmony_ci SpSystemTrace.DATA_DICT.clear(); 332fb726d48Sopenharmony_ci let dict = await queryDataDICT(); //@ts-ignore 333fb726d48Sopenharmony_ci dict.map((d) => SpSystemTrace.DATA_DICT.set(d.id, d.data)); 334fb726d48Sopenharmony_ci await this.cacheDataDictToWorker(); 335fb726d48Sopenharmony_ci await perfDataQuery.initPerfCache(); 336fb726d48Sopenharmony_ci await this.nativeMemory.initNativeMemory(); 337fb726d48Sopenharmony_ci await this.fileSystem.initFileCallchain(); 338fb726d48Sopenharmony_ci this.perf.resetAllChartData(); 339fb726d48Sopenharmony_ci } 340fb726d48Sopenharmony_ci 341fb726d48Sopenharmony_ci handleProcessThread(arr: { id: number; name: string; type: string }[], traceId?: string): void { 342fb726d48Sopenharmony_ci Utils.getInstance().getProcessMap(traceId).clear(); 343fb726d48Sopenharmony_ci Utils.getInstance().getThreadMap(traceId).clear(); 344fb726d48Sopenharmony_ci for (let pt of arr) { 345fb726d48Sopenharmony_ci if (pt.type === 'p') { 346fb726d48Sopenharmony_ci Utils.getInstance().getProcessMap(traceId).set(pt.id, pt.name); 347fb726d48Sopenharmony_ci } else { 348fb726d48Sopenharmony_ci Utils.getInstance().getThreadMap(traceId).set(pt.id, pt.name); 349fb726d48Sopenharmony_ci } 350fb726d48Sopenharmony_ci } 351fb726d48Sopenharmony_ci } 352fb726d48Sopenharmony_ci 353fb726d48Sopenharmony_ci // 将callstatck表信息转为map存入utils 354fb726d48Sopenharmony_ci handleFuncName(funcNameArray: Array<unknown>, traceId?: string): void { 355fb726d48Sopenharmony_ci if (traceId) { 356fb726d48Sopenharmony_ci funcNameArray.forEach((it) => { 357fb726d48Sopenharmony_ci //@ts-ignore 358fb726d48Sopenharmony_ci Utils.getInstance().getCallStatckMap().set(`${traceId}_${it.id!}`, it.name); 359fb726d48Sopenharmony_ci //@ts-ignore 360fb726d48Sopenharmony_ci Utils.getInstance().getCallStatckMap().set(it.name, it.colorIndex); 361fb726d48Sopenharmony_ci }); 362fb726d48Sopenharmony_ci } else { 363fb726d48Sopenharmony_ci funcNameArray.forEach((it) => { 364fb726d48Sopenharmony_ci //@ts-ignore 365fb726d48Sopenharmony_ci Utils.getInstance().getCallStatckMap().set(it.id, it.name); 366fb726d48Sopenharmony_ci //@ts-ignore 367fb726d48Sopenharmony_ci Utils.getInstance().getCallStatckMap().set(it.name, it.colorIndex); 368fb726d48Sopenharmony_ci }); 369fb726d48Sopenharmony_ci } 370fb726d48Sopenharmony_ci } 371fb726d48Sopenharmony_ci 372fb726d48Sopenharmony_ci initTotalTime = async (isDistributed: boolean = false): Promise<void> => { 373fb726d48Sopenharmony_ci let res1 = await queryTotalTime('1'); 374fb726d48Sopenharmony_ci let total = res1[0].total; 375fb726d48Sopenharmony_ci Utils.getInstance().trace1RecordStartNS = res1[0].recordStartNS; 376fb726d48Sopenharmony_ci Utils.getInstance().trace1RecordEndNS = Math.max(res1[0].recordEndNS, res1[0].recordStartNS + 1); 377fb726d48Sopenharmony_ci if (isDistributed) { 378fb726d48Sopenharmony_ci let res2 = await queryTotalTime('2'); 379fb726d48Sopenharmony_ci total = Math.max(total, res2[0].total); 380fb726d48Sopenharmony_ci Utils.getInstance().trace2RecordStartNS = res2[0].recordStartNS; 381fb726d48Sopenharmony_ci Utils.getInstance().trace2RecordEndNS = Math.max(res2[0].recordEndNS, res2[0].recordStartNS + 1); 382fb726d48Sopenharmony_ci } 383fb726d48Sopenharmony_ci if (this.trace.timerShaftEL) { 384fb726d48Sopenharmony_ci if (total === 0) { 385fb726d48Sopenharmony_ci total = 1; 386fb726d48Sopenharmony_ci } 387fb726d48Sopenharmony_ci Utils.getInstance().totalNS = total; 388fb726d48Sopenharmony_ci this.trace.timerShaftEL.totalNS = total; 389fb726d48Sopenharmony_ci this.trace.timerShaftEL.getRangeRuler()!.drawMark = true; 390fb726d48Sopenharmony_ci this.trace.timerShaftEL.setRangeNS(0, total); 391fb726d48Sopenharmony_ci window.recordStartNS = Utils.getInstance().trace1RecordStartNS; 392fb726d48Sopenharmony_ci window.recordEndNS = Utils.getInstance().trace1RecordEndNS; 393fb726d48Sopenharmony_ci window.totalNS = total; 394fb726d48Sopenharmony_ci this.trace.timerShaftEL.loadComplete = true; 395fb726d48Sopenharmony_ci } 396fb726d48Sopenharmony_ci }; 397fb726d48Sopenharmony_ci 398fb726d48Sopenharmony_ci initSampleTime = async (ev: File, type: string): Promise<unknown> => { 399fb726d48Sopenharmony_ci let res; 400fb726d48Sopenharmony_ci let endNS = 30_000_000_000; 401fb726d48Sopenharmony_ci if (type === 'gpucounter') { 402fb726d48Sopenharmony_ci res = await this.spGpuCounterChart.getCsvData(ev); 403fb726d48Sopenharmony_ci // @ts-ignore 404fb726d48Sopenharmony_ci const endTime = Number(res[res.length - 1].split(',')[0]); 405fb726d48Sopenharmony_ci // @ts-ignore 406fb726d48Sopenharmony_ci const minIndex = this.spGpuCounterChart.getMinData(res) + 1; 407fb726d48Sopenharmony_ci // @ts-ignore 408fb726d48Sopenharmony_ci const startTime = Number(res[minIndex].split(',')[0]); 409fb726d48Sopenharmony_ci endNS = Number((endTime - startTime).toString().slice(0, 11)); 410fb726d48Sopenharmony_ci } 411fb726d48Sopenharmony_ci if (this.trace.timerShaftEL) { 412fb726d48Sopenharmony_ci let total = endNS; 413fb726d48Sopenharmony_ci let startNS = 0; 414fb726d48Sopenharmony_ci this.trace.timerShaftEL.totalNS = total; 415fb726d48Sopenharmony_ci this.trace.timerShaftEL.getRangeRuler()!.drawMark = true; 416fb726d48Sopenharmony_ci this.trace.timerShaftEL.setRangeNS(0, total); // @ts-ignore 417fb726d48Sopenharmony_ci (window as unknown).recordStartNS = startNS; // @ts-ignore 418fb726d48Sopenharmony_ci (window as unknown).recordEndNS = endNS; // @ts-ignore 419fb726d48Sopenharmony_ci (window as unknown).totalNS = total; 420fb726d48Sopenharmony_ci this.trace.timerShaftEL.loadComplete = true; 421fb726d48Sopenharmony_ci } 422fb726d48Sopenharmony_ci return res; 423fb726d48Sopenharmony_ci }; 424fb726d48Sopenharmony_ci 425fb726d48Sopenharmony_ci initCpuRate = async (rates: Array<{ cpu: number; ro: number; rate: number; }>): Promise<void> => { 426fb726d48Sopenharmony_ci if (this.trace.timerShaftEL) { 427fb726d48Sopenharmony_ci this.trace.timerShaftEL.cpuUsage = rates; 428fb726d48Sopenharmony_ci } 429fb726d48Sopenharmony_ci info('Cpu UtilizationRate data size is: ', rates.length); 430fb726d48Sopenharmony_ci }; 431fb726d48Sopenharmony_ci 432fb726d48Sopenharmony_ci initTraceConfig = async (): Promise<void> => { 433fb726d48Sopenharmony_ci queryMemoryConfig().then((result) => { 434fb726d48Sopenharmony_ci if (result && result.length > 0) { 435fb726d48Sopenharmony_ci const config = result[0]; 436fb726d48Sopenharmony_ci MemoryConfig.getInstance().updateConfig(config.pid, config.iPid, config.processName, config.interval); 437fb726d48Sopenharmony_ci } 438fb726d48Sopenharmony_ci }); 439fb726d48Sopenharmony_ci }; 440fb726d48Sopenharmony_ci 441fb726d48Sopenharmony_ci async cacheDataDictToWorker(): Promise<void> { 442fb726d48Sopenharmony_ci return new Promise((resolve) => { 443fb726d48Sopenharmony_ci procedurePool.submitWithName( 444fb726d48Sopenharmony_ci 'logic0', 445fb726d48Sopenharmony_ci 'cache-data-dict', 446fb726d48Sopenharmony_ci { dataDict: SpSystemTrace.DATA_DICT }, 447fb726d48Sopenharmony_ci undefined, 448fb726d48Sopenharmony_ci (res: unknown): void => { 449fb726d48Sopenharmony_ci resolve(); 450fb726d48Sopenharmony_ci } 451fb726d48Sopenharmony_ci ); 452fb726d48Sopenharmony_ci }); 453fb726d48Sopenharmony_ci } 454fb726d48Sopenharmony_ci 455fb726d48Sopenharmony_ci // @ts-ignore 456fb726d48Sopenharmony_ci createFolderRow(rowId: string, rowType: string, rowName: string, traceId?: string): TraceRow<unknown> { 457fb726d48Sopenharmony_ci let row = TraceRow.skeleton<BaseStruct>(traceId); 458fb726d48Sopenharmony_ci row.setAttribute('disabled-check', ''); 459fb726d48Sopenharmony_ci row.rowId = rowId; 460fb726d48Sopenharmony_ci row.rowType = rowType; 461fb726d48Sopenharmony_ci row.rowParentId = ''; 462fb726d48Sopenharmony_ci row.folder = true; 463fb726d48Sopenharmony_ci row.style.height = '40px'; 464fb726d48Sopenharmony_ci row.name = rowName; 465fb726d48Sopenharmony_ci // @ts-ignore 466fb726d48Sopenharmony_ci row.supplier = folderSupplier(); 467fb726d48Sopenharmony_ci row.onThreadHandler = folderThreadHandler(row, this.trace); 468fb726d48Sopenharmony_ci row.addEventListener('expansion-change', (evt) => { 469fb726d48Sopenharmony_ci if (!row.expansion) { 470fb726d48Sopenharmony_ci this.trace.clickEmptyArea(); 471fb726d48Sopenharmony_ci } 472fb726d48Sopenharmony_ci }); 473fb726d48Sopenharmony_ci return row; 474fb726d48Sopenharmony_ci } 475fb726d48Sopenharmony_ci 476fb726d48Sopenharmony_ci //存名字 477fb726d48Sopenharmony_ci handleDmaFenceName<T extends { id: number; cat: string; seqno: number; driver: string; context: string }>(arr: T[]): void { 478fb726d48Sopenharmony_ci Utils.DMAFENCECAT_MAP.clear(); 479fb726d48Sopenharmony_ci for (let item of arr) { 480fb726d48Sopenharmony_ci Utils.DMAFENCECAT_MAP.set(item.id, item); 481fb726d48Sopenharmony_ci } 482fb726d48Sopenharmony_ci } 483fb726d48Sopenharmony_ci} 484fb726d48Sopenharmony_ci 485fb726d48Sopenharmony_ciexport const folderSupplier = (): () => Promise<BaseStruct[]> => { 486fb726d48Sopenharmony_ci return () => new Promise<Array<BaseStruct>>((resolve) => resolve([])); 487fb726d48Sopenharmony_ci}; 488fb726d48Sopenharmony_ci 489fb726d48Sopenharmony_ciexport const folderThreadHandler = (row: TraceRow<BaseStruct>, trace: SpSystemTrace) => { 490fb726d48Sopenharmony_ci return (useCache: boolean): void => { 491fb726d48Sopenharmony_ci row.canvasSave(trace.canvasPanelCtx!); 492fb726d48Sopenharmony_ci if (row.expansion) { 493fb726d48Sopenharmony_ci // @ts-ignore 494fb726d48Sopenharmony_ci trace.canvasPanelCtx?.clearRect(0, 0, row.frame.width, row.frame.height); 495fb726d48Sopenharmony_ci } else { 496fb726d48Sopenharmony_ci (renders.empty as EmptyRender).renderMainThread( 497fb726d48Sopenharmony_ci { 498fb726d48Sopenharmony_ci context: trace.canvasPanelCtx, 499fb726d48Sopenharmony_ci useCache: useCache, 500fb726d48Sopenharmony_ci type: '', 501fb726d48Sopenharmony_ci }, 502fb726d48Sopenharmony_ci row 503fb726d48Sopenharmony_ci ); 504fb726d48Sopenharmony_ci } 505fb726d48Sopenharmony_ci row.canvasRestore(trace.canvasPanelCtx!, trace); 506fb726d48Sopenharmony_ci }; 507fb726d48Sopenharmony_ci}; 508fb726d48Sopenharmony_ci 509fb726d48Sopenharmony_ciexport function rowThreadHandler<T>( 510fb726d48Sopenharmony_ci tag: string, 511fb726d48Sopenharmony_ci contextField: string, 512fb726d48Sopenharmony_ci arg: unknown, // @ts-ignore 513fb726d48Sopenharmony_ci row: TraceRow<unknown>, 514fb726d48Sopenharmony_ci trace: SpSystemTrace 515fb726d48Sopenharmony_ci) { 516fb726d48Sopenharmony_ci return (useCache: boolean): void => { 517fb726d48Sopenharmony_ci let context: CanvasRenderingContext2D = getRowContext(row, trace); 518fb726d48Sopenharmony_ci row.canvasSave(context); // @ts-ignore 519fb726d48Sopenharmony_ci arg.useCache = useCache; 520fb726d48Sopenharmony_ci if (contextField) { 521fb726d48Sopenharmony_ci // @ts-ignore 522fb726d48Sopenharmony_ci arg[contextField] = context; 523fb726d48Sopenharmony_ci } // @ts-ignore 524fb726d48Sopenharmony_ci (renders[tag] as unknown).renderMainThread(arg, row); 525fb726d48Sopenharmony_ci row.canvasRestore(context, trace); 526fb726d48Sopenharmony_ci }; 527fb726d48Sopenharmony_ci} 528fb726d48Sopenharmony_ci// @ts-ignore 529fb726d48Sopenharmony_ciexport const getRowContext = (row: TraceRow<unknown>, trace: SpSystemTrace): CanvasRenderingContext2D => { 530fb726d48Sopenharmony_ci if (row.currentContext) { 531fb726d48Sopenharmony_ci return row.currentContext; 532fb726d48Sopenharmony_ci } else { 533fb726d48Sopenharmony_ci return row.collect ? trace.canvasFavoritePanelCtx! : trace.canvasPanelCtx!; 534fb726d48Sopenharmony_ci } 535fb726d48Sopenharmony_ci}; 536