From 0d1f999418b8d44f766b0df1e63482b25a75f6b6 Mon Sep 17 00:00:00 2001 From: JustinYT Date: Wed, 23 Apr 2025 17:55:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=86=85=E6=A0=B8trace=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BC=98=E5=8C=96=EF=BC=8Ctrace=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=A2=9E=E7=BA=A7=E5=88=AB=E3=80=81tag=E3=80=81cat?= =?UTF-8?q?=E3=80=81args=E9=80=82=E9=85=8D=202.=E6=A1=86=E9=80=89Occurrenc?= =?UTF-8?q?es=E6=B1=87=E6=80=BB=E6=95=B0=E6=8D=AEbug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: JustinYT --- ide/src/trace/bean/FuncStruct.ts | 4 +++ ide/src/trace/component/SpSystemTrace.init.ts | 8 +++++ .../trace/component/chart/SpProcessChart.ts | 33 +++++++++++++---- .../trace/sheet/TabPaneCurrentSelection.ts | 20 +++++++++++ .../trace/sheet/process/TabPaneSliceChild.ts | 6 ++-- ide/src/trace/database/sql/Func.sql.ts | 36 ++++++++++++++----- ide/src/trace/database/sql/SqlLite.sql.ts | 33 +++++++++++++++-- 7 files changed, 120 insertions(+), 20 deletions(-) diff --git a/ide/src/trace/bean/FuncStruct.ts b/ide/src/trace/bean/FuncStruct.ts index 214bf1103..3c3a156a8 100644 --- a/ide/src/trace/bean/FuncStruct.ts +++ b/ide/src/trace/bean/FuncStruct.ts @@ -46,6 +46,10 @@ export class FuncStruct extends BaseStruct { spanId: string | undefined; parentSpanId: string | undefined; chainFlag: string | undefined; + trace_level: string | undefined; + trace_tag: string | undefined; + custom_args: string | undefined; + category: string | undefined; static draw(funcBeanStructCanvasCtx: CanvasRenderingContext2D, funcBeanStruct: FuncStruct): void { if (funcBeanStruct.frame) { diff --git a/ide/src/trace/component/SpSystemTrace.init.ts b/ide/src/trace/component/SpSystemTrace.init.ts index 69a4599be..2b5d8afb0 100644 --- a/ide/src/trace/component/SpSystemTrace.init.ts +++ b/ide/src/trace/component/SpSystemTrace.init.ts @@ -1125,6 +1125,14 @@ function findEntryTypeFunc(sp: SpSystemTrace, findEntry: unknown): void { // @ts-ignore cookie: findEntry.cookie, // @ts-ignore + trace_level: findEntry.trace_level, + // @ts-ignore + trace_tag: findEntry.trace_tag, + // @ts-ignore + custom_args: findEntry.custom_args, + // @ts-ignore + category:findEntry.category, + // @ts-ignore //因异步trace分类出的rowId类型有三种,故新增row_id字段,该字段为异步方法的对应的rowId,支持搜索查询定位到该方法属于那个row,只有缓存的异步trace数据中含该字段 row_id: findEntry.rowId ? findEntry.rowId : null, }, diff --git a/ide/src/trace/component/chart/SpProcessChart.ts b/ide/src/trace/component/chart/SpProcessChart.ts index 019a765c8..58265a037 100644 --- a/ide/src/trace/component/chart/SpProcessChart.ts +++ b/ide/src/trace/component/chart/SpProcessChart.ts @@ -39,7 +39,7 @@ import { processDeliverInputEventDataSender } from '../../database/data-trafic/p import { processTouchEventDispatchDataSender } from '../../database/data-trafic/process/ProcessTouchEventDispatchDataSender'; import { getMaxDepthByTid, queryProcessAsyncFunc, queryProcessAsyncFuncCat } from '../../database/sql/Func.sql'; import { queryMemFilterIdMaxValue, queryMemFilterIdMinValue } from '../../database/sql/Memory.sql'; -import { queryAllSoInitNames, queryAllSrcSlices, queryEventCountMap } from '../../database/sql/SqlLite.sql'; +import { queryAllSoInitNames, queryAllSrcSlices, queryEventCountMap, queryCallstackDetail } from '../../database/sql/SqlLite.sql'; import { queryProcessByTable, queryProcessContentCount, @@ -97,6 +97,7 @@ export class SpProcessChart { private traceId?: string | undefined; private parentRow: TraceRow | undefined; static asyncFuncCache: unknown[] = []; + private callStackDetail: Map = new Map(); static threadStateList: Map = new Map(); static processRowSortMap: Map = new Map(); private sameThreadFolder!: TraceRow; @@ -127,6 +128,7 @@ export class SpProcessChart { this.distributedDataMap.clear(); this.renderRow = null; SpProcessChart.asyncFuncCache = []; + this.callStackDetail.clear(); if (this.parentRow) { this.parentRow.clearMemory(); this.parentRow = undefined; @@ -378,6 +380,7 @@ export class SpProcessChart { //@ts-ignore it.flag = 'Did not end'; } + this.addCallStackDetail(it as FuncStruct) createDepth(0, i); }); if (funcRow && !funcRow.isComplete) { @@ -518,6 +521,13 @@ export class SpProcessChart { traceId: traceId!, }); }); + let callstackData: Array = await queryCallstackDetail(); + for (let index = 0; index < callstackData.length; index++) { + const indexData = callstackData[index]; + if (indexData && !this.callStackDetail.has(indexData.id!)) { + this.callStackDetail.set(indexData.id!, indexData); + } + } info('The amount of initialized process threads data is : ', this.processThreads!.length); } @@ -1475,6 +1485,7 @@ export class SpProcessChart { funs[index].ipid = thread.upid; funs[index].tid = thread.tid; funs[index].pid = thread.pid; + this.addCallStackDetail(funs[index]) funs[index].funName = this.traceId ? Utils.getInstance().getCallStatckMap().get(`${this.traceId}_${funs[index].id}`) : Utils.getInstance().getCallStatckMap().get(funs[index].id!); if (Utils.isBinder(fun)) { } else { @@ -1680,18 +1691,18 @@ export class SpProcessChart { for (let i = 0; i < asyncFuncList.length; i++) { const el = asyncFuncList[i]; // @ts-ignore - if (el.cat !== null) { + if (el.category !== null) { if (flag) {//business first asyncCatArr.push(el); } else {//thread first //@ts-ignore - if (asyncCatMap.has(`${el.cat}:${el.threadName} ${el.tid}`)) { + if (asyncCatMap.has(`${el.category}:${el.threadName} ${el.tid}`)) { //@ts-ignore - let item: Array = asyncCatMap.get(`${el.cat}:${el.threadName} ${el.tid}`); + let item: Array = asyncCatMap.get(`${el.category}:${el.threadName} ${el.tid}`); item.push(el); } else { //@ts-ignore - asyncCatMap.set(`${el.cat}:${el.threadName} ${el.tid}`, [el]); + asyncCatMap.set(`${el.category}:${el.threadName} ${el.tid}`, [el]); } } } else { @@ -1699,7 +1710,7 @@ export class SpProcessChart { asyncRemoveCatArr.push(el); } } - asyncCat = flag ? Utils.groupBy(asyncCatArr, 'cat') : Object.fromEntries(asyncCatMap); + asyncCat = flag ? Utils.groupBy(asyncCatArr, 'category') : Object.fromEntries(asyncCatMap); return { asyncRemoveCatArr, asyncCat }; } //处理cat字段为null的数据,按funname分类,分别按len>1和=1去处理 @@ -1845,6 +1856,16 @@ export class SpProcessChart { processRow.addChildTraceRow(funcRow); } + addCallStackDetail(item: FuncStruct): void { + if (this.callStackDetail.has(item.id!)) { + const data: FuncStruct | undefined = this.callStackDetail.get(item.id!); + item.custom_args = data!.custom_args; + item.trace_level = data!.trace_level; + item.trace_tag = data!.trace_tag; + item.category = data!.category; + } + } + addAsyncCatFunction(it: { pid: number; processName: string | null }, processRow: TraceRow): void { //@ts-ignore let asyncFuncCatList = this.processAsyncFuncCatMap[it.pid] || []; diff --git a/ide/src/trace/component/trace/sheet/TabPaneCurrentSelection.ts b/ide/src/trace/component/trace/sheet/TabPaneCurrentSelection.ts index 9e4d54868..0f82b5616 100644 --- a/ide/src/trace/component/trace/sheet/TabPaneCurrentSelection.ts +++ b/ide/src/trace/component/trace/sheet/TabPaneCurrentSelection.ts @@ -473,6 +473,7 @@ export class TabPaneCurrentSelection extends BaseElement { } list.push(item); }); + this.addTabSliceDetail(data, list) this.currentSelectionTbl!.dataSource = list; // @ts-ignore let startTimeAbsolute = (data.startTs || 0) + (window as unknown).recordStartNS; @@ -494,6 +495,7 @@ export class TabPaneCurrentSelection extends BaseElement { name: 'Thread', value: (this.transferString(threadName ?? '') || 'NULL') + ' [' + dataTid + '] ', }); + this.addTabSliceDetail(data, list) list.push({ name: 'StartTime(Relative)', value: getTimeString(data.startTs || 0), @@ -599,6 +601,7 @@ export class TabPaneCurrentSelection extends BaseElement { argset.forEach((item) => { list.push({ name: item.keyName, value: item.strValue }); }); + this.addTabSliceDetail(data, list) this.addTabPanelContent(list, data, information); this.currentSelectionTbl!.dataSource = list; }); @@ -653,6 +656,7 @@ export class TabPaneCurrentSelection extends BaseElement { } ); } + this.addTabSliceDetail(data, list) this.addTabPanelContent(list, data, information); this.currentSelectionTbl!.dataSource = list; let funcClick = this.currentSelectionTbl?.shadowRoot?.querySelector('#function-jump'); @@ -686,6 +690,21 @@ export class TabPaneCurrentSelection extends BaseElement { }); } + private addTabSliceDetail(data: FuncStruct, list: unknown[]) { + const properties = [ + {key: 'trace_level', name: 'TraceLevel'}, + {key: 'trace_tag', name: 'TraceTag'}, + {key: 'category', name: 'Category'}, + {key: 'custom_args', name: 'CustomArgs'}, + ]; + properties.forEach(prop => { + if (data[prop.key] && list !== undefined) { + list!.push({name: prop.name, value: data[prop.key]}); + } + }); + return list; + } + private handleAsyncBinder( data: FuncStruct, list: unknown[], @@ -748,6 +767,7 @@ export class TabPaneCurrentSelection extends BaseElement { value: (this.transferString(threadName ?? '') || 'NULL') + ' [' + data.tid + '] ', }); } + this.addTabSliceDetail(data, list) this.addTabPanelContent(list, data, information); this.currentSelectionTbl!.dataSource = list; let funcClick = this.currentSelectionTbl?.shadowRoot?.querySelector('#function-jump'); diff --git a/ide/src/trace/component/trace/sheet/process/TabPaneSliceChild.ts b/ide/src/trace/component/trace/sheet/process/TabPaneSliceChild.ts index e75097d1d..c8e6916c3 100644 --- a/ide/src/trace/component/trace/sheet/process/TabPaneSliceChild.ts +++ b/ide/src/trace/component/trace/sheet/process/TabPaneSliceChild.ts @@ -37,8 +37,10 @@ export class TabPaneSliceChild extends BaseElement { //合并SF异步信息,相同pid和tid的name let sfAsyncFuncMap: Map = new Map(); let filterSfAsyncFuncName = boxChildValue.selection!.funAsync; - if (!boxChildValue.param.isSummary!) { - filterSfAsyncFuncName = filterSfAsyncFuncName.filter((item) => item.name === boxChildValue.param.name![0]); + if (boxChildValue.param.name) { + filterSfAsyncFuncName = filterSfAsyncFuncName.filter((item) => + boxChildValue.param.name?.some((boxItem) => item.name === boxItem) + ); } filterSfAsyncFuncName.forEach((it: { name: string; pid: number, tid: number | undefined }) => { if (sfAsyncFuncMap.has(`${it.pid}-${it.tid}`)) { diff --git a/ide/src/trace/database/sql/Func.sql.ts b/ide/src/trace/database/sql/Func.sql.ts index d99a23090..f9ca8595c 100644 --- a/ide/src/trace/database/sql/Func.sql.ts +++ b/ide/src/trace/database/sql/Func.sql.ts @@ -152,14 +152,19 @@ export const queryProcessAsyncFunc = ( P.pid, c.ts-${traceRange.startTs} as startTs, c.dur, - c.cat, + c.custom_category as category, c.id, c.depth, c.argsetid, - c.cookie + c.cookie, + c.trace_level, + c.trace_tag, + c.custom_args, + c.child_callid FROM - (SELECT id, ts, parent_id, dur, depth, argsetid, cookie, cat from callstack where cookie NOT NULL) c - LEFT JOIN thread A ON A.id = c.parent_id + (SELECT id, ts, parent_id, dur, depth, argsetid, cookie, custom_category, child_callid, trace_level, + trace_tag, custom_args from callstack where cookie NOT NULL) c + LEFT JOIN thread A ON A.id = c.child_callid LEFT JOIN process P ON P.id = A.ipid WHERE startTs NOT NULL;`, @@ -179,21 +184,26 @@ export const queryProcessAsyncFuncCat = ( select A.tid, P.pid, - c.cat as threadName, + c.custom_category as threadName, c.name as funName, c.ts-${traceRange.startTs} as startTs, c.dur, c.depth, - c.cookie + c.cookie, + c.trace_level, + c.trace_tag, + c.custom_args, + c.child_callid from - (select callid, name, ts, dur, cat, depth, cookie, parent_id from callstack where cookie not null and cat not null and parent_id is null) C + (select callid, name, ts, dur, custom_category, depth, cookie, parent_id,trace_level,trace_tag, + custom_args,child_callid from callstack where cookie not null and custom_category not null and child_callid is null) c left join - thread A on A.id = C.callid + thread A on A.id = c.callid left join process P on P.id = A.ipid where startTs not null - order by cat; + order by custom_category; `, {} ); @@ -590,6 +600,10 @@ export const querySearchFunc = (search: string): Promise> t.name as threadName, p.pid, c.argsetid, + c.trace_level, + c.trace_tag, + c.custom_args, + c.custom_category as category, 'func' as type from callstack c left join thread t on c.callid = t.id left join process p on t.ipid = p.id left join trace_range r @@ -613,6 +627,10 @@ export const querySearchFunc = (search: string): Promise> t.name as threadName, p.pid, c.argsetid, + c.trace_level, + c.trace_tag, + c.custom_args, + c.custom_category as category, 'func' as type from callstack c left join thread t on c.callid = t.id left join process p on t.ipid = p.id left join trace_range r diff --git a/ide/src/trace/database/sql/SqlLite.sql.ts b/ide/src/trace/database/sql/SqlLite.sql.ts index 2b547526c..aa6364e1f 100644 --- a/ide/src/trace/database/sql/SqlLite.sql.ts +++ b/ide/src/trace/database/sql/SqlLite.sql.ts @@ -29,6 +29,7 @@ import type { DeviceStruct } from '../../bean/FrameComponentBean'; import { LogStruct } from '../ui-worker/ProcedureWorkerLog'; import { query } from '../SqlLite'; import { Utils } from '../../component/trace/base/Utils'; +import { FuncStruct } from '../ui-worker/ProcedureWorkerFunc'; export const queryEventCountMap = ( traceId?: string @@ -405,7 +406,11 @@ export const queryBinderBySliceId = ( c.depth, c.argsetid, c.name AS funName, - c.cookie + c.cookie, + c.trace_level, + c.trace_tag, + c.custom_category as category, + c.custom_args FROM callstack c, trace_range D @@ -449,8 +454,12 @@ export const queryBinderByArgsId = ( p.pid, c.depth, c.argsetid, - c.name as funName, - c.cookie + c.name as funName, + c.cookie, + c.trace_level, + c.trace_tag, + c.custom_category as category, + c.custom_args from callstack c,trace_range D left join thread t on c.callid = t.id left join process p on p.id = t.ipid @@ -1592,3 +1601,21 @@ export const queryPerfToolsDur = (): Promise> => dur FROM callstack where name = 'H:GRAB'` ); + +export const queryCallstackDetail = (): Promise> => + query( + 'queryCallstackDetail', + `SELECT + id, + trace_level, + trace_tag, + custom_category as category, + custom_args + FROM callstack, trace_range AS TR + where (trace_level is not null or + trace_tag is not null or + custom_args is not null or + custom_category is not null) + and ts - TR.start_ts >= 0 + and TR.end_ts - ts >=0;` + ); -- Gitee