• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2/*
3 * Copyright (C) 2022 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { type SpSystemTrace } from '../SpSystemTrace';
17import { TraceRow } from '../trace/base/TraceRow';
18import { renders } from '../../database/ui-worker/ProcedureWorker';
19import { type EmptyRender } from '../../database/ui-worker/cpu/ProcedureWorkerCPU';
20import { type FreqExtendRender, CpuFreqExtendStruct } from '../../database/ui-worker/ProcedureWorkerFreqExtend';
21import { type BinderRender, BinderStruct } from '../../database/ui-worker/procedureWorkerBinder';
22import { type BaseStruct } from '../../bean/BaseStruct';
23import { type AllStatesRender, AllstatesStruct } from '../../database/ui-worker/ProcedureWorkerAllStates';
24import { StateGroup } from '../../bean/StateModle';
25import { queryAllFuncNames } from '../../database/sql/Func.sql';
26import { Utils } from '../trace/base/Utils';
27import { TabPaneFreqUsage } from '../trace/sheet/frequsage/TabPaneFreqUsage';
28const UNIT_HEIGHT: number = 20;
29const MS_TO_US: number = 1000000;
30const MIN_HEIGHT: number = 2;
31export class SpSegmentationChart {
32  static trace: SpSystemTrace;
33  static cpuRow: TraceRow<CpuFreqExtendStruct> | undefined;
34  static GpuRow: TraceRow<CpuFreqExtendStruct> | undefined;
35  static binderRow: TraceRow<BinderStruct> | undefined;
36  static schedRow: TraceRow<CpuFreqExtendStruct> | undefined;
37  static freqInfoMapData = new Map<number, unknown>();
38  static hoverLine: Array<HeightLine> = [];
39  static tabHoverObj: { key: string, cycle: number };
40  private rowFolder!: TraceRow<BaseStruct>;
41  static chartData: Array<Object> = [];
42  static statesRow: TraceRow<AllstatesStruct> | undefined;
43  // 数据切割联动
44  static setChartData(type: string, data: Array<FreqChartDataStruct>): void {
45    SpSegmentationChart.tabHoverObj = { key: '', cycle: -1 };
46    if (SpSegmentationChart.trace.traceSheetEL) {
47      SpSegmentationChart.trace.traceSheetEL.systemLogFlag = undefined;
48    }
49    if (type === 'CPU-FREQ') {
50      setCpuData(data);
51    } else if (type === 'GPU-FREQ') {
52      setGpuData(data);
53    } else {
54      setSchedData(data);
55    }
56    SpSegmentationChart.trace.refreshCanvas(false);
57  }
58
59  // state泳道联动
60  static setStateChartData(data: Array<StateGroup>) {
61    SpSegmentationChart.tabHoverObj = { key: '', cycle: -1 };
62    SpSegmentationChart.trace.traceSheetEL!.systemLogFlag = undefined;
63    let stateChartData = new Array();
64    stateChartData = data.map(v => {
65      return {
66        dur: v.dur,
67        chartDur: v.chartDur,
68        pid: v.pid,
69        tid: v.tid,
70        end_ts: v.startTs! + v.chartDur!,
71        id: v.id,
72        name: 'all-state',
73        startTime: v.startTs,
74        start_ts: v.startTs,
75        state: v.state,
76        type: v.type,
77        cycle: v.cycle,
78      };
79    });
80    SpSegmentationChart.statesRow!.dataList = [];
81    SpSegmentationChart.statesRow!.dataListCache = [];
82    SpSegmentationChart.statesRow!.isComplete = false;
83    // @ts-ignore
84    SpSegmentationChart.statesRow!.supplier = (): Promise<Array<ThreadStruct>> =>
85      new Promise<Array<AllstatesStruct>>((resolve) => resolve(stateChartData));
86    SpSegmentationChart.trace.refreshCanvas(false);
87  };
88
89  // binder联动调用
90  static setBinderChartData(data: Array<Array<FreqChartDataStruct>>): void {
91    SpSegmentationChart.tabHoverObj = { key: '', cycle: -1 };
92    SpSegmentationChart.trace.traceSheetEL!.systemLogFlag = undefined;
93    BinderStruct.maxHeight = 0;
94    SpSegmentationChart.binderRow!.dataList = [];
95    SpSegmentationChart.binderRow!.dataListCache = [];
96    SpSegmentationChart.binderRow!.isComplete = false;
97    if (data.length === 0) {
98      SpSegmentationChart.binderRow!.style.height = `40px`;
99      SpSegmentationChart.binderRow!.funcMaxHeight = 40;
100      // @ts-ignore
101      SpSegmentationChart.binderRow!.supplier = (): Promise<Array<FreqChartDataStruct>> =>
102        new Promise<Array<FreqChartDataStruct>>((resolve) => resolve([]));
103    } else {
104      let binderList: Array<FreqChartDataStruct> = [];
105      let chartData: Array<FreqChartDataStruct> = [];
106      setBinderData(data, binderList);
107      chartData = binderList.map((v: FreqChartDataStruct) => {
108        return {
109          cpu:
110            v.name === 'binder transaction'
111              ? 0
112              : v.name === 'binder transaction async'
113                ? 1
114                : v.name === 'binder reply'
115                  ? MS_TO_US
116                  : 3,
117          startNS: v.startNS,
118          dur: v.dur,
119          name: `${v.name}`,
120          value: v.value,
121          depth: v.depth,
122          cycle: v.cycle,
123        };
124      });
125      // @ts-ignore
126      SpSegmentationChart.binderRow!.supplier = (): Promise<Array<FreqChartDataStruct>> =>
127        new Promise<Array<FreqChartDataStruct>>((resolve) => resolve(chartData));
128      SpSegmentationChart.binderRow!.style.height = `${BinderStruct.maxHeight > MIN_HEIGHT ? BinderStruct.maxHeight * UNIT_HEIGHT + UNIT_HEIGHT : 40}px`;
129      SpSegmentationChart.binderRow!.funcMaxHeight = BinderStruct.maxHeight > MIN_HEIGHT ? BinderStruct.maxHeight * UNIT_HEIGHT + UNIT_HEIGHT : 40;
130    }
131    TraceRow.range && (TraceRow.range.refresh = true);
132    SpSegmentationChart.binderRow!.needRefresh = true;
133    SpSegmentationChart.binderRow!.draw(false);
134    if (SpSegmentationChart.binderRow!.collect) {
135      window.publish(window.SmartEvent.UI.RowHeightChange, {
136        expand: SpSegmentationChart.binderRow!.funcExpand,
137        value: SpSegmentationChart.binderRow!.funcMaxHeight - 40,
138      });
139    }
140    if (SpSegmentationChart.trace.favoriteChartListEL) {
141      SpSegmentationChart.trace.favoriteChartListEL.scrollTo(0, 0);
142    }
143    SpSegmentationChart.trace.refreshCanvas(false);
144  }
145  // 悬浮联动
146  static tabHover(type: string, tableIsHover: boolean = false, cycle: number = -1): void {
147    if (tableIsHover) {
148      if (SpSegmentationChart.tabHoverObj.cycle === cycle && SpSegmentationChart.tabHoverObj.key === type) {
149        SpSegmentationChart.tabHoverObj = { cycle: -1, key: '' };
150      } else {
151        SpSegmentationChart.tabHoverObj = { cycle, key: type };
152      }
153    } else {
154      SpSegmentationChart.tabHoverObj = { cycle: -1, key: '' };
155    }
156
157    SpSegmentationChart.trace.refreshCanvas(false);
158  }
159  constructor(trace: SpSystemTrace) {
160    SpSegmentationChart.trace = trace;
161  }
162  async init() {
163    if (Utils.getInstance().getCallStatckMap().size > 0) {
164      await this.initFolder();
165      await this.initCpuFreq();
166      await this.initGpuTrace();
167      await this.initSchedTrace();
168      await this.initBinderTrace();
169      await this.initAllStates();
170    } else {
171      return;
172    }
173  }
174  async initFolder() {
175    let row = TraceRow.skeleton();
176    row.rowId = 'segmentation';
177    row.index = 0;
178    row.rowType = TraceRow.ROW_TYPE_SPSEGNENTATION;
179    row.rowParentId = '';
180    row.folder = true;
181    row.style.height = '40px';
182    row.name = 'Segmentation';
183    row.supplier = (): Promise<Array<BaseStruct>> => new Promise<Array<BaseStruct>>((resolve) => resolve([]));
184    row.onThreadHandler = (useCache): void => {
185      row.canvasSave(SpSegmentationChart.trace.canvasPanelCtx!);
186      if (row.expansion) {
187        SpSegmentationChart.trace.canvasPanelCtx?.clearRect(0, 0, row.frame.width, row.frame.height);
188      } else {
189        (renders['empty'] as EmptyRender).renderMainThread(
190          {
191            context: SpSegmentationChart.trace.canvasPanelCtx,
192            useCache: useCache,
193            type: '',
194          },
195          row
196        );
197      }
198      row.canvasRestore(SpSegmentationChart.trace.canvasPanelCtx!);
199    };
200    this.rowFolder = row;
201    SpSegmentationChart.trace.rowsEL?.appendChild(row);
202  }
203  async initCpuFreq() {
204    // json文件泳道
205    SpSegmentationChart.cpuRow = TraceRow.skeleton<CpuFreqExtendStruct>();
206    SpSegmentationChart.cpuRow.rowId = 'cpu-freq';
207    SpSegmentationChart.cpuRow.rowType = TraceRow.ROW_TYPE_CPU_COMPUTILITY;
208    SpSegmentationChart.cpuRow.rowParentId = '';
209    SpSegmentationChart.cpuRow.style.height = '40px';
210    SpSegmentationChart.cpuRow.name = 'Cpu Computility';
211    SpSegmentationChart.cpuRow.favoriteChangeHandler = SpSegmentationChart.trace.favoriteChangeHandler;
212    SpSegmentationChart.cpuRow.addRowCheckFilePop();
213    SpSegmentationChart.cpuRow.rowSetting = 'checkFile';
214    // 拿到了用户传递的数据
215    SpSegmentationChart.cpuRow.onRowCheckFileChangeHandler = (): void => {
216      SpSegmentationChart.freqInfoMapData = new Map<number, unknown>();
217      if (sessionStorage.getItem('freqInfoData')) {
218        // @ts-ignore
219        let chartData = JSON.parse(JSON.parse(sessionStorage.getItem('freqInfoData')));
220        let mapData = new Map<number, number>();
221        // @ts-ignore
222        chartData.map((v) => {
223          for (let key in v.freqInfo) {
224            mapData.set(Number(key), Number(v.freqInfo[key]));
225          }
226          SpSegmentationChart.freqInfoMapData.set(v.cpuId, { 'broId': v.broId, 'smtRate': v.smtRate, mapData });
227          mapData = new Map();
228        });
229        TabPaneFreqUsage.refresh();
230      }
231    };
232    SpSegmentationChart.cpuRow.focusHandler = (ev): void => {
233      SpSegmentationChart.trace?.displayTip(
234        SpSegmentationChart.cpuRow!,
235        CpuFreqExtendStruct.hoverStruct,
236        `<span>${CpuFreqExtendStruct.hoverStruct === undefined ? 0 : CpuFreqExtendStruct.hoverStruct.value!
237        }</span>`
238      );
239    };
240    SpSegmentationChart.cpuRow.findHoverStruct = (): void => {
241      CpuFreqExtendStruct.hoverStruct = SpSegmentationChart.cpuRow!.getHoverStruct();
242    };
243    // @ts-ignore
244    SpSegmentationChart.cpuRow.supplier = (): Promise<Array<freqChartDataStruct>> =>
245      new Promise<Array<FreqChartDataStruct>>((resolve) => resolve([]));
246    SpSegmentationChart.cpuRow.onThreadHandler = (useCache): void => {
247      let context: CanvasRenderingContext2D;
248      if (SpSegmentationChart.cpuRow!.currentContext) {
249        context = SpSegmentationChart.cpuRow!.currentContext;
250      } else {
251        context = SpSegmentationChart.cpuRow!.collect
252          ? SpSegmentationChart.trace.canvasFavoritePanelCtx!
253          : SpSegmentationChart.trace.canvasPanelCtx!;
254      }
255      SpSegmentationChart.cpuRow!.canvasSave(context);
256      (renders['freq-extend'] as FreqExtendRender).renderMainThread(
257        {
258          context: context,
259          useCache: useCache,
260          type: 'CPU-FREQ',
261        },
262        SpSegmentationChart.cpuRow!
263      );
264      SpSegmentationChart.cpuRow!.canvasRestore(context);
265    };
266    SpSegmentationChart.trace.rowsEL?.appendChild(SpSegmentationChart.cpuRow);
267    this.rowFolder!.addChildTraceRow(SpSegmentationChart.cpuRow);
268  }
269  async initGpuTrace() {
270    SpSegmentationChart.GpuRow = TraceRow.skeleton<CpuFreqExtendStruct>();
271    SpSegmentationChart.GpuRow.rowId = 'gpurow';
272    SpSegmentationChart.GpuRow.rowType = TraceRow.ROW_TYPE_GPU_COMPUTILITY;
273    SpSegmentationChart.GpuRow.rowParentId = '';
274    SpSegmentationChart.GpuRow.style.height = '40px';
275    SpSegmentationChart.GpuRow.name = 'Gpu Computility';
276    SpSegmentationChart.GpuRow.favoriteChangeHandler = SpSegmentationChart.trace.favoriteChangeHandler;
277    SpSegmentationChart.GpuRow.selectChangeHandler = SpSegmentationChart.trace.selectChangeHandler;
278    // @ts-ignore
279    SpSegmentationChart.GpuRow.supplier = (): Promise<Array<freqChartDataStruct>> =>
280      new Promise<Array<FreqChartDataStruct>>((resolve) => resolve([]));
281    SpSegmentationChart.GpuRow.focusHandler = (ev): void => {
282      SpSegmentationChart.trace?.displayTip(
283        SpSegmentationChart.GpuRow!,
284        CpuFreqExtendStruct.hoverStruct,
285        `<span>${CpuFreqExtendStruct.hoverStruct === undefined ? 0 : CpuFreqExtendStruct.hoverStruct.value!
286        }</span>`
287      );
288    };
289    SpSegmentationChart.GpuRow.findHoverStruct = (): void => {
290      CpuFreqExtendStruct.hoverStruct = SpSegmentationChart.GpuRow!.getHoverStruct();
291    };
292    SpSegmentationChart.GpuRow.onThreadHandler = (useCache): void => {
293      let context: CanvasRenderingContext2D;
294      if (SpSegmentationChart.GpuRow!.currentContext) {
295        context = SpSegmentationChart.GpuRow!.currentContext;
296      } else {
297        context = SpSegmentationChart.GpuRow!.collect
298          ? SpSegmentationChart.trace.canvasFavoritePanelCtx!
299          : SpSegmentationChart.trace.canvasPanelCtx!;
300      }
301      SpSegmentationChart.GpuRow!.canvasSave(context);
302      (renders['freq-extend'] as FreqExtendRender).renderMainThread(
303        {
304          context: context,
305          useCache: useCache,
306          type: 'GPU-FREQ',
307        },
308        SpSegmentationChart.GpuRow!
309      );
310      SpSegmentationChart.GpuRow!.canvasRestore(context);
311    };
312    SpSegmentationChart.trace.rowsEL?.appendChild(SpSegmentationChart.GpuRow);
313    this.rowFolder!.addChildTraceRow(SpSegmentationChart.GpuRow);
314  }
315  async initSchedTrace() {
316    SpSegmentationChart.schedRow = TraceRow.skeleton<CpuFreqExtendStruct>();
317    SpSegmentationChart.schedRow.rowId = 'sched_switch Count';
318    SpSegmentationChart.schedRow.rowType = TraceRow.ROW_TYPE_SCHED_SWITCH;
319    SpSegmentationChart.schedRow.rowParentId = '';
320    SpSegmentationChart.schedRow.style.height = '40px';
321    SpSegmentationChart.schedRow.name = 'Sched_switch Count';
322    SpSegmentationChart.schedRow.favoriteChangeHandler = SpSegmentationChart.trace.favoriteChangeHandler;
323    SpSegmentationChart.schedRow.selectChangeHandler = SpSegmentationChart.trace.selectChangeHandler;
324    SpSegmentationChart.schedRow.focusHandler = (ev): void => {
325      SpSegmentationChart.trace?.displayTip(
326        SpSegmentationChart.schedRow!,
327        CpuFreqExtendStruct.hoverStruct,
328        `<span>${CpuFreqExtendStruct.hoverStruct?.value!}</span>`
329      );
330    };
331    SpSegmentationChart.schedRow.findHoverStruct = (): void => {
332      CpuFreqExtendStruct.hoverStruct = SpSegmentationChart.schedRow!.getHoverStruct();
333    };
334    // @ts-ignore
335    SpSegmentationChart.schedRow.supplier = (): Promise<Array<freqChartDataStruct>> =>
336      new Promise<Array<FreqChartDataStruct>>((resolve) => resolve([]));
337    SpSegmentationChart.schedRow.onThreadHandler = (useCache): void => {
338      let context: CanvasRenderingContext2D;
339      if (SpSegmentationChart.schedRow!.currentContext) {
340        context = SpSegmentationChart.schedRow!.currentContext;
341      } else {
342        context = SpSegmentationChart.schedRow!.collect
343          ? SpSegmentationChart.trace.canvasFavoritePanelCtx!
344          : SpSegmentationChart.trace.canvasPanelCtx!;
345      }
346      SpSegmentationChart.schedRow!.canvasSave(context);
347      (renders['freq-extend'] as FreqExtendRender).renderMainThread(
348        {
349          context: context,
350          useCache: useCache,
351          type: 'SCHED-SWITCH',
352        },
353        SpSegmentationChart.schedRow!
354      );
355      SpSegmentationChart.schedRow!.canvasRestore(context);
356    };
357    SpSegmentationChart.trace.rowsEL?.appendChild(SpSegmentationChart.schedRow);
358    this.rowFolder!.addChildTraceRow(SpSegmentationChart.schedRow);
359  }
360
361  async initAllStates() {
362    SpSegmentationChart.statesRow = TraceRow.skeleton<AllstatesStruct>();
363    SpSegmentationChart.statesRow.rowId = `statesrow`;
364    SpSegmentationChart.statesRow.rowType = TraceRow.ROW_TYPE_THREAD;
365    SpSegmentationChart.statesRow.rowParentId = '';
366    SpSegmentationChart.statesRow.style.height = '30px';
367    SpSegmentationChart.statesRow.name = `All States`;
368    SpSegmentationChart.statesRow.favoriteChangeHandler = SpSegmentationChart.trace.favoriteChangeHandler;
369    SpSegmentationChart.statesRow.selectChangeHandler = SpSegmentationChart.trace.selectChangeHandler;
370    // @ts-ignore
371    SpSegmentationChart.statesRow.supplier = (): Promise<Array<freqChartDataStruct>> =>
372      new Promise<Array<FreqChartDataStruct>>((resolve) => resolve([]));
373    SpSegmentationChart.statesRow.onThreadHandler = (useCache) => {
374      let context: CanvasRenderingContext2D;
375      if (SpSegmentationChart.statesRow!.currentContext) {
376        context = SpSegmentationChart.statesRow!.currentContext;
377      } else {
378        context = SpSegmentationChart.statesRow!.collect ? SpSegmentationChart.trace.canvasFavoritePanelCtx! : SpSegmentationChart.trace.canvasPanelCtx!;
379      }
380      SpSegmentationChart.statesRow!.canvasSave(context);
381      (renders.stateCut as AllStatesRender).renderMainThread(
382        {
383          context: context,
384          useCache: useCache,
385          type: ``,
386          translateY: SpSegmentationChart.statesRow!.translateY,
387        },
388        SpSegmentationChart.statesRow!
389      );
390      SpSegmentationChart.statesRow!.canvasRestore(context);
391    };
392    SpSegmentationChart.trace.rowsEL?.appendChild(SpSegmentationChart.statesRow);
393    this.rowFolder!.addChildTraceRow(SpSegmentationChart.statesRow);
394  }
395
396  async initBinderTrace() {
397    SpSegmentationChart.binderRow = TraceRow.skeleton<BinderStruct>();
398    SpSegmentationChart.binderRow.rowId = 'binderrow';
399    SpSegmentationChart.binderRow.rowType = TraceRow.ROW_TYPE_BINDER_COUNT;
400    SpSegmentationChart.binderRow.enableCollapseChart(40, SpSegmentationChart.trace);
401    SpSegmentationChart.binderRow.rowParentId = '';
402    SpSegmentationChart.binderRow.name = 'Binder Count';
403    SpSegmentationChart.binderRow.style.height = '40px';
404    SpSegmentationChart.binderRow.favoriteChangeHandler = SpSegmentationChart.trace.favoriteChangeHandler;
405    SpSegmentationChart.binderRow.selectChangeHandler = SpSegmentationChart.trace.selectChangeHandler;
406    SpSegmentationChart.binderRow.findHoverStruct = () => {
407      BinderStruct.hoverCpuFreqStruct = SpSegmentationChart.binderRow!.dataListCache.find((v: BinderStruct) => {
408        if (SpSegmentationChart.binderRow!.isHover) {
409          if (v.frame!.x < SpSegmentationChart.binderRow!.hoverX + 1 &&
410            v.frame!.x + v.frame!.width > SpSegmentationChart.binderRow!.hoverX - 1 &&
411            (BinderStruct.maxHeight * 20 - v.depth * 20 + 20) < SpSegmentationChart.binderRow!.hoverY &&
412            BinderStruct.maxHeight * 20 - v.depth * 20 + v.value * 20 + 20 > SpSegmentationChart.binderRow!.hoverY) {
413            return v;
414          }
415        }
416      })
417    };
418    SpSegmentationChart.binderRow.focusHandler = (ev): void => {
419      SpSegmentationChart.trace!.displayTip(
420        SpSegmentationChart.binderRow!,
421        BinderStruct.hoverCpuFreqStruct,
422        `<span style='font-weight: bold;'>Cycle: ${BinderStruct.hoverCpuFreqStruct ? BinderStruct.hoverCpuFreqStruct.cycle : 0
423        }</span><br>
424                <span style='font-weight: bold;'>Name: ${BinderStruct.hoverCpuFreqStruct ? BinderStruct.hoverCpuFreqStruct.name : ''
425        }</span><br>
426                <span style='font-weight: bold;'>Count: ${BinderStruct.hoverCpuFreqStruct ? BinderStruct.hoverCpuFreqStruct.value : 0
427        }</span>`
428      );
429    };
430
431    SpSegmentationChart.binderRow.supplier = (): Promise<Array<BinderStruct>> =>
432      new Promise<Array<BinderStruct>>((resolve) => resolve([]));
433    SpSegmentationChart.binderRow.onThreadHandler = (useCache): void => {
434      let context: CanvasRenderingContext2D;
435      if (SpSegmentationChart.binderRow!.currentContext) {
436        context = SpSegmentationChart.binderRow!.currentContext;
437      } else {
438        context = SpSegmentationChart.binderRow!.collect
439          ? SpSegmentationChart.trace.canvasFavoritePanelCtx!
440          : SpSegmentationChart.trace.canvasPanelCtx!;
441      }
442      SpSegmentationChart.binderRow!.canvasSave(context);
443      (renders.binder as BinderRender).renderMainThread(
444        {
445          context: context,
446          useCache: useCache,
447          type: 'BINDER',
448        },
449        SpSegmentationChart.binderRow!
450      );
451      SpSegmentationChart.binderRow!.canvasRestore(context);
452    };
453    SpSegmentationChart.trace.rowsEL?.appendChild(SpSegmentationChart.binderRow);
454    this.rowFolder!.addChildTraceRow(SpSegmentationChart.binderRow);
455  }
456}
457class FreqChartDataStruct {
458  colorIndex?: number = 0;
459  dur: number = 0;
460  value: number = 0;
461  startNS: number = 0;
462  cycle: number = 0;
463  depth?: number = 1;
464  name?: string = '';
465}
466
467function setCpuData(data: Array<FreqChartDataStruct>) {
468  let currentMaxValue = 0;
469  data.map((v: FreqChartDataStruct) => {
470    if (v.value > currentMaxValue) {
471      currentMaxValue = v.value;
472    }
473  });
474  CpuFreqExtendStruct.hoverType = 'CPU-FREQ';
475  CpuFreqExtendStruct.cpuMaxValue = currentMaxValue;
476  SpSegmentationChart.cpuRow!.dataList = [];
477  SpSegmentationChart.cpuRow!.dataListCache = [];
478  SpSegmentationChart.cpuRow!.isComplete = false;
479  // @ts-ignore
480  SpSegmentationChart.cpuRow!.supplier = (): Promise<Array<FreqChartDataStruct>> =>
481    new Promise<Array<FreqChartDataStruct>>((resolve) => resolve(data));
482}
483function setGpuData(data: Array<FreqChartDataStruct>): void {
484  let currentMaxValue = 0;
485  data.map((v: FreqChartDataStruct) => {
486    if (v.value && v.value > currentMaxValue!) {
487      currentMaxValue = v.value;
488    }
489  });
490  CpuFreqExtendStruct.hoverType = 'GPU-FREQ';
491  CpuFreqExtendStruct.gpuMaxValue = currentMaxValue;
492  SpSegmentationChart.GpuRow!.dataList = [];
493  SpSegmentationChart.GpuRow!.dataListCache = [];
494  SpSegmentationChart.GpuRow!.isComplete = false;
495  // @ts-ignore
496  SpSegmentationChart.GpuRow!.supplier = (): Promise<Array<FreqChartDataStruct>> =>
497    new Promise<Array<FreqChartDataStruct>>((resolve) => resolve(data));
498}
499function setSchedData(data: Array<FreqChartDataStruct>): void {
500  let currentMaxValue = 0;
501  data.map((v: FreqChartDataStruct) => {
502    if (v.value && v.value > currentMaxValue!) {
503      currentMaxValue = v.value;
504    }
505  });
506  CpuFreqExtendStruct.hoverType = 'SCHED-SWITCH';
507  CpuFreqExtendStruct.schedMaxValue = currentMaxValue!;
508  SpSegmentationChart.schedRow!.dataList = [];
509  SpSegmentationChart.schedRow!.dataListCache = [];
510  SpSegmentationChart.schedRow!.isComplete = false;
511  // @ts-ignore
512  SpSegmentationChart.schedRow!.supplier = (): Promise<Array<FreqChartDataStruct>> =>
513    new Promise<Array<FreqChartDataStruct>>((resolve) => resolve(data));
514}
515function setBinderData(data: Array<Array<FreqChartDataStruct>>, binderList: Array<FreqChartDataStruct>): void {
516  data.map((v: Array<FreqChartDataStruct>) => {
517    // 统计每一竖列的最大count
518    let listCount = 0;
519    v.map((t: FreqChartDataStruct) => {
520      listCount += t.value;
521      if (t.name === 'binder transaction') {
522        t.depth = t.value;
523      }
524      if (t.name === 'binder transaction async') {
525        t.depth =
526          t.value +
527          (v.filter((i: FreqChartDataStruct) => {
528            return i.name === 'binder transaction';
529          }).length > 0
530            ? v.filter((i: FreqChartDataStruct) => {
531              return i.name === 'binder transaction';
532            })[0].value
533            : 0);
534      }
535      if (t.name === 'binder reply') {
536        t.depth =
537          t.value +
538          (v.filter((i: FreqChartDataStruct) => {
539            return i.name === 'binder transaction';
540          }).length > 0
541            ? v.filter((i: FreqChartDataStruct) => {
542              return i.name === 'binder transaction';
543            })[0].value
544            : 0) +
545          (v.filter((i: FreqChartDataStruct) => {
546            return i.name === 'binder transaction async';
547          }).length > 0
548            ? v.filter((i: FreqChartDataStruct) => {
549              return i.name === 'binder transaction async';
550            })[0].value
551            : 0);
552      }
553      if (t.name === 'binder async rcv') {
554        t.depth =
555          t.value +
556          (v.filter((i: FreqChartDataStruct) => {
557            return i.name === 'binder transaction';
558          }).length > 0
559            ? v.filter((i: FreqChartDataStruct) => {
560              return i.name === 'binder transaction';
561            })[0].value
562            : 0) +
563          (v.filter((i: FreqChartDataStruct) => {
564            return i.name === 'binder transaction async';
565          }).length > 0
566            ? v.filter((i: FreqChartDataStruct) => {
567              return i.name === 'binder transaction async';
568            })[0].value
569            : 0) +
570          (v.filter((i: FreqChartDataStruct) => {
571            return i.name === 'binder reply';
572          }).length > 0
573            ? v.filter((i: FreqChartDataStruct) => {
574              return i.name === 'binder reply';
575            })[0].value
576            : 0);
577      }
578      binderList.push(t);
579    });
580    BinderStruct.maxHeight =
581      BinderStruct.maxHeight > listCount ? BinderStruct.maxHeight : JSON.parse(JSON.stringify(listCount));
582    listCount = 0;
583  });
584}
585
586class HeightLine {
587  key: string = '';
588  cycle: number = -1;
589}
590