• 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 { SpSystemTrace } from '../SpSystemTrace';
17import { TraceRow } from '../trace/base/TraceRow';
18import { info } from '../../../log/Log';
19import { renders } from '../../database/ui-worker/ProcedureWorker';
20import { EmptyRender } from '../../database/ui-worker/cpu/ProcedureWorkerCPU';
21import { IrqRender, IrqStruct } from '../../database/ui-worker/ProcedureWorkerIrq';
22import { irqDataSender } from '../../database/data-trafic/IrqDataSender';
23import { queryAllIrqNames, queryIrqList } from '../../database/sql/Irq.sql';
24import { getRowContext, rowThreadHandler } from './SpChartManager';
25
26export class SpIrqChart {
27  private trace: SpSystemTrace;
28  private irqNameMap: Map<number, { name: string; ipiName: string }> = new Map();
29
30  constructor(trace: SpSystemTrace) {
31    this.trace = trace;
32  }
33
34  async init(): Promise<void> {
35    let folder = await this.initFolder();
36    await this.initData(folder);
37  }
38
39  //@ts-ignore
40  async initData(folder: TraceRow<unknown>): Promise<void> {
41    let irqStartTime = new Date().getTime();
42    let irqList = await queryIrqList();
43    if (irqList.length === 0) {
44      return;
45    }
46    //加载irq table所有id和name数据
47    let irqNamesArray = await queryAllIrqNames();
48    irqNamesArray.forEach((it) => {
49      this.irqNameMap.set(it.id, { ipiName: it.ipiName, name: it.name });
50    });
51    info('irqList data size is: ', irqList!.length);
52    this.trace.rowsEL?.appendChild(folder);
53    for (let i = 0; i < irqList.length; i++) {
54      const it = irqList[i];
55      this.addIrqRow(it, i, folder);
56    }
57    let durTime = new Date().getTime() - irqStartTime;
58    info('The time to load the ClockData is: ', durTime);
59  }
60
61  //@ts-ignore
62  addIrqRow(it: unknown, index: number, folder: TraceRow<unknown>): void {
63    let traceRow = TraceRow.skeleton<IrqStruct>();
64    //@ts-ignore
65    traceRow.rowId = it.name + it.cpu;
66    traceRow.rowType = TraceRow.ROW_TYPE_IRQ;
67    traceRow.rowParentId = folder.rowId;
68    traceRow.style.height = '40px'; //@ts-ignore
69    traceRow.name = `${it.name} Cpu ${it.cpu}`;
70    traceRow.rowHidden = !folder.expansion;
71    traceRow.setAttribute('children', ''); //@ts-ignore
72    traceRow.setAttribute('callId', `${it.cpu}`); //@ts-ignore
73    traceRow.setAttribute('cat', `${it.name}`);
74    traceRow.favoriteChangeHandler = this.trace.favoriteChangeHandler;
75    traceRow.selectChangeHandler = this.trace.selectChangeHandler;
76    traceRow.supplierFrame = (): Promise<IrqStruct[]> => {
77      //@ts-ignore
78      return irqDataSender(it.cpu, it.name, traceRow).then((irqs) => {
79        irqs.forEach((irq): void => {
80          let irqData = this.irqNameMap.get(irq.id!); //@ts-ignore
81          irq.name = (it.name === 'irq' ? irqData?.ipiName : irqData?.name) || '';
82        });
83        return irqs;
84      });
85    };
86    traceRow.focusHandler = (): void => {
87      this.trace?.displayTip(
88        traceRow,
89        IrqStruct.hoverIrqStruct,
90        `<span>${IrqStruct.hoverIrqStruct?.name || ''}</span>`
91      );
92    };
93    traceRow.findHoverStruct = (): void => {
94      IrqStruct.hoverIrqStruct = traceRow.getHoverStruct();
95    };
96    traceRow.onThreadHandler = rowThreadHandler<IrqRender>(
97      'irq',
98      'context',
99      {
100        //@ts-ignore
101        type: it.name,
102        index: index,
103      },
104      traceRow,
105      this.trace
106    );
107    folder.addChildTraceRow(traceRow);
108  }
109
110  //@ts-ignore
111  async initFolder(): Promise<TraceRow<unknown>> {
112    let irqFolder = TraceRow.skeleton();
113    irqFolder.rowId = 'Irs';
114    irqFolder.index = 0;
115    irqFolder.rowType = TraceRow.ROW_TYPE_IRQ_GROUP;
116    irqFolder.rowParentId = '';
117    irqFolder.style.height = '40px';
118    irqFolder.folder = true;
119    irqFolder.name = 'Irs'; /* & I/O Latency */
120    irqFolder.favoriteChangeHandler = this.trace.favoriteChangeHandler;
121    irqFolder.selectChangeHandler = this.trace.selectChangeHandler; //@ts-ignore
122    irqFolder.supplier = (): Promise<Array<unknown>> => new Promise<Array<unknown>>((resolve) => resolve([]));
123    irqFolder.onThreadHandler = (useCache): void => {
124      irqFolder.canvasSave(this.trace.canvasPanelCtx!);
125      if (irqFolder.expansion) {
126        // @ts-ignore
127        this.trace.canvasPanelCtx?.clearRect(0, 0, irqFolder.frame.width, irqFolder.frame.height);
128      } else {
129        (renders.empty as EmptyRender).renderMainThread(
130          {
131            context: this.trace.canvasPanelCtx,
132            useCache: useCache,
133            type: '',
134          },
135          irqFolder
136        );
137      }
138      irqFolder.canvasRestore(this.trace.canvasPanelCtx!, this.trace);
139    };
140    return irqFolder;
141  }
142}
143