From 61841ca2d8ecdad4db46d2e183400c1d718dabba Mon Sep 17 00:00:00 2001 From: zhangzepeng Date: Tue, 11 Jun 2024 15:36:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:perf=E7=81=AB=E7=84=B0=E5=9B=BESampleCountF?= =?UTF-8?q?ilter=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=BA=BF=E7=A8=8B=E8=B7=9F?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangzepeng --- ide/src/trace/bean/BoxSelection.ts | 2 +- .../trace/component/chart/SpProcessChart.ts | 42 +++++++++---------- .../trace/component/trace/base/TraceRow.ts | 2 +- .../component/trace/base/TraceSheetConfig.ts | 2 +- .../trace/sheet/process/TabPaneSlices.ts | 4 +- .../logic-worker/ProcedureLogicWorkerPerf.ts | 8 +++- ide/src/trace/database/sql/Func.sql.ts | 2 +- 7 files changed, 34 insertions(+), 28 deletions(-) diff --git a/ide/src/trace/bean/BoxSelection.ts b/ide/src/trace/bean/BoxSelection.ts index 3dd17be30..2b6bf58f4 100644 --- a/ide/src/trace/bean/BoxSelection.ts +++ b/ide/src/trace/bean/BoxSelection.ts @@ -323,7 +323,7 @@ export class SelectionParam { for (let i = 0; i < it.asyncFuncThreadName.length; i++) { const tn = it.asyncFuncThreadName[i]; this.funCatAsync.push({ - pid: it.asyncFuncNamePID || 0, + pid: it.asyncFuncNamePID || 0,//@ts-ignore threadName: tn }); } diff --git a/ide/src/trace/component/chart/SpProcessChart.ts b/ide/src/trace/component/chart/SpProcessChart.ts index 42a0673fa..47be8264c 100644 --- a/ide/src/trace/component/chart/SpProcessChart.ts +++ b/ide/src/trace/component/chart/SpProcessChart.ts @@ -58,7 +58,7 @@ export class SpProcessChart { private readonly trace: SpSystemTrace; private processAsyncFuncMap: unknown = {}; private processAsyncFuncArray: unknown[] = []; - private processAsyncFuncCatMap: any = {}; + private processAsyncFuncCatMap: unknown = {}; private eventCountMap: unknown; private processThreads: Array = []; private processMem: Array = []; @@ -95,7 +95,7 @@ export class SpProcessChart { this.processAsyncFuncArray = asyncFuncList; this.processAsyncFuncMap = Utils.groupBy(asyncFuncList, 'pid'); - let asyncFuncCatList: any[] = await queryProcessAsyncFuncCat(); + let asyncFuncCatList: unknown[] = await queryProcessAsyncFuncCat(); info('AsyncFuncCatData Count is: ', asyncFuncCatList!.length); this.processAsyncFuncCatMap = Utils.groupBy(asyncFuncCatList, 'pid'); }; @@ -1109,32 +1109,32 @@ export class SpProcessChart { }); } - addAsyncCatFunction(it: { pid: number; processName: string | null }, processRow: TraceRow): void { + addAsyncCatFunction(it: { pid: number; processName: string | null }, processRow: TraceRow): void {//@ts-ignore let asyncFuncCatList = this.processAsyncFuncCatMap[it.pid] || []; - let asyncFuncGroup:any = Utils.groupBy(asyncFuncCatList, 'threadName'); - Reflect.ownKeys(asyncFuncGroup).map((key: any) => { - let asyncFunctions: Array = asyncFuncGroup[key]; + let asyncFuncGroup: unknown = Utils.groupBy(asyncFuncCatList, 'threadName');//@ts-ignore + Reflect.ownKeys(asyncFuncGroup).map((key: unknown) => {//@ts-ignore + let asyncFunctions: Array = asyncFuncGroup[key]; if (asyncFunctions.length > 0) { - let isIntersect = (a: any, b: any): boolean => + let isIntersect = (a: unknown, b: unknown): boolean =>//@ts-ignore Math.max(a.startTs + a.dur, b.startTs + b.dur) - Math.min(a.startTs, b.startTs) < a.dur + b.dur; - let depthArray: any = []; - asyncFunctions.forEach((it, i) => { - if (it.dur === -1 || it.dur === null || it.dur === undefined) { - it.dur = (TraceRow.range?.endNS || 0) - it.startTs; - it.flag = 'Did not end'; + let depthArray: unknown = []; + asyncFunctions.forEach((it, i) => {//@ts-ignore + if (it.dur === -1 || it.dur === null || it.dur === undefined) {//@ts-ignore + it.dur = (TraceRow.range?.endNS || 0) - it.startTs;//@ts-ignore + it.flag = 'Did not end';//@ts-ignore it.nofinish = true; } let currentDepth = 0; - let index = i; + let index = i;//@ts-ignore while (depthArray[currentDepth] !== undefined && isIntersect(depthArray[currentDepth], asyncFunctions[index])) { currentDepth++; - } - asyncFunctions[index].depth = currentDepth; + }//@ts-ignore + asyncFunctions[index].depth = currentDepth;//@ts-ignore depthArray[currentDepth] = asyncFunctions[index]; }); const maxHeight = this.calMaxHeight(asyncFunctions); - let funcRow = TraceRow.skeleton(); - funcRow.rowId = `${asyncFunctions[0].threadName}`; + let funcRow = TraceRow.skeleton();//@ts-ignore + funcRow.rowId = `${asyncFunctions[0].threadName}`;//@ts-ignore funcRow.asyncFuncThreadName = asyncFunctions[0].threadName; funcRow.asyncFuncNamePID = it.pid; funcRow.rowType = TraceRow.ROW_TYPE_FUNC; @@ -1143,16 +1143,16 @@ export class SpProcessChart { funcRow.rowHidden = !processRow.expansion; funcRow.style.width = '100%'; funcRow.style.height = `${maxHeight}px`; - funcRow.setAttribute('height', `${maxHeight}`); + funcRow.setAttribute('height', `${maxHeight}`);//@ts-ignore funcRow.name = `${asyncFunctions[0].threadName}`; funcRow.setAttribute('children', ''); funcRow.findHoverStruct = (): void => { FuncStruct.hoverFuncStruct = funcRow.getHoverStruct(); - } - funcRow.supplier = (): Promise => new Promise((resolve) => resolve(asyncFunctions)); + }; //@ts-ignore + funcRow.supplier = (): Promise => new Promise((resolve) => resolve(asyncFunctions)); funcRow.favoriteChangeHandler = this.trace.favoriteChangeHandler; funcRow.selectChangeHandler = this.trace.selectChangeHandler; - funcRow.onThreadHandler = rowThreadHandler('func', 'context', { + funcRow.onThreadHandler = rowThreadHandler('func', 'context', {//@ts-ignore type: `func-${asyncFunctions[0].threadName}-${it.pid}`, }, funcRow, this.trace); processRow.addChildTraceRow(funcRow); diff --git a/ide/src/trace/component/trace/base/TraceRow.ts b/ide/src/trace/component/trace/base/TraceRow.ts index 68c7bd997..43655a21b 100644 --- a/ide/src/trace/component/trace/base/TraceRow.ts +++ b/ide/src/trace/component/trace/base/TraceRow.ts @@ -184,7 +184,7 @@ export class TraceRow extends HTMLElement { static isUserInteraction: boolean; asyncFuncName: string | undefined | null; asyncFuncNamePID: number | undefined | null; - asyncFuncThreadName: Array| string | undefined | null; + asyncFuncThreadName: Array | string | undefined | null; translateY: number = 0; //single canvas offsetY; // @ts-ignore childrenList: Array> = []; // @ts-ignore diff --git a/ide/src/trace/component/trace/base/TraceSheetConfig.ts b/ide/src/trace/component/trace/base/TraceSheetConfig.ts index 04a2e0e5c..4e14c5eb4 100644 --- a/ide/src/trace/component/trace/base/TraceSheetConfig.ts +++ b/ide/src/trace/component/trace/base/TraceSheetConfig.ts @@ -200,7 +200,7 @@ export let tabConfig: unknown = { 'box-slices': { title: 'Slices', type: TabPaneSlices, - require: (param: SelectionParam) => param.funTids.length > 0 || param.funAsync.length || param.funCatAsync.length > 0, + require: (param: SelectionParam) => param.funTids.length > 0 || param.funAsync.length || param.funCatAsync.length > 0, }, 'box-counters': { title: 'Counters', diff --git a/ide/src/trace/component/trace/sheet/process/TabPaneSlices.ts b/ide/src/trace/component/trace/sheet/process/TabPaneSlices.ts index 6bb275804..c67283191 100644 --- a/ide/src/trace/component/trace/sheet/process/TabPaneSlices.ts +++ b/ide/src/trace/component/trace/sheet/process/TabPaneSlices.ts @@ -51,8 +51,8 @@ export class TabPaneSlices extends BaseElement { let asyncCatNames: Array = []; let asyncCatPid: Array = [];//@ts-ignore - slicesParam.funCatAsync.forEach((it: any) => { - asyncCatNames.push(it.threadName); + slicesParam.funCatAsync.forEach((it: unknown) => {//@ts-ignore + asyncCatNames.push(it.threadName);//@ts-ignore asyncCatPid.push(it.pid); }); this.slicesTbl!.loading = true; diff --git a/ide/src/trace/database/logic-worker/ProcedureLogicWorkerPerf.ts b/ide/src/trace/database/logic-worker/ProcedureLogicWorkerPerf.ts index 25d5d140d..b6216a0ec 100644 --- a/ide/src/trace/database/logic-worker/ProcedureLogicWorkerPerf.ts +++ b/ide/src/trace/database/logic-worker/ProcedureLogicWorkerPerf.ts @@ -456,6 +456,7 @@ export class ProcedureLogicWorkerPerf extends LogicHandler { threadCallChain.name = `${this.threadData[countSample.tid].threadName || 'Thread'}(${countSample.tid})`; let threadStateCallChain = new PerfCallChain(); //新增的线程状态数据 threadStateCallChain.tid = countSample.tid; + threadStateCallChain.isThreadState = true; threadStateCallChain.name = countSample.threadState || 'Unknown State'; threadStateCallChain.fileName = threadStateCallChain.name === '-' ? 'Unknown Thread State' : ''; threadStateCallChain.canCharge = false; @@ -659,7 +660,7 @@ export class ProcedureLogicWorkerPerf extends LogicHandler { ): void { if (sample.initChildren.length > 0) { sample.initChildren.forEach((child): void => { - if (rule(child)) { + if (rule(child) && !child.isThread && !child.isState) { if (!this.splitMapData.has(ruleName)) { this.splitMapData.set(ruleName, []); } @@ -1119,6 +1120,7 @@ export class PerfCallChain { nextNode: PerfCallChain | undefined = undefined; isThread: boolean = false; isProcess: boolean = false; + isThreadState : boolean = false; static setNextNode(currentNode: PerfCallChain, nextNode: PerfCallChain): void { currentNode.nextNode = nextNode; @@ -1170,6 +1172,7 @@ export class PerfCallChainMerageData extends ChartStruct { isSelected: boolean = false; searchShow: boolean = true; isSearch: boolean = false; + isState : boolean = false; set parentNode(data: PerfCallChainMerageData | undefined) { this.parent = data; this.#parentNode = data; @@ -1230,6 +1233,9 @@ export class PerfCallChainMerageData extends ChartStruct { if (callChain.isThread && !currentNode.isThread) { currentNode.isThread = callChain.isThread; } + if (callChain.isThreadState && !currentNode.isState){ + currentNode.isState = callChain.isThreadState; + } currentNode.dur += sample.count; currentNode.count += sample.count; currentNode.eventCount += sample.eventCount; diff --git a/ide/src/trace/database/sql/Func.sql.ts b/ide/src/trace/database/sql/Func.sql.ts index b6cbe75e4..f2a0f29ad 100644 --- a/ide/src/trace/database/sql/Func.sql.ts +++ b/ide/src/trace/database/sql/Func.sql.ts @@ -136,7 +136,7 @@ Promise> => {} ); - export const queryProcessAsyncFuncCat = (): Promise> => + export const queryProcessAsyncFuncCat = (): Promise> => query( 'queryProcessAsyncFuncCat', ` -- Gitee