* 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 unknown KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { SpSystemTrace } from './SpSystemTrace';
import { TabPaneFrequencySample } from './trace/sheet/cpu/TabPaneFrequencySample';
import { TabPaneFreqByCpu } from './trace/sheet/cpu/TanpaneFreqByCpu';
import { TabPaneCounterSample } from './trace/sheet/cpu/TabPaneCounterSample';
import { RangeSelect } from './trace/base/RangeSelect';
import { TraceRow } from './trace/base/TraceRow';
import { SportRuler } from './trace/timer-shaft/SportRuler';
import { SelectionParam } from '../bean/BoxSelection';
import { error, info } from '../../log/Log';
import { SpStatisticsHttpUtil } from '../../statistics/util/SpStatisticsHttpUtil';
import { queryEbpfSamplesCount, queryPlugins } from '../database/sql/Memory.sql';
import { SpChartManager } from './chart/SpChartManager';
import { ThreadStruct } from '../database/ui-worker/ProcedureWorkerThread';
import { FlagsConfig } from './SpFlags';
import { threadPool, threadPool2 } from '../database/SqlLite';
import { JankStruct } from '../database/ui-worker/ProcedureWorkerJank';
import { CpuStruct } from '../database/ui-worker/cpu/ProcedureWorkerCPU';
import { PairPoint } from '../database/ui-worker/ProcedureWorkerCommon';
import { TraceSheet } from './trace/base/TraceSheet';
import { TimerShaftElement } from './trace/TimerShaftElement';
import { SpChartList } from './trace/SpChartList';
type HTMLElementAlias = HTMLElement | null | undefined;
import { Utils } from './trace/base/Utils';
import { fuzzyQueryFuncRowData, queryFuncRowData } from '../database/sql/Func.sql';
import { convertTitle } from './chart/SpXpowerChart';
import { TabPaneSchedTaskByCpu } from './trace/sheet/cpu/TabPaneSchedTaskByCpu';
const pluginArray = [
{
pluginName: 'ftrace-plugin',
tables: [
'animation', 'app_startup', 'args', 'callstack', 'clk_event_filter',
'clock_event_filter', 'cpu_measure_filter', 'device_info', 'dynamic_frame', 'frame_maps',
'frame_slice', 'gpu_slice', 'instant', 'irq', 'process_measure_filter', 'process_measure',
'sched_slice', 'static_initalize', 'symbols', 'syscall', 'task_pool', 'thread_state', 'dma_fence'
]
},
{
pluginName: 'hiperf-plugin',
tables: [
'perf_callchain', 'perf_files', 'perf_report', 'perf_sample', 'perf_thread'
]
},
{
pluginName: 'nativehook-plugin',
tables: [
'native_hook', 'native_hook_frame', 'native_hook_statistic'
]
},
{
pluginName: 'arkTs-plugin',
tables: [
'js_config', 'js_cpu_profiler_node', 'js_cpu_profiler_sample', 'js_heap_files', 'js_heap_info', 'js_heap_location',
'js_heap_nodes', 'js_heap_sample', 'js_heap_string', 'js_heap_trace_function_info', 'js_heap_trace_node', 'js_heap_edges'
]
},
{
pluginName: 'memory-plugin',
tables: [
'memory_ashmem', 'memory_cpu', 'memory_dma', 'memory_process_gpu', 'memory_profile,', 'memory_rs_image', 'memory_window_gpu', 'smaps', 'sys_event_filter', 'sys_mem_measure'
]
},
{
pluginName: 'hisysevent-plugin',
tables: [
'app_name', 'device_state', 'hisys_all_event', 'hisys_event_measure'
]
},
{
pluginName: 'ebpf-plugin',
tables: [
'bio_latency_sample', 'ebpf_callstack', 'file_system_sample', 'paged_memory_sample'
]
},
{
pluginName: 'cpu-plugin',
tables: [
'cpu_usage'
]
},
{
pluginName: 'diskio-plugin',
tables: [
'diskio'
]
},
{
pluginName: 'hidump-plugin',
tables: [
'hidump'
]
},
{
pluginName: 'process-plugin',
tables: [
'live_process'
]
},
{
pluginName: 'hilog-plugin',
tables: [
'log'
]
},
{
pluginName: 'network-plugin',
tables: [
'network'
]
},
{
pluginName: 'xpower-plugin',
tables: [
'xpower_measure'
]
}
];
function rightButtonOnClick(sp: SpSystemTrace, rightStar: HTMLElementAlias): unknown {
Object.assign(sp, {
ext(): string {
return 'Handle the right button click event';
},
});
return function (event: unknown): void {
if (SpSystemTrace.btnTimer) {
return;
}
sp.checkclick = true;
const startIndex = CpuStruct.selectCpuStruct!.displayProcess?.indexOf('[');
if (SpSystemTrace.wakeupList.length === 0) {
SpSystemTrace.wakeupList.unshift(CpuStruct.wakeupBean!);
sp.queryCPUWakeUpList(CpuStruct.wakeupBean!);
CpuStruct.selectCpuStruct!.ts = CpuStruct.selectCpuStruct!.startTime;
CpuStruct.selectCpuStruct!.thread = CpuStruct.selectCpuStruct!.name;
CpuStruct.selectCpuStruct!.pid = CpuStruct.selectCpuStruct!.processId;
CpuStruct.selectCpuStruct!.process = CpuStruct.selectCpuStruct!.displayProcess?.substring(0, startIndex).trim() || CpuStruct.selectCpuStruct!.processName;
CpuStruct.selectCpuStruct!.itid = CpuStruct.wakeupBean!.itid;
sessionStorage.setItem('saveselectcpustruct', JSON.stringify(CpuStruct.selectCpuStruct));
} else {
sp.wakeupListNull();
SpSystemTrace.wakeupList.unshift(CpuStruct.wakeupBean!);
sp.queryCPUWakeUpList(CpuStruct.wakeupBean!);
CpuStruct.selectCpuStruct!.ts = CpuStruct.selectCpuStruct!.startTime;
CpuStruct.selectCpuStruct!.thread = CpuStruct.selectCpuStruct!.name;
CpuStruct.selectCpuStruct!.pid = CpuStruct.selectCpuStruct!.processId;
CpuStruct.selectCpuStruct!.process = CpuStruct.selectCpuStruct!.displayProcess?.substring(0, startIndex).trim() || CpuStruct.selectCpuStruct!.processName;
CpuStruct.selectCpuStruct!.itid = CpuStruct.wakeupBean!.itid;
sessionStorage.setItem('saveselectcpustruct', JSON.stringify(CpuStruct.selectCpuStruct));
}
let rightButton: HTMLElement | null | undefined = sp.traceSheetEL?.shadowRoot
?.querySelector('#current-selection > tabpane-current-selection')
?.shadowRoot?.querySelector('#rightButton');
rightButton?.blur();
setTimeout(() => {
requestAnimationFrame(() => sp.refreshCanvas(false));
}, 300);
rightStar!.style.visibility = 'visible';
rightStar!.style.cursor = 'pointer';
SpSystemTrace.btnTimer = setTimeout((): void => {
SpSystemTrace.btnTimer = null;
}, 2000);
};
}
function rightStarOnClick(sp: SpSystemTrace) {
return function (ev: unknown): void {
let wakeupLists = [];
wakeupLists.push(CpuStruct.selectCpuStruct?.cpu);
for (let wakeupBean of SpSystemTrace.wakeupList) {
wakeupLists.push(wakeupBean.cpu);
}
let wakeupCpuLists = Array.from(new Set(wakeupLists)).sort();
for (let wakeupCpu of wakeupCpuLists) {
let cpuFavoriteRow: unknown = sp.shadowRoot?.querySelector<TraceRow<unknown>>(
`trace-row[row-type='cpu-data'][row-id='${Utils.getDistributedRowId(wakeupCpu)}']`
);
if (cpuFavoriteRow === null || cpuFavoriteRow === undefined) {
continue;
}
cpuFavoriteRow!.setAttribute('collect-type', '');
let replaceRow = document.createElement('div');
replaceRow.setAttribute('row-id', `${cpuFavoriteRow.rowId}-${cpuFavoriteRow.rowType}`);
replaceRow.setAttribute('type', 'replaceRow');
replaceRow.setAttribute('row-parent-id', cpuFavoriteRow.rowParentId);
replaceRow.style.display = 'none';
cpuFavoriteRow.rowHidden = !cpuFavoriteRow.hasAttribute('scene');
if (sp.rowsEL!.contains(cpuFavoriteRow)) {
sp.rowsEL!.replaceChild(replaceRow, cpuFavoriteRow);
}
cpuFavoriteRow.tampName = cpuFavoriteRow.name;
sp.favoriteChartListEL!.insertRow(cpuFavoriteRow, cpuFavoriteRow.traceId || sp.currentCollectGroup, true);
sp.collectRows.push(cpuFavoriteRow);
sp.timerShaftEL?.displayCollect(sp.collectRows.length !== 0);
sp.currentClickRow = null;
cpuFavoriteRow.setAttribute('draggable', 'true');
cpuFavoriteRow.addEventListener('dragstart', cpuFavoriteRowDragStart(sp, cpuFavoriteRow));
cpuFavoriteRow.addEventListener('dragover', cpuFavoriteRowDragOver(sp));
cpuFavoriteRow.addEventListener('drop', cpuFavoriteRowDropHandler(sp, cpuFavoriteRow));
cpuFavoriteRow.addEventListener('dragend', cpuFavoriteRowDragendHandler(sp));
}
sp.refreshFavoriteCanvas();
sp.refreshCanvas(true);
};
}
function cpuFavoriteRowDragStart(sp: SpSystemTrace, cpuFavoriteRow: unknown) {
return function (): void {
sp.currentClickRow = cpuFavoriteRow;
};
}
function cpuFavoriteRowDragOver(sp: SpSystemTrace) {
return function (ev: unknown): void {
ev.preventDefault();
ev.dataTransfer.dropEffect = 'move';
};
}
function cpuFavoriteRowDropHandler(sp: SpSystemTrace, cpuFavoriteRow: unknown) {
return function (ev: unknown): void {
if (sp.favoriteChartListEL && sp.currentClickRow && sp.currentClickRow !== cpuFavoriteRow) {
let rect = cpuFavoriteRow.getBoundingClientRect();
if (ev.clientY >= rect.top && ev.clientY < rect.top + rect.height / 2) {
sp.favoriteChartListEL.insertRowBefore(sp.currentClickRow, cpuFavoriteRow);
} else if (ev.clientY <= rect.bottom && ev.clientY > rect.top + rect.height / 2) {
sp.favoriteChartListEL.insertRowBefore(sp.currentClickRow, cpuFavoriteRow.nextSibling);
}
sp.refreshFavoriteCanvas();
}
};
}
function cpuFavoriteRowDragendHandler(sp: SpSystemTrace): () => void {
return function (): void {
sp.linkNodes.forEach((itln) => {
if (itln[0].rowEL.collect) {
itln[0].rowEL.translateY = itln[0].rowEL.getBoundingClientRect().top - 195;
} else {
itln[0].rowEL.translateY = itln[0].rowEL.offsetTop - sp.rowsPaneEL!.scrollTop;
}
if (itln[1].rowEL.collect) {
itln[1].rowEL.translateY = itln[1].rowEL.getBoundingClientRect().top - 195;
} else {
itln[1].rowEL.translateY = itln[1].rowEL.offsetTop - sp.rowsPaneEL!.scrollTop;
}
itln[0].y = itln[0].rowEL.translateY + itln[0].offsetY;
itln[1].y = itln[1].rowEL.translateY + itln[1].offsetY;
});
sp.currentClickRow = null;
};
}
function triangleFlagHandler(sp: SpSystemTrace): (event: unknown) => void {
return function (event: unknown): void {
let temporaryTime = sp.timerShaftEL?.drawTriangle(event.detail.time, event.detail.type);
if (event.detail.timeCallback && temporaryTime) {
event.detail.timeCallback(temporaryTime);
}
};
}
function numberCalibrationHandler(sp: SpSystemTrace): (event: unknown) => void {
return function (event: unknown): void {
sp.timerShaftEL!.sportRuler!.times = event.detail.time;
sp.timerShaftEL!.sportRuler!.counts = event.detail.counts;
sp.timerShaftEL!.sportRuler!.durations = event.detail.durations;
sp.timerShaftEL!.sportRuler!.showRuler = event.detail.isShow;
sp.timerShaftEL!.sportRuler?.draw();
};
}
function flagChangeHandler(sp: SpSystemTrace): (event: unknown) => void {
return function (event: unknown): void {
sp.timerShaftEL?.modifyFlagList(event.detail);
if (event.detail.hidden) {
sp.selectFlag = undefined;
if (sp._flagList.length <= 0) {
let showTab = sp.getShowTab();
showTab = showTab.filter((it) => it !== 'box-flag');
if (TraceRow.rangeSelectObject && showTab.length > 0) {
sp.traceSheetEL?.displayTab(...showTab);
} else {
sp.traceSheetEL?.setMode('hidden');
}
}
sp.refreshCanvas(true);
}
};
}
function slicesChangeHandler(sp: SpSystemTrace): (event: unknown) => void {
return function (event: unknown): void {
sp.timerShaftEL?.modifySlicesList(event.detail);
if (event.detail.hidden) {
sp.slicestime = null;
if (sp._slicesList.length <= 0) {
let showTab = sp.getShowTab();
showTab = showTab.filter((it) => it !== 'tabpane-current');
if (TraceRow.rangeSelectObject && showTab.length > 0) {
sp.traceSheetEL?.displayTab(...showTab);
} else {
sp.traceSheetEL?.setMode('hidden');
}
}
sp.refreshCanvas(true);
}
};
}
function collectHandler(sp: SpSystemTrace): (event: unknown) => void {
return function (event: unknown): void {
let currentRow = event.detail.row;
if (currentRow.collect) {
collectHandlerYes(sp, currentRow, event);
} else {
collectHandlerNo(sp, currentRow, event);
}
sp.timerShaftEL?.displayCollect(sp.collectRows.length !== 0);
sp.refreshFavoriteCanvas();
sp.refreshCanvas(true);
sp.linkNodes.forEach((itln) => {
if (itln[0].rowEL === currentRow) {
if (itln[0].rowEL.collect) {
itln[0].rowEL.translateY = itln[0].rowEL.getBoundingClientRect().top - 195;
} else {
itln[0].rowEL.translateY = itln[0].rowEL.offsetTop - sp.rowsPaneEL!.scrollTop;
}
itln[0].y = itln[0].rowEL.translateY + itln[0].offsetY;
} else if (itln[1].rowEL === currentRow) {
if (itln[1].rowEL.collect) {
itln[1].rowEL.translateY = itln[1].rowEL.getBoundingClientRect().top - 195;
} else {
itln[1].rowEL.translateY = itln[1].rowEL.offsetTop - sp.rowsPaneEL!.scrollTop;
}
itln[1].y = itln[1].rowEL.translateY + itln[1].offsetY;
}
});
sp.currentClickRow = null;
currentRow.setAttribute('draggable', 'true');
currentRow.addEventListener('dragstart', () => {
sp.currentClickRow = currentRow;
});
currentRow.addEventListener('dragover', (ev: unknown) => {
ev.preventDefault();
ev.dataTransfer.dropEffect = 'move';
});
currentRow.addEventListener('drop', collectHandlerDrop(sp, currentRow));
currentRow.addEventListener('dragend', collectHandlerDragEnd(sp));
};
}
function collectHandlerNo(sp: SpSystemTrace, currentRow: unknown, event: unknown): void {
sp.favoriteChartListEL?.deleteRow(currentRow, event.detail.type !== 'auto-collect');
if (event.detail.type !== 'auto-collect') {
let rowIndex = sp.collectRows.indexOf(currentRow);
if (rowIndex !== -1) {
sp.collectRows.splice(rowIndex, 1);
}
}
let row = currentRow;
let allowExpansionRow = [];
while (row.hasParentRowEl) {
let parent = row.parentRowEl;
allowExpansionRow.push(parent);
row = parent;
}
if (allowExpansionRow.length === 1) {
for (let index: number = allowExpansionRow.length - 1; index >= 0; index--) {
if (allowExpansionRow[index]?.hasAttribute('scene')) {
if (allowExpansionRow[index]!.expansion) {
allowExpansionRow[index].updateChildRowStatus();
} else {
allowExpansionRow[index].expansion = true;
}
}
}
} else {
for (let index: number = allowExpansionRow.length - 1; index >= 0; index--) {
let currentItemRow = allowExpansionRow[index];
if (currentItemRow.hasAttribute('scene')) {
if (currentItemRow.rowParentId !== '') {
if (currentItemRow.expansion) {
currentItemRow.updateChildRowStatus();
} else {
currentItemRow.expansion = true;
}
}
else {
currentItemRow.expansion = true;
let number = currentItemRow.childrenList.indexOf(currentRow);
if (number !== -1) {
let childrenEl = currentItemRow.childrenList[number];
let childrenNextEl = currentItemRow.childrenList[number + 1];
if (childrenEl) {
if (childrenNextEl) {
currentItemRow.parentNode.insertBefore(childrenEl, currentItemRow.childrenList[number + 1]);
} else if (childrenEl.nextSibling) {
currentItemRow.parentNode.insertBefore(childrenEl, childrenEl.nextSibling);
} else {
currentItemRow.parentNode.appendChild(childrenEl);
}
}
}
}
}
}
}
allowExpansionRow.length = 0;
let traceId = currentRow.traceId ? `${currentRow.traceId}-` : '';
let replaceRow = sp.rowsEL!.querySelector<HTMLCanvasElement>(
`div[row-id='${traceId}${currentRow.rowId}-${currentRow.rowType}']`
);
if (currentRow!.tampName.startsWith("CallChart")) {
let index = currentRow!.name.indexOf(']') + 1;
currentRow!.tampName = index !== -1 ? currentRow!.name.substring(0, index) : currentRow!.name;
}
currentRow.name = currentRow.tampName;
if (currentRow.rowType === 'xpower-system' || (currentRow.parentRowEl && currentRow.parentRowEl.rowType === 'xpower-bundle-name-group')) {
let titleEl = currentRow.shadowRoot?.querySelector('.name') as HTMLLabelElement;
titleEl.title = convertTitle(currentRow.tampName);
}
if (replaceRow !== null) {
sp.rowsEL!.replaceChild(currentRow, replaceRow);
currentRow.style.boxShadow = '0 10px 10px #00000000';
}
}
function collectHandlerYes(sp: SpSystemTrace, currentRow: unknown, event: unknown): void {
if (!sp.collectRows.find((find) => find === currentRow)) {
sp.collectRows.push(currentRow);
}
let replaceRow = document.createElement('div');
let traceId = currentRow.traceId ? `${currentRow.traceId}-` : '';
replaceRow.setAttribute('row-id', `${traceId}${currentRow.rowId}-${currentRow.rowType}`);
replaceRow.setAttribute('type', 'replaceRow');
replaceRow.setAttribute('row-parent-id', currentRow.rowParentId);
replaceRow.style.display = 'none';
if (!currentRow.hasAttribute('scene')) {
currentRow.setAttribute('row-hidden', '');
} else {
currentRow.removeAttribute('row-hidden');
}
let rowParentId = currentRow.rowParentId;
currentRow.tampName = currentRow.name;
if (rowParentId) {
let parentRows = sp.shadowRoot?.querySelectorAll<TraceRow<unknown>>(`trace-row[row-id='${rowParentId}']`);
parentRows?.forEach((parentRow) => {
if (
parentRow?.name &&
parentRow?.name !== currentRow.name &&
!parentRow.rowType!.startsWith('cpu') &&
!parentRow.rowType!.startsWith('thread') &&
!parentRow.rowType!.startsWith('func') &&
!currentRow.name.includes(parentRow.name)
) {
currentRow.name = currentRow.protoParentId ? `${currentRow.name} (${currentRow.protoParentId})` :
`${currentRow.name} (${parentRow.name})`;
}
});
}
if (!currentRow.hasParentRowEl) {
sp.rowsEL!.replaceChild(replaceRow, currentRow);
}
if (currentRow.rowType === 'xpower-system' || (currentRow.parentRowEl && currentRow.parentRowEl.rowType === 'xpower-bundle-name-group')) {
let titleEl = currentRow.shadowRoot?.querySelector('.name') as HTMLLabelElement;
titleEl.title = convertTitle(currentRow.tampName);
}
let group = currentRow.traceId || sp.currentCollectGroup;
sp.favoriteChartListEL?.insertRow(currentRow, group, event.detail.type !== 'auto-collect');
}
function collectHandlerDrop(sp: SpSystemTrace, currentRow: HTMLDivElement | undefined | null): (ev: unknown) => void {
return function (ev: unknown) {
if (sp.favoriteChartListEL !== null && sp.currentClickRow !== null && sp.currentClickRow !== currentRow) {
let rect = currentRow!.getBoundingClientRect();
if (ev.clientY >= rect.top && ev.clientY < rect.top + rect.height / 2) {
sp.favoriteChartListEL!.insertRowBefore(sp.currentClickRow!, currentRow!);
} else if (ev.clientY <= rect.bottom && ev.clientY > rect.top + rect.height / 2) {
sp.favoriteChartListEL!.insertRowBefore(sp.currentClickRow!, currentRow!.nextSibling!);
}
sp.refreshFavoriteCanvas();
}
};
}
function collectHandlerDragEnd(sp: SpSystemTrace): (ev: unknown) => void {
return function (ev: unknown): void {
sp.linkNodes.forEach((itln) => {
if (itln[0].rowEL.collect) {
if (sp.timerShaftEL?._checkExpand) {
itln[0].rowEL.translateY =
itln[0].rowEL.getBoundingClientRect().top - 195 + sp.timerShaftEL._usageFoldHeight!;
} else {
itln[0].rowEL.translateY = itln[0].rowEL.getBoundingClientRect().top - 195;
}
} else {
itln[0].rowEL.translateY = itln[0].rowEL.offsetTop - sp.rowsPaneEL!.scrollTop;
}
if (itln[1].rowEL.collect) {
if (sp.timerShaftEL?._checkExpand) {
itln[1].rowEL.translateY =
itln[1].rowEL.getBoundingClientRect().top - 195 + sp.timerShaftEL._usageFoldHeight!;
} else {
itln[1].rowEL.translateY = itln[1].rowEL.getBoundingClientRect().top - 195;
}
} else {
itln[1].rowEL.translateY = itln[1].rowEL.offsetTop - sp.rowsPaneEL!.scrollTop;
}
itln[0].y = itln[0].rowEL.translateY + itln[0].offsetY;
itln[1].y = itln[1].rowEL.translateY + itln[1].offsetY;
});
sp.currentClickRow = null;
};
}
function selectHandler(sp: SpSystemTrace): void {
sp.rangeSelect.selectHandler = (rows, refreshCheckBox): void => {
rows.forEach((item) => {
sp.setAttribute('clickRow', item.rowType!);
sp.setAttribute('rowName', item.name);
sp.setAttribute('rowId', item.rowId!);
});
if (rows.length === 0) {
const allRows = [
...sp.shadowRoot!.querySelectorAll<TraceRow<unknown>>('trace-row'),
...sp.favoriteChartListEL!.getAllCollectRows(),
];
for (const row of allRows) {
row.checkType = '-1';
if (row.folder) {
row.childrenList.forEach((item) => {
row.checkType = '-1';
});
}
}
sp.refreshCanvas(true);
if (!SportRuler.isMouseInSportRuler) {
sp.traceSheetEL?.setMode('max');
sp.traceSheetEL?.setMode('hidden');
}
return;
}
let checkRows = rows;
if (!refreshCheckBox) {
checkRows = [
...rows,
...sp.shadowRoot!.querySelectorAll<TraceRow<unknown>>(`trace-row[check-type='2']`),
...sp.favoriteChartListEL!.getAllSelectCollectRows(),
];
}
checkRows = checkRows.filter((item, index, self) => {
return self.findIndex(
obj => obj.rowId === item.rowId && obj.rowType === item.rowType && obj.name === item.name && obj.rowParentId === item.rowParentId
) === index;
});
selectHandlerRefreshCheckBox(sp, checkRows, refreshCheckBox);
if (!sp.isSelectClick) {
sp.rangeTraceRow = [];
}
selectHandlerRows(sp, checkRows);
};
}
function selectHandlerRefreshCheckBox(sp: SpSystemTrace, rows: Array<TraceRow<unknown>>, refreshCheckBox: boolean): void {
if (refreshCheckBox) {
if (rows.length > 0) {
sp.queryAllTraceRow().forEach((row) => (row.checkType = '0'));
rows.forEach((it) => (it.checkType = '2'));
} else {
sp.queryAllTraceRow().forEach((row) => (row.checkType = '-1'));
return;
}
}
}
function selectHandlerRows(sp: SpSystemTrace, rows: Array<TraceRow<unknown>>): void {
Utils.isRangeSelectRefresh = true;
let selection = new SelectionParam();
selection.traceId = Utils.currentSelectTrace;
selection.cpuStateRowsId = sp.stateRowsId;
selection.leftNs = TraceRow.rangeSelectObject?.startNS || 0;
selection.rightNs = TraceRow.rangeSelectObject?.endNS || 0;
selection.recordStartNs = Utils.getInstance().getRecordStartNS(Utils.currentSelectTrace);
rows.forEach((it) => {
selection.pushSelection(it, sp);
if (sp.rangeTraceRow!.length !== rows.length) {
let event = sp.createPointEvent(it);
SpStatisticsHttpUtil.addOrdinaryVisitAction({
action: 'trace_row',
event: event,
});
}
sp.setParentCheckStatus(it);
});
let hasNetworkCount = rows.some(row =>
row.rowType === TraceRow.ROW_TYPE_NETWORK_COUNT || row.rowType === TraceRow.ROW_TYPE_NETWORK_COUNT_FOLDER
);
let hasNetworkSummary = rows.some(row => row.rowType === TraceRow.ROW_TYPE_NETWORK_SUMMARY);
let hasNetworkDetail = rows.some(row =>
row.rowType === TraceRow.ROW_TYPE_NETWORK_DETAIL || row.rowType === TraceRow.ROW_TYPE_NETWORK_DETAIL_FOLDER
);
if (hasNetworkDetail && !hasNetworkCount && !hasNetworkSummary) {
selection.shouldQueryByProcess = true;
} else if (hasNetworkCount || hasNetworkSummary) {
selection.shouldQueryByProcess = false;
}
if (selection.diskIOipids.length > 0 && !selection.diskIOLatency) {
selection.promiseList.push(
queryEbpfSamplesCount(
TraceRow.rangeSelectObject?.startNS || 0,
TraceRow.rangeSelectObject?.endNS || 0,
selection.diskIOipids
).then((res) => {
if (res.length > 0) {
selection.fsCount = res[0].fsCount;
selection.vmCount = res[0].vmCount;
}
return new Promise((resolve) => resolve(1));
})
);
}
sp.rangeTraceRow = rows;
sp.isSelectClick = false;
sp.selectStructNull();
sp.timerShaftEL?.removeTriangle('inverted');
if (selection.promiseList.length > 0) {
Promise.all(selection.promiseList).then(() => {
selection.promiseList = [];
sp.traceSheetEL?.rangeSelect(selection);
});
} else {
sp.traceSheetEL?.rangeSelect(selection);
}
sp.timerShaftEL!.selectionList.push(selection);
sp.selectionParam = selection;
sp.refreshCanvas(true);
}
function resizeObserverHandler(sp: SpSystemTrace): void {
new ResizeObserver((entries) => {
TraceRow.FRAME_WIDTH = sp.clientWidth - 249 - sp.getScrollWidth();
requestAnimationFrame(() => {
sp.timerShaftEL?.updateWidth(sp.clientWidth - 1 - sp.getScrollWidth());
sp.shadowRoot!.querySelectorAll<TraceRow<unknown>>('trace-row').forEach((it) => {
it.updateWidth(sp.clientWidth);
});
});
}).observe(sp);
new ResizeObserver((entries) => {
sp.canvasPanelConfig();
if (sp.traceSheetEL!.getAttribute('mode') === 'hidden') {
sp.timerShaftEL?.removeTriangle('triangle');
}
if (sp.favoriteChartListEL?.style.display === 'flex') {
sp.refreshFavoriteCanvas();
}
sp.refreshCanvas(true);
}).observe(sp.rowsPaneEL!);
}
function mutationObserverHandler(sp: SpSystemTrace): void {
new MutationObserver((mutations, observer) => {
for (const mutation of mutations) {
if (mutation.type === 'attributes') {
if (sp.style.visibility === 'visible') {
if (TraceRow.rangeSelectObject && SpSystemTrace.sliceRangeMark) {
sp.timerShaftEL?.setSlicesMark(
TraceRow.rangeSelectObject.startNS || 0,
TraceRow.rangeSelectObject.endNS || 0,
false
);
SpSystemTrace.sliceRangeMark = undefined;
window.publish(window.SmartEvent.UI.RefreshCanvas, {});
}
}
}
}
}).observe(sp, {
attributes: true,
childList: false,
subtree: false,
});
}
function intersectionObserverHandler(sp: SpSystemTrace): void {
sp.intersectionObserver = new IntersectionObserver(
(entries) => {
entries.forEach((it) => {
let tr = it.target as TraceRow<unknown>;
tr.intersectionRatio = it.intersectionRatio;
if (!it.isIntersecting) {
tr.sleeping = true;
sp.invisibleRows.indexOf(tr) === -1 && sp.invisibleRows.push(tr);
} else {
tr.sleeping = false;
sp.visibleRows.indexOf(tr) === -1 && sp.visibleRows.push(tr);
}
});
sp.visibleRows = sp.visibleRows.filter((it) => !it.sleeping);
sp.invisibleRows = sp.invisibleRows.filter((it) => it.sleeping);
if (sp.handler === -1) {
cancelAnimationFrame(sp.handler);
}
sp.handler = requestAnimationFrame(() => sp.refreshCanvas(false));
},
{ threshold: [0, 0.01, 0.99, 1] }
);
}
function observerHandler(sp: SpSystemTrace): void {
resizeObserverHandler(sp);
mutationObserverHandler(sp);
intersectionObserverHandler(sp);
}
function windowKeyDownHandler(sp: SpSystemTrace): (ev: KeyboardEvent) => void {
return function (ev: KeyboardEvent) {
if (ev.key.toLocaleLowerCase() === 'escape') {
sp.queryAllTraceRow().forEach((it) => {
it.checkType = '-1';
});
TraceRow.rangeSelectObject = undefined;
sp.rangeSelect.rangeTraceRow = [];
sp.selectStructNull();
sp.timerShaftEL?.setSlicesMark();
sp.traceSheetEL?.setMode('hidden');
sp.removeLinkLinesByBusinessType('janks', 'task');
}
};
}
function smartEventSubscribe(sp: SpSystemTrace): void {
window.subscribe(window.SmartEvent.UI.SliceMark, (data) => sp.sliceMarkEventHandler(data));
window.subscribe(window.SmartEvent.UI.TraceRowComplete, (tr) => { });
window.subscribe(window.SmartEvent.UI.RefreshCanvas, () => sp.refreshCanvas(false));
window.subscribe(window.SmartEvent.UI.KeyboardEnable, (tr) => {
sp.keyboardEnable = tr.enable;
if (!sp.keyboardEnable) {
sp.stopWASD();
}
});
window.subscribe(window.SmartEvent.UI.CollapseAllLane, (collapse: boolean) => {
if (!collapse) {
sp.expandRowList = Array.from(sp.rowsEL!.querySelectorAll<TraceRow<unknown>>('trace-row[folder][expansion]')) || [];
}
sp.collapseAll = true;
sp.setAttribute('disable', '');
sp.expandRowList!.forEach((it) => (it.expansion = collapse));
sp.collapseAll = false;
sp.removeAttribute('disable');
sp.refreshCanvas(true);
});
window.subscribe(window.SmartEvent.UI.MouseEventEnable, (tr) => {
sp.mouseEventEnable = tr.mouseEnable;
if (sp.mouseEventEnable) {
sp.removeAttribute('disable');
} else {
sp.setAttribute('disable', '');
}
});
window.subscribe(window.SmartEvent.UI.CollectGroupChange, (group: string) => (sp.currentCollectGroup = group));
}
export function documentInitEvent(sp: SpSystemTrace): void {
if (!document) {
return;
}
document.addEventListener('triangle-flag', triangleFlagHandler(sp));
document.addEventListener('number_calibration', numberCalibrationHandler(sp));
document.addEventListener('flag-change', flagChangeHandler(sp));
document.addEventListener('slices-change', slicesChangeHandler(sp));
if (sp.timerShaftEL?.collecBtn) {
sp.timerShaftEL.collecBtn.onclick = (): void => {
if (sp.timerShaftEL!.collecBtn!.hasAttribute('close')) {
sp.timerShaftEL!.collecBtn!.removeAttribute('close');
sp.favoriteChartListEL?.showCollectArea();
} else {
sp.timerShaftEL!.collecBtn!.setAttribute('close', '');
sp.favoriteChartListEL?.hideCollectArea();
}
};
}
document.addEventListener('collect', collectHandler(sp));
}
export function spSystemTraceInitElement(sp: SpSystemTrace): void {
window.subscribe(window.SmartEvent.UI.LoadFinishFrame, () => sp.drawAllLines());
sp.traceSheetEL = sp.shadowRoot?.querySelector<TraceSheet>('.trace-sheet');
if (!sp || !sp.shadowRoot || !sp.traceSheetEL) {
return;
}
let rightButton: HTMLElement | null | undefined = sp.traceSheetEL.shadowRoot
?.querySelector('#current-selection > tabpane-current-selection')
?.shadowRoot?.querySelector('#rightButton');
let rightStar: HTMLElement | null | undefined = sp.traceSheetEL.shadowRoot
?.querySelector('#current-selection > tabpane-current-selection')
?.shadowRoot?.querySelector('#right-star');
sp.tipEL = sp.shadowRoot.querySelector<HTMLDivElement>('.tip');
sp.rowsPaneEL = sp.shadowRoot.querySelector<HTMLDivElement>('.rows-pane');
sp.rowsEL = sp.rowsPaneEL;
sp.spacerEL = sp.shadowRoot.querySelector<HTMLDivElement>('.spacer');
sp.timerShaftEL = sp.shadowRoot.querySelector<TimerShaftElement>('.timer-shaft');
sp.favoriteChartListEL = sp.shadowRoot.querySelector<SpChartList>('#favorite-chart-list');
sp.collectEl1 = sp.favoriteChartListEL?.shadowRoot?.querySelector<HTMLDivElement>('#collect-group-1');
sp.collectEl2 = sp.favoriteChartListEL?.shadowRoot?.querySelector<HTMLDivElement>('#collect-group-2');
sp.groupTitle1 = sp.favoriteChartListEL?.shadowRoot?.querySelector<HTMLDivElement>('#group-1-title');
sp.groupTitle2 = sp.favoriteChartListEL?.shadowRoot?.querySelector<HTMLDivElement>('#group-2-title');
if (!sp.traceSheetEL.shadowRoot) {
return;
}
sp.tabCpuFreq = sp.traceSheetEL.shadowRoot.querySelector<TabPaneFrequencySample>('tabpane-frequency-sample');
sp.tabCpuState = sp.traceSheetEL.shadowRoot.querySelector<TabPaneCounterSample>('tabpane-counter-sample');
sp.tabSchedTaskByCpu = sp.traceSheetEL.shadowRoot.querySelector<TabPaneSchedTaskByCpu>('tabpane-schedTask-cpu');
sp.wakeupListTbl = sp.traceSheetEL.shadowRoot?.querySelector('#current-selection > tabpane-current-selection')?.
shadowRoot?.querySelector('#wakeupListTbl');
sp.rangeSelect = new RangeSelect(sp);
rightButton?.addEventListener('click', rightButtonOnClick(sp, rightStar));
rightStar?.addEventListener('click', rightStarOnClick(sp));
documentInitEvent(sp);
SpSystemTrace.scrollViewWidth = sp.getScrollWidth();
selectHandler(sp);
observerHandler(sp);
window.addEventListener('keydown', windowKeyDownHandler(sp));
sp.chartManager = new SpChartManager(sp);
sp.canvasPanel = sp.shadowRoot.querySelector<HTMLCanvasElement>('#canvas-panel')!;
sp.canvasPanelCtx = sp.canvasPanel.getContext('2d');
sp.canvasFavoritePanelCtx = sp.favoriteChartListEL!.context();
sp.canvasPanelConfig();
smartEventSubscribe(sp);
}
function moveRangeToCenterAndHighlight(sp: SpSystemTrace, findEntry: unknown, currentEntry: unknown): void {
if (findEntry) {
if (findEntry.startTime + findEntry.dur > TraceRow.range!.endNS || findEntry.startTime < TraceRow.range!.startNS) {
sp.moveRangeToLeft(findEntry.startTime!, findEntry.dur!);
}
cancelCurrentTraceRowHighlight(sp, currentEntry);
if (findEntry.type === 'cpu') {
findEntryTypeCpu(sp, findEntry);
} else if (findEntry.type === 'func') {
findEntryTypeFunc(sp, findEntry);
} else if (findEntry.type === 'thread||process') {
findEntryTypeThreadProcess(sp, findEntry);
} else if (findEntry.type === 'sdk') {
findEntryTypeSdk(sp, findEntry);
}
}
}
export function cancelCurrentTraceRowHighlight(sp: SpSystemTrace, currentEntry: unknown): void {
if (currentEntry?.type === 'cpu') {
sp.queryAllTraceRow(`trace-row[row-type='cpu-data'][row-id='${currentEntry.cpu}']`,
(row) => row.rowType === 'cpu-data' && row.rowId === `${currentEntry.cpu}`)[0].highlight = false;
} else if (currentEntry?.type === 'func') {
let funId = (currentEntry.rowId === null || currentEntry.rowId === undefined) ? `${currentEntry.funName}-${currentEntry.pid}` : currentEntry.rowId;
let funcRowID = (currentEntry.cookie === null || currentEntry.cookie === undefined) ? `${Utils.getDistributedRowId(currentEntry.tid)}` : funId;
let parentRow = sp.queryAllTraceRow(`trace-row[row-id='${Utils.getDistributedRowId(currentEntry.pid)}'][folder]`,
(row) => row.rowId === `trace-row[row-id='${Utils.getDistributedRowId(currentEntry.pid)}'][folder]`)[0];
if (!parentRow) {
return;
}
let filterRow: TraceRow<unknown> | undefined;
parentRow.childrenList.forEach((item) => {
if (item.rowId === 'sameThreadProcess') {
filterRow = parentRow.childrenList.concat(item.childrenList).filter((child) => child.rowId === funcRowID && child.rowType === 'func')[0];
} else {
filterRow = parentRow.childrenList.filter((child) => child.rowId === funcRowID && child.rowType === 'func')[0];
}
});
if (!filterRow) {
let rowsPaneEL = document.querySelector('body > sp-application')?.shadowRoot?.querySelector('#sp-system-trace')?.shadowRoot?.querySelector('div > div.rows-pane');
let funcRow = rowsPaneEL?.querySelector<TraceRow<unknown>>(`trace-row[row-id='${funcRowID}'][row-type='func']`);
if (funcRow) {
filterRow = funcRow;
} else {
return;
}
}
filterRow.highlight = false;
} else if (currentEntry?.type === 'sdk') {
let parentRow = sp.shadowRoot!.querySelector<TraceRow<unknown>>("trace-row[row-type='sdk'][folder]");
if (parentRow) {
let sdkRow = parentRow.childrenList.filter(
(child) => child.rowId === currentEntry.rowId && child.rowType === currentEntry.rowType
)[0];
sdkRow!.highlight = false;
}
}
}
export function spSystemTraceShowStruct(
sp: SpSystemTrace,
previous: boolean,
currentIndex: number,
structs: Array<unknown>,
retargetIndex?: number
): number {
if (structs.length === 0) {
return 0;
}
let findIndex = spSystemTraceShowStructFindIndex(previous, currentIndex, structs, retargetIndex);
let findEntry: unknown = structs[findIndex];
let currentEntry: unknown = undefined;
if (currentIndex >= 0) {
currentEntry = structs[currentIndex];
}
moveRangeToCenterAndHighlight(sp, findEntry, currentEntry);
return findIndex;
}
function spSystemTraceShowStructFindIndex(
previous: boolean,
currentIndex: number,
structs: Array<unknown>,
retargetIndex: number | undefined
): number {
const rangeStart = TraceRow.range!.startNS;
const rangeEnd = TraceRow.range!.endNS;
let findIndex = -1;
if (retargetIndex) {
findIndex = retargetIndex - 1;
} else if (previous) {
if (structs[currentIndex].startTime! >= Math.round(rangeStart)) {
findIndex = findPreviousOne(currentIndex - 1, 0, structs);
findIndex = findIndex === -1 ? structs.length - 1 : findIndex;
} else {
findIndex = findPreviousOne(structs.length - 1, currentIndex + 1, structs);
}
} else {
if (currentIndex === -1) {
findIndex = findNextOne(0, structs.length - 1, structs);
return findIndex === -1 ? 0 : findIndex;
}
if (structs[currentIndex].startTime! < Math.round(rangeEnd)) {
findIndex = findNextOne(currentIndex + 1, structs.length - 1, structs);
findIndex = findIndex === -1 ? 0 : findIndex;
} else {
findIndex = findNextOne(0, currentIndex - 1, structs);
}
}
return findIndex;
}
function findPreviousOne(start: number, end: number, structs: Array<unknown>): number {
let findIndex = -1;
const rangeEnd = TraceRow.range!.endNS;
for (let i = start; i >= end; i--) {
let it = structs[i];
if (it.startTime! < rangeEnd) {
findIndex = i;
break;
}
}
return findIndex;
}
function findNextOne(start: number, end: number, structs: Array<unknown>): number {
let findIndex = -1;
const rangeStart = TraceRow.range!.startNS;
for (let i = start; i <= end; i++) {
let it = structs[i];
if (it.startTime > rangeStart) {
findIndex = i;
break;
}
}
return findIndex;
}
function findEntryTypeCpu(sp: SpSystemTrace, findEntry: unknown): void {
CpuStruct.selectCpuStruct = findEntry;
CpuStruct.hoverCpuStruct = CpuStruct.selectCpuStruct;
sp.queryAllTraceRow(`trace-row[row-type='cpu-data']`, (row): boolean => row.rowType === 'cpu-data').forEach(
(item): void => {
if (item.rowId === `${Utils.getDistributedRowId(findEntry.cpu)}`) {
sp.rechargeCpuData(
findEntry,
item.dataListCache.find((it) => it.startTime > findEntry.startTime)
);
let _findEntry = JSON.parse(JSON.stringify(findEntry));
_findEntry.type = 'thread';
item.fixedList = [_findEntry];
}
item.highlight = item.rowId === `${Utils.getDistributedRowId(findEntry.cpu)}`;
item.draw(true);
}
);
sp.scrollToProcess(`${findEntry.cpu}`, '', 'cpu-data', true);
sp.onClickHandler(TraceRow.ROW_TYPE_CPU);
}
function findEntryTypeFunc(sp: SpSystemTrace, findEntry: unknown): void {
sp.observerScrollHeightEnable = true;
sp.scrollToActFunc(
{
startTs: findEntry.startTime,
dur: findEntry.dur,
tid: findEntry.tid,
pid: findEntry.pid,
depth: findEntry.depth,
argsetid: findEntry.argsetid,
funName: findEntry.funName,
cookie: findEntry.cookie,
trace_level: findEntry.trace_level,
trace_tag: findEntry.trace_tag,
custom_args: findEntry.custom_args,
category:findEntry.category,
row_id: findEntry.rowId ? findEntry.rowId : null,
},
true
);
}
function findEntryTypeThreadProcess(sp: SpSystemTrace, findEntry: unknown): void {
let threadProcessRow = sp.rowsEL?.querySelectorAll<TraceRow<ThreadStruct>>('trace-row')[0];
if (threadProcessRow) {
let filterRow = threadProcessRow.childrenList.filter(
(row) => row.rowId === Utils.getDistributedRowId(findEntry.rowId) && row.rowId === findEntry.rowType
)[0];
filterRow!.highlight = true;
sp.closeAllExpandRows(Utils.getDistributedRowId(findEntry.rowParentId));
sp.scrollToProcess(`${findEntry.rowId}`, `${findEntry.rowParentId}`, findEntry.rowType, true);
let completeEntry = (): void => {
sp.hoverStructNull();
sp.selectStructNull();
sp.wakeupListNull();
sp.scrollToProcess(`${findEntry.rowId}`, `${findEntry.rowParentId}`, findEntry.rowType, true);
};
if (filterRow!.isComplete) {
completeEntry();
} else {
filterRow!.onComplete = completeEntry;
}
}
}
function findEntryTypeSdk(sp: SpSystemTrace, findEntry: unknown): void {
let parentRow = sp.shadowRoot!.querySelector<TraceRow<unknown>>(`trace-row[row-type='sdk'][folder]`);
if (parentRow) {
let sdkRow = parentRow.childrenList.filter(
(child) => child.rowId === findEntry.rowId && child.rowType === findEntry.rowType
)[0];
sdkRow!.highlight = true;
}
sp.hoverStructNull();
sp.selectStructNull();
sp.wakeupListNull();
sp.onClickHandler(findEntry.rowType!);
sp.closeAllExpandRows(findEntry.rowParentId);
sp.scrollToProcess(`${findEntry.rowId}`, `${findEntry.rowParentId}`, findEntry.rowType, true);
}
async function spSystemTraceInitBuffer(
sp: SpSystemTrace,
param: { buf?: ArrayBuffer; Url?: string; buf2?: ArrayBuffer },
wasmConfigUri: string,
configUri: string,
progress: Function
): Promise<{
status: boolean;
msg: string;
} | null> {
if (param.buf) {
let configJson = '';
try {
configJson = await fetch(wasmConfigUri).then((res) => res.text());
} catch (e) {
error('getWasmConfigFailed', e);
}
let parseConfig = FlagsConfig.getSpTraceStreamParseConfig();
let systemParseConfigJson = '';
try {
systemParseConfigJson = await fetch(configUri).then((res) => res.text());
let systemParseConfig = JSON.parse(systemParseConfigJson);
let parseConfigObj = JSON.parse(parseConfig);
systemParseConfig.config = parseConfigObj.config;
systemParseConfigJson = JSON.stringify(systemParseConfig);
} catch (e) {
systemParseConfigJson = parseConfig;
error('systemParseConfigJsonFailed', e);
}
let { status, msg, sdkConfigMap } = await threadPool.initSqlite(param.buf, systemParseConfigJson, configJson, progress);
if (!status) {
return { status: false, msg: msg };
}
SpSystemTrace.SDK_CONFIG_MAP = sdkConfigMap;
if (param.buf2) {
let { status, msg } = await threadPool2.initSqlite(param.buf2, systemParseConfigJson, configJson, progress);
if (!status) {
return { status: false, msg: msg };
}
}
return null;
} else {
return null;
}
}
async function spSystemTraceInitUrl(
sp: SpSystemTrace,
param: { buf?: ArrayBuffer; url?: string },
wasmConfigUri: string,
configUri: string,
progress: Function
): Promise<{
status: boolean;
msg: string;
} | null> {
if (param.url) {
let { status, msg } = await threadPool.initServer(param.url, progress);
if (!status) {
return { status: false, msg: msg };
} else {
return null;
}
} else {
return null;
}
}
export async function spSystemTraceInit(
sp: SpSystemTrace,
param: { buf?: ArrayBuffer; url?: string; buf2?: ArrayBuffer; fileName1?: string; fileName2?: string },
wasmConfigUri: string,
configUri: string,
progress: Function,
isDistributed: boolean
): Promise<unknown> {
progress('Load database', 6);
sp.rowsPaneEL!.scroll({ top: 0, left: 0 });
let rsBuf = await spSystemTraceInitBuffer(sp, param, wasmConfigUri, configUri, progress);
if (rsBuf) {
return rsBuf;
}
let rsUrl = await spSystemTraceInitUrl(sp, param, wasmConfigUri, configUri, progress);
if (rsUrl) {
return rsUrl;
}
if (isDistributed) {
await sp.chartManager?.initDistributedChart(progress, param.fileName1 || 'Trace 1', param.fileName2 || 'Trace 2');
} else {
await sp.chartManager?.init(progress);
}
let rowId: string = '';
sp.rowsEL?.querySelectorAll<TraceRow<unknown>>('trace-row').forEach((it) => {
if (it.name.includes('Ark Ts')) {
rowId = it.rowId!;
}
if (it.folder) {
it.addEventListener('expansion-change', sp.extracted(it));
}
});
progress('completed', 100);
info('All TraceRow Data initialized');
sp.loadTraceCompleted = true;
sp.rowsEL!.querySelectorAll<TraceRow<unknown>>('trace-row').forEach((it) => {
if (rowId !== '' && (it.rowId?.includes(rowId) || it.name.includes(rowId))) {
it.addTemplateTypes('Ark Ts');
for (let child of it.childrenList) {
child.addTemplateTypes('Ark Ts');
}
}
if (it.folder) {
let offsetYTimeOut: unknown = undefined;
it.addEventListener('expansion-change', expansionChangeHandler(sp, offsetYTimeOut));
}
if (sp.loadTraceCompleted) {
sp.traceSheetEL?.displaySystemLogsData();
sp.traceSheetEL?.displayHangsData();
sp.traceSheetEL?.displaySystemStatesData();
}
if (it.getAttribute('name')?.includes('render_service') && it.getAttribute('row-type') === 'process') {
queryRowsData(sp, it.childrenList);
}
sp.intersectionObserver?.observe(it);
});
for (let i = 0; i < pluginArray.length; i++) {
let item = pluginArray[i];
for (let j = 0; j < item.tables.length; j++) {
let tableItem = item.tables[j];
let res = await queryPlugins(tableItem) || [];
if (res.length > 0) {
SpStatisticsHttpUtil.recordPlugin.push(item.pluginName);
break;
} else {
continue;
}
}
}
SpStatisticsHttpUtil.recordPluginUsage();
let funDetailUrl = `https://${window.location.host.split(':')[0]}:${window.location.port
}${window.location.pathname}doc/funDetail.json`;
let xhr = new XMLHttpRequest();
xhr.open('GET', funDetailUrl);
xhr.onreadystatechange = function (): void {
if (xhr.readyState === 4 && xhr.status === 200) {
let content = xhr.responseText;
caches.open('/funDetail').then((cache) => {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return cache
.put(
'/funDetail',
new Response(content, {
status: 200,
headers,
})
)
.then();
});
}
};
xhr.send();
return { status: true, msg: 'success' };
}
function expansionChangeHandler(sp: SpSystemTrace, offsetYTimeOut: unknown): (event: unknown) => void {
return function (event: unknown) {
sp.scrollH = sp.rowsPaneEL!.scrollHeight;
let max = [...sp.rowsPaneEL!.querySelectorAll('trace-row')].reduce((pre, cur) => pre + cur.clientHeight!, 0);
let offset = sp.rowsPaneEL!.scrollHeight - max;
sp.rowsPaneEL!.scrollTop = sp.rowsPaneEL!.scrollTop - offset;
JankStruct.delJankLineFlag = false;
if (offsetYTimeOut) {
clearTimeout(offsetYTimeOut);
}
if (event.detail.expansion) {
offsetYTimeOut = setTimeout(() => {
sp.linkNodes.forEach((linkNode) => {
JankStruct.selectJankStructList?.forEach((selectStruct: unknown) => {
if (event.detail.rowId === selectStruct.pid) {
JankStruct.selectJankStruct = selectStruct;
JankStruct.hoverJankStruct = selectStruct;
}
});
linkNodeHandler(linkNode, sp);
});
}, 300);
} else {
if (JankStruct!.selectJankStruct) {
JankStruct.selectJankStructList?.push(<JankStruct>JankStruct!.selectJankStruct);
}
offsetYTimeOut = setTimeout(() => {
sp.linkNodes?.forEach((linkNode) => linkNodeHandler(linkNode, sp));
}, 300);
}
let refreshTimeOut = setTimeout(() => {
sp.refreshCanvas(true);
clearTimeout(refreshTimeOut);
}, 360);
};
}
function queryRowsData(sp: SpSystemTrace, rowList: Array<TraceRow<unknown>>): void {
rowList.forEach((row): void => {
if (row.getAttribute('row-type') === 'func') {
if (row.getAttribute('name')?.startsWith('render_service')) {
saveFrameRateData(sp, row, 'H:RSMainThread::DoComposition');
} else if (row.getAttribute('name')?.startsWith('RSHardwareThrea')) {
saveFrameRateData(sp, row, 'H:Repaint');
}else if(row.getAttribute('name')?.startsWith('PresentFence_')){
savePresentData(sp, row, 'H:Waiting for PresentFence_');
}else if (row.getAttribute('name')?.startsWith('Present')) {
savePresentData(sp, row, 'H:Waiting for Present Fence');
}else if(row.getAttribute('name')?.startsWith('CompThread_')){
saveFrameRateData(sp, row, 'H:Repaint');
}
}
});
}
function saveFrameRateData(sp: SpSystemTrace, row: TraceRow<unknown>, funcName: string): void {
let dataList: unknown = [];
queryFuncRowData(funcName, Number(row?.getAttribute('row-id'))).then((res): void => {
if (res.length) {
res.forEach((item): void => {
dataList?.push({ startTime: item.startTime!, tid: item.tid });
});
if (funcName === 'H:RSMainThread::DoComposition') {
sp.docomList = dataList;
} else {
sp.repaintMap.set(row.getAttribute('name-prefix'),dataList);
}
}
});
}
function savePresentData(sp: SpSystemTrace, row: TraceRow<unknown>, funcName: string): void {
let dataList: unknown = [];
fuzzyQueryFuncRowData(funcName, Number(row?.getAttribute('row-id'))).then((res): void => {
if (res.length) {
res.forEach((item): void => {
dataList?.push({ endTime: item.endTime!, tid: item.tid });
});
sp.presentMap.set(row.getAttribute('name-prefix'),dataList);
}
});
}
function linkNodeHandler(linkNode: PairPoint[], sp: SpSystemTrace): void {
sp.handleCollectFunc([linkNode]);
}
const eventMap = {
'cpu-data': 'Cpu',
'cpu-state': 'Cpu State',
'cpu-freq': 'Cpu Frequency',
'cpu-limit-freq': 'Cpu Freq Limit',
process: 'Process',
'native-memory': 'Native Memory',
thread: 'Thread',
func: 'Func',
mem: 'Memory',
'virtual-memory-cell': 'Virtual Memory',
'virtual-memory-group': 'Virtual Memory',
fps: 'FPS',
'ability-monitor': 'Ability Monitor',
'cpu-ability': 'Cpu Ability',
'memory-ability': 'Memory Ability',
'disk-ability': 'DiskIO Ability',
'network-ability': 'Network Ability',
'network-count': 'Network Count',
'network-summary': 'Network Traffic',
'network-detail': 'Network Process Detail',
sdk: 'Sdk',
'sdk-counter': 'SDK Counter',
'sdk-slice': 'Sdk Slice',
energy: 'Energy',
'power-energy': 'Power Event',
'system-energy': 'System Event',
'anomaly-energy': 'Anomaly Event',
'clock-group': 'Clocks',
clock: 'clock',
'irq-group': 'Irqs',
irq: 'irq',
hiperf: 'HiPerf (All)',
'hiperf-event': 'HiPerf Event',
'hiperf-report': 'HiPerf Report',
'hiperf-process': 'HiPerf Process',
'hiperf-thread': 'HiPerf Thread',
'js-memory': 'Js Memory',
};
export function spSystemTraceInitPointToEvent(sp: SpSystemTrace): void {
sp.eventMap = eventMap;
}
export function spSystemTraceParentRowSticky(sp: SpSystemTrace, deltaY: number): void {
if (deltaY > 0) {
const expandRowList = sp.visibleRows.filter((vr) => vr.expansion);
expandRowList.forEach((vr: TraceRow<unknown>) => {
const visibleNotCollectList = vr.childrenList.filter((child: TraceRow<unknown>) => !child.collect && !child.sleeping);
vr.sticky = visibleNotCollectList.length > 0;
});
} else if (deltaY < 0) {
sp.visibleRows
.filter((vr) => !vr.folder && vr.parentRowEl && vr.parentRowEl.expansion && !vr.collect)
.forEach((vr) => (vr.parentRowEl!.sticky = true));
} else {
return;
}
}