• 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 { type LitTable } from '../../../../../base-ui/table/lit-table';
18import { type SelectionParam } from '../../../../bean/BoxSelection';
19import { log } from '../../../../../log/Log';
20import { getProbablyTime } from '../../../../database/logic-worker/ProcedureLogicWorkerCommon';
21import { resizeObserver } from '../SheetUtils';
22import { SpSystemTrace } from '../../../SpSystemTrace';
23import { MemoryConfig } from '../../../../bean/MemoryConfig';
24import { Utils } from '../../base/Utils';
25import { queryGpuDataByRange } from '../../../../database/sql/Gpu.sql';
26
27interface Gpu {
28  startTs: number;
29  startTsStr?: string;
30  windowId: number;
31  moduleId: number;
32  categoryId: number;
33  gpuName?: string;
34  avgSize: number;
35  avgSizeStr?: string;
36  maxSize: number;
37  maxSizeStr?: string;
38  minSize: number;
39  minSizeStr?: string;
40}
41
42@element('tabpane-gpu-window-box-select')
43export class TabPaneGpuWindowBoxSelect extends BaseElement {
44  private gpuBoxTbl: LitTable | null | undefined;
45  private range: HTMLLabelElement | null | undefined;
46  private gpuBoxSource: Array<Gpu> = [];
47  private currentSelectionParam: SelectionParam | undefined;
48
49  set data(gpuBoxParam: SelectionParam | unknown) {
50    if (this.currentSelectionParam === gpuBoxParam) {
51      return;
52    }
53    // @ts-ignore
54    this.currentSelectionParam = gpuBoxParam;
55    //@ts-ignore
56    this.gpuBoxTbl?.shadowRoot?.querySelector('.table')?.style?.height = this.parentElement!.clientHeight - 45 + 'px';
57    this.range!.textContent =
58      // @ts-ignore
59      'Selected range: ' + ((gpuBoxParam.rightNs - gpuBoxParam.leftNs) / 1000000.0).toFixed(5) + ' ms';
60    this.gpuBoxTbl!.loading = true;
61    // @ts-ignore
62    queryGpuDataByRange(gpuBoxParam.leftNs, gpuBoxParam.rightNs, MemoryConfig.getInstance().snapshotDur).then(
63      (result) => {
64        this.gpuBoxTbl!.loading = false;
65        if (result != null && result.length > 0) {
66          log('getTabStartups result size : ' + result.length);
67          let target = result.filter((it) => it.windowId !== 0);
68          target.forEach((it: Gpu) => {
69            let windowName = SpSystemTrace.DATA_DICT.get(it.windowId) || 'NULL';
70            let moduleName = SpSystemTrace.DATA_DICT.get(it.moduleId) || 'NULL';
71            let categoryName = SpSystemTrace.DATA_DICT.get(it.categoryId) || 'NULL';
72            it.gpuName = `${windowName} / ${moduleName} / ${categoryName}`;
73            it.startTsStr = getProbablyTime(it.startTs);
74            it.avgSizeStr = Utils.getBinaryByteWithUnit(it.avgSize);
75            it.minSizeStr = Utils.getBinaryByteWithUnit(it.minSize);
76            it.maxSizeStr = Utils.getBinaryByteWithUnit(it.maxSize);
77          });
78          this.gpuBoxSource = target;
79          this.gpuBoxTbl!.recycleDataSource = this.gpuBoxSource;
80        } else {
81          this.gpuBoxSource = [];
82          this.gpuBoxTbl!.recycleDataSource = [];
83        }
84      }
85    );
86  }
87
88  initElements(): void {
89    this.gpuBoxTbl = this.shadowRoot?.querySelector<LitTable>('#tb-gpu-box');
90    this.range = this.shadowRoot?.querySelector('#gpu-box-time-range');
91    this.gpuBoxTbl!.addEventListener('column-click', (evt: unknown) => {
92      // @ts-ignore
93      this.sortByColumn(evt.detail);
94    });
95  }
96
97  connectedCallback(): void {
98    super.connectedCallback();
99    resizeObserver(this.parentElement!, this.gpuBoxTbl!);
100  }
101
102  initHtml(): string {
103    return `
104        <style>
105        .gpuBox-table{
106          flex-direction: row;
107          margin-bottom: 5px;
108        }
109        :host{
110            display: flex;
111            flex-direction: column;
112            padding: 10px 10px;
113        }
114        </style>
115        <div class="gpu-box-table" style="display: flex;height: 20px;align-items: center;flex-direction: row;margin-bottom: 5px">
116            <div style="flex: 1"></div>
117            <label id="gpu-box-time-range"  style="width: auto;text-align: end;font-size: 10pt;">Selected range:0.0 ms</label>
118        </div>
119        <div style="overflow: auto">
120            <lit-table id="tb-gpu-box" style="height: auto">
121                </lit-table-column>
122                <lit-table-column width="500px" title="Window / Module / Category" data-index="gpuName" key="gpuName"  align="flex-start">
123                </lit-table-column>
124                <lit-table-column width="160px" title="AvgSize" data-index="avgSizeStr" key="avgSizeStr"  align="flex-start" order >
125                </lit-table-column>
126                <lit-table-column width="160px" title="MaxSize" data-index="maxSizeStr" key="maxSizeStr"  align="flex-start" order >
127                </lit-table-column>
128                <lit-table-column width="160px" title="MinSize" data-index="minSizeStr" key="minSizeStr"  align="flex-start" order >
129                </lit-table-column>
130            </lit-table>
131        </div>
132        `;
133  }
134
135  sortByColumn(detail: { key: string; sort: number }): void {
136    this.gpuBoxSource.sort((gpuA, gpuB) => {
137      if (detail.sort === 0) {
138        return gpuA.startTs - gpuB.startTs;
139      } else {
140        let key = detail.key.replace('Str', '');
141        // @ts-ignore
142        let valueA = (gpuA as unknown)[key];
143        // @ts-ignore
144        let valueB = (gpuB as unknown)[key];
145        return detail.sort === 1 ? valueA - valueB : valueB - valueA;
146      }
147    });
148    this.gpuBoxTbl!.recycleDataSource = this.gpuBoxSource;
149  }
150}
151