• 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 { BaseElement, element } from '../../../../../base-ui/BaseElement';
17import { LitTable } from '../../../../../base-ui/table/lit-table';
18import { SelectionParam } from '../../../../bean/BoxSelection';
19import '../../../../../base-ui/slicer/lit-slicer';
20import { LitProgressBar } from '../../../../../base-ui/progress-bar/LitProgressBar';
21import { FilterData, TabPaneFilter } from '../TabPaneFilter';
22import { FileSysEvent } from '../../../../database/logic-worker/ProcedureLogicWorkerFileSystem';
23import { procedurePool } from '../../../../database/Procedure';
24import { TabPaneFileSystemDescHistoryHtml } from './TabPaneFileSystemDescHistory.html';
25
26@element('tabpane-filesystem-desc-history')
27export class TabPaneFileSystemDescHistory extends BaseElement {
28  private fsDescHistoryTbl: LitTable | null | undefined;
29  private fsDescHistoryTblData: LitTable | null | undefined;
30  private fsDescHistoryFilter: TabPaneFilter | null | undefined;
31  private fsDescHistoryProgressEL: LitProgressBar | null | undefined;
32  private fsDescHistoryLoadingList: number[] = [];
33  private fsDescHistoryLoadingPage: unknown;
34  private fsDescHistorySource: Array<FileSysEvent> = [];
35  private fsDescHistoryFilterSource: Array<FileSysEvent> = [];
36  private fsDescHistorySortKey: string = 'startTs';
37  private fsDescHistorySortType: number = 0;
38  private filterEventType: string = '0';
39  private filterProcess: string = '0';
40  private filterPath: string = '0';
41  private currentSelection: SelectionParam | undefined | null;
42  private eventList: string[] | null | undefined;
43  private processList: string[] | null | undefined;
44  private pathList: string[] | null | undefined;
45
46  set data(fsDescHistorySelection: SelectionParam | null | undefined) {
47    if (fsDescHistorySelection === this.currentSelection) {
48      return;
49    }
50    this.currentSelection = fsDescHistorySelection;
51    if (this.fsDescHistoryTbl) {
52      // @ts-ignore
53      this.fsDescHistoryTbl.shadowRoot.querySelector('.table').style.height = `${
54        this.parentElement!.clientHeight - 20 - 31
55      }px`;
56      this.fsDescHistoryTbl.recycleDataSource = [];
57    }
58    if (this.fsDescHistoryTblData) {
59      // @ts-ignore
60      this.fsDescHistoryTblData.shadowRoot.querySelector('.table').style.height = `${
61        this.parentElement!.clientHeight - 20 - 31
62      }px`;
63      this.fsDescHistoryTblData.recycleDataSource = [];
64    }
65    if (fsDescHistorySelection) {
66      this.fsDescHistoryLoadingList.push(1);
67      this.fsDescHistoryProgressEL!.loading = true; // @ts-ignore
68      this.fsDescHistoryLoadingPage.style.visibility = 'visible';
69      this.fsDescHistorySource = [];
70      procedurePool.submitWithName(
71        'logic0',
72        'fileSystem-queryFileSysEvents',
73        {
74          leftNs: fsDescHistorySelection.leftNs,
75          rightNs: fsDescHistorySelection.rightNs,
76          typeArr: [0, 1],
77          tab: 'history',
78        },
79        undefined,
80        (res: unknown): void => {
81          // @ts-ignore
82          this.fsDescHistorySource = this.fsDescHistorySource.concat(res.data); // @ts-ignore
83          res.data = null; // @ts-ignore
84          if (!res.isSending) {
85            this.fsDescHistoryTbl!.recycleDataSource = this.fsDescHistorySource;
86            this.fsDescHistoryFilterSource = this.fsDescHistorySource;
87            this.setProcessFilter();
88            this.fsDescHistoryLoadingList.splice(0, 1);
89            if (this.fsDescHistoryLoadingList.length === 0) {
90              this.fsDescHistoryProgressEL!.loading = false; // @ts-ignore
91              this.fsDescHistoryLoadingPage.style.visibility = 'hidden';
92            }
93          }
94        }
95      );
96    }
97  }
98
99  setProcessFilter(): void {
100    this.processList = ['All Process'];
101    this.pathList = ['All Path'];
102    this.fsDescHistorySource.map((historyItem): void => {
103      if (this.processList!.findIndex((processItem): boolean => processItem === historyItem.process) === -1) {
104        this.processList!.push(historyItem.process);
105      }
106      if (this.pathList!.findIndex((pathItem): boolean => pathItem === historyItem.path) === -1) {
107        this.pathList!.push(historyItem.path);
108      }
109    });
110    this.fsDescHistoryFilter!.setSelectList(this.eventList, this.processList, '', '', this.pathList, '');
111    this.fsDescHistoryFilter!.firstSelect = '0';
112    this.fsDescHistoryFilter!.secondSelect = '0';
113    this.fsDescHistoryFilter!.thirdSelect = '0';
114    this.filterProcess = '0';
115    this.filterPath = '0';
116    this.filterEventType = '0';
117  }
118
119  filterData(): void {
120    let pfv = parseInt(this.filterProcess);
121    let pathIndex = parseInt(this.filterPath);
122    this.fsDescHistoryFilterSource = this.fsDescHistorySource.filter((fsHistoryEvent) => {
123      let pathFilter = true;
124      let eventFilter = true;
125      let processFilter = true;
126      if (this.filterPath !== '0') {
127        pathFilter = fsHistoryEvent.path === this.pathList![pathIndex];
128      }
129      if (this.filterEventType === '1') {
130        eventFilter = fsHistoryEvent.type === 0;
131      } else if (this.filterEventType === '2') {
132        eventFilter = fsHistoryEvent.type === 1;
133      }
134      if (this.filterProcess !== '0') {
135        processFilter = fsHistoryEvent.process === this.processList![pfv];
136      }
137      return pathFilter && eventFilter && processFilter;
138    });
139    this.fsDescHistoryTblData!.recycleDataSource = [];
140    this.sortFsDescHistoryTable(this.fsDescHistorySortKey, this.fsDescHistorySortType);
141  }
142
143  initElements(): void {
144    this.fsDescHistoryLoadingPage = this.shadowRoot?.querySelector('.filesystem-desc-history-loading');
145    this.fsDescHistoryProgressEL = this.shadowRoot?.querySelector(
146      '.filesystem-desc-history-progress'
147    ) as LitProgressBar;
148    this.fsDescHistoryTbl = this.shadowRoot?.querySelector<LitTable>('#tbl-file-system-desc-history');
149    this.fsDescHistoryTblData = this.shadowRoot?.querySelector<LitTable>('#tbr-file-system-desc-history');
150    this.fsDescHistoryTbl!.addEventListener('row-click', (e): void => {
151      // @ts-ignore
152      let data = e.detail.data as FileSysEvent; // @ts-ignore
153      (data as unknown).isSelected = true;
154      // @ts-ignore
155      if ((e.detail as unknown).callBack) {
156        // @ts-ignore
157        (e.detail as unknown).callBack(true);
158      }
159      procedurePool.submitWithName(
160        'logic0',
161        'fileSystem-queryStack',
162        { callchainId: data.callchainId },
163        undefined,
164        (res: unknown): void => {
165          // @ts-ignore
166          this.fsDescHistoryTblData!.recycleDataSource = res;
167        }
168      );
169    });
170    this.fsDescHistoryTbl!.addEventListener('column-click', (evt): void => {
171      // @ts-ignore
172      this.fsDescHistorySortKey = evt.detail.key;
173      // @ts-ignore
174      this.fsDescHistorySortType = evt.detail.sort;
175      // @ts-ignore
176      this.sortFsDescHistoryTable(evt.detail.key, evt.detail.sort);
177    });
178    this.fsDescHistoryFilter = this.shadowRoot?.querySelector<TabPaneFilter>('#filesystem-desc-history-filter');
179    this.eventList = ['All FD Event', 'All Open Event', 'All Close Event'];
180    this.processList = ['All Process'];
181    this.pathList = ['All Path'];
182    this.fsDescHistoryFilter!.setSelectList(this.eventList, this.processList, '', '', this.pathList, '');
183    this.fsDescHistoryFilter!.firstSelect = '0';
184    this.fsDescHistoryFilter!.getFilterData((data: FilterData): void => {
185      this.filterEventType = data.firstSelect || '0';
186      this.filterProcess = data.secondSelect || '0';
187      this.filterPath = data.thirdSelect || '0';
188      this.filterData();
189    });
190  }
191
192  connectedCallback(): void {
193    super.connectedCallback();
194    new ResizeObserver((): void => {
195      if (this.parentElement?.clientHeight !== 0) {
196        if (this.fsDescHistoryTbl) {
197          // @ts-ignore
198          this.fsDescHistoryTbl.shadowRoot.querySelector('.table').style.height = `${
199            this.parentElement!.clientHeight - 10 - 31
200          }px`;
201          this.fsDescHistoryTbl.reMeauseHeight();
202        }
203        if (this.fsDescHistoryTblData) {
204          // @ts-ignore
205          this.fsDescHistoryTblData.shadowRoot.querySelector('.table').style.height = `${
206            this.parentElement!.clientHeight - 10 - 31
207          }px`;
208          this.fsDescHistoryTblData.reMeauseHeight();
209        } // @ts-ignore
210        this.fsDescHistoryLoadingPage.style.height = `${this.parentElement!.clientHeight - 24}px`;
211      }
212    }).observe(this.parentElement!);
213  }
214
215  sortFsDescHistoryTable(key: string, type: number): void {
216    if (type === 0) {
217      this.fsDescHistoryTbl!.recycleDataSource = this.fsDescHistoryFilterSource;
218    } else {
219      let arr = Array.from(this.fsDescHistoryFilterSource);
220      arr.sort((fsHistoryA, fsHistoryB): number => {
221        if (key === 'startTsStr') {
222          return this.compareStartTs(fsHistoryA, fsHistoryB, type);
223        } else if (key === 'durStr') {
224          return this.compareDur(fsHistoryA, fsHistoryB, type);
225        } else if (key === 'process') {
226          return this.compareProcess(fsHistoryA, fsHistoryB, type);
227        } else if (key === 'typeStr') {
228          return this.compareTypeStr(fsHistoryA, fsHistoryB, type);
229        } else if (key === 'fd') {
230          return this.compareFd(fsHistoryA, fsHistoryB, type);
231        } else {
232          return 0;
233        }
234      });
235      this.fsDescHistoryTbl!.recycleDataSource = arr;
236    }
237  }
238
239  compareStartTs(fsHistoryA: unknown, fsHistoryB: unknown, type: number): number {
240    if (type === 1) {
241      // @ts-ignore
242      return fsHistoryA.startTs - fsHistoryB.startTs;
243    } else {
244      // @ts-ignore
245      return fsHistoryB.startTs - fsHistoryA.startTs;
246    }
247  }
248
249  compareDur(fsHistoryA: unknown, fsHistoryB: unknown, type: number): number {
250    if (type === 1) {
251      // @ts-ignore
252      return fsHistoryA.dur - fsHistoryB.dur;
253    } else {
254      // @ts-ignore
255      return fsHistoryB.dur - fsHistoryA.dur;
256    }
257  }
258
259  compareProcess(fsHistoryA: unknown, fsHistoryB: unknown, type: number): number {
260    // @ts-ignore
261    if (fsHistoryA.process > fsHistoryB.process) {
262      return type === 2 ? 1 : -1; // @ts-ignore
263    } else if (fsHistoryA.process === fsHistoryB.process) {
264      return 0;
265    } else {
266      return type === 2 ? -1 : 1;
267    }
268  }
269
270  compareTypeStr(fsHistoryA: unknown, fsHistoryB: unknown, type: number): number {
271    // @ts-ignore
272    if (fsHistoryA.typeStr > fsHistoryB.typeStr) {
273      return type === 2 ? 1 : -1; // @ts-ignore
274    } else if (fsHistoryA.typeStr === fsHistoryB.typeStr) {
275      return 0;
276    } else {
277      return type === 2 ? -1 : 1;
278    }
279  }
280
281  compareFd(fsHistoryA: unknown, fsHistoryB: unknown, type: number): number {
282    if (type === 1) {
283      // @ts-ignore
284      return fsHistoryA.fd - fsHistoryB.fd;
285    } else {
286      // @ts-ignore
287      return fsHistoryB.fd - fsHistoryA.fd;
288    }
289  }
290
291  initHtml(): string {
292    return TabPaneFileSystemDescHistoryHtml;
293  }
294}
295