/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { BaseElement, element } from '../../../base-ui/BaseElement'; import { LitTable } from '../../../base-ui/table/lit-table'; import { SpSchedulingAnalysis } from './SpSchedulingAnalysis'; import { procedurePool } from '../../database/Procedure'; import { info } from '../../../log/Log'; import '../../../base-ui/progress-bar/LitProgressBar'; import { LitProgressBar } from '../../../base-ui/progress-bar/LitProgressBar'; import './TableNoData'; import { TableNoData } from './TableNoData'; @element('top20-thread-run-time') export class Top20ThreadRunTime extends BaseElement { traceChange: boolean = false; private threadRunTimeTbl: LitTable | null | undefined; private threadRunTimeProgress: LitProgressBar | null | undefined; private nodata: TableNoData | null | undefined; private threadRunTimeData: Array = []; initElements(): void { this.threadRunTimeProgress = this.shadowRoot!.querySelector('#loading'); this.threadRunTimeTbl = this.shadowRoot!.querySelector('#tb-thread-run-time'); this.nodata = this.shadowRoot!.querySelector('#nodata'); this.threadRunTimeTbl!.addEventListener('row-click', (evt: unknown): void => { //@ts-ignore let data = evt.detail.data; data.isSelected = true; // @ts-ignore if ((evt.detail as unknown).callBack) { // @ts-ignore (evt.detail as unknown).callBack(true); } }); this.threadRunTimeTbl!.addEventListener('column-click', (evt): void => { // @ts-ignore this.sortByColumn(evt.detail); }); } init(): void { if (!this.traceChange) { if (this.threadRunTimeTbl!.recycleDataSource.length > 0) { this.threadRunTimeTbl?.reMeauseHeight(); } return; } this.threadRunTimeProgress!.loading = true; this.traceChange = false; this.queryLogicWorker('scheduling-Thread RunTime', 'query Thread Cpu Run Time Analysis Time:', (res): void => { //@ts-ignore this.nodata!.noData = res === undefined || res.length === 0; //@ts-ignore this.threadRunTimeTbl!.recycleDataSource = res; this.threadRunTimeTbl?.reMeauseHeight(); this.threadRunTimeProgress!.loading = false; //@ts-ignore this.threadRunTimeData = res; }); } clearData(): void { this.traceChange = true; this.threadRunTimeTbl!.recycleDataSource = []; } queryLogicWorker(option: string, log: string, handler: (res: unknown) => void): void { let threadRunTime = new Date().getTime(); procedurePool.submitWithName('logic0', option, { cpuMax: SpSchedulingAnalysis.cpuCount - 1 }, undefined, handler); let durTime = new Date().getTime() - threadRunTime; info(log, durTime); } sortByColumn(detail: unknown): void { // @ts-ignore function compare(threadRunTimeProperty, sort, type) { return function (a: unknown, b: unknown) { if (type === 'number') { return sort === 2 ? // @ts-ignore parseFloat(b[threadRunTimeProperty]) - parseFloat(a[threadRunTimeProperty]) : //@ts-ignore parseFloat(a[threadRunTimeProperty]) - parseFloat(b[threadRunTimeProperty]); } else { if (sort === 2) { //@ts-ignore return b[threadRunTimeProperty].toString().localeCompare(a[threadRunTimeProperty].toString()); } else { //@ts-ignore return a[threadRunTimeProperty].toString().localeCompare(b[threadRunTimeProperty].toString()); } } }; } //@ts-ignore let key = detail.key; if (key === 'maxDurationStr') { key = 'maxDuration'; //@ts-ignore this.threadRunTimeData.sort(compare(key, detail.sort, 'number')); } else if (key === 'cpu' || key === 'no' || key === 'pid' || key === 'tid' || key === 'timestamp') { //@ts-ignore this.threadRunTimeData.sort(compare(key, detail.sort, 'number')); } else { //@ts-ignore this.threadRunTimeData.sort(compare(key, detail.sort, 'string')); } this.threadRunTimeTbl!.recycleDataSource = this.threadRunTimeData; } initHtml(): string { return `
`; } }