• 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.js';
17import { LitTable } from '../../../base-ui/table/lit-table.js';
18import { procedurePool } from '../../database/Procedure.js';
19import { info } from '../../../log/Log.js';
20import { LitChartPie } from '../../../base-ui/chart/pie/LitChartPie.js';
21import '../../../base-ui/progress-bar/LitProgressBar.js';
22import { LitProgressBar } from '../../../base-ui/progress-bar/LitProgressBar.js';
23import './TableNoData.js';
24import { TableNoData } from './TableNoData.js';
25
26@element('top20-process-switch-count')
27export class Top20ProcessSwitchCount extends BaseElement {
28  traceChange: boolean = false;
29  private processSwitchCountTbl: LitTable | null | undefined;
30  private processSwitchCountPie: LitChartPie | null | undefined;
31  private processSwitchCountProgress: LitProgressBar | null | undefined;
32  private nodata: TableNoData | null | undefined;
33  private processSwitchCountData: Array<any> = [];
34
35  initElements(): void {
36    this.nodata = this.shadowRoot!.querySelector<TableNoData>('#nodata');
37    this.processSwitchCountProgress = this.shadowRoot!.querySelector<LitProgressBar>('#loading');
38    this.processSwitchCountTbl = this.shadowRoot!.querySelector<LitTable>('#tb-process-switch-count');
39    this.processSwitchCountPie = this.shadowRoot!.querySelector<LitChartPie>('#pie');
40
41    this.processSwitchCountTbl!.addEventListener('row-click', (evt: any) => {
42      let data = evt.detail.data;
43      data.isSelected = true;
44      // @ts-ignore
45      if ((evt.detail as any).callBack) {
46        // @ts-ignore
47        (evt.detail as any).callBack(true);
48      }
49    });
50
51    this.processSwitchCountTbl!.addEventListener('column-click', (evt) => {
52      // @ts-ignore
53      this.sortByColumn(evt.detail);
54    });
55    this.processSwitchCountTbl!.addEventListener('row-hover', (evt: any) => {
56      if (evt.detail.data) {
57        let data = evt.detail.data;
58        data.isHover = true;
59        if ((evt.detail as any).callBack) {
60          (evt.detail as any).callBack(true);
61        }
62      }
63      this.processSwitchCountPie?.showHover();
64    });
65  }
66
67  init() {
68    if (!this.traceChange) {
69      if (this.processSwitchCountTbl!.recycleDataSource.length > 0) {
70        this.processSwitchCountTbl?.reMeauseHeight();
71      }
72      return;
73    }
74    this.traceChange = false;
75    this.processSwitchCountProgress!.loading = true;
76    this.queryLogicWorker('scheduling-Process SwitchCount', 'query Process Switch Count Analysis Time:', (res) => {
77      this.nodata!.noData = res === undefined || res.length === 0;
78      this.processSwitchCountTbl!.recycleDataSource = res;
79      this.processSwitchCountData = res;
80      this.processSwitchCountTbl?.reMeauseHeight();
81      this.processSwitchCountPie!.config = {
82        appendPadding: 10,
83        data: res,
84        angleField: 'switchCount',
85        colorField: 'pid',
86        radius: 0.8,
87        tip: (obj) => {
88          return `<div>
89                             <div>pid:${obj.obj.tid}</div>
90                             <div>p_name:${obj.obj.tName}</div>
91                             <div>sched_switch count:${obj.obj.switchCount}</div>
92                        </div>
93                `;
94        },
95        label: {
96          type: 'outer',
97        },
98        hoverHandler: (data) => {
99          if (data) {
100            this.processSwitchCountTbl!.setCurrentHover(data);
101          } else {
102            this.processSwitchCountTbl!.mouseOut();
103          }
104        },
105        interactions: [
106          {
107            type: 'element-active',
108          },
109        ],
110      };
111      this.processSwitchCountProgress!.loading = false;
112    });
113  }
114
115  clearData() {
116    this.traceChange = true;
117    this.processSwitchCountPie!.dataSource = [];
118    this.processSwitchCountTbl!.recycleDataSource = [];
119  }
120
121  queryLogicWorker(option: string, log: string, handler: (res: any) => void) {
122    let processSwitchCountTime = new Date().getTime();
123    procedurePool.submitWithName('logic1', option, {}, undefined, handler);
124    let durTime = new Date().getTime() - processSwitchCountTime;
125    info(log, durTime);
126  }
127
128  sortByColumn(detail: any) {
129    // @ts-ignore
130    function compare(processSwitchCountProperty, sort, type) {
131      return function (a: any, b: any) {
132        if (type === 'number') {
133          // @ts-ignore
134          return sort === 2
135            ? parseFloat(b[processSwitchCountProperty]) - parseFloat(a[processSwitchCountProperty])
136            : parseFloat(a[processSwitchCountProperty]) - parseFloat(b[processSwitchCountProperty]);
137        } else {
138          if (sort === 2) {
139            return b[processSwitchCountProperty].toString().localeCompare(a[processSwitchCountProperty].toString());
140          } else {
141            return a[processSwitchCountProperty].toString().localeCompare(b[processSwitchCountProperty].toString());
142          }
143        }
144      };
145    }
146
147    if (detail.key === 'NO' || detail.key === 'pid' || detail.key === 'switchCount' || detail.key === 'tid') {
148      this.processSwitchCountData.sort(compare(detail.key, detail.sort, 'number'));
149    } else {
150      this.processSwitchCountData.sort(compare(detail.key, detail.sort, 'string'));
151    }
152    this.processSwitchCountTbl!.recycleDataSource = this.processSwitchCountData;
153  }
154
155  initHtml(): string {
156    return `
157        <style>
158        :host {
159            width: 100%;
160            height: 100%;
161            background-color: var(--dark-background5,#F6F6F6);
162        }
163        .tb_switch_count{
164            flex: 1;
165            overflow: auto ;
166            border-radius: 5px;
167            border: solid 1px var(--dark-border1,#e0e0e0);
168            margin: 15px;
169            padding: 5px 15px
170        }
171        .pie-chart{
172            display: flex;
173            box-sizing: border-box;
174            width: 500px;
175            height: 500px;
176        }
177        .root{
178            width: 100%;
179            height: 100%;
180            display: flex;
181            flex-direction: row;
182            box-sizing: border-box;
183        }
184        </style>
185        <lit-progress-bar id="loading" style="height: 1px;width: 100%" loading></lit-progress-bar>
186        <table-no-data id="nodata" contentHeight="500px">
187        <div class="root">
188            <div style="display: flex;flex-direction: column;align-items: center">
189                <div>Statistics By Sched_Switch Count</div>
190                <lit-chart-pie id="pie" class="pie-chart"></lit-chart-pie>
191            </div>
192            <div class="tb_switch_count" >
193                <lit-table id="tb-process-switch-count" hideDownload style="height: auto">
194                    <lit-table-column width="1fr" title="NO" data-index="NO" key="NO" align="flex-start" order></lit-table-column>
195                    <lit-table-column width="1fr" title="tid" data-index="tid" key="tid" align="flex-start" order></lit-table-column>
196                    <lit-table-column width="1fr" title="t_name" data-index="tName" key="tName" align="flex-start" order></lit-table-column>
197                    <lit-table-column width="1fr" title="pid" data-index="pid" key="pid" align="flex-start" order></lit-table-column>
198                    <lit-table-column width="1fr" title="p_name" data-index="pName" key="pName" align="flex-start" order></lit-table-column>
199                    <lit-table-column width="1fr" title="sched_switch count" data-index="switchCount" key="switchCount" align="flex-start" order></lit-table-column>
200                </lit-table>
201            </div>
202        </div>
203        </table-no-data>
204        `;
205  }
206}
207