/* * 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 { SelectionParam } from '../../../../bean/BoxSelection'; import { log } from '../../../../../log/Log'; import { getProbablyTime } from '../../../../database/logic-worker/ProcedureLogicWorkerCommon'; import { resizeObserver } from '../SheetUtils'; import { Utils } from '../../base/Utils'; import { MemoryConfig } from '../../../../bean/MemoryConfig'; import { queryGpuDataTab } from '../../../../database/sql/Gpu.sql'; interface Graph { startTs: number; startTsStr?: string; size: number; sizeStr?: string; } @element('tabpane-gpu-graph') export class TabPaneGpuGraph extends BaseElement { private graphTbl: LitTable | null | undefined; private range: HTMLLabelElement | null | undefined; private graphSource: Array = []; private currentSelectionParam: SelectionParam | undefined; set data(graphParam: SelectionParam | unknown) { if (this.currentSelectionParam === graphParam) { return; } // @ts-ignore this.currentSelectionParam = graphParam; //@ts-ignore this.graphTbl?.shadowRoot?.querySelector('.table')?.style?.height = this.parentElement!.clientHeight - 45 + 'px'; this.range!.textContent = // @ts-ignore 'Selected range: ' + ((graphParam.rightNs - graphParam.leftNs) / 1000000.0).toFixed(5) + ' ms'; this.graphTbl!.loading = true; queryGpuDataTab( MemoryConfig.getInstance().iPid, // @ts-ignore graphParam.leftNs, // @ts-ignore graphParam.rightNs, MemoryConfig.getInstance().snapshotDur, "'mem.graph_pss'" ).then((result) => { this.graphTbl!.loading = false; log('queryGpuDataTab result size : ' + result.length); if (result.length > 0) { result.forEach((it: Graph) => { it.startTsStr = getProbablyTime(it.startTs); it.sizeStr = Utils.getBinaryByteWithUnit(it.size); }); this.graphSource = result; this.graphTbl!.recycleDataSource = this.graphSource; } else { this.graphSource = []; this.graphTbl!.recycleDataSource = []; } }); } initElements(): void { this.graphTbl = this.shadowRoot?.querySelector('#tb-graph'); this.range = this.shadowRoot?.querySelector('#graph-time-range'); } connectedCallback(): void { super.connectedCallback(); resizeObserver(this.parentElement!, this.graphTbl!); } initHtml(): string { return `
`; } }