From 54706818e5567259262e90e1199c7418dd360cbe Mon Sep 17 00:00:00 2001 From: "lizhuosong@huawei.com" Date: Wed, 25 Oct 2023 09:39:08 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=A1=86=E9=80=89CPU=E6=B3=B3=E9=81=93?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=A2=91=E7=82=B9=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lizhuosong@huawei.com --- .../component/trace/base/TraceSheetConfig.ts | 12 + .../sheet/frequsage/TabPaneFreqDataCut.ts | 434 ++++++++++++++++++ .../trace/sheet/frequsage/TabPaneFreqUsage.ts | 199 ++++++++ ide/src/trace/database/SqlLite.ts | 65 +++ 4 files changed, 710 insertions(+) create mode 100644 ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts create mode 100644 ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts diff --git a/ide/src/trace/component/trace/base/TraceSheetConfig.ts b/ide/src/trace/component/trace/base/TraceSheetConfig.ts index dcd8b04b7..f4517bb78 100644 --- a/ide/src/trace/component/trace/base/TraceSheetConfig.ts +++ b/ide/src/trace/component/trace/base/TraceSheetConfig.ts @@ -118,6 +118,8 @@ import { TabPaneHiLogSummary } from '../sheet/hilog/TabPaneHiLogSummary.js'; import { TabPaneSchedPriority } from '../sheet/cpu/TabPaneSchedPriority.js'; import { TabPaneGpuResourceVmTracker } from '../sheet/vmtracker/TabPaneGpuResourceVmTracker.js'; import { TabPaneGpuGraph } from '../sheet/gpu/TabPaneGraph.js'; +import { TabPaneFreqUsage } from '../sheet/frequsage/TabPaneFreqUsage.js'; +import { TabPaneFreqDataCut } from '../sheet/frequsage/TabPaneFreqDataCut.js'; export let tabConfig: any = { 'current-selection': { @@ -626,4 +628,14 @@ export let tabConfig: any = { type: TabPaneCurrent, require: (param: SelectionParam) => param.isCurrentPane, }, //current selection + 'tabpane-frequsage': { + title: 'Freq Usage', + type: TabPaneFreqUsage, + require: (param: SelectionParam) => param.threadIds.length > 0, + }, + 'tabpane-freqdatacut': { + title: 'Freq DataCut', + type: TabPaneFreqDataCut, + require: (param: SelectionParam) => param.threadIds.length > 0, + }, }; diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts new file mode 100644 index 000000000..86f24363c --- /dev/null +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts @@ -0,0 +1,434 @@ +import { BaseElement, element } from '../../../../../base-ui/BaseElement.js'; +import { LitTable } from '../../../../../base-ui/table/lit-table'; +import { SelectionData, SelectionParam } from '../../../../bean/BoxSelection'; +import '../../../StackBar.js' +import { getTabRunningPercent, querySearchFuncData, queryCpuFreqUsageData, queryCpuFreqFilterId } from '../../../../database/SqlLite.js'; +import { Utils } from '../../base/Utils.js'; +import { log } from '../../../../../log/Log.js'; +import { resizeObserver } from '../SheetUtils.js'; + +@element('tabpane-freqdatacut') +export class TabPaneFreqDataCut extends BaseElement{ + private threadStatesTbl: LitTable|null|undefined; + private threadStatesTblSource:Array = []; + private currentSelectionParam: SelectionParam|any; + private threadStatesDIV:Element|null|undefined; + private initData:Array = []; + + set data(threadStatesParam: SelectionParam|any){ + if (this.currentSelectionParam === threadStatesParam) { + return; + } + this.currentSelectionParam = threadStatesParam; + this.threadStatesTblSource = []; + this.threadStatesTbl!.recycleDataSource = []; + + getTabRunningPercent(threadStatesParam.threadIds, threadStatesParam.leftNs, threadStatesParam.rightNs).then((result) => { + queryCpuFreqFilterId().then(r =>{ + let IdMap = new Map(); + let queryId = new Array(); + for(let i = 0; i < r.length; i++){ + queryId.push(r[i].id); + IdMap.set(r[i].id,r[i].cpu); + } + queryCpuFreqUsageData(queryId).then((res) =>{ + if(result != null && result.length > 0){ + log('getTabRunningPercent result size : ' + result.length); + let sum = 0; + let dealArr = new Array(); + for(let i of res){ + dealArr.push({'startNS': i.startNS + threadStatesParam.recordStartNs, 'dur': i.dur, 'value': i.value, 'cpu': IdMap.get(i.filter_id)}); + } + let targetList = new Array(); + let cpuArr = new Array(); + let finalResultArr = new Array(); + finalResultArr.push({'thread': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': '100.00', 'state': 'Running', children: new Array()}); + for(let e of result){ + if(threadStatesParam.processIds.includes(e.pid) && e.state == 'Running'){ + let process = Utils.PROCESS_MAP.get(e.pid); + let thread = Utils.THREAD_MAP.get(e.tid); + e.process = process == null || process.length == 0 ? '[NULL]' : process; + e.thread = thread == null || thread.length == 0 ? '[NULL]' : thread; + e.stateJX = e.state; + e.state = Utils.getEndState(e.stateJX); + sum += e.dur; + targetList.push(e); + if(!cpuArr.includes(e.cpu)){ + cpuArr.push(e.cpu); + finalResultArr[0].thread = finalResultArr[0].thread == '' ? e.tid + '_' + e.thread : finalResultArr[0].thread; + finalResultArr[0].children.push({'thread': e.tid + '_' + e.thread, 'count': 0, 'cpu': e.cpu, 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array()}); + } + } + } + // 用来存放数据切割之前的汇总数据 + let resultList = new Array(); + // 通过循环获取每个running状态线程的相关信息,此处或许可以进行算法优化 + for(let i = 0; i < targetList.length; i++){ + for(let j = 0; j < dealArr.length; j++){ + if(targetList[i].cpu == dealArr[j].cpu){ + if(targetList[i].ts > dealArr[j].startNS){ + if(targetList[i].ts < (dealArr[j].startNS + dealArr[j].dur)){ + if(targetList[i].dur < (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)){ + resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * targetList[i].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts}); + break; + }else{ + resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts), 'percent': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts) / sum *100, 'state': 'Running', 'ts': targetList[i].ts}); + } + } + }else{ + if((targetList[i].ts + targetList[i].dur) > dealArr[j].startNS){ + if((targetList[i].dur + targetList[i].ts - dealArr[j].startNS) < dealArr[j].dur){ + resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (targetList[i].dur + targetList[i].ts - dealArr[j].startNS)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS), 'percent': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS) / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS}); + break; + }else{ + resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * dealArr[j].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': dealArr[j].dur, 'percent': dealArr[j].dur / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS}); + } + }else{ + resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': 0, 'cpu': targetList[i].cpu, 'freq': 'unknown', 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts}); + break; + } + } + } + } + } + // 深拷贝,用来进行数据切割操作,避免数据污染 + this.initData = JSON.parse(JSON.stringify(resultList)); + //合并同一线程内,当运行所在cpu和频点相同时,dur及percent进行累加求和,或许可以进行算法优化 + for(let i = 0; i < resultList.length ; i++){ + for(let j = i + 1; j < resultList.length; j++){ + if(resultList[i].cpu == resultList[j].cpu && resultList[i].freq == resultList[j].freq){ + resultList[i].dur += resultList[j].dur; + resultList[i].percent += resultList[j].percent; + resultList[i].count += resultList[j].count; + resultList.splice(j, 1); + j--; + } + } + resultList[i].percent = Number((resultList[i].percent).toFixed(2)); + resultList[i].ts = resultList[i].ts - threadStatesParam.recordStartNs; + } + finalResultArr[0].children.sort((a:any, b:any) => a.cpu - b.cpu); + // 转成树结构数据进行展示 + for(let i = 0; i < finalResultArr[0].children.length; i++){ + for(let j = 0; j < resultList.length; j++){ + if(finalResultArr[0].children[i].cpu == resultList[j].cpu){ + finalResultArr[0].children[i].children.push(resultList[j]); + finalResultArr[0].children[i].dur += resultList[j].dur; + finalResultArr[0].children[i].percent += resultList[j].percent; + finalResultArr[0].children[i].count += resultList[j].count; + resultList.splice(j, 1); + j--; + } + } + finalResultArr[0].children[i].percent = finalResultArr[0].children[i].percent.toFixed(2); + finalResultArr[0].dur += finalResultArr[0].children[i].dur; + finalResultArr[0].count += finalResultArr[0].children[i].count; + } + this.threadStatesTblSource = finalResultArr; + this.threadStatesTbl!.recycleDataSource = finalResultArr; + }else{ + this.threadStatesTblSource = []; + this.threadStatesTbl!.recycleDataSource = []; + this.initData = []; + } + }) + }) + + }); + } + initElements(): void { + this.threadStatesTbl = this.shadowRoot?.querySelector('#tb-running-percent'); + // 暂时屏蔽列排序功能,后续增加则重写排序方法 + // this.threadStatesTbl!.addEventListener('column-click', (evt: any) => { + // this.sortByColumn(evt.detail); + // }); + this.threadStatesDIV = this.shadowRoot?.querySelector('#dataCut'); + this.threadStatesDIV?.children[2].children[0].addEventListener('click', (e)=>{ + this.dataSingleCut(this.threadStatesDIV?.children[0], this.threadStatesDIV?.children[1], this.initData); + }) + this.threadStatesDIV?.children[2].children[1].addEventListener('click', (e)=>{ + this.dataLoopCut(this.threadStatesDIV?.children[0], this.threadStatesDIV?.children[1], this.initData); + }) + } + connectedCallback(){ + super.connectedCallback(); + resizeObserver(this.parentElement!, this.threadStatesTbl!); + } + initHtml(): string { + return ` + +
+ + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + ` + } + sortByColumn(treadStateDetail: any){ + function compare(property: any, treadStatesSort: any, type: any){ + return function(threadStatesLeftData: SelectionData | any, threadStatesRightData: SelectionData | any){ + if(threadStatesLeftData.process == ' ' || threadStatesRightData.process == ' '){ + return 0; + } + if(type === 'number'){ + return treadStatesSort === 2 + ? parseFloat(threadStatesRightData[property]) - parseFloat(threadStatesLeftData[property]) + : parseFloat(threadStatesLeftData[property]) - parseFloat(threadStatesRightData[property]); + }else{ + if(threadStatesRightData[property] > threadStatesLeftData[property]){ + return treadStatesSort === 2 ? 1 : -1; + }else if(threadStatesRightData[property] == threadStatesLeftData[property]){ + return 0; + }else{ + return treadStatesSort === 2 ? -1 : 1; + } + } + }; + } + + if(treadStateDetail.key === 'name' || treadStateDetail.key === 'thread' || treadStateDetail.key === 'state'){ + this.threadStatesTblSource.sort(compare(treadStateDetail.key, treadStateDetail.sort, 'string')); + }else{ + this.threadStatesTblSource.sort(compare(treadStateDetail.key, treadStateDetail.sort, 'number')); + } + this.threadStatesTbl!.recycleDataSource = this.threadStatesTblSource; + } + dataLoopCut(threadId: any, threadFunc:any, resultList:any){ + let threadIdValue = threadId.value.trim(); + let threadFuncName = threadFunc.value.trim(); + let leftNS = this.currentSelectionParam.leftNs; + let rightNS = this.currentSelectionParam.rightNs; + if(/^[0-9]*$/.test(threadIdValue)){ + querySearchFuncData(threadFuncName, threadIdValue, leftNS, rightNS).then(res => { + let displayArr = JSON.parse(JSON.stringify(resultList)); + let timeDur = this.currentSelectionParam.recordStartNs; + let cutArr = new Array(); + // 根据线程id及方法名获取的数据,处理后用作切割时间依据,时间跨度为整个方法开始时间到末个方法开始时间 + for(let i of res){ + cutArr.push({'ts': i.startTime + timeDur}); + } + // 将数据进行切割处理 + let finalArr = new Array(); + let finalResultArr = new Array(); + let tsArr = new Array(); + finalResultArr.push({'thread': displayArr[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array()}); + for(let i = 0; i < cutArr.length - 1; i++){ + for(let j = 0; j < displayArr.length; j++){ + if(displayArr[j].ts >= cutArr[i].ts){ + if((displayArr[j].ts + displayArr[j].dur) <= cutArr[i+1].ts){ + finalArr.push({'thread': displayArr[j].thread, 'count': (displayArr[j].freq * displayArr[j].dur) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': displayArr[j].dur, 'percent': displayArr[j].percent, 'state': 'Running', 'ts': (displayArr[j].ts - timeDur) / 1000000000, 'id': i}); + }else{ + if(cutArr[i+1].ts - displayArr[j].ts > 0){ + finalArr.push({'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (cutArr[i+1].ts - displayArr[j].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': cutArr[i+1].ts - displayArr[j].ts, 'percent': displayArr[j].percent * ((cutArr[i+1].ts - displayArr[j].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (displayArr[j].ts - timeDur) / 1000000000, 'id': i}); + break; + } + } + }else{ + if((displayArr[j].ts + displayArr[j].dur) > cutArr[i+1].ts){ + finalArr.push({'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (cutArr[i+1].ts - cutArr[i].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': cutArr[i+1].ts - cutArr[i].ts, 'percent': displayArr[j].percent * ((cutArr[i+1].ts - cutArr[i].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (cutArr[i].ts - timeDur) / 1000000000, 'id': i}); + } + if((displayArr[j].ts + displayArr[j].dur) > cutArr[i].ts && (displayArr[j].ts + displayArr[j].dur) < cutArr[i+1].ts){ + finalArr.push({'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (displayArr[j].dur + displayArr[j].ts - cutArr[i].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': displayArr[j].dur + displayArr[j].ts - cutArr[i].ts, 'percent': displayArr[j].percent * ((displayArr[j].dur + displayArr[j].ts - cutArr[i].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (cutArr[i].ts - timeDur) / 1000000000, 'id': i}); + } + } + } + finalResultArr[0].children.push({'thread': displayArr[0].thread, 'ts': (cutArr[i].ts - timeDur) / 1000000000,'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array(), 'id': i}); + } + + for(let i = 0; i < finalArr.length; i++){ + for(let j = i+1; j < finalArr.length; j++){ + if(finalArr[i].cpu === finalArr[j].cpu && finalArr[i].freq === finalArr[j].freq && finalArr[i].id === finalArr[j].id){ + finalArr[i].dur += finalArr[j].dur; + finalArr[i].percent += finalArr[j].percent; + finalArr[i].count += finalArr[j].count; + finalArr.splice(j, 1); + j--; + } + } + finalArr[i].percent = Number((finalArr[i].percent).toFixed(2)); + } + + let newArr1 = JSON.parse(JSON.stringify(finalResultArr[0])); + let newArr2 = JSON.parse(JSON.stringify(finalArr)); + let finalResult = new Array(this.mergeTree(newArr1, newArr2)); + this.threadStatesTblSource = finalResult[0].children.length > 0 ? finalResult : []; + this.threadStatesTbl!.recycleDataSource = finalResult[0].children.length > 0 ? finalResult : []; + }) + }else{ + alert('请输入正确的线程ID'); + } + } + dataSingleCut(threadId: any, threadFunc:any, resultList:any){ + let threadIdValue = threadId.value.trim(); + let threadFuncName = threadFunc.value.trim(); + let leftNS = this.currentSelectionParam.leftNs; + let rightNS = this.currentSelectionParam.rightNs; + if(/^[0-9]*$/.test(threadIdValue)){ + querySearchFuncData(threadFuncName, threadIdValue, leftNS, rightNS).then(result => { + let [...targetList] = JSON.parse(JSON.stringify(resultList)); + let timeDur = this.currentSelectionParam.recordStartNs; + let dealArr = new Array(); + for(let i of result){ + if(i.startTime + timeDur + i.dur > this.currentSelectionParam.rightNs + timeDur){ + dealArr.push({'ts': i.startTime + timeDur, 'dur': this.currentSelectionParam.rightNs + timeDur - (i.startTime + timeDur)}); + }else{ + dealArr.push({'ts': i.startTime + timeDur, 'dur': i.dur}); + } + } + let finalResultArr = new Array(); + finalResultArr.push({'thread': targetList[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array()}); + let resList = new Array(); + for(let i = 0; i < dealArr.length; i++){ + for(let j = 0; j < targetList.length; j++){ + if(dealArr[i].ts < targetList[j].ts){ + if(dealArr[i].ts + dealArr[i].dur > targetList[j].ts){ + if(dealArr[i].ts + dealArr[i].dur > targetList[j].ts + targetList[j].dur){ + resList.push({'thread': targetList[i].thread, 'ts': (targetList[j].ts - timeDur) / 1000000000, 'count': (targetList[j].freq * targetList[j].dur) / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': targetList[j].dur, 'percent': targetList[j].percent, 'state': 'Running', 'id': i}); + }else{ + resList.push({'thread': targetList[j].thread, 'ts': (targetList[j].ts - timeDur) / 1000000000, 'count': (dealArr[i].ts + dealArr[i].dur - targetList[j].ts) * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': dealArr[i].ts + dealArr[i].dur - targetList[j].ts, 'percent': (dealArr[i].ts + dealArr[i].dur - targetList[j].ts) / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i}); + break; + } + } + }else{ + if(targetList[j].ts + targetList[j].dur > dealArr[i].ts){ + if(targetList[j].ts + targetList[j].dur > dealArr[i].ts + dealArr[i].dur){ + resList.push({'thread': targetList[j].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000, 'count': dealArr[i].dur * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': dealArr[i].dur, 'percent': dealArr[i].dur / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i}); + break; + }else{ + resList.push({'thread': targetList[j].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000, 'count': (targetList[j].ts + targetList[j].dur - dealArr[i].ts) * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': targetList[j].ts + targetList[j].dur - dealArr[i].ts, 'percent': (targetList[j].ts + targetList[j].dur - dealArr[i].ts) / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i}); + } + } + } + } + finalResultArr[0].children.push({'thread': targetList[0].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000,'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array(), 'id': i}); + } + // 合并相同周期内的数据 + for(let i = 0; i < resList.length; i++){ + for(let j = i+1; j < resList.length; j++){ + if(resList[i].cpu === resList[j].cpu && resList[i].freq === resList[j].freq && resList[i].id === resList[j].id){ + resList[i].dur += resList[j].dur; + resList[i].percent += resList[j].percent; + resList[i].count += resList[j].count; + resList.splice(j, 1); + j--; + } + } + resList[i].percent = Number((resList[i].percent).toFixed(2)); + } + + let newArr1 = JSON.parse(JSON.stringify(finalResultArr[0])); + let newArr2 = JSON.parse(JSON.stringify(resList)); + let finalResult = new Array(this.mergeTree(newArr1, newArr2)); + + this.threadStatesTblSource = finalResult[0].children.length > 0 ? finalResult : []; + this.threadStatesTbl!.recycleDataSource = finalResult[0].children.length > 0 ? finalResult : []; + }) + }else{ + alert('请输入正确的线程ID'); + } + } + + mergeTree (arr1:any, arr2:any) { + for(let i = 0; i < arr1.children.length; i++){ + // 改成map对象做标记 + let cpuArr = new Array(); + let flagMap = new Map(); + let flag = 0; + for(let j = 0; j < arr2.length; j++){ + if(arr1.children[i].id == arr2[j].id){ + if(!cpuArr.includes(arr2[j].cpu)){ + flagMap.set(arr2[j].cpu, flag); + cpuArr.push(arr2[j].cpu); + arr1.children[i].children.push({'thread': arr2[j].thread, 'count': 0, 'cpu': arr2[j].cpu, 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', 'ts': '', children: new Array(), 'id': arr2[j].id}); + if(arr1.children[i].children[flag].cpu == arr2[j].cpu && arr1.children[i].children[flag].id == arr2[j].id){ + arr1.children[i].children[flag].children.push(arr2[j]); + arr1.children[i].children[flag].dur += arr2[j].dur; + arr1.children[i].children[flag].percent += arr2[j].percent; + arr1.children[i].children[flag].count += arr2[j].count; + arr1.children[i].percent += arr1.children[i].children[flag].percent; + arr1.children[i].children[flag].percent = Number(arr1.children[i].children[flag].percent.toFixed(2)); + arr1.children[i].dur += arr1.children[i].children[flag].dur; + arr1.children[i].count += arr1.children[i].children[flag].count; + // arr1.children[i].thread = arr1.children[i].children[flag].thread; + flag++; + arr2.splice(j, 1); + j--; + } + }else{ + // 利用map做数据处理 + let count = flagMap.get(arr2[j].cpu); + if(arr1.children[i].children[count].cpu == arr2[j].cpu && arr1.children[i].children[count].id == arr2[j].id){ + arr1.children[i].children[count].children.push(arr2[j]); + arr1.children[i].children[count].dur += arr2[j].dur; + arr1.children[i].children[count].percent += arr2[j].percent; + arr1.children[i].children[count].count += arr2[j].count; + arr1.children[i].percent += arr2[j].percent; + arr1.children[i].children[count].percent = Number(arr2[j].percent.toFixed(2)); + arr1.children[i].dur += arr2[j].dur; + arr1.children[i].count += arr2[j].count; + // arr1.children[i].thread = arr2[j].thread; + arr2.splice(j, 1); + j--; + } + } + }else{ + break; + } + } + arr1.children[i].children.sort((a:any, b:any) => a.cpu - b.cpu); + arr1.percent += arr1.children[i].percent; + arr1.children[i].percent = Number(arr1.children[i].percent.toFixed(2)); + arr1.dur += arr1.children[i].dur; + arr1.count += arr1.children[i].count; + // arr1.thread = arr1.children[i].thread == '' ? arr1.thread : arr1.children[i].thread; + } + arr1.percent = Number(arr1.percent.toFixed(2)); + return arr1; + } +} \ No newline at end of file diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts new file mode 100644 index 000000000..21f1a3c5d --- /dev/null +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts @@ -0,0 +1,199 @@ +import { BaseElement, element } from '../../../../../base-ui/BaseElement.js'; +import { LitTable } from '../../../../../base-ui/table/lit-table'; +import { SelectionData, SelectionParam } from '../../../../bean/BoxSelection'; +import '../../../StackBar.js' +import { getTabRunningPercent, queryCpuFreqUsageData, queryCpuFreqFilterId } from '../../../../database/SqlLite.js'; +import { Utils } from '../../base/Utils.js'; +import { log } from '../../../../../log/Log.js'; +import { resizeObserver } from '../SheetUtils.js'; + +@element('tabpane-frequsage') +export class TabPaneFreqUsage extends BaseElement { + private threadStatesTbl: LitTable | null | undefined; + private threadStatesTblSource: Array = []; + private currentSelectionParam: Selection | undefined; + + set data(threadStatesParam: SelectionParam | any) { + if (this.currentSelectionParam === threadStatesParam) { + return; + } + this.currentSelectionParam = threadStatesParam; + this.threadStatesTblSource = []; + this.threadStatesTbl!.recycleDataSource = []; + getTabRunningPercent(threadStatesParam.threadIds, threadStatesParam.leftNs, threadStatesParam.rightNs).then((result) => { + queryCpuFreqFilterId().then(r =>{ + let IdMap = new Map(); + let queryId = new Array(); + for(let i = 0; i < r.length; i++){ + queryId.push(r[i].id); + IdMap.set(r[i].id,r[i].cpu); + } + queryCpuFreqUsageData(queryId).then((res) =>{ + if(result != null && result.length > 0){ + let sum = 0; + let dealArr = new Array(); + for(let i of res){ + dealArr.push({'startNS': i.startNS + threadStatesParam.recordStartNs, 'dur': i.dur, 'value': i.value, 'cpu': IdMap.get(i.filter_id)}); + } + let targetList = new Array(); + let cpuArr = new Array(); + let finalResultArr = new Array(); + finalResultArr.push({'thread': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': '100.00', 'state': 'Running', children: new Array()}); + for(let e of result){ + if(threadStatesParam.processIds.includes(e.pid) && e.state == 'Running'){ + let process = Utils.PROCESS_MAP.get(e.pid); + let thread = Utils.THREAD_MAP.get(e.tid); + e.process = process == null || process.length == 0 ? '[NULL]' : process; + e.thread = thread == null || thread.length == 0 ? '[NULL]' : thread; + e.stateJX = e.state; + e.state = Utils.getEndState(e.stateJX); + sum += e.dur; + targetList.push(e); + if(!cpuArr.includes(e.cpu)){ + cpuArr.push(e.cpu); + finalResultArr[0].thread = finalResultArr[0].thread == '' ? e.tid + '_' + e.thread : finalResultArr[0].thread; + finalResultArr[0].children.push({'thread': e.tid + '_' + e.thread, 'count': 0, 'cpu': e.cpu, 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array()}); + } + } + } + let resultList = new Array(); + for(let i = 0; i < targetList.length; i++){ + for(let j = 0; j < dealArr.length; j++){ + if(targetList[i].cpu == dealArr[j].cpu){ + if(targetList[i].ts > dealArr[j].startNS){ + if(targetList[i].ts < (dealArr[j].startNS + dealArr[j].dur)){ + if(targetList[i].dur < (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)){ + resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * targetList[i].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts}); + break; + }else{ + resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts), 'percent': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts) / sum *100, 'state': 'Running', 'ts': targetList[i].ts}); + } + } + }else{ + if((targetList[i].ts + targetList[i].dur) > dealArr[j].startNS){ + if((targetList[i].dur + targetList[i].ts - dealArr[j].startNS) < dealArr[j].dur){ + resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (targetList[i].dur + targetList[i].ts - dealArr[j].startNS)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS), 'percent': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS) / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS}); + break; + }else{ + resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * dealArr[j].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': dealArr[j].dur, 'percent': dealArr[j].dur / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS}); + } + }else{ + // resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': 'unknown', 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts}); + resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': 0, 'cpu': targetList[i].cpu, 'freq': 'unknown', 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts}); + break; + } + } + } + } + } + //合并同一线程内,当运行所在cpu和频点相同时,dur及percent进行累加求和,或许可以进行算法优化 + for(let i = 0; i < resultList.length ; i++){ + for(let j = i + 1; j < resultList.length; j++){ + if(resultList[i].cpu == resultList[j].cpu && resultList[i].freq == resultList[j].freq){ + resultList[i].dur += resultList[j].dur; + resultList[i].percent += resultList[j].percent; + resultList[i].count += resultList[j].count; + resultList.splice(j, 1); + j--; + } + } + resultList[i].percent = Number((resultList[i].percent).toFixed(2)); + resultList[i].ts = resultList[i].ts - threadStatesParam.recordStartNs; + } + finalResultArr[0].children.sort((a:any, b:any) => a.cpu - b.cpu); + // 转成树结构数据进行展示 + for(let i = 0; i < finalResultArr[0].children.length; i++){ + for(let j = 0; j < resultList.length; j++){ + if(finalResultArr[0].children[i].cpu == resultList[j].cpu){ + finalResultArr[0].children[i].children.push(resultList[j]); + finalResultArr[0].children[i].dur += resultList[j].dur; + finalResultArr[0].children[i].percent += resultList[j].percent; + finalResultArr[0].children[i].count += resultList[j].count; + resultList.splice(j, 1); + j--; + } + } + finalResultArr[0].children[i].percent = finalResultArr[0].children[i].percent.toFixed(2); + finalResultArr[0].dur += finalResultArr[0].children[i].dur; + finalResultArr[0].count += finalResultArr[0].children[i].count; + } + this.threadStatesTblSource = finalResultArr; + this.threadStatesTbl!.recycleDataSource = finalResultArr; + }else{ + this.threadStatesTblSource = []; + this.threadStatesTbl!.recycleDataSource = []; + } + }); + }); + + }) + } + initElements(): void { + this.threadStatesTbl = this.shadowRoot?.querySelector('#tb-running-percent'); + // 列排序暂时屏蔽 + // this.threadStatesTbl!.addEventListener('column-click', (evt: any) => { + // this.sortByColumn(evt.detail); + // }); + } + connectedCallback() { + super.connectedCallback(); + resizeObserver(this.parentElement!, this.threadStatesTbl!); + } + initHtml(): string { + return ` + + + + + + + + + + + + + + + + + + ` + } + sortByColumn(treadStateDetail: any) { + function compare(property: any, treadStatesSort: any, type: any){ + return function(threadStatesLeftData: SelectionData | any, threadStatesRightData: SelectionData | any){ + if(threadStatesLeftData.process == ' ' || threadStatesRightData.process == ' '){ + return 0; + } + if(type === 'number'){ + return treadStatesSort === 2 + ? parseFloat(threadStatesRightData[property]) - parseFloat(threadStatesLeftData[property]) + : parseFloat(threadStatesLeftData[property]) - parseFloat(threadStatesRightData[property]); + }else{ + if(threadStatesRightData[property] > threadStatesLeftData[property]){ + return treadStatesSort === 2 ? 1 : -1; + }else if(threadStatesRightData[property] == threadStatesLeftData[property]){ + return 0; + }else{ + return treadStatesSort === 2 ? -1 : 1; + } + } + }; + } + + if(treadStateDetail.key === 'name' || treadStateDetail.key === 'thread' || treadStateDetail.key === 'state'){ + this.threadStatesTblSource.sort(compare(treadStateDetail.key, treadStateDetail.sort, 'string')); + }else{ + this.threadStatesTblSource.sort(compare(treadStateDetail.key, treadStateDetail.sort, 'number')); + } + this.threadStatesTbl!.recycleDataSource = this.threadStatesTblSource; + } + +} \ No newline at end of file diff --git a/ide/src/trace/database/SqlLite.ts b/ide/src/trace/database/SqlLite.ts index 0d8e59865..9dd4fd62e 100644 --- a/ide/src/trace/database/SqlLite.ts +++ b/ide/src/trace/database/SqlLite.ts @@ -5494,3 +5494,68 @@ export const queryTraceType = (): Promise< export const queryTransferList = (): Promise> => query('queryTransferList', `select id, report_value as cmdStr from perf_report where report_type = 'config_name'`); + + export const getTabRunningPercent = (tIds: Array, leftNS: number, rightNS: number): Promise> => +query( + 'getTabRunningPercent', + ` + select + B.pid,B.tid,B.state,B.cpu,B.dur,B.ts + from + thread_state AS B + left join + trace_range AS TR + where + B.tid in (${tIds.join(',')}) + and + B.state='Running' + and + not ((B.ts - TR.start_ts + ifnull(B.dur,0) < ${leftNS}) or (B.ts - TR.start_ts > ${rightNS})) + order by ts + `, + {$leftNS:leftNS, $rightNS:rightNS} +); + +export const querySearchFuncData = (funcName: string, tIds: Array, leftNS: number, rightNS: number): Promise> => +query( + 'querySearchFuncData', + ` + select c.cookie,c.id,c.name as funName,c.ts - r.start_ts as startTime,c.dur,c.depth,t.tid,t.name as threadName, + p.pid,'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 + where c.name = '${funcName}' and t.tid = ${tIds} and + not ((startTime < ${leftNS}) or (startTime > ${rightNS})); + `, + {$search: funcName} +); + +export const queryCpuFreqUsageData = (Ids: Array): Promise> => +query( + 'queryCpuFreqUsageData', + `select + value, + ifnull(dur,tb.end_ts - c.ts) dur, + ts-tb.start_ts as startNS, + filter_id + from + measure c, + trace_range tb + where + c.filter_id in (${Ids.join(',')}) + ` +); + +export const queryCpuFreqFilterId = (): Promise> => +query( + 'queryCpuFreqFilterId', + `select + id, + cpu + from + cpu_measure_filter + where + name='cpufreq' + or + name='cpu_frequency' + ` +); \ No newline at end of file -- Gitee From 793d3f933b1d4a0b3bc0acdcf83dab6526c02c69 Mon Sep 17 00:00:00 2001 From: "lizhuosong@huawei.com" Date: Wed, 25 Oct 2023 16:12:37 +0800 Subject: [PATCH 2/8] =?UTF-8?q?single=E5=88=87=E5=89=B2=E5=91=A8=E6=9C=9F?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lizhuosong@huawei.com --- .../component/trace/sheet/frequsage/TabPaneFreqDataCut.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts index 86f24363c..a32d4f68b 100644 --- a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts @@ -315,9 +315,7 @@ export class TabPaneFreqDataCut extends BaseElement{ let timeDur = this.currentSelectionParam.recordStartNs; let dealArr = new Array(); for(let i of result){ - if(i.startTime + timeDur + i.dur > this.currentSelectionParam.rightNs + timeDur){ - dealArr.push({'ts': i.startTime + timeDur, 'dur': this.currentSelectionParam.rightNs + timeDur - (i.startTime + timeDur)}); - }else{ + if(i.startTime + timeDur + i.dur < this.currentSelectionParam.rightNs + timeDur){ dealArr.push({'ts': i.startTime + timeDur, 'dur': i.dur}); } } -- Gitee From e8fe743853ffa39a15572a70625453f11feca4ce Mon Sep 17 00:00:00 2001 From: "lizhuosong@huawei.com" Date: Thu, 26 Oct 2023 10:57:58 +0800 Subject: [PATCH 3/8] add License Signed-off-by: lizhuosong@huawei.com --- .../trace/sheet/frequsage/TabPaneFreqDataCut.ts | 15 +++++++++++++++ .../trace/sheet/frequsage/TabPaneFreqUsage.ts | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts index a32d4f68b..f72c5c031 100644 --- a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { BaseElement, element } from '../../../../../base-ui/BaseElement.js'; import { LitTable } from '../../../../../base-ui/table/lit-table'; import { SelectionData, SelectionParam } from '../../../../bean/BoxSelection'; diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts index 21f1a3c5d..4f7bd7b7d 100644 --- a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { BaseElement, element } from '../../../../../base-ui/BaseElement.js'; import { LitTable } from '../../../../../base-ui/table/lit-table'; import { SelectionData, SelectionParam } from '../../../../bean/BoxSelection'; -- Gitee From d8c9e3b18c93a8624ac7e746b8d92d1c5eeccab3 Mon Sep 17 00:00:00 2001 From: "lizhuosong@huawei.com" Date: Thu, 26 Oct 2023 14:59:58 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E9=A1=B5=E6=87=92=E5=8A=A0=E8=BD=BD=E6=9D=A1=E4=BB=B6=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lizhuosong@huawei.com --- .../component/trace/base/TraceSheetConfig.ts | 6 +- .../sheet/frequsage/TabPaneFreqDataCut.ts | 263 ++++++++---------- .../trace/sheet/frequsage/TabPaneFreqUsage.ts | 113 +++----- ide/src/trace/database/SqlLite.ts | 53 ++-- 4 files changed, 182 insertions(+), 253 deletions(-) diff --git a/ide/src/trace/component/trace/base/TraceSheetConfig.ts b/ide/src/trace/component/trace/base/TraceSheetConfig.ts index f4517bb78..2c7ab24c1 100644 --- a/ide/src/trace/component/trace/base/TraceSheetConfig.ts +++ b/ide/src/trace/component/trace/base/TraceSheetConfig.ts @@ -627,15 +627,15 @@ export let tabConfig: any = { title: 'M Selection', type: TabPaneCurrent, require: (param: SelectionParam) => param.isCurrentPane, - }, //current selection + }, 'tabpane-frequsage': { title: 'Freq Usage', type: TabPaneFreqUsage, - require: (param: SelectionParam) => param.threadIds.length > 0, + require: (param: SelectionParam) => param.threadIds.length > 0 && param.threadIds.length < 2, }, 'tabpane-freqdatacut': { title: 'Freq DataCut', type: TabPaneFreqDataCut, - require: (param: SelectionParam) => param.threadIds.length > 0, + require: (param: SelectionParam) => param.threadIds.length > 0 && param.threadIds.length < 2, }, }; diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts index f72c5c031..3327b140e 100644 --- a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,43 +23,46 @@ import { log } from '../../../../../log/Log.js'; import { resizeObserver } from '../SheetUtils.js'; @element('tabpane-freqdatacut') -export class TabPaneFreqDataCut extends BaseElement{ - private threadStatesTbl: LitTable|null|undefined; - private threadStatesTblSource:Array = []; - private currentSelectionParam: SelectionParam|any; - private threadStatesDIV:Element|null|undefined; - private initData:Array = []; +export class TabPaneFreqDataCut extends BaseElement { + private threadStatesTbl: LitTable | null | undefined; + private threadStatesTblSource: Array = []; + private currentSelectionParam: SelectionParam | any; + private threadStatesDIV: Element | null | undefined; + private initData: Array = []; - set data(threadStatesParam: SelectionParam|any){ + set data(threadStatesParam: SelectionParam | any) { if (this.currentSelectionParam === threadStatesParam) { return; } this.currentSelectionParam = threadStatesParam; this.threadStatesTblSource = []; this.threadStatesTbl!.recycleDataSource = []; - + let divRoot1: any = this.shadowRoot?.querySelector('#dataCutThreadId'); + divRoot1.value = ''; + let divRoot2: any = this.shadowRoot?.querySelector('#dataCutThreadFunc'); + divRoot2.value = ''; getTabRunningPercent(threadStatesParam.threadIds, threadStatesParam.leftNs, threadStatesParam.rightNs).then((result) => { - queryCpuFreqFilterId().then(r =>{ + queryCpuFreqFilterId().then(r => { let IdMap = new Map(); let queryId = new Array(); - for(let i = 0; i < r.length; i++){ + for (let i = 0; i < r.length; i++) { queryId.push(r[i].id); - IdMap.set(r[i].id,r[i].cpu); + IdMap.set(r[i].id, r[i].cpu); } - queryCpuFreqUsageData(queryId).then((res) =>{ - if(result != null && result.length > 0){ + queryCpuFreqUsageData(queryId).then((res) => { + if (result != null && result.length > 0) { log('getTabRunningPercent result size : ' + result.length); let sum = 0; let dealArr = new Array(); - for(let i of res){ - dealArr.push({'startNS': i.startNS + threadStatesParam.recordStartNs, 'dur': i.dur, 'value': i.value, 'cpu': IdMap.get(i.filter_id)}); + for (let i of res) { + dealArr.push({ 'startNS': i.startNS + threadStatesParam.recordStartNs, 'dur': i.dur, 'value': i.value, 'cpu': IdMap.get(i.filter_id) }); } let targetList = new Array(); let cpuArr = new Array(); let finalResultArr = new Array(); - finalResultArr.push({'thread': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': '100.00', 'state': 'Running', children: new Array()}); - for(let e of result){ - if(threadStatesParam.processIds.includes(e.pid) && e.state == 'Running'){ + finalResultArr.push({ 'thread': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': '100.00', 'state': 'Running', children: new Array() }); + for (let e of result) { + if (threadStatesParam.processIds.includes(e.pid) && e.state == 'Running') { let process = Utils.PROCESS_MAP.get(e.pid); let thread = Utils.THREAD_MAP.get(e.tid); e.process = process == null || process.length == 0 ? '[NULL]' : process; @@ -68,38 +71,38 @@ export class TabPaneFreqDataCut extends BaseElement{ e.state = Utils.getEndState(e.stateJX); sum += e.dur; targetList.push(e); - if(!cpuArr.includes(e.cpu)){ + if (!cpuArr.includes(e.cpu)) { cpuArr.push(e.cpu); finalResultArr[0].thread = finalResultArr[0].thread == '' ? e.tid + '_' + e.thread : finalResultArr[0].thread; - finalResultArr[0].children.push({'thread': e.tid + '_' + e.thread, 'count': 0, 'cpu': e.cpu, 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array()}); + finalResultArr[0].children.push({ 'thread': e.tid + '_' + e.thread, 'count': 0, 'cpu': e.cpu, 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array() }); } } } // 用来存放数据切割之前的汇总数据 let resultList = new Array(); // 通过循环获取每个running状态线程的相关信息,此处或许可以进行算法优化 - for(let i = 0; i < targetList.length; i++){ - for(let j = 0; j < dealArr.length; j++){ - if(targetList[i].cpu == dealArr[j].cpu){ - if(targetList[i].ts > dealArr[j].startNS){ - if(targetList[i].ts < (dealArr[j].startNS + dealArr[j].dur)){ - if(targetList[i].dur < (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)){ - resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * targetList[i].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts}); + for (let i = 0; i < targetList.length; i++) { + for (let j = 0; j < dealArr.length; j++) { + if (targetList[i].cpu == dealArr[j].cpu) { + if (targetList[i].ts > dealArr[j].startNS) { + if (targetList[i].ts < (dealArr[j].startNS + dealArr[j].dur)) { + if (targetList[i].dur < (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) { + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * targetList[i].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts }); break; - }else{ - resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts), 'percent': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts) / sum *100, 'state': 'Running', 'ts': targetList[i].ts}); + } else { + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts), 'percent': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts) / sum * 100, 'state': 'Running', 'ts': targetList[i].ts }); } } - }else{ - if((targetList[i].ts + targetList[i].dur) > dealArr[j].startNS){ - if((targetList[i].dur + targetList[i].ts - dealArr[j].startNS) < dealArr[j].dur){ - resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (targetList[i].dur + targetList[i].ts - dealArr[j].startNS)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS), 'percent': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS) / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS}); + } else { + if ((targetList[i].ts + targetList[i].dur) > dealArr[j].startNS) { + if ((targetList[i].dur + targetList[i].ts - dealArr[j].startNS) < dealArr[j].dur) { + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (targetList[i].dur + targetList[i].ts - dealArr[j].startNS)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS), 'percent': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS) / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS }); break; - }else{ - resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * dealArr[j].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': dealArr[j].dur, 'percent': dealArr[j].dur / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS}); + } else { + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * dealArr[j].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': dealArr[j].dur, 'percent': dealArr[j].dur / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS }); } - }else{ - resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': 0, 'cpu': targetList[i].cpu, 'freq': 'unknown', 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts}); + } else { + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': 0, 'cpu': targetList[i].cpu, 'freq': 'unknown', 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts }); break; } } @@ -109,9 +112,9 @@ export class TabPaneFreqDataCut extends BaseElement{ // 深拷贝,用来进行数据切割操作,避免数据污染 this.initData = JSON.parse(JSON.stringify(resultList)); //合并同一线程内,当运行所在cpu和频点相同时,dur及percent进行累加求和,或许可以进行算法优化 - for(let i = 0; i < resultList.length ; i++){ - for(let j = i + 1; j < resultList.length; j++){ - if(resultList[i].cpu == resultList[j].cpu && resultList[i].freq == resultList[j].freq){ + for (let i = 0; i < resultList.length; i++) { + for (let j = i + 1; j < resultList.length; j++) { + if (resultList[i].cpu == resultList[j].cpu && resultList[i].freq == resultList[j].freq) { resultList[i].dur += resultList[j].dur; resultList[i].percent += resultList[j].percent; resultList[i].count += resultList[j].count; @@ -122,11 +125,11 @@ export class TabPaneFreqDataCut extends BaseElement{ resultList[i].percent = Number((resultList[i].percent).toFixed(2)); resultList[i].ts = resultList[i].ts - threadStatesParam.recordStartNs; } - finalResultArr[0].children.sort((a:any, b:any) => a.cpu - b.cpu); + finalResultArr[0].children.sort((a: any, b: any) => a.cpu - b.cpu); // 转成树结构数据进行展示 - for(let i = 0; i < finalResultArr[0].children.length; i++){ - for(let j = 0; j < resultList.length; j++){ - if(finalResultArr[0].children[i].cpu == resultList[j].cpu){ + for (let i = 0; i < finalResultArr[0].children.length; i++) { + for (let j = 0; j < resultList.length; j++) { + if (finalResultArr[0].children[i].cpu == resultList[j].cpu) { finalResultArr[0].children[i].children.push(resultList[j]); finalResultArr[0].children[i].dur += resultList[j].dur; finalResultArr[0].children[i].percent += resultList[j].percent; @@ -141,31 +144,28 @@ export class TabPaneFreqDataCut extends BaseElement{ } this.threadStatesTblSource = finalResultArr; this.threadStatesTbl!.recycleDataSource = finalResultArr; - }else{ + } else { this.threadStatesTblSource = []; this.threadStatesTbl!.recycleDataSource = []; this.initData = []; } }) }) - + }); } initElements(): void { this.threadStatesTbl = this.shadowRoot?.querySelector('#tb-running-percent'); // 暂时屏蔽列排序功能,后续增加则重写排序方法 - // this.threadStatesTbl!.addEventListener('column-click', (evt: any) => { - // this.sortByColumn(evt.detail); - // }); this.threadStatesDIV = this.shadowRoot?.querySelector('#dataCut'); - this.threadStatesDIV?.children[2].children[0].addEventListener('click', (e)=>{ + this.threadStatesDIV?.children[2].children[0].addEventListener('click', (e) => { this.dataSingleCut(this.threadStatesDIV?.children[0], this.threadStatesDIV?.children[1], this.initData); }) - this.threadStatesDIV?.children[2].children[1].addEventListener('click', (e)=>{ + this.threadStatesDIV?.children[2].children[1].addEventListener('click', (e) => { this.dataLoopCut(this.threadStatesDIV?.children[0], this.threadStatesDIV?.children[1], this.initData); }) } - connectedCallback(){ + connectedCallback() { super.connectedCallback(); resizeObserver(this.parentElement!, this.threadStatesTbl!); } @@ -225,81 +225,51 @@ export class TabPaneFreqDataCut extends BaseElement{ ` } - sortByColumn(treadStateDetail: any){ - function compare(property: any, treadStatesSort: any, type: any){ - return function(threadStatesLeftData: SelectionData | any, threadStatesRightData: SelectionData | any){ - if(threadStatesLeftData.process == ' ' || threadStatesRightData.process == ' '){ - return 0; - } - if(type === 'number'){ - return treadStatesSort === 2 - ? parseFloat(threadStatesRightData[property]) - parseFloat(threadStatesLeftData[property]) - : parseFloat(threadStatesLeftData[property]) - parseFloat(threadStatesRightData[property]); - }else{ - if(threadStatesRightData[property] > threadStatesLeftData[property]){ - return treadStatesSort === 2 ? 1 : -1; - }else if(threadStatesRightData[property] == threadStatesLeftData[property]){ - return 0; - }else{ - return treadStatesSort === 2 ? -1 : 1; - } - } - }; - } - - if(treadStateDetail.key === 'name' || treadStateDetail.key === 'thread' || treadStateDetail.key === 'state'){ - this.threadStatesTblSource.sort(compare(treadStateDetail.key, treadStateDetail.sort, 'string')); - }else{ - this.threadStatesTblSource.sort(compare(treadStateDetail.key, treadStateDetail.sort, 'number')); - } - this.threadStatesTbl!.recycleDataSource = this.threadStatesTblSource; - } - dataLoopCut(threadId: any, threadFunc:any, resultList:any){ + dataLoopCut(threadId: any, threadFunc: any, resultList: any) { let threadIdValue = threadId.value.trim(); let threadFuncName = threadFunc.value.trim(); let leftNS = this.currentSelectionParam.leftNs; let rightNS = this.currentSelectionParam.rightNs; - if(/^[0-9]*$/.test(threadIdValue)){ + if (/^[0-9]*$/.test(threadIdValue)) { querySearchFuncData(threadFuncName, threadIdValue, leftNS, rightNS).then(res => { let displayArr = JSON.parse(JSON.stringify(resultList)); let timeDur = this.currentSelectionParam.recordStartNs; let cutArr = new Array(); // 根据线程id及方法名获取的数据,处理后用作切割时间依据,时间跨度为整个方法开始时间到末个方法开始时间 - for(let i of res){ - cutArr.push({'ts': i.startTime + timeDur}); + for (let i of res) { + cutArr.push({ 'ts': i.startTime + timeDur }); } // 将数据进行切割处理 let finalArr = new Array(); let finalResultArr = new Array(); - let tsArr = new Array(); - finalResultArr.push({'thread': displayArr[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array()}); - for(let i = 0; i < cutArr.length - 1; i++){ - for(let j = 0; j < displayArr.length; j++){ - if(displayArr[j].ts >= cutArr[i].ts){ - if((displayArr[j].ts + displayArr[j].dur) <= cutArr[i+1].ts){ - finalArr.push({'thread': displayArr[j].thread, 'count': (displayArr[j].freq * displayArr[j].dur) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': displayArr[j].dur, 'percent': displayArr[j].percent, 'state': 'Running', 'ts': (displayArr[j].ts - timeDur) / 1000000000, 'id': i}); - }else{ - if(cutArr[i+1].ts - displayArr[j].ts > 0){ - finalArr.push({'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (cutArr[i+1].ts - displayArr[j].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': cutArr[i+1].ts - displayArr[j].ts, 'percent': displayArr[j].percent * ((cutArr[i+1].ts - displayArr[j].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (displayArr[j].ts - timeDur) / 1000000000, 'id': i}); + finalResultArr.push({ 'thread': displayArr[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array() }); + for (let i = 0; i < cutArr.length - 1; i++) { + for (let j = 0; j < displayArr.length; j++) { + if (displayArr[j].ts >= cutArr[i].ts) { + if ((displayArr[j].ts + displayArr[j].dur) <= cutArr[i + 1].ts) { + finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * displayArr[j].dur) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': displayArr[j].dur, 'percent': displayArr[j].percent, 'state': 'Running', 'ts': (displayArr[j].ts - timeDur) / 1000000000, 'id': i }); + } else { + if (cutArr[i + 1].ts - displayArr[j].ts > 0) { + finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (cutArr[i + 1].ts - displayArr[j].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': cutArr[i + 1].ts - displayArr[j].ts, 'percent': displayArr[j].percent * ((cutArr[i + 1].ts - displayArr[j].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (displayArr[j].ts - timeDur) / 1000000000, 'id': i }); break; } } - }else{ - if((displayArr[j].ts + displayArr[j].dur) > cutArr[i+1].ts){ - finalArr.push({'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (cutArr[i+1].ts - cutArr[i].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': cutArr[i+1].ts - cutArr[i].ts, 'percent': displayArr[j].percent * ((cutArr[i+1].ts - cutArr[i].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (cutArr[i].ts - timeDur) / 1000000000, 'id': i}); + } else { + if ((displayArr[j].ts + displayArr[j].dur) > cutArr[i + 1].ts) { + finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (cutArr[i + 1].ts - cutArr[i].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': cutArr[i + 1].ts - cutArr[i].ts, 'percent': displayArr[j].percent * ((cutArr[i + 1].ts - cutArr[i].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (cutArr[i].ts - timeDur) / 1000000000, 'id': i }); } - if((displayArr[j].ts + displayArr[j].dur) > cutArr[i].ts && (displayArr[j].ts + displayArr[j].dur) < cutArr[i+1].ts){ - finalArr.push({'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (displayArr[j].dur + displayArr[j].ts - cutArr[i].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': displayArr[j].dur + displayArr[j].ts - cutArr[i].ts, 'percent': displayArr[j].percent * ((displayArr[j].dur + displayArr[j].ts - cutArr[i].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (cutArr[i].ts - timeDur) / 1000000000, 'id': i}); + if ((displayArr[j].ts + displayArr[j].dur) > cutArr[i].ts && (displayArr[j].ts + displayArr[j].dur) < cutArr[i + 1].ts) { + finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (displayArr[j].dur + displayArr[j].ts - cutArr[i].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': displayArr[j].dur + displayArr[j].ts - cutArr[i].ts, 'percent': displayArr[j].percent * ((displayArr[j].dur + displayArr[j].ts - cutArr[i].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (cutArr[i].ts - timeDur) / 1000000000, 'id': i }); } } } - finalResultArr[0].children.push({'thread': displayArr[0].thread, 'ts': (cutArr[i].ts - timeDur) / 1000000000,'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array(), 'id': i}); + finalResultArr[0].children.push({ 'thread': displayArr[0].thread, 'ts': (cutArr[i].ts - timeDur) / 1000000000, 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array(), 'id': i }); } - for(let i = 0; i < finalArr.length; i++){ - for(let j = i+1; j < finalArr.length; j++){ - if(finalArr[i].cpu === finalArr[j].cpu && finalArr[i].freq === finalArr[j].freq && finalArr[i].id === finalArr[j].id){ - finalArr[i].dur += finalArr[j].dur; + for (let i = 0; i < finalArr.length; i++) { + for (let j = i + 1; j < finalArr.length; j++) { + if (finalArr[i].cpu === finalArr[j].cpu && finalArr[i].freq === finalArr[j].freq && finalArr[i].id === finalArr[j].id) { + finalArr[i].dur += finalArr[j].dur; finalArr[i].percent += finalArr[j].percent; finalArr[i].count += finalArr[j].count; finalArr.splice(j, 1); @@ -315,56 +285,56 @@ export class TabPaneFreqDataCut extends BaseElement{ this.threadStatesTblSource = finalResult[0].children.length > 0 ? finalResult : []; this.threadStatesTbl!.recycleDataSource = finalResult[0].children.length > 0 ? finalResult : []; }) - }else{ + } else { alert('请输入正确的线程ID'); } } - dataSingleCut(threadId: any, threadFunc:any, resultList:any){ + dataSingleCut(threadId: any, threadFunc: any, resultList: any) { let threadIdValue = threadId.value.trim(); let threadFuncName = threadFunc.value.trim(); let leftNS = this.currentSelectionParam.leftNs; let rightNS = this.currentSelectionParam.rightNs; - if(/^[0-9]*$/.test(threadIdValue)){ + if (/^[0-9]*$/.test(threadIdValue)) { querySearchFuncData(threadFuncName, threadIdValue, leftNS, rightNS).then(result => { let [...targetList] = JSON.parse(JSON.stringify(resultList)); let timeDur = this.currentSelectionParam.recordStartNs; let dealArr = new Array(); - for(let i of result){ - if(i.startTime + timeDur + i.dur < this.currentSelectionParam.rightNs + timeDur){ - dealArr.push({'ts': i.startTime + timeDur, 'dur': i.dur}); + for (let i of result) { + if (i.startTime + timeDur + i.dur < this.currentSelectionParam.rightNs + timeDur) { + dealArr.push({ 'ts': i.startTime + timeDur, 'dur': i.dur }); } } let finalResultArr = new Array(); - finalResultArr.push({'thread': targetList[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array()}); + finalResultArr.push({ 'thread': targetList[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array() }); let resList = new Array(); - for(let i = 0; i < dealArr.length; i++){ - for(let j = 0; j < targetList.length; j++){ - if(dealArr[i].ts < targetList[j].ts){ - if(dealArr[i].ts + dealArr[i].dur > targetList[j].ts){ - if(dealArr[i].ts + dealArr[i].dur > targetList[j].ts + targetList[j].dur){ - resList.push({'thread': targetList[i].thread, 'ts': (targetList[j].ts - timeDur) / 1000000000, 'count': (targetList[j].freq * targetList[j].dur) / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': targetList[j].dur, 'percent': targetList[j].percent, 'state': 'Running', 'id': i}); - }else{ - resList.push({'thread': targetList[j].thread, 'ts': (targetList[j].ts - timeDur) / 1000000000, 'count': (dealArr[i].ts + dealArr[i].dur - targetList[j].ts) * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': dealArr[i].ts + dealArr[i].dur - targetList[j].ts, 'percent': (dealArr[i].ts + dealArr[i].dur - targetList[j].ts) / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i}); + for (let i = 0; i < dealArr.length; i++) { + for (let j = 0; j < targetList.length; j++) { + if (dealArr[i].ts < targetList[j].ts) { + if (dealArr[i].ts + dealArr[i].dur > targetList[j].ts) { + if (dealArr[i].ts + dealArr[i].dur > targetList[j].ts + targetList[j].dur) { + resList.push({ 'thread': targetList[i].thread, 'ts': (targetList[j].ts - timeDur) / 1000000000, 'count': (targetList[j].freq * targetList[j].dur) / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': targetList[j].dur, 'percent': targetList[j].percent, 'state': 'Running', 'id': i }); + } else { + resList.push({ 'thread': targetList[j].thread, 'ts': (targetList[j].ts - timeDur) / 1000000000, 'count': (dealArr[i].ts + dealArr[i].dur - targetList[j].ts) * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': dealArr[i].ts + dealArr[i].dur - targetList[j].ts, 'percent': (dealArr[i].ts + dealArr[i].dur - targetList[j].ts) / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i }); break; - } + } } - }else{ - if(targetList[j].ts + targetList[j].dur > dealArr[i].ts){ - if(targetList[j].ts + targetList[j].dur > dealArr[i].ts + dealArr[i].dur){ - resList.push({'thread': targetList[j].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000, 'count': dealArr[i].dur * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': dealArr[i].dur, 'percent': dealArr[i].dur / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i}); + } else { + if (targetList[j].ts + targetList[j].dur > dealArr[i].ts) { + if (targetList[j].ts + targetList[j].dur > dealArr[i].ts + dealArr[i].dur) { + resList.push({ 'thread': targetList[j].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000, 'count': dealArr[i].dur * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': dealArr[i].dur, 'percent': dealArr[i].dur / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i }); break; - }else{ - resList.push({'thread': targetList[j].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000, 'count': (targetList[j].ts + targetList[j].dur - dealArr[i].ts) * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': targetList[j].ts + targetList[j].dur - dealArr[i].ts, 'percent': (targetList[j].ts + targetList[j].dur - dealArr[i].ts) / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i}); + } else { + resList.push({ 'thread': targetList[j].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000, 'count': (targetList[j].ts + targetList[j].dur - dealArr[i].ts) * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': targetList[j].ts + targetList[j].dur - dealArr[i].ts, 'percent': (targetList[j].ts + targetList[j].dur - dealArr[i].ts) / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i }); } } } } - finalResultArr[0].children.push({'thread': targetList[0].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000,'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array(), 'id': i}); + finalResultArr[0].children.push({ 'thread': targetList[0].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000, 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array(), 'id': i }); } // 合并相同周期内的数据 - for(let i = 0; i < resList.length; i++){ - for(let j = i+1; j < resList.length; j++){ - if(resList[i].cpu === resList[j].cpu && resList[i].freq === resList[j].freq && resList[i].id === resList[j].id){ + for (let i = 0; i < resList.length; i++) { + for (let j = i + 1; j < resList.length; j++) { + if (resList[i].cpu === resList[j].cpu && resList[i].freq === resList[j].freq && resList[i].id === resList[j].id) { resList[i].dur += resList[j].dur; resList[i].percent += resList[j].percent; resList[i].count += resList[j].count; @@ -378,28 +348,28 @@ export class TabPaneFreqDataCut extends BaseElement{ let newArr1 = JSON.parse(JSON.stringify(finalResultArr[0])); let newArr2 = JSON.parse(JSON.stringify(resList)); let finalResult = new Array(this.mergeTree(newArr1, newArr2)); - + this.threadStatesTblSource = finalResult[0].children.length > 0 ? finalResult : []; this.threadStatesTbl!.recycleDataSource = finalResult[0].children.length > 0 ? finalResult : []; }) - }else{ + } else { alert('请输入正确的线程ID'); } } - mergeTree (arr1:any, arr2:any) { - for(let i = 0; i < arr1.children.length; i++){ + mergeTree(arr1: any, arr2: any) { + for (let i = 0; i < arr1.children.length; i++) { // 改成map对象做标记 let cpuArr = new Array(); let flagMap = new Map(); let flag = 0; - for(let j = 0; j < arr2.length; j++){ - if(arr1.children[i].id == arr2[j].id){ - if(!cpuArr.includes(arr2[j].cpu)){ + for (let j = 0; j < arr2.length; j++) { + if (arr1.children[i].id == arr2[j].id) { + if (!cpuArr.includes(arr2[j].cpu)) { flagMap.set(arr2[j].cpu, flag); cpuArr.push(arr2[j].cpu); - arr1.children[i].children.push({'thread': arr2[j].thread, 'count': 0, 'cpu': arr2[j].cpu, 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', 'ts': '', children: new Array(), 'id': arr2[j].id}); - if(arr1.children[i].children[flag].cpu == arr2[j].cpu && arr1.children[i].children[flag].id == arr2[j].id){ + arr1.children[i].children.push({ 'thread': arr2[j].thread, 'count': 0, 'cpu': arr2[j].cpu, 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', 'ts': '', children: new Array(), 'id': arr2[j].id }); + if (arr1.children[i].children[flag].cpu == arr2[j].cpu && arr1.children[i].children[flag].id == arr2[j].id) { arr1.children[i].children[flag].children.push(arr2[j]); arr1.children[i].children[flag].dur += arr2[j].dur; arr1.children[i].children[flag].percent += arr2[j].percent; @@ -408,15 +378,14 @@ export class TabPaneFreqDataCut extends BaseElement{ arr1.children[i].children[flag].percent = Number(arr1.children[i].children[flag].percent.toFixed(2)); arr1.children[i].dur += arr1.children[i].children[flag].dur; arr1.children[i].count += arr1.children[i].children[flag].count; - // arr1.children[i].thread = arr1.children[i].children[flag].thread; flag++; arr2.splice(j, 1); j--; } - }else{ + } else { // 利用map做数据处理 let count = flagMap.get(arr2[j].cpu); - if(arr1.children[i].children[count].cpu == arr2[j].cpu && arr1.children[i].children[count].id == arr2[j].id){ + if (arr1.children[i].children[count].cpu == arr2[j].cpu && arr1.children[i].children[count].id == arr2[j].id) { arr1.children[i].children[count].children.push(arr2[j]); arr1.children[i].children[count].dur += arr2[j].dur; arr1.children[i].children[count].percent += arr2[j].percent; @@ -425,21 +394,19 @@ export class TabPaneFreqDataCut extends BaseElement{ arr1.children[i].children[count].percent = Number(arr2[j].percent.toFixed(2)); arr1.children[i].dur += arr2[j].dur; arr1.children[i].count += arr2[j].count; - // arr1.children[i].thread = arr2[j].thread; arr2.splice(j, 1); j--; } } - }else{ + } else { break; } } - arr1.children[i].children.sort((a:any, b:any) => a.cpu - b.cpu); + arr1.children[i].children.sort((a: any, b: any) => a.cpu - b.cpu); arr1.percent += arr1.children[i].percent; arr1.children[i].percent = Number(arr1.children[i].percent.toFixed(2)); arr1.dur += arr1.children[i].dur; arr1.count += arr1.children[i].count; - // arr1.thread = arr1.children[i].thread == '' ? arr1.thread : arr1.children[i].thread; } arr1.percent = Number(arr1.percent.toFixed(2)); return arr1; diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts index 4f7bd7b7d..321e3ef50 100644 --- a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,7 +19,6 @@ import { SelectionData, SelectionParam } from '../../../../bean/BoxSelection'; import '../../../StackBar.js' import { getTabRunningPercent, queryCpuFreqUsageData, queryCpuFreqFilterId } from '../../../../database/SqlLite.js'; import { Utils } from '../../base/Utils.js'; -import { log } from '../../../../../log/Log.js'; import { resizeObserver } from '../SheetUtils.js'; @element('tabpane-frequsage') @@ -36,26 +35,26 @@ export class TabPaneFreqUsage extends BaseElement { this.threadStatesTblSource = []; this.threadStatesTbl!.recycleDataSource = []; getTabRunningPercent(threadStatesParam.threadIds, threadStatesParam.leftNs, threadStatesParam.rightNs).then((result) => { - queryCpuFreqFilterId().then(r =>{ + queryCpuFreqFilterId().then(r => { let IdMap = new Map(); let queryId = new Array(); - for(let i = 0; i < r.length; i++){ + for (let i = 0; i < r.length; i++) { queryId.push(r[i].id); - IdMap.set(r[i].id,r[i].cpu); + IdMap.set(r[i].id, r[i].cpu); } - queryCpuFreqUsageData(queryId).then((res) =>{ - if(result != null && result.length > 0){ + queryCpuFreqUsageData(queryId).then((res) => { + if (result != null && result.length > 0) { let sum = 0; let dealArr = new Array(); - for(let i of res){ - dealArr.push({'startNS': i.startNS + threadStatesParam.recordStartNs, 'dur': i.dur, 'value': i.value, 'cpu': IdMap.get(i.filter_id)}); + for (let i of res) { + dealArr.push({ 'startNS': i.startNS + threadStatesParam.recordStartNs, 'dur': i.dur, 'value': i.value, 'cpu': IdMap.get(i.filter_id) }); } let targetList = new Array(); let cpuArr = new Array(); let finalResultArr = new Array(); - finalResultArr.push({'thread': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': '100.00', 'state': 'Running', children: new Array()}); - for(let e of result){ - if(threadStatesParam.processIds.includes(e.pid) && e.state == 'Running'){ + finalResultArr.push({ 'thread': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': '100.00', 'state': 'Running', children: new Array() }); + for (let e of result) { + if (threadStatesParam.processIds.includes(e.pid) && e.state == 'Running') { let process = Utils.PROCESS_MAP.get(e.pid); let thread = Utils.THREAD_MAP.get(e.tid); e.process = process == null || process.length == 0 ? '[NULL]' : process; @@ -64,37 +63,36 @@ export class TabPaneFreqUsage extends BaseElement { e.state = Utils.getEndState(e.stateJX); sum += e.dur; targetList.push(e); - if(!cpuArr.includes(e.cpu)){ + if (!cpuArr.includes(e.cpu)) { cpuArr.push(e.cpu); finalResultArr[0].thread = finalResultArr[0].thread == '' ? e.tid + '_' + e.thread : finalResultArr[0].thread; - finalResultArr[0].children.push({'thread': e.tid + '_' + e.thread, 'count': 0, 'cpu': e.cpu, 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array()}); + finalResultArr[0].children.push({ 'thread': e.tid + '_' + e.thread, 'count': 0, 'cpu': e.cpu, 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array() }); } } } let resultList = new Array(); - for(let i = 0; i < targetList.length; i++){ - for(let j = 0; j < dealArr.length; j++){ - if(targetList[i].cpu == dealArr[j].cpu){ - if(targetList[i].ts > dealArr[j].startNS){ - if(targetList[i].ts < (dealArr[j].startNS + dealArr[j].dur)){ - if(targetList[i].dur < (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)){ - resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * targetList[i].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts}); + for (let i = 0; i < targetList.length; i++) { + for (let j = 0; j < dealArr.length; j++) { + if (targetList[i].cpu == dealArr[j].cpu) { + if (targetList[i].ts > dealArr[j].startNS) { + if (targetList[i].ts < (dealArr[j].startNS + dealArr[j].dur)) { + if (targetList[i].dur < (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) { + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * targetList[i].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts }); break; - }else{ - resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts), 'percent': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts) / sum *100, 'state': 'Running', 'ts': targetList[i].ts}); + } else { + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts), 'percent': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts) / sum * 100, 'state': 'Running', 'ts': targetList[i].ts }); } } - }else{ - if((targetList[i].ts + targetList[i].dur) > dealArr[j].startNS){ - if((targetList[i].dur + targetList[i].ts - dealArr[j].startNS) < dealArr[j].dur){ - resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (targetList[i].dur + targetList[i].ts - dealArr[j].startNS)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS), 'percent': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS) / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS}); + } else { + if ((targetList[i].ts + targetList[i].dur) > dealArr[j].startNS) { + if ((targetList[i].dur + targetList[i].ts - dealArr[j].startNS) < dealArr[j].dur) { + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (targetList[i].dur + targetList[i].ts - dealArr[j].startNS)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS), 'percent': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS) / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS }); break; - }else{ - resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * dealArr[j].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': dealArr[j].dur, 'percent': dealArr[j].dur / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS}); + } else { + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * dealArr[j].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': dealArr[j].dur, 'percent': dealArr[j].dur / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS }); } - }else{ - // resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': 'unknown', 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts}); - resultList.push({'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': 0, 'cpu': targetList[i].cpu, 'freq': 'unknown', 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts}); + } else { + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': 0, 'cpu': targetList[i].cpu, 'freq': 'unknown', 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts }); break; } } @@ -102,9 +100,9 @@ export class TabPaneFreqUsage extends BaseElement { } } //合并同一线程内,当运行所在cpu和频点相同时,dur及percent进行累加求和,或许可以进行算法优化 - for(let i = 0; i < resultList.length ; i++){ - for(let j = i + 1; j < resultList.length; j++){ - if(resultList[i].cpu == resultList[j].cpu && resultList[i].freq == resultList[j].freq){ + for (let i = 0; i < resultList.length; i++) { + for (let j = i + 1; j < resultList.length; j++) { + if (resultList[i].cpu == resultList[j].cpu && resultList[i].freq == resultList[j].freq) { resultList[i].dur += resultList[j].dur; resultList[i].percent += resultList[j].percent; resultList[i].count += resultList[j].count; @@ -115,11 +113,11 @@ export class TabPaneFreqUsage extends BaseElement { resultList[i].percent = Number((resultList[i].percent).toFixed(2)); resultList[i].ts = resultList[i].ts - threadStatesParam.recordStartNs; } - finalResultArr[0].children.sort((a:any, b:any) => a.cpu - b.cpu); + finalResultArr[0].children.sort((a: any, b: any) => a.cpu - b.cpu); // 转成树结构数据进行展示 - for(let i = 0; i < finalResultArr[0].children.length; i++){ - for(let j = 0; j < resultList.length; j++){ - if(finalResultArr[0].children[i].cpu == resultList[j].cpu){ + for (let i = 0; i < finalResultArr[0].children.length; i++) { + for (let j = 0; j < resultList.length; j++) { + if (finalResultArr[0].children[i].cpu == resultList[j].cpu) { finalResultArr[0].children[i].children.push(resultList[j]); finalResultArr[0].children[i].dur += resultList[j].dur; finalResultArr[0].children[i].percent += resultList[j].percent; @@ -134,21 +132,17 @@ export class TabPaneFreqUsage extends BaseElement { } this.threadStatesTblSource = finalResultArr; this.threadStatesTbl!.recycleDataSource = finalResultArr; - }else{ + } else { this.threadStatesTblSource = []; this.threadStatesTbl!.recycleDataSource = []; } }); }); - + }) } initElements(): void { this.threadStatesTbl = this.shadowRoot?.querySelector('#tb-running-percent'); - // 列排序暂时屏蔽 - // this.threadStatesTbl!.addEventListener('column-click', (evt: any) => { - // this.sortByColumn(evt.detail); - // }); } connectedCallback() { super.connectedCallback(); @@ -181,34 +175,5 @@ export class TabPaneFreqUsage extends BaseElement { ` } - sortByColumn(treadStateDetail: any) { - function compare(property: any, treadStatesSort: any, type: any){ - return function(threadStatesLeftData: SelectionData | any, threadStatesRightData: SelectionData | any){ - if(threadStatesLeftData.process == ' ' || threadStatesRightData.process == ' '){ - return 0; - } - if(type === 'number'){ - return treadStatesSort === 2 - ? parseFloat(threadStatesRightData[property]) - parseFloat(threadStatesLeftData[property]) - : parseFloat(threadStatesLeftData[property]) - parseFloat(threadStatesRightData[property]); - }else{ - if(threadStatesRightData[property] > threadStatesLeftData[property]){ - return treadStatesSort === 2 ? 1 : -1; - }else if(threadStatesRightData[property] == threadStatesLeftData[property]){ - return 0; - }else{ - return treadStatesSort === 2 ? -1 : 1; - } - } - }; - } - - if(treadStateDetail.key === 'name' || treadStateDetail.key === 'thread' || treadStateDetail.key === 'state'){ - this.threadStatesTblSource.sort(compare(treadStateDetail.key, treadStateDetail.sort, 'string')); - }else{ - this.threadStatesTblSource.sort(compare(treadStateDetail.key, treadStateDetail.sort, 'number')); - } - this.threadStatesTbl!.recycleDataSource = this.threadStatesTblSource; - } } \ No newline at end of file diff --git a/ide/src/trace/database/SqlLite.ts b/ide/src/trace/database/SqlLite.ts index 9dd4fd62e..66025fee4 100644 --- a/ide/src/trace/database/SqlLite.ts +++ b/ide/src/trace/database/SqlLite.ts @@ -296,8 +296,8 @@ export class DbPool { } } }; - thread!.onmessageerror = (e) => {}; - thread!.onerror = (e) => {}; + thread!.onmessageerror = (e) => { }; + thread!.onerror = (e) => { }; thread!.id = i; thread!.busy = false; this.works?.push(thread!); @@ -1271,8 +1271,7 @@ export const queryVirtualMemory = (): Promise> => export const queryVirtualMemoryData = (filterId: number): Promise> => query( 'queryVirtualMemoryData', - `select ts-${ - (window as any).recordStartNS + `select ts-${(window as any).recordStartNS } as startTime,value,filter_id as filterID from sys_mem_measure where filter_id=$filter_id`, { $filter_id: filterId } ); @@ -3839,11 +3838,9 @@ export const queryEbpfSamplesCount = (startTime: number, endTime: number, ipids: select fsCount, vmCount from -(select count(1) as fsCount from file_system_sample s,trace_range t where s.end_ts between $startTime + t.start_ts and $endTime + t.start_ts ${ - ipids.length > 0 ? `and s.ipid in (${ipids.join(',')})` : '' +(select count(1) as fsCount from file_system_sample s,trace_range t where s.end_ts between $startTime + t.start_ts and $endTime + t.start_ts ${ipids.length > 0 ? `and s.ipid in (${ipids.join(',')})` : '' }) -,(select count(1) as vmCount from paged_memory_sample s,trace_range t where s.end_ts between $startTime + t.start_ts and $endTime + t.start_ts ${ - ipids.length > 0 ? `and s.ipid in (${ipids.join(',')})` : '' +,(select count(1) as vmCount from paged_memory_sample s,trace_range t where s.end_ts between $startTime + t.start_ts and $endTime + t.start_ts ${ipids.length > 0 ? `and s.ipid in (${ipids.join(',')})` : '' }); `, { $startTime: startTime, $endTime: endTime } @@ -5495,10 +5492,10 @@ export const queryTraceType = (): Promise< export const queryTransferList = (): Promise> => query('queryTransferList', `select id, report_value as cmdStr from perf_report where report_type = 'config_name'`); - export const getTabRunningPercent = (tIds: Array, leftNS: number, rightNS: number): Promise> => -query( - 'getTabRunningPercent', - ` +export const getTabRunningPercent = (tIds: Array, leftNS: number, rightNS: number): Promise> => + query( + 'getTabRunningPercent', + ` select B.pid,B.tid,B.state,B.cpu,B.dur,B.ts from @@ -5513,26 +5510,26 @@ query( not ((B.ts - TR.start_ts + ifnull(B.dur,0) < ${leftNS}) or (B.ts - TR.start_ts > ${rightNS})) order by ts `, - {$leftNS:leftNS, $rightNS:rightNS} -); - + { $leftNS: leftNS, $rightNS: rightNS } + ); + export const querySearchFuncData = (funcName: string, tIds: Array, leftNS: number, rightNS: number): Promise> => -query( - 'querySearchFuncData', - ` + query( + 'querySearchFuncData', + ` select c.cookie,c.id,c.name as funName,c.ts - r.start_ts as startTime,c.dur,c.depth,t.tid,t.name as threadName, p.pid,'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 where c.name = '${funcName}' and t.tid = ${tIds} and not ((startTime < ${leftNS}) or (startTime > ${rightNS})); `, - {$search: funcName} -); + { $search: funcName } + ); export const queryCpuFreqUsageData = (Ids: Array): Promise> => -query( - 'queryCpuFreqUsageData', - `select + query( + 'queryCpuFreqUsageData', + `select value, ifnull(dur,tb.end_ts - c.ts) dur, ts-tb.start_ts as startNS, @@ -5543,12 +5540,12 @@ query( where c.filter_id in (${Ids.join(',')}) ` -); + ); export const queryCpuFreqFilterId = (): Promise> => -query( - 'queryCpuFreqFilterId', - `select + query( + 'queryCpuFreqFilterId', + `select id, cpu from @@ -5558,4 +5555,4 @@ query( or name='cpu_frequency' ` -); \ No newline at end of file + ); \ No newline at end of file -- Gitee From 79eccd350f1218fdaf3ddb31d8f3750e1bc685b7 Mon Sep 17 00:00:00 2001 From: "lizhuosong@huawei.com" Date: Thu, 26 Oct 2023 15:11:21 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lizhuosong@huawei.com --- ide/src/trace/database/SqlLite.ts | 94 +++++++++++++++++++------------ 1 file changed, 59 insertions(+), 35 deletions(-) diff --git a/ide/src/trace/database/SqlLite.ts b/ide/src/trace/database/SqlLite.ts index 66025fee4..3c4a18a6b 100644 --- a/ide/src/trace/database/SqlLite.ts +++ b/ide/src/trace/database/SqlLite.ts @@ -5496,19 +5496,19 @@ export const getTabRunningPercent = (tIds: Array, leftNS: number, rightN query( 'getTabRunningPercent', ` - select - B.pid,B.tid,B.state,B.cpu,B.dur,B.ts - from - thread_state AS B - left join - trace_range AS TR - where - B.tid in (${tIds.join(',')}) - and - B.state='Running' - and - not ((B.ts - TR.start_ts + ifnull(B.dur,0) < ${leftNS}) or (B.ts - TR.start_ts > ${rightNS})) - order by ts + select + B.pid,B.tid,B.state,B.cpu,B.dur,B.ts + from + thread_state AS B + left join + trace_range AS TR + where + B.tid in (${tIds.join(',')}) + and + B.state='Running' + and + not ((B.ts - TR.start_ts + ifnull(B.dur,0) < ${leftNS}) or (B.ts - TR.start_ts > ${rightNS})) + order by ts `, { $leftNS: leftNS, $rightNS: rightNS } ); @@ -5517,11 +5517,35 @@ export const querySearchFuncData = (funcName: string, tIds: Array, leftN query( 'querySearchFuncData', ` - select c.cookie,c.id,c.name as funName,c.ts - r.start_ts as startTime,c.dur,c.depth,t.tid,t.name as threadName, - p.pid,'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 - where c.name = '${funcName}' and t.tid = ${tIds} and - not ((startTime < ${leftNS}) or (startTime > ${rightNS})); + select + c.cookie, + c.id, + c.name as funName, + c.ts - r.start_ts as startTime, + c.dur, + c.depth, + t.tid, + t.name as threadName, + p.pid, + '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 + where + c.name = '${funcName}' + and + t.tid = ${tIds} + and + not ((startTime < ${leftNS}) or (startTime > ${rightNS})); `, { $search: funcName } ); @@ -5530,15 +5554,15 @@ export const queryCpuFreqUsageData = (Ids: Array): Promise> = query( 'queryCpuFreqUsageData', `select - value, - ifnull(dur,tb.end_ts - c.ts) dur, - ts-tb.start_ts as startNS, - filter_id - from - measure c, - trace_range tb - where - c.filter_id in (${Ids.join(',')}) + value, + ifnull(dur,tb.end_ts - c.ts) dur, + ts-tb.start_ts as startNS, + filter_id + from + measure c, + trace_range tb + where + c.filter_id in (${Ids.join(',')}) ` ); @@ -5546,13 +5570,13 @@ export const queryCpuFreqFilterId = (): Promise> => query( 'queryCpuFreqFilterId', `select - id, - cpu - from - cpu_measure_filter - where - name='cpufreq' - or - name='cpu_frequency' + id, + cpu + from + cpu_measure_filter + where + name='cpufreq' + or + name='cpu_frequency' ` ); \ No newline at end of file -- Gitee From a22ff77a6a5bc81d400ca939d4ec91235801f3cc Mon Sep 17 00:00:00 2001 From: "lizhuosong@huawei.com" Date: Thu, 26 Oct 2023 17:39:38 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lizhuosong@huawei.com --- .../sheet/frequsage/TabPaneFreqDataCut.ts | 41 +++++++++++-------- .../trace/sheet/frequsage/TabPaneFreqUsage.ts | 4 +- ide/src/trace/database/SqlLite.ts | 19 +++++---- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts index 3327b140e..70f79b50c 100644 --- a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts @@ -37,6 +37,8 @@ export class TabPaneFreqDataCut extends BaseElement { this.currentSelectionParam = threadStatesParam; this.threadStatesTblSource = []; this.threadStatesTbl!.recycleDataSource = []; + let tableValue: any = this.threadStatesTbl; + tableValue.value = []; let divRoot1: any = this.shadowRoot?.querySelector('#dataCutThreadId'); divRoot1.value = ''; let divRoot2: any = this.shadowRoot?.querySelector('#dataCutThreadFunc'); @@ -81,28 +83,29 @@ export class TabPaneFreqDataCut extends BaseElement { // 用来存放数据切割之前的汇总数据 let resultList = new Array(); // 通过循环获取每个running状态线程的相关信息,此处或许可以进行算法优化 + const tsMutiple = 1000000000; for (let i = 0; i < targetList.length; i++) { for (let j = 0; j < dealArr.length; j++) { if (targetList[i].cpu == dealArr[j].cpu) { if (targetList[i].ts > dealArr[j].startNS) { if (targetList[i].ts < (dealArr[j].startNS + dealArr[j].dur)) { if (targetList[i].dur < (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) { - resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * targetList[i].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts }); + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * targetList[i].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts / tsMutiple }); break; } else { - resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts), 'percent': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts) / sum * 100, 'state': 'Running', 'ts': targetList[i].ts }); + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts), 'percent': (dealArr[j].startNS + dealArr[j].dur - targetList[i].ts) / sum * 100, 'state': 'Running', 'ts': targetList[i].ts / tsMutiple }); } } } else { if ((targetList[i].ts + targetList[i].dur) > dealArr[j].startNS) { if ((targetList[i].dur + targetList[i].ts - dealArr[j].startNS) < dealArr[j].dur) { - resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (targetList[i].dur + targetList[i].ts - dealArr[j].startNS)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS), 'percent': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS) / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS }); + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * (targetList[i].dur + targetList[i].ts - dealArr[j].startNS)) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS), 'percent': (targetList[i].dur + targetList[i].ts - dealArr[j].startNS) / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS / tsMutiple }); break; } else { - resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * dealArr[j].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': dealArr[j].dur, 'percent': dealArr[j].dur / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS }); + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': (dealArr[j].value * dealArr[j].dur) / 1000, 'cpu': targetList[i].cpu, 'freq': dealArr[j].value, 'dur': dealArr[j].dur, 'percent': dealArr[j].dur / sum * 100, 'state': 'Running', 'ts': dealArr[j].startNS / tsMutiple }); } } else { - resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': 0, 'cpu': targetList[i].cpu, 'freq': 'unknown', 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts }); + resultList.push({ 'thread': targetList[i].tid + '_' + targetList[i].thread, 'count': 0, 'cpu': targetList[i].cpu, 'freq': 'unknown', 'dur': targetList[i].dur, 'percent': targetList[i].dur / sum * 100, 'state': 'Running', 'ts': targetList[i].ts / tsMutiple }); break; } } @@ -123,7 +126,7 @@ export class TabPaneFreqDataCut extends BaseElement { } } resultList[i].percent = Number((resultList[i].percent).toFixed(2)); - resultList[i].ts = resultList[i].ts - threadStatesParam.recordStartNs; + resultList[i].ts = (resultList[i].ts * tsMutiple - threadStatesParam.recordStartNs) / tsMutiple; } finalResultArr[0].children.sort((a: any, b: any) => a.cpu - b.cpu); // 转成树结构数据进行展示 @@ -206,7 +209,7 @@ export class TabPaneFreqDataCut extends BaseElement { - + @@ -242,28 +245,30 @@ export class TabPaneFreqDataCut extends BaseElement { // 将数据进行切割处理 let finalArr = new Array(); let finalResultArr = new Array(); + const tsMutiple = 1000000000; finalResultArr.push({ 'thread': displayArr[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array() }); for (let i = 0; i < cutArr.length - 1; i++) { for (let j = 0; j < displayArr.length; j++) { + displayArr[j].ts = displayArr[j].ts * tsMutiple; if (displayArr[j].ts >= cutArr[i].ts) { if ((displayArr[j].ts + displayArr[j].dur) <= cutArr[i + 1].ts) { - finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * displayArr[j].dur) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': displayArr[j].dur, 'percent': displayArr[j].percent, 'state': 'Running', 'ts': (displayArr[j].ts - timeDur) / 1000000000, 'id': i }); + finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * displayArr[j].dur) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': displayArr[j].dur, 'percent': displayArr[j].percent, 'state': 'Running', 'ts': (displayArr[j].ts - timeDur) / tsMutiple, 'id': i }); } else { if (cutArr[i + 1].ts - displayArr[j].ts > 0) { - finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (cutArr[i + 1].ts - displayArr[j].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': cutArr[i + 1].ts - displayArr[j].ts, 'percent': displayArr[j].percent * ((cutArr[i + 1].ts - displayArr[j].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (displayArr[j].ts - timeDur) / 1000000000, 'id': i }); + finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (cutArr[i + 1].ts - displayArr[j].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': cutArr[i + 1].ts - displayArr[j].ts, 'percent': displayArr[j].percent * ((cutArr[i + 1].ts - displayArr[j].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (displayArr[j].ts - timeDur) / tsMutiple, 'id': i }); break; } } } else { if ((displayArr[j].ts + displayArr[j].dur) > cutArr[i + 1].ts) { - finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (cutArr[i + 1].ts - cutArr[i].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': cutArr[i + 1].ts - cutArr[i].ts, 'percent': displayArr[j].percent * ((cutArr[i + 1].ts - cutArr[i].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (cutArr[i].ts - timeDur) / 1000000000, 'id': i }); + finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (cutArr[i + 1].ts - cutArr[i].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': cutArr[i + 1].ts - cutArr[i].ts, 'percent': displayArr[j].percent * ((cutArr[i + 1].ts - cutArr[i].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (cutArr[i].ts - timeDur) / tsMutiple, 'id': i }); } if ((displayArr[j].ts + displayArr[j].dur) > cutArr[i].ts && (displayArr[j].ts + displayArr[j].dur) < cutArr[i + 1].ts) { - finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (displayArr[j].dur + displayArr[j].ts - cutArr[i].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': displayArr[j].dur + displayArr[j].ts - cutArr[i].ts, 'percent': displayArr[j].percent * ((displayArr[j].dur + displayArr[j].ts - cutArr[i].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (cutArr[i].ts - timeDur) / 1000000000, 'id': i }); + finalArr.push({ 'thread': displayArr[j].thread, 'count': (displayArr[j].freq * (displayArr[j].dur + displayArr[j].ts - cutArr[i].ts)) / 1000, 'cpu': displayArr[j].cpu, 'freq': displayArr[j].freq, 'dur': displayArr[j].dur + displayArr[j].ts - cutArr[i].ts, 'percent': displayArr[j].percent * ((displayArr[j].dur + displayArr[j].ts - cutArr[i].ts) / displayArr[j].dur), 'state': 'Running', 'ts': (cutArr[i].ts - timeDur) / tsMutiple, 'id': i }); } } } - finalResultArr[0].children.push({ 'thread': displayArr[0].thread, 'ts': (cutArr[i].ts - timeDur) / 1000000000, 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array(), 'id': i }); + finalResultArr[0].children.push({ 'thread': displayArr[0].thread, 'ts': (cutArr[i].ts - timeDur) / tsMutiple, 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array(), 'id': i }); } for (let i = 0; i < finalArr.length; i++) { @@ -307,29 +312,31 @@ export class TabPaneFreqDataCut extends BaseElement { let finalResultArr = new Array(); finalResultArr.push({ 'thread': targetList[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array() }); let resList = new Array(); + const tsMutiple = 1000000000; for (let i = 0; i < dealArr.length; i++) { for (let j = 0; j < targetList.length; j++) { + targetList[j].ts = targetList[j].ts * tsMutiple; if (dealArr[i].ts < targetList[j].ts) { if (dealArr[i].ts + dealArr[i].dur > targetList[j].ts) { if (dealArr[i].ts + dealArr[i].dur > targetList[j].ts + targetList[j].dur) { - resList.push({ 'thread': targetList[i].thread, 'ts': (targetList[j].ts - timeDur) / 1000000000, 'count': (targetList[j].freq * targetList[j].dur) / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': targetList[j].dur, 'percent': targetList[j].percent, 'state': 'Running', 'id': i }); + resList.push({ 'thread': targetList[i].thread, 'ts': (targetList[j].ts - timeDur) / tsMutiple, 'count': (targetList[j].freq * targetList[j].dur) / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': targetList[j].dur, 'percent': targetList[j].percent, 'state': 'Running', 'id': i }); } else { - resList.push({ 'thread': targetList[j].thread, 'ts': (targetList[j].ts - timeDur) / 1000000000, 'count': (dealArr[i].ts + dealArr[i].dur - targetList[j].ts) * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': dealArr[i].ts + dealArr[i].dur - targetList[j].ts, 'percent': (dealArr[i].ts + dealArr[i].dur - targetList[j].ts) / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i }); + resList.push({ 'thread': targetList[j].thread, 'ts': (targetList[j].ts - timeDur) / tsMutiple, 'count': (dealArr[i].ts + dealArr[i].dur - targetList[j].ts) * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': dealArr[i].ts + dealArr[i].dur - targetList[j].ts, 'percent': (dealArr[i].ts + dealArr[i].dur - targetList[j].ts) / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i }); break; } } } else { if (targetList[j].ts + targetList[j].dur > dealArr[i].ts) { if (targetList[j].ts + targetList[j].dur > dealArr[i].ts + dealArr[i].dur) { - resList.push({ 'thread': targetList[j].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000, 'count': dealArr[i].dur * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': dealArr[i].dur, 'percent': dealArr[i].dur / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i }); + resList.push({ 'thread': targetList[j].thread, 'ts': (dealArr[i].ts - timeDur) / tsMutiple, 'count': dealArr[i].dur * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': dealArr[i].dur, 'percent': dealArr[i].dur / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i }); break; } else { - resList.push({ 'thread': targetList[j].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000, 'count': (targetList[j].ts + targetList[j].dur - dealArr[i].ts) * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': targetList[j].ts + targetList[j].dur - dealArr[i].ts, 'percent': (targetList[j].ts + targetList[j].dur - dealArr[i].ts) / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i }); + resList.push({ 'thread': targetList[j].thread, 'ts': (dealArr[i].ts - timeDur) / tsMutiple, 'count': (targetList[j].ts + targetList[j].dur - dealArr[i].ts) * targetList[j].freq / 1000, 'cpu': targetList[j].cpu, 'freq': targetList[j].freq, 'dur': targetList[j].ts + targetList[j].dur - dealArr[i].ts, 'percent': (targetList[j].ts + targetList[j].dur - dealArr[i].ts) / targetList[j].dur * targetList[j].percent, 'state': 'Running', 'id': i }); } } } } - finalResultArr[0].children.push({ 'thread': targetList[0].thread, 'ts': (dealArr[i].ts - timeDur) / 1000000000, 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array(), 'id': i }); + finalResultArr[0].children.push({ 'thread': targetList[0].thread, 'ts': (dealArr[i].ts - timeDur) / tsMutiple, 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array(), 'id': i }); } // 合并相同周期内的数据 for (let i = 0; i < resList.length; i++) { diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts index 321e3ef50..8c75ee2fd 100644 --- a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqUsage.ts @@ -34,6 +34,8 @@ export class TabPaneFreqUsage extends BaseElement { this.currentSelectionParam = threadStatesParam; this.threadStatesTblSource = []; this.threadStatesTbl!.recycleDataSource = []; + let tableValue:any = this.threadStatesTbl; + tableValue.value = []; getTabRunningPercent(threadStatesParam.threadIds, threadStatesParam.leftNs, threadStatesParam.rightNs).then((result) => { queryCpuFreqFilterId().then(r => { let IdMap = new Map(); @@ -158,7 +160,7 @@ export class TabPaneFreqUsage extends BaseElement { } - + diff --git a/ide/src/trace/database/SqlLite.ts b/ide/src/trace/database/SqlLite.ts index 3c4a18a6b..7655dc89a 100644 --- a/ide/src/trace/database/SqlLite.ts +++ b/ide/src/trace/database/SqlLite.ts @@ -5569,14 +5569,15 @@ export const queryCpuFreqUsageData = (Ids: Array): Promise> = export const queryCpuFreqFilterId = (): Promise> => query( 'queryCpuFreqFilterId', - `select - id, - cpu - from - cpu_measure_filter + ` + select + id, + cpu + from + cpu_measure_filter where - name='cpufreq' - or - name='cpu_frequency' - ` + name='cpufreq' + or + name='cpu_frequency' + ` ); \ No newline at end of file -- Gitee From 6601ea9d6080f3da0b5cca9c55a098bb777fe6fd Mon Sep 17 00:00:00 2001 From: "lizhuosong@huawei.com" Date: Fri, 27 Oct 2023 16:11:31 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=8E=9F=E5=A7=8B?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lizhuosong@huawei.com --- .../sheet/frequsage/TabPaneFreqDataCut.ts | 37 ++----------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts index 70f79b50c..78897f83b 100644 --- a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts @@ -114,39 +114,6 @@ export class TabPaneFreqDataCut extends BaseElement { } // 深拷贝,用来进行数据切割操作,避免数据污染 this.initData = JSON.parse(JSON.stringify(resultList)); - //合并同一线程内,当运行所在cpu和频点相同时,dur及percent进行累加求和,或许可以进行算法优化 - for (let i = 0; i < resultList.length; i++) { - for (let j = i + 1; j < resultList.length; j++) { - if (resultList[i].cpu == resultList[j].cpu && resultList[i].freq == resultList[j].freq) { - resultList[i].dur += resultList[j].dur; - resultList[i].percent += resultList[j].percent; - resultList[i].count += resultList[j].count; - resultList.splice(j, 1); - j--; - } - } - resultList[i].percent = Number((resultList[i].percent).toFixed(2)); - resultList[i].ts = (resultList[i].ts * tsMutiple - threadStatesParam.recordStartNs) / tsMutiple; - } - finalResultArr[0].children.sort((a: any, b: any) => a.cpu - b.cpu); - // 转成树结构数据进行展示 - for (let i = 0; i < finalResultArr[0].children.length; i++) { - for (let j = 0; j < resultList.length; j++) { - if (finalResultArr[0].children[i].cpu == resultList[j].cpu) { - finalResultArr[0].children[i].children.push(resultList[j]); - finalResultArr[0].children[i].dur += resultList[j].dur; - finalResultArr[0].children[i].percent += resultList[j].percent; - finalResultArr[0].children[i].count += resultList[j].count; - resultList.splice(j, 1); - j--; - } - } - finalResultArr[0].children[i].percent = finalResultArr[0].children[i].percent.toFixed(2); - finalResultArr[0].dur += finalResultArr[0].children[i].dur; - finalResultArr[0].count += finalResultArr[0].children[i].count; - } - this.threadStatesTblSource = finalResultArr; - this.threadStatesTbl!.recycleDataSource = finalResultArr; } else { this.threadStatesTblSource = []; this.threadStatesTbl!.recycleDataSource = []; @@ -233,6 +200,8 @@ export class TabPaneFreqDataCut extends BaseElement { let threadFuncName = threadFunc.value.trim(); let leftNS = this.currentSelectionParam.leftNs; let rightNS = this.currentSelectionParam.rightNs; + let tableValue: any = this.threadStatesTbl; + tableValue.value = []; if (/^[0-9]*$/.test(threadIdValue)) { querySearchFuncData(threadFuncName, threadIdValue, leftNS, rightNS).then(res => { let displayArr = JSON.parse(JSON.stringify(resultList)); @@ -299,6 +268,8 @@ export class TabPaneFreqDataCut extends BaseElement { let threadFuncName = threadFunc.value.trim(); let leftNS = this.currentSelectionParam.leftNs; let rightNS = this.currentSelectionParam.rightNs; + let tableValue: any = this.threadStatesTbl; + tableValue.value = []; if (/^[0-9]*$/.test(threadIdValue)) { querySearchFuncData(threadFuncName, threadIdValue, leftNS, rightNS).then(result => { let [...targetList] = JSON.parse(JSON.stringify(resultList)); -- Gitee From b861303274636a38ba681800562f394b6c4c3713 Mon Sep 17 00:00:00 2001 From: "lizhuosong@huawei.com" Date: Fri, 27 Oct 2023 18:25:59 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=91=A8=E6=9C=9F?= =?UTF-8?q?=E5=88=87=E5=89=B2=E5=90=8E=E6=97=B6=E9=97=B4=E6=88=90=E5=80=8D?= =?UTF-8?q?=E6=95=B0=E5=A2=9E=E9=95=BF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lizhuosong@huawei.com --- .../trace/sheet/frequsage/TabPaneFreqDataCut.ts | 14 ++++++++------ ide/src/trace/database/SqlLite.ts | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts index 78897f83b..55bd1b18c 100644 --- a/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts +++ b/ide/src/trace/component/trace/sheet/frequsage/TabPaneFreqDataCut.ts @@ -203,8 +203,8 @@ export class TabPaneFreqDataCut extends BaseElement { let tableValue: any = this.threadStatesTbl; tableValue.value = []; if (/^[0-9]*$/.test(threadIdValue)) { - querySearchFuncData(threadFuncName, threadIdValue, leftNS, rightNS).then(res => { - let displayArr = JSON.parse(JSON.stringify(resultList)); + querySearchFuncData(threadFuncName, Number(threadIdValue), leftNS, rightNS).then(res => { + let display = JSON.parse(JSON.stringify(resultList)); let timeDur = this.currentSelectionParam.recordStartNs; let cutArr = new Array(); // 根据线程id及方法名获取的数据,处理后用作切割时间依据,时间跨度为整个方法开始时间到末个方法开始时间 @@ -215,8 +215,9 @@ export class TabPaneFreqDataCut extends BaseElement { let finalArr = new Array(); let finalResultArr = new Array(); const tsMutiple = 1000000000; - finalResultArr.push({ 'thread': displayArr[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array() }); + finalResultArr.push({ 'thread': display[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array() }); for (let i = 0; i < cutArr.length - 1; i++) { + let displayArr = JSON.parse(JSON.stringify(display)); for (let j = 0; j < displayArr.length; j++) { displayArr[j].ts = displayArr[j].ts * tsMutiple; if (displayArr[j].ts >= cutArr[i].ts) { @@ -271,8 +272,8 @@ export class TabPaneFreqDataCut extends BaseElement { let tableValue: any = this.threadStatesTbl; tableValue.value = []; if (/^[0-9]*$/.test(threadIdValue)) { - querySearchFuncData(threadFuncName, threadIdValue, leftNS, rightNS).then(result => { - let [...targetList] = JSON.parse(JSON.stringify(resultList)); + querySearchFuncData(threadFuncName, Number(threadIdValue), leftNS, rightNS).then(result => { + let [...target] = JSON.parse(JSON.stringify(resultList)); let timeDur = this.currentSelectionParam.recordStartNs; let dealArr = new Array(); for (let i of result) { @@ -281,10 +282,11 @@ export class TabPaneFreqDataCut extends BaseElement { } } let finalResultArr = new Array(); - finalResultArr.push({ 'thread': targetList[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array() }); + finalResultArr.push({ 'thread': target[0].thread, 'ts': '', 'count': 0, 'cpu': '', 'freq': '', 'dur': 0, 'percent': 0, 'state': 'Running', children: new Array() }); let resList = new Array(); const tsMutiple = 1000000000; for (let i = 0; i < dealArr.length; i++) { + let targetList = JSON.parse(JSON.stringify(target)); for (let j = 0; j < targetList.length; j++) { targetList[j].ts = targetList[j].ts * tsMutiple; if (dealArr[i].ts < targetList[j].ts) { diff --git a/ide/src/trace/database/SqlLite.ts b/ide/src/trace/database/SqlLite.ts index 7655dc89a..c0852e003 100644 --- a/ide/src/trace/database/SqlLite.ts +++ b/ide/src/trace/database/SqlLite.ts @@ -5513,7 +5513,7 @@ export const getTabRunningPercent = (tIds: Array, leftNS: number, rightN { $leftNS: leftNS, $rightNS: rightNS } ); -export const querySearchFuncData = (funcName: string, tIds: Array, leftNS: number, rightNS: number): Promise> => +export const querySearchFuncData = (funcName: string, tIds: number, leftNS: number, rightNS: number): Promise> => query( 'querySearchFuncData', ` -- Gitee