1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import { JsCpuProfilerChartFrame } from '../bean/JsStruct.js'; 16import { SnapshotStruct } from '../database/ui-worker/ProcedureWorkerSnapshot.js'; 17import { RangeSelectStruct, TraceRow } from './trace/base/TraceRow.js'; 18 19export function setSelectState( 20 data: JsCpuProfilerChartFrame, 21 frameSelectDataIdArr: Array<number>, 22 parent?: JsCpuProfilerChartFrame 23) { 24 if (TraceRow.rangeSelectObject?.startNS && TraceRow.rangeSelectObject?.endNS) { 25 let startTime = 0; 26 let endTime = 0; 27 if (data.startTime < TraceRow.rangeSelectObject?.startNS) { 28 startTime = TraceRow.rangeSelectObject?.startNS; 29 } else { 30 startTime = data.startTime; 31 } 32 if (data.endTime > TraceRow.rangeSelectObject.endNS) { 33 endTime = TraceRow.rangeSelectObject?.endNS; 34 } else { 35 endTime = data.endTime; 36 } 37 data.totalTime = endTime - startTime; 38 data.selfTime = data.totalTime; 39 if (parent) { 40 parent.selfTime -= data.totalTime; 41 } 42 } 43 44 data.isSelect = true; 45 if (data.children.length > 0) { 46 for (let child of data.children) { 47 if (frameSelectDataIdArr.includes(child.id)) { 48 setSelectState(child, frameSelectDataIdArr, data); 49 } 50 } 51 } 52} 53 54export function intersectData(row:TraceRow<any>) { 55 let isIntersect = (snapshotStruct: SnapshotStruct, rangeSelectStruct: RangeSelectStruct) => 56 Math.max(snapshotStruct.startNs! + snapshotStruct.dur!, rangeSelectStruct!.endNS || 0) - Math.min(snapshotStruct.startNs!, rangeSelectStruct!.startNS || 0) < 57 snapshotStruct.dur! + (rangeSelectStruct!.endNS || 0) - (rangeSelectStruct!.startNS || 0); 58 let intersectData = row.dataList.filter((struct: SnapshotStruct) => { 59 return isIntersect(struct, TraceRow.rangeSelectObject!); 60 }); 61 return intersectData; 62} 63