• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15
16import { CpuFreqLimitsStruct } from '../database/ui-worker/cpu/ProcedureWorkerCpuFreqLimits';
17import { ClockStruct } from '../database/ui-worker/ProcedureWorkerClock';
18import { IrqStruct } from '../database/ui-worker/ProcedureWorkerIrq';
19import { FuncStruct } from '../database/ui-worker/ProcedureWorkerFunc';
20import { FrameDynamicStruct } from '../database/ui-worker/ProcedureWorkerFrameDynamic';
21import { FrameAnimationStruct } from '../database/ui-worker/ProcedureWorkerFrameAnimation';
22import { FrameSpacingStruct } from '../database/ui-worker/ProcedureWorkerFrameSpacing';
23import { JsCpuProfilerChartFrame } from './JsStruct';
24import { LogStruct } from '../database/ui-worker/ProcedureWorkerLog';
25import { HiSysEventStruct } from '../database/ui-worker/ProcedureWorkerHiSysEvent';
26import { RangeSelectStruct, TraceRow } from '../component/trace/base/TraceRow';
27import { info } from '../../log/Log';
28import { SpSystemTrace } from '../component/SpSystemTrace';
29import { intersectData, isExistPidInArray, setSelectState } from '../component/Utils';
30import { TabPaneTaskFrames } from '../component/trace/sheet/task/TabPaneTaskFrames';
31import { JanksStruct } from './JanksStruct';
32import { HeapDataInterface } from '../../js-heap/HeapDataInterface';
33import { LitTabs } from '../../base-ui/tabs/lit-tabs';
34import { TabPaneSummary } from '../component/trace/sheet/ark-ts/TabPaneSummary';
35import { JsCpuProfilerStruct } from '../database/ui-worker/ProcedureWorkerCpuProfiler';
36
37export class SelectionParam {
38  recordStartNs: number = 0;
39  leftNs: number = 0;
40  rightNs: number = 0;
41  hasFps: boolean = false;
42  statisticsSelectData: any = undefined;
43  fileSystemVMData: any = undefined;
44  fileSystemIoData: any = undefined;
45  fileSystemFsData: any = undefined;
46  perfAll: boolean = false;
47  fileSysVirtualMemory: boolean = false;
48  diskIOLatency: boolean = false;
49  fsCount: number = 0;
50  vmCount: number = 0;
51  isCurrentPane: boolean = false;
52  startup: boolean = false;
53  staticInit: boolean = false;
54  isRowClick: boolean = false;
55  eventTypeId: string = '';
56  cpus: Array<number> = [];
57  cpuStateRowsId: Array<object> = [];
58  //新增框选cpu freq row名
59  cpuFreqFilterNames: Array<string> = [];
60  cpuStateFilterIds: Array<number> = [];
61  cpuFreqFilterIds: Array<number> = [];
62  threadIds: Array<number> = [];
63  processIds: Array<number> = [];
64  processTrackIds: Array<number> = [];
65  virtualTrackIds: Array<number> = [];
66  cpuFreqLimit: Array<any> = [];
67  clockMapData: Map<string, ((arg: any) => Promise<Array<any>> | undefined) | undefined> = new Map<
68    string,
69    ((arg: any) => Promise<Array<any>> | undefined) | undefined
70  >();
71  irqCallIds: Array<number> = [];
72  softIrqCallIds: Array<number> = [];
73  funTids: Array<number> = [];
74  funAsync: Array<{ name: string; pid: number }> = [];
75  nativeMemory: Array<String> = [];
76  nativeMemoryStatistic: Array<String> = [];
77  nativeMemoryAllProcess: Array<{ pid: number; ipid: number }> = [];
78  nativeMemoryCurrentIPid: number = -1;
79  cpuAbilityIds: Array<string> = [];
80  memoryAbilityIds: Array<string> = [];
81  diskAbilityIds: Array<string> = [];
82  networkAbilityIds: Array<string> = [];
83  perfSampleIds: Array<number> = [];
84  perfEventTypeId?: number;
85  perfCpus: Array<number> = [];
86  perfProcess: Array<number> = [];
87  perfThread: Array<number> = [];
88  fileSystemType: Array<number> = [];
89  sdkCounterIds: Array<string> = [];
90  sdkSliceIds: Array<string> = [];
91  diskIOipids: Array<number> = [];
92  diskIOReadIds: Array<number> = [];
93  diskIOWriteIds: Array<number> = [];
94  systemEnergy: Array<string> = [];
95  powerEnergy: Array<string> = [];
96  anomalyEnergy: Array<string> = [];
97  smapsType: Array<string> = [];
98  vmtrackershm: Array<string> = [];
99  promiseList: Array<Promise<any>> = [];
100  jankFramesData: Array<any> = [];
101  jsMemory: Array<any> = [];
102  taskFramesData: Array<FuncStruct> = [];
103  frameDynamic: Array<FrameDynamicStruct> = [];
104  frameAnimation: Array<FrameAnimationStruct> = [];
105  frameSpacing: Array<FrameSpacingStruct> = [];
106  jsCpuProfilerData: Array<JsCpuProfilerChartFrame> = [];
107  gpu: {
108    gl: boolean;
109    graph: boolean;
110    gpuTotal: boolean;
111    gpuWindow: boolean;
112  } = {
113    gl: false,
114    graph: false,
115    gpuWindow: false,
116    gpuTotal: false,
117  };
118  purgeableTotalAbility: Array<any> = [];
119  purgeableTotalVM: Array<any> = [];
120  purgeablePinAbility: Array<any> = [];
121  purgeablePinVM: Array<any> = [];
122  purgeableTotalSelection: Array<any> = [];
123  purgeablePinSelection: Array<any> = [];
124  dmaAbilityData: Array<any> = [];
125  gpuMemoryAbilityData: Array<any> = [];
126  dmaVmTrackerData: Array<any> = [];
127  gpuMemoryTrackerData: Array<any> = [];
128  hiLogs: Array<string> = [];
129  sysAllEventsData: Array<HiSysEventStruct> = [];
130  sysAlllogsData: Array<LogStruct> = [];
131  hiSysEvents: Array<string> = [];
132  pushCpus(it: TraceRow<any>) {
133    if (it.rowType == TraceRow.ROW_TYPE_CPU) {
134      this.cpus.push(parseInt(it.rowId!));
135      info('load CPU traceRow id is : ', it.rowId);
136    }
137  }
138
139  pushCpuStateFilterIds(it: TraceRow<any>) {
140    if (it.rowType == TraceRow.ROW_TYPE_CPU_STATE) {
141      let filterId = parseInt(it.rowId!);
142      if (this.cpuStateFilterIds.indexOf(filterId) == -1) {
143        this.cpuStateFilterIds.push(filterId);
144      }
145    }
146  }
147
148  pushCpuFreqFilter(it: TraceRow<any>) {
149    if (it.rowType == TraceRow.ROW_TYPE_CPU_FREQ) {
150      let filterId = parseInt(it.rowId!);
151      let filterName = it.name!;
152      if (this.cpuFreqFilterIds.indexOf(filterId) == -1) {
153        this.cpuFreqFilterIds.push(filterId);
154      }
155      if (this.cpuFreqFilterNames.indexOf(filterName) == -1) {
156        this.cpuFreqFilterNames.push(filterName);
157      }
158    }
159  }
160
161  pushCpuFreqLimit(it: TraceRow<any>) {
162    if (it.rowType == TraceRow.ROW_TYPE_CPU_FREQ_LIMIT) {
163      this.cpuFreqLimit.push({
164        maxFilterId: it.getAttribute('maxFilterId'),
165        minFilterId: it.getAttribute('minFilterId'),
166        cpu: it.getAttribute('cpu'),
167      });
168    }
169  }
170
171  pushProcess(it: TraceRow<any>, sp: SpSystemTrace) {
172    if (it.rowType == TraceRow.ROW_TYPE_PROCESS) {
173      sp.pushPidToSelection(this, it.rowId!);
174      if (it.getAttribute('hasStartup') === 'true') {
175        this.startup = true;
176      }
177      if (it.getAttribute('hasStaticInit') === 'true') {
178        this.staticInit = true;
179      }
180      let processChildRows: Array<TraceRow<any>> = [
181        ...sp.shadowRoot!.querySelectorAll<TraceRow<any>>(`trace-row[row-parent-id='${it.rowId}']`),
182      ];
183      if (!it.expansion) {
184        processChildRows = [...it.childrenList];
185      }
186      processChildRows.forEach((th) => {
187        th.rangeSelect = true;
188        th.checkType = '2';
189        if (th.rowType == TraceRow.ROW_TYPE_THREAD) {
190          this.threadIds.push(parseInt(th.rowId!));
191        } else if (th.rowType == TraceRow.ROW_TYPE_FUNC) {
192          if (th.asyncFuncName) {
193            this.funAsync.push({
194              name: th.asyncFuncName,
195              pid: th.asyncFuncNamePID || 0,
196            });
197          } else {
198            this.funTids.push(parseInt(th.rowId!));
199          }
200        } else if (th.rowType == TraceRow.ROW_TYPE_MEM) {
201          this.processTrackIds.push(parseInt(th.rowId!));
202        }
203      });
204      info('load process traceRow id is : ', it.rowId);
205    }
206  }
207
208  pushNativeMemory(it: TraceRow<any>, sp: SpSystemTrace) {
209    if (it.rowType == TraceRow.ROW_TYPE_NATIVE_MEMORY) {
210      let memoryRows: Array<TraceRow<any>> = [
211        ...sp.shadowRoot!.querySelectorAll<TraceRow<any>>(`trace-row[row-parent-id='${it.rowId}']`),
212      ];
213      if (!it.expansion) {
214        memoryRows = [...it.childrenList];
215      }
216      const rowKey = it.rowId!.split(' ');
217      const process = {
218        ipid: Number(rowKey[rowKey.length - 1]),
219        pid: Number(rowKey[rowKey.length - 2]),
220      };
221      if (!isExistPidInArray(this.nativeMemoryAllProcess, process.pid)) {
222        this.nativeMemoryAllProcess.push(process);
223      }
224      if (this.nativeMemoryCurrentIPid === -1) {
225        this.nativeMemoryCurrentIPid = process.ipid;
226      }
227      memoryRows.forEach((th) => {
228        th.rangeSelect = true;
229        th.checkType = '2';
230        if (th.getAttribute('heap-type') === 'native_hook_statistic') {
231          this.nativeMemoryStatistic.push(th.rowId!);
232        } else {
233          this.nativeMemory.push(th.rowId!);
234        }
235      });
236      info('load nativeMemory traceRow id is : ', it.rowId);
237    }
238  }
239
240  pushFunc(it: TraceRow<any>, sp: SpSystemTrace) {
241    if (it.rowType == TraceRow.ROW_TYPE_FUNC) {
242      TabPaneTaskFrames.TaskArray = [];
243      sp.pushPidToSelection(this, it.rowParentId!);
244      if (it.asyncFuncName) {
245        this.funAsync.push({
246          name: it.asyncFuncName,
247          pid: it.asyncFuncNamePID || 0,
248        });
249      } else {
250        this.funTids.push(parseInt(it.rowId!));
251      }
252
253      let isIntersect = (filterFunc: FuncStruct, rangeData: RangeSelectStruct) =>
254        Math.max(filterFunc.startTs! + filterFunc.dur!, rangeData!.endNS || 0) -
255          Math.min(filterFunc.startTs!, rangeData!.startNS || 0) <
256          filterFunc.dur! + (rangeData!.endNS || 0) - (rangeData!.startNS || 0) &&
257        filterFunc.funName!.indexOf('H:Task ') >= 0;
258      let taskData = it.dataListCache.filter((taskData: FuncStruct) => {
259        taskData!.tid = parseInt(it.rowId!);
260        return isIntersect(taskData, TraceRow.rangeSelectObject!);
261      });
262      if (taskData.length > 0) {
263        this.taskFramesData.push(...taskData);
264      }
265      info('load func traceRow id is : ', it.rowId);
266    }
267  }
268
269  pushHeap(it: TraceRow<any>, sp: SpSystemTrace) {
270    if (it.rowType == TraceRow.ROW_TYPE_HEAP) {
271      const key = it.rowParentId!.split(' ');
272      const process = {
273        ipid: Number(key[key.length - 1]),
274        pid: Number(key[key.length - 2]),
275      };
276
277      if (!isExistPidInArray(this.nativeMemoryAllProcess, process.pid)) {
278        this.nativeMemoryAllProcess.push(process);
279      }
280      if (this.nativeMemoryCurrentIPid === -1) {
281        this.nativeMemoryCurrentIPid = process.ipid;
282      }
283      if (this.nativeMemoryAllProcess)
284        if (it.getAttribute('heap-type') === 'native_hook_statistic') {
285          this.nativeMemoryStatistic.push(it.rowId!);
286        } else {
287          this.nativeMemory.push(it.rowId!);
288        }
289      info('load nativeMemory traceRow id is : ', it.rowId);
290    }
291  }
292
293  pushMonitor(it: TraceRow<any>, sp: SpSystemTrace) {
294    if (it.rowType == TraceRow.ROW_TYPE_MONITOR) {
295      let abilityChildRows: Array<TraceRow<any>> = [
296        ...sp.shadowRoot!.querySelectorAll<TraceRow<any>>(`trace-row[row-parent-id='${it.rowId}']`),
297      ];
298      if (!it.expansion) {
299        abilityChildRows = [...it.childrenList];
300      }
301      abilityChildRows.forEach((th) => {
302        th.rangeSelect = true;
303        th.checkType = '2';
304        if (th.rowType == TraceRow.ROW_TYPE_CPU_ABILITY) {
305          this.cpuAbilityIds.push(th.rowId!);
306        } else if (th.rowType == TraceRow.ROW_TYPE_MEMORY_ABILITY) {
307          this.memoryAbilityIds.push(th.rowId!);
308        } else if (th.rowType == TraceRow.ROW_TYPE_DISK_ABILITY) {
309          this.diskAbilityIds.push(th.rowId!);
310        } else if (th.rowType == TraceRow.ROW_TYPE_NETWORK_ABILITY) {
311          this.networkAbilityIds.push(th.rowId!);
312        } else if (th.rowType == TraceRow.ROW_TYPE_DMA_ABILITY) {
313          this.dmaAbilityData.push(...intersectData(th)!);
314        } else if (th.rowType == TraceRow.ROW_TYPE_GPU_MEMORY_ABILITY) {
315          this.gpuMemoryAbilityData.push(...intersectData(th)!);
316        } else if (th.rowType === TraceRow.ROW_TYPE_PURGEABLE_TOTAL_ABILITY) {
317          this.purgeableTotalAbility.push(...intersectData(th));
318        } else if (th.rowType === TraceRow.ROW_TYPE_PURGEABLE_PIN_ABILITY) {
319          this.purgeablePinAbility.push(...intersectData(th));
320        }
321      });
322    }
323  }
324
325  pushHiperf(it: TraceRow<any>, sp: SpSystemTrace) {
326    if (it.rowType?.startsWith('hiperf')) {
327      if (it.rowType == TraceRow.ROW_TYPE_HIPERF_EVENT || it.rowType == TraceRow.ROW_TYPE_HIPERF_REPORT) {
328        return;
329      }
330      this.perfEventTypeId = it.drawType === -2 ? undefined : it.drawType;
331      this.perfSampleIds.push(1);
332      if (it.rowType === TraceRow.ROW_TYPE_PERF_CALLCHART) {
333        let setting = it.getRowSettingKeys();
334        if (setting && setting.length > 0) {
335          //type 0:cpu,1:process,2:thread
336          let key: string = setting[0];
337          let id = Number(key.split('-')[0]);
338          if (key.includes('p')) {
339            this.perfProcess.push(id);
340          } else if (key.includes('t')) {
341            this.perfThread.push(id);
342          } else {
343            this.perfCpus.push(id);
344          }
345        }
346      }
347      if (it.rowType == TraceRow.ROW_TYPE_HIPERF_PROCESS) {
348        let hiperfProcessRows: Array<TraceRow<any>> = [
349          ...sp.shadowRoot!.querySelectorAll<TraceRow<any>>(`trace-row[row-parent-id='${it.rowId}']`),
350        ];
351        if (!it.expansion) {
352          hiperfProcessRows = [...it.childrenList];
353        }
354        hiperfProcessRows.forEach((th) => {
355          th.rangeSelect = true;
356          th.checkType = '2';
357        });
358      }
359      if (it.rowType == TraceRow.ROW_TYPE_HIPERF || it.rowId == 'HiPerf-cpu-merge') {
360        this.perfAll = true;
361      }
362      if (it.rowType == TraceRow.ROW_TYPE_HIPERF_CPU) {
363        this.perfCpus.push(it.index);
364      }
365      if (it.rowType == TraceRow.ROW_TYPE_HIPERF_PROCESS) {
366        this.perfProcess.push(parseInt(it.rowId!.split('-')[0]));
367      }
368      if (it.rowType == TraceRow.ROW_TYPE_HIPERF_THREAD) {
369        this.perfThread.push(parseInt(it.rowId!.split('-')[0]));
370      }
371    }
372  }
373
374  pushFileSystem(it: TraceRow<any>, sp: SpSystemTrace) {
375    if (it.rowType == TraceRow.ROW_TYPE_FILE_SYSTEM) {
376      if (it.rowId == 'FileSystemLogicalWrite') {
377        if (this.fileSystemType.length == 0) {
378          this.fileSystemType = [0, 1, 3];
379        } else {
380          if (this.fileSystemType.indexOf(3) == -1) {
381            this.fileSystemType.push(3);
382          }
383        }
384      } else if (it.rowId == 'FileSystemLogicalRead') {
385        if (this.fileSystemType.length == 0) {
386          this.fileSystemType = [0, 1, 2];
387        } else {
388          if (this.fileSystemType.indexOf(2) == -1) {
389            this.fileSystemType.push(2);
390          }
391        }
392      } else if (it.rowId == 'FileSystemVirtualMemory') {
393        this.fileSysVirtualMemory = true;
394      } else if (it.rowId == 'FileSystemDiskIOLatency') {
395        this.diskIOLatency = true;
396      } else {
397        if (!this.diskIOLatency) {
398          let arr = it.rowId!.split('-').reverse();
399          let ipid = parseInt(arr[0]);
400          if (this.diskIOipids.indexOf(ipid) == -1) {
401            this.diskIOipids.push(ipid);
402          }
403          if (arr[1] == 'read') {
404            this.diskIOReadIds.indexOf(ipid) == -1 ? this.diskIOReadIds.push(ipid) : '';
405          } else if (arr[1] == 'write') {
406            this.diskIOWriteIds.indexOf(ipid) == -1 ? this.diskIOWriteIds.push(ipid) : '';
407          }
408        }
409      }
410    }
411  }
412  vMTrackerGpuChildRowsEvery(item: TraceRow<any>) {
413    item.rangeSelect = true;
414    if (item.rowType == TraceRow.ROW_TYPE_GPU_MEMORY_VMTRACKER) {
415      this.gpuMemoryTrackerData.push(...intersectData(item)!);
416    } else if (item.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_GL) {
417      this.gpu.gl =
418        item.dataListCache.filter(
419          (it) =>
420            (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
421            (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
422        ).length > 0;
423    } else if (item.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_GRAPH) {
424      this.gpu.graph =
425        item.dataListCache.filter(
426          (it) =>
427            (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
428            (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
429        ).length > 0;
430    } else if (item.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_TOTAL) {
431      this.gpu.gpuTotal =
432        item.dataListCache.filter(
433          (it) =>
434            (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
435            (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
436        ).length > 0;
437    } else if (item.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_WINDOW) {
438      this.gpu.gpuWindow =
439        item.dataListCache.filter(
440          (it) =>
441            (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
442            (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
443        ).length > 0;
444    }
445  }
446  pushVmTracker(it: TraceRow<any>, sp: SpSystemTrace) {
447    if (it.rowType === TraceRow.ROW_TYPE_VM_TRACKER) {
448      let vMTrackerChildRows: Array<TraceRow<any>> = [
449        ...sp.shadowRoot!.querySelectorAll<TraceRow<any>>(`trace-row[row-parent-id='${it.rowId}']`),
450      ];
451      if (!it.expansion) {
452        vMTrackerChildRows = [...it.childrenList];
453      }
454      vMTrackerChildRows.forEach((th) => {
455        th.rangeSelect = true;
456        if (th.rowType === TraceRow.ROW_TYPE_DMA_VMTRACKER) {
457          this.dmaVmTrackerData.push(...intersectData(th)!);
458        } else if (th.rowType === TraceRow.ROW_TYPE_SYS_MEMORY_GPU) {
459          let vMTrackerGpuChildRows: Array<TraceRow<any>> = [
460            ...sp.shadowRoot!.querySelectorAll<TraceRow<any>>(`trace-row[row-parent-id='${th.rowId}']`),
461          ];
462          if (!th.expansion) {
463            vMTrackerGpuChildRows = [...th.childrenList];
464          }
465          vMTrackerGpuChildRows.forEach((item) => {
466            this.vMTrackerGpuChildRowsEvery(item);
467          });
468        } else if (th.rowType === TraceRow.ROW_TYPE_PURGEABLE_TOTAL_VM) {
469          this.purgeableTotalVM.push(...intersectData(th));
470        } else if (th.rowType === TraceRow.ROW_TYPE_PURGEABLE_PIN_VM) {
471          this.purgeablePinVM.push(...intersectData(th));
472        } else if (th.rowType === TraceRow.ROW_TYPE_VM_TRACKER_SMAPS) {
473          let sMapsChildRows: Array<TraceRow<any>> = [
474            ...sp.shadowRoot!.querySelectorAll<TraceRow<any>>(`trace-row[row-parent-id='${th.rowId}']`),
475          ];
476          if (!th.expansion) {
477            sMapsChildRows = [...th.childrenList];
478          }
479          sMapsChildRows.forEach((item) => {
480            item.rangeSelect = true;
481            if (item.rowType == TraceRow.ROW_TYPE_VM_TRACKER_SMAPS) {
482              this.smapsType.push(...intersectData(item)!);
483            }
484          });
485        } else if (th.rowType == TraceRow.ROW_TYPE_VMTRACKER_SHM) {
486          this.vmtrackershm.push(...intersectData(th)!);
487        }
488      });
489    }
490  }
491
492  pushJank(it: TraceRow<any>, sp: SpSystemTrace) {
493    if (it.rowType == TraceRow.ROW_TYPE_JANK) {
494      let isIntersect = (filterJank: JanksStruct, rangeData: RangeSelectStruct) =>
495        Math.max(filterJank.ts! + filterJank.dur!, rangeData!.endNS || 0) -
496          Math.min(filterJank.ts!, rangeData!.startNS || 0) <
497        filterJank.dur! + (rangeData!.endNS || 0) - (rangeData!.startNS || 0);
498      if (it.name == 'Actual Timeline') {
499        if (it.rowParentId === 'frameTime') {
500          it.dataListCache.forEach((jankData: any) => {
501            if (isIntersect(jankData, TraceRow.rangeSelectObject!)) {
502              this.jankFramesData.push(jankData);
503            }
504          });
505        } else {
506          this.jankFramesData.push(it.rowParentId);
507        }
508      } else if (it.folder) {
509        this.jankFramesData = [];
510        it.childrenList.forEach((child) => {
511          if (child.rowType == TraceRow.ROW_TYPE_JANK && child.name == 'Actual Timeline') {
512            if (it.rowParentId === 'frameTime') {
513              it.dataListCache.forEach((jankData: any) => {
514                if (isIntersect(jankData, TraceRow.rangeSelectObject!)) {
515                  this.jankFramesData.push(jankData);
516                }
517              });
518            } else {
519              this.jankFramesData.push(child.rowParentId);
520            }
521          }
522        });
523      }
524    }
525  }
526
527  pushHeapTimeline(it: TraceRow<any>, sp: SpSystemTrace) {
528    if (it.rowType == TraceRow.ROW_TYPE_HEAP_TIMELINE) {
529      const [rangeStart, rangeEnd] = [TraceRow.range?.startNS, TraceRow.range?.endNS];
530      const endNS = TraceRow.rangeSelectObject?.endNS || rangeStart;
531      const startNS = TraceRow.rangeSelectObject?.startNS || rangeEnd;
532      let minNodeId, maxNodeId;
533      if (!it.dataListCache || it.dataListCache.length === 0) {
534        return;
535      }
536      for (let sample of it.dataListCache) {
537        if (sample.timestamp * 1000 <= startNS!) {
538          minNodeId = sample.lastAssignedId;
539        }
540        // 个别文件的sample的最大timestamp小于时间的框选结束时间,不能给maxNodeId赋值
541        // 所以加上此条件:sample.timestamp === it.dataListCache[it.dataListCache.length -1].timestamp
542        if (
543          sample.timestamp * 1000 >= endNS! ||
544          sample.timestamp === it.dataListCache[it.dataListCache.length - 1].timestamp
545        ) {
546          if (maxNodeId === undefined) {
547            maxNodeId = sample.lastAssignedId;
548          }
549        }
550      }
551
552      // If the start time range of the selected box is greater than the end time of the sampled data
553      if (startNS! >= it.dataListCache[it.dataListCache.length - 1].timestamp * 1000) {
554        minNodeId = it.dataListCache[it.dataListCache.length - 1].lastAssignedId;
555      }
556      // If you select the box from the beginning
557      if (startNS! <= rangeStart!) {
558        minNodeId = HeapDataInterface.getInstance().getMinNodeId(sp.snapshotFiles!.id);
559      }
560      //If you select the box from the ending
561      if (endNS! >= rangeEnd! || endNS! >= it.dataListCache[it.dataListCache.length - 1].timestampUs * 1000) {
562        maxNodeId = HeapDataInterface.getInstance().getMaxNodeId(sp.snapshotFiles!.id);
563      }
564      let summary = (sp.traceSheetEL!.shadowRoot!.querySelector('#tabs') as LitTabs)
565        .querySelector('#box-heap-summary')
566        ?.querySelector('tabpane-summary') as TabPaneSummary;
567      summary.initSummaryData(sp.snapshotFiles!, minNodeId, maxNodeId);
568      this.jsMemory.push(1);
569    }
570  }
571
572  pushJsCpuProfiler(it: TraceRow<any>, sp: SpSystemTrace) {
573    if (it.rowType == TraceRow.ROW_TYPE_JS_CPU_PROFILER) {
574      let isIntersect = (a: JsCpuProfilerStruct, b: RangeSelectStruct) =>
575        Math.max(a.startTime! + a.totalTime!, b!.endNS || 0) - Math.min(a.startTime!, b!.startNS || 0) <
576        a.totalTime! + (b!.endNS || 0) - (b!.startNS || 0);
577      let frameSelectData = it.dataListCache.filter((frameSelectData: any) => {
578        return isIntersect(frameSelectData, TraceRow.rangeSelectObject!);
579      });
580      let copyFrameSelectData = JSON.parse(JSON.stringify(frameSelectData));
581      let frameSelectDataIdArr: Array<number> = [];
582      for (let data of copyFrameSelectData) {
583        frameSelectDataIdArr.push(data.id);
584      }
585      let jsCpuProfilerData = copyFrameSelectData.filter((item: any) => {
586        if (item.depth === 0) {
587          setSelectState(item, frameSelectDataIdArr);
588          item.isSelect = true;
589          return item;
590        }
591      });
592      this.jsCpuProfilerData = jsCpuProfilerData;
593    }
594  }
595
596  pushSysMemoryGpu(it: TraceRow<any>, sp: SpSystemTrace) {
597    if (it.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU) {
598      let vMTrackerGpuChildRows: Array<TraceRow<any>> = [
599        ...sp.shadowRoot!.querySelectorAll<TraceRow<any>>(`trace-row[row-parent-id='${it.rowId}']`),
600      ];
601      if (!it.expansion) {
602        vMTrackerGpuChildRows = [...it.childrenList];
603      }
604      vMTrackerGpuChildRows.forEach((th) => {
605        th.rangeSelect = true;
606        if (th.rowType == TraceRow.ROW_TYPE_GPU_MEMORY_VMTRACKER) {
607          this.gpuMemoryTrackerData.push(...intersectData(th)!);
608        } else if (th.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_GL) {
609          this.gpu.gl =
610            th.dataListCache.filter(
611              (it) =>
612                (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
613                (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
614            ).length > 0;
615        } else if (th.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_GRAPH) {
616          this.gpu.graph =
617            th.dataListCache.filter(
618              (it) =>
619                (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
620                (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
621            ).length > 0;
622        } else if (th.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_TOTAL) {
623          this.gpu.gpuTotal =
624            th.dataListCache.filter(
625              (it) =>
626                (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
627                (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
628            ).length > 0;
629        } else if (th.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_WINDOW) {
630          this.gpu.gpuWindow =
631            th.dataListCache.filter(
632              (it) =>
633                (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
634                (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
635            ).length > 0;
636        }
637      });
638    }
639  }
640
641  pushSDK(it: TraceRow<any>, sp: SpSystemTrace) {
642    if (it.rowType?.startsWith(TraceRow.ROW_TYPE_SDK)) {
643      if (it.rowType == TraceRow.ROW_TYPE_SDK) {
644        let sdkRows: Array<TraceRow<any>> = [
645          ...sp.shadowRoot!.querySelectorAll<TraceRow<any>>(`trace-row[row-parent-id='${it.rowId}']`),
646        ];
647        if (!it.expansion) {
648          sdkRows = [...it.childrenList];
649        }
650        sdkRows.forEach((th) => {
651          th.rangeSelect = true;
652          th.checkType = '2';
653        });
654      }
655      if (it.rowType == TraceRow.ROW_TYPE_SDK_COUNTER) {
656        this.sdkCounterIds.push(it.rowId!);
657      }
658      if (it.rowType == TraceRow.ROW_TYPE_SDK_SLICE) {
659        this.sdkSliceIds.push(it.rowId!);
660      }
661    }
662  }
663
664  pushVmTrackerSmaps(it: TraceRow<any>, sp: SpSystemTrace) {
665    if (it.rowType == TraceRow.ROW_TYPE_VM_TRACKER_SMAPS) {
666      this.smapsType.push(...intersectData(it)!);
667      let sMapsChildRows: Array<TraceRow<any>> = [
668        ...sp.shadowRoot!.querySelectorAll<TraceRow<any>>(`trace-row[row-parent-id='${it.rowId}']`),
669      ];
670      if (!it.expansion) {
671        sMapsChildRows = [...it.childrenList];
672      }
673      sMapsChildRows.forEach((item) => {
674        item.rangeSelect = true;
675        if (item.rowType == TraceRow.ROW_TYPE_VM_TRACKER_SMAPS) {
676          this.smapsType.push(...intersectData(item)!);
677        }
678      });
679    }
680  }
681
682  pushIrq(it: TraceRow<any>, sp: SpSystemTrace) {
683    if (it.rowType == TraceRow.ROW_TYPE_IRQ) {
684      if (it.getAttribute('cat') === 'irq') {
685        this.irqCallIds.push(parseInt(it.getAttribute('callId') || '-1'));
686      } else {
687        this.softIrqCallIds.push(parseInt(it.getAttribute('callId') || '-1'));
688      }
689    }
690  }
691
692  pushSysMemoryGpuGl(it: TraceRow<any>, sp: SpSystemTrace) {
693    if (it.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_GL) {
694      this.gpu.gl =
695        it.dataListCache.filter(
696          (it) =>
697            (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
698            (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
699        ).length > 0;
700    }
701  }
702
703  pushFrameDynamic(it: TraceRow<any>, sp: SpSystemTrace) {
704    if (it.rowType == TraceRow.ROW_TYPE_FRAME_DYNAMIC) {
705      let appName = it.getAttribute('model-name');
706      let isSelect = (dynamicStruct: FrameDynamicStruct, b: RangeSelectStruct) =>
707        dynamicStruct.ts >= b.startNS! && dynamicStruct.ts <= b.endNS!;
708      let frameDynamicList = it.dataListCache.filter(
709        (frameAnimationBean: FrameDynamicStruct) =>
710          isSelect(frameAnimationBean, TraceRow.rangeSelectObject!) &&
711          frameAnimationBean.groupId !== -1 &&
712          frameAnimationBean.appName === appName
713      );
714      this.frameDynamic.push(...frameDynamicList);
715    }
716  }
717
718  pushFrameSpacing(it: TraceRow<any>) {
719    if (it.rowType == TraceRow.ROW_TYPE_FRAME_SPACING) {
720      let appName = it.getAttribute('model-name');
721      let isSelect = (a: FrameSpacingStruct, b: RangeSelectStruct) =>
722        a.currentTs >= b.startNS! && a.currentTs <= b.endNS!;
723      let frameDatas = it.dataListCache.filter((frameData: FrameSpacingStruct) => {
724        return (
725          isSelect(frameData, TraceRow.rangeSelectObject!) &&
726          frameData.groupId !== -1 &&
727          frameData.frameSpacingResult !== -1 &&
728          frameData.nameId === appName
729        );
730      });
731      this.frameSpacing.push(...frameDatas);
732    }
733  }
734
735  pushFrameAnimation(it: TraceRow<any>) {
736    if (it.rowType == TraceRow.ROW_TYPE_FRAME_ANIMATION) {
737      let isIntersect = (animationStruct: FrameAnimationStruct, selectStruct: RangeSelectStruct) =>
738        Math.max(animationStruct.startTs! + animationStruct.dur!, selectStruct!.endNS || 0) -
739          Math.min(animationStruct.startTs!, selectStruct!.startNS || 0) <
740        animationStruct.dur! + (selectStruct!.endNS || 0) - (selectStruct!.startNS || 0);
741      let frameAnimationList = it.dataListCache.filter((frameAnimationBean: FrameAnimationStruct) => {
742        return isIntersect(frameAnimationBean, TraceRow.rangeSelectObject!);
743      });
744      this.frameAnimation.push(...frameAnimationList);
745    }
746  }
747
748  pushSysMemoryGpuWindow(it: TraceRow<any>) {
749    if (it.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_WINDOW) {
750      this.gpu.gpuWindow =
751        it.dataListCache.filter(
752          (it) =>
753            (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
754            (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
755        ).length > 0;
756    }
757  }
758
759  pushSysMemoryGpuTotal(it: TraceRow<any>) {
760    if (it.rowType == TraceRow.ROW_TYPE_SYS_MEMORY_GPU_TOTAL) {
761      this.gpu.gpuTotal =
762        it.dataListCache.filter(
763          (it) =>
764            (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
765            (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
766        ).length > 0;
767    }
768  }
769
770  pushSysMemoryGpuGraph(it: TraceRow<any>) {
771    if (it.rowType === TraceRow.ROW_TYPE_SYS_MEMORY_GPU_GRAPH) {
772      this.gpu.graph =
773        it.dataListCache.filter(
774          (it) =>
775            (it.startNs >= this.leftNs && it.startNs <= this.rightNs) ||
776            (it.endNs >= this.leftNs && it.endNs <= this.rightNs)
777        ).length > 0;
778    }
779  }
780
781  pushStaticInit(it: TraceRow<any>, sp: SpSystemTrace) {
782    if (it.rowType == TraceRow.ROW_TYPE_STATIC_INIT) {
783      this.staticInit = true;
784      sp.pushPidToSelection(this, it.rowParentId!);
785      info('load thread traceRow id is : ', it.rowId);
786    }
787  }
788
789  pushAppStartUp(it: TraceRow<any>, sp: SpSystemTrace) {
790    if (it.rowType == TraceRow.ROW_TYPE_APP_STARTUP) {
791      this.startup = true;
792      sp.pushPidToSelection(this, it.rowParentId!);
793      info('load thread traceRow id is : ', it.rowId);
794    }
795  }
796
797  pushThread(it: TraceRow<any>, sp: SpSystemTrace) {
798    if (it.rowType == TraceRow.ROW_TYPE_THREAD) {
799      sp.pushPidToSelection(this, it.rowParentId!);
800      this.threadIds.push(parseInt(it.rowId!));
801      info('load thread traceRow id is : ', it.rowId);
802    }
803  }
804
805  pushVirtualMemory(it: TraceRow<any>, sp: SpSystemTrace) {
806    if (it.rowType == TraceRow.ROW_TYPE_MEM || it.rowType == TraceRow.ROW_TYPE_VIRTUAL_MEMORY) {
807      if (it.rowType == TraceRow.ROW_TYPE_MEM) {
808        this.processTrackIds.push(parseInt(it.rowId!));
809      } else {
810        this.virtualTrackIds.push(parseInt(it.rowId!));
811      }
812      info('load memory traceRow id is : ', it.rowId);
813    }
814  }
815
816  pushFps(it: TraceRow<any>, sp: SpSystemTrace) {
817    if (it.rowType == TraceRow.ROW_TYPE_FPS) {
818      this.hasFps = true;
819      info('load FPS traceRow id is : ', it.rowId);
820    }
821  }
822
823  pushCpuAbility(it: TraceRow<any>, sp: SpSystemTrace) {
824    if (it.rowType == TraceRow.ROW_TYPE_CPU_ABILITY) {
825      this.cpuAbilityIds.push(it.rowId!);
826      info('load CPU Ability traceRow id is : ', it.rowId);
827    }
828  }
829
830  pushMemoryAbility(it: TraceRow<any>, sp: SpSystemTrace) {
831    if (it.rowType == TraceRow.ROW_TYPE_MEMORY_ABILITY) {
832      this.memoryAbilityIds.push(it.rowId!);
833      info('load Memory Ability traceRow id is : ', it.rowId);
834    }
835  }
836
837  pushDiskAbility(it: TraceRow<any>, sp: SpSystemTrace) {
838    if (it.rowType == TraceRow.ROW_TYPE_DISK_ABILITY) {
839      this.diskAbilityIds.push(it.rowId!);
840      info('load DiskIo Ability traceRow id is : ', it.rowId);
841    }
842  }
843
844  pushNetworkAbility(it: TraceRow<any>, sp: SpSystemTrace) {
845    if (it.rowType == TraceRow.ROW_TYPE_NETWORK_ABILITY) {
846      this.networkAbilityIds.push(it.rowId!);
847      info('load Network Ability traceRow id is : ', it.rowId);
848    }
849  }
850
851  pushDmaAbility(it: TraceRow<any>, sp: SpSystemTrace) {
852    if (it.rowType == TraceRow.ROW_TYPE_DMA_ABILITY) {
853      this.dmaAbilityData.push(...intersectData(it)!);
854    }
855  }
856
857  pushGpuMemoryAbility(it: TraceRow<any>, sp: SpSystemTrace) {
858    if (it.rowType == TraceRow.ROW_TYPE_GPU_MEMORY_ABILITY) {
859      this.gpuMemoryAbilityData.push(...intersectData(it)!);
860    }
861  }
862
863  pushPowerEnergy(it: TraceRow<any>, sp: SpSystemTrace) {
864    if (it.rowType == TraceRow.ROW_TYPE_POWER_ENERGY) {
865      this.powerEnergy.push(it.rowId!);
866    }
867  }
868
869  pushSystemEnergy(it: TraceRow<any>, sp: SpSystemTrace) {
870    if (it.rowType == TraceRow.ROW_TYPE_SYSTEM_ENERGY) {
871      this.systemEnergy.push(it.rowId!);
872    }
873  }
874
875  pushAnomalyEnergy(it: TraceRow<any>, sp: SpSystemTrace) {
876    if (it.rowType == TraceRow.ROW_TYPE_ANOMALY_ENERGY) {
877      this.anomalyEnergy.push(it.rowId!);
878    }
879  }
880
881  pushVmTrackerShm(it: TraceRow<any>, sp: SpSystemTrace) {
882    if (it.rowType == TraceRow.ROW_TYPE_VMTRACKER_SHM) {
883      this.vmtrackershm.push(...intersectData(it)!);
884    }
885  }
886
887  pushClock(it: TraceRow<any>, sp: SpSystemTrace) {
888    if (it.rowType == TraceRow.ROW_TYPE_CLOCK) {
889      this.clockMapData.set(it.rowId || '', it.getCacheData);
890    }
891  }
892
893  pushGpuMemoryVmTracker(it: TraceRow<any>, sp: SpSystemTrace) {
894    if (it.rowType == TraceRow.ROW_TYPE_GPU_MEMORY_VMTRACKER) {
895      this.gpuMemoryTrackerData.push(...intersectData(it)!);
896    }
897  }
898
899  pushDmaVmTracker(it: TraceRow<any>, sp: SpSystemTrace) {
900    if (it.rowType == TraceRow.ROW_TYPE_DMA_VMTRACKER) {
901      this.dmaVmTrackerData.push(...intersectData(it)!);
902    }
903  }
904
905  pushPugreable(it: TraceRow<any>, sp: SpSystemTrace) {
906    if (it.rowType == TraceRow.ROW_TYPE_PURGEABLE_TOTAL_ABILITY) {
907      this.purgeableTotalAbility.push(...intersectData(it));
908    }
909    if (it.rowType == TraceRow.ROW_TYPE_PURGEABLE_PIN_ABILITY) {
910      this.purgeablePinAbility.push(...intersectData(it));
911    }
912    if (it.rowType == TraceRow.ROW_TYPE_PURGEABLE_TOTAL_VM) {
913      this.purgeableTotalVM.push(...intersectData(it));
914    }
915    if (it.rowType == TraceRow.ROW_TYPE_PURGEABLE_PIN_VM) {
916      this.purgeablePinVM.push(...intersectData(it));
917    }
918  }
919
920  pushPugreablePinAbility(it: TraceRow<any>, sp: SpSystemTrace) {
921    if (it.rowType == TraceRow.ROW_TYPE_PURGEABLE_PIN_ABILITY) {
922      this.purgeablePinAbility.push(...intersectData(it));
923    }
924  }
925
926  pushPugreableTotalVm(it: TraceRow<any>, sp: SpSystemTrace) {
927    if (it.rowType == TraceRow.ROW_TYPE_PURGEABLE_TOTAL_VM) {
928      this.purgeableTotalVM.push(...intersectData(it));
929    }
930  }
931
932  pushPugreablePinVm(it: TraceRow<any>, sp: SpSystemTrace) {
933    if (it.rowType == TraceRow.ROW_TYPE_PURGEABLE_PIN_VM) {
934      this.purgeablePinVM.push(...intersectData(it));
935    }
936  }
937
938  pushLogs(it: TraceRow<any>, sp: SpSystemTrace) {
939    if (it.rowType === TraceRow.ROW_TYPE_LOGS) {
940      this.hiLogs.push(it.rowId!);
941    }
942  }
943
944  pushHiSysEvent(it: TraceRow<any>, sp: SpSystemTrace) {
945    if (it.rowType === TraceRow.ROW_TYPE_HI_SYSEVENT) {
946      this.hiSysEvents.push(it.rowId!);
947    }
948  }
949
950  pushSelection(it: TraceRow<any>, sp: SpSystemTrace) {
951    this.pushCpus(it);
952    this.pushCpuStateFilterIds(it);
953    this.pushCpuFreqFilter(it);
954    this.pushCpuFreqLimit(it);
955    this.pushProcess(it, sp);
956    this.pushNativeMemory(it, sp);
957    this.pushFunc(it, sp);
958    this.pushHeap(it, sp);
959    this.pushMonitor(it, sp);
960    this.pushHiperf(it, sp);
961    this.pushFileSystem(it, sp);
962    this.pushJank(it, sp);
963    this.pushHeapTimeline(it, sp);
964    this.pushJsCpuProfiler(it, sp);
965    this.pushSysMemoryGpu(it, sp);
966    this.pushSDK(it, sp);
967    this.pushVmTrackerSmaps(it, sp);
968    this.pushIrq(it, sp);
969    this.pushSysMemoryGpuGl(it, sp);
970    this.pushFrameDynamic(it, sp);
971    this.pushFrameSpacing(it);
972    this.pushFrameAnimation(it);
973    this.pushSysMemoryGpuWindow(it);
974    this.pushSysMemoryGpuTotal(it);
975    this.pushSysMemoryGpuGraph(it);
976    this.pushStaticInit(it, sp);
977    this.pushAppStartUp(it, sp);
978    this.pushThread(it, sp);
979    this.pushVirtualMemory(it, sp);
980    this.pushFps(it, sp);
981    this.pushCpuAbility(it, sp);
982    this.pushMemoryAbility(it, sp);
983    this.pushDiskAbility(it, sp);
984    this.pushNetworkAbility(it, sp);
985    this.pushDmaAbility(it, sp);
986    this.pushGpuMemoryAbility(it, sp);
987    this.pushPowerEnergy(it, sp);
988    this.pushSystemEnergy(it, sp);
989    this.pushAnomalyEnergy(it, sp);
990    this.pushVmTracker(it, sp);
991    this.pushVmTrackerShm(it, sp);
992    this.pushClock(it, sp);
993    this.pushGpuMemoryVmTracker(it, sp);
994    this.pushDmaVmTracker(it, sp);
995    this.pushPugreable(it, sp);
996    this.pushLogs(it, sp);
997    this.pushHiSysEvent(it, sp);
998  }
999}
1000
1001export class BoxJumpParam {
1002  leftNs: number = 0;
1003  rightNs: number = 0;
1004  cpus: Array<number> = [];
1005  state: string = '';
1006  processId: number = 0;
1007  threadId: number = 0;
1008}
1009
1010export class SelectionData {
1011  name: string = '';
1012  process: string = '';
1013  pid: string = '';
1014  thread: string = '';
1015  tid: string = '';
1016  wallDuration: number = 0;
1017  wallDurationFormat: string = '';
1018  avgDuration: string = '';
1019  maxDuration: number = 0;
1020  maxDurationFormat: string = '';
1021  occurrences: number = 0;
1022  state: string = '';
1023  trackId: number = 0;
1024  delta: string = '';
1025  rate: string = '';
1026  avgWeight: string = '';
1027  count: string = '';
1028  first: string = '';
1029  last: string = '';
1030  min: string = '';
1031  max: string = '';
1032  stateJX: string = '';
1033  cpu: number = 0;
1034  recordStartNs: number = 0;
1035  leftNs: number = 0;
1036  rightNs: number = 0;
1037  threadIds: Array<number> = [];
1038  ts: number = 0;
1039  dur: number = 0;
1040}
1041
1042export class Counter {
1043  id: number = 0;
1044  trackId: number = 0;
1045  name: string = '';
1046  value: number = 0;
1047  startTime: number = 0;
1048}
1049
1050export class Fps {
1051  startNS: number = 0;
1052  timeStr: string = '';
1053  fps: number = 0;
1054}
1055