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