• 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 { LitCheckBox } from '../../../base-ui/checkbox/LitCheckBox';
18import '../../../base-ui/checkbox/LitCheckBox';
19import { SpSchedulingAnalysis } from './SpSchedulingAnalysis';
20import { SpStatisticsHttpUtil } from '../../../statistics/util/SpStatisticsHttpUtil';
21import { CheckCpuSettingHtml } from './CheckCpuSetting.html';
22
23export class CpuSetting {
24  cpu: number = 0;
25  big: boolean = false;
26  middle: boolean = true;
27  small: boolean = false;
28}
29
30@element('check-cpu-setting')
31export class CheckCpuSetting extends BaseElement {
32  static mid_cores: number[] = [];
33  static big_cores: number[] = [];
34  static small_cores: number[] = [];
35  static init_setting: boolean = false;
36
37  private table: HTMLDivElement | null | undefined;
38  private setUpload: HTMLDivElement | null | undefined;
39  private listener?: () => void | undefined;
40
41  initElements(): void {
42    this.table = this.shadowRoot!.querySelector<HTMLDivElement>('#tb_cpu_setting');
43    this.setUpload = this.shadowRoot!.querySelector<HTMLDivElement>('#set_upload');
44    this.setUpload!.addEventListener('click', (e) => {
45      SpStatisticsHttpUtil.addOrdinaryVisitAction({
46        event: 'Analysis Upload',
47        action: 'scheduling_analysis',
48      });
49      CheckCpuSetting.init_setting = true;
50      this.listener?.();
51    });
52  }
53
54  set cpuSetListener(listener: () => void | undefined) {
55    this.listener = listener;
56  }
57
58  init() {
59    this.initDefaultSetting();
60    let data: any[] = [];
61    this.table!.innerHTML = '';
62    this.createHeaderDiv();
63    for (let i = 0; i < SpSchedulingAnalysis.cpuCount; i++) {
64      let obj = {
65        cpu: i,
66        // @ts-ignore
67        big: CheckCpuSetting.big_cores.includes(i),
68        // @ts-ignore
69        middle: CheckCpuSetting.mid_cores.includes(i),
70        // @ts-ignore
71        small: CheckCpuSetting.small_cores.includes(i),
72      };
73      data.push(obj);
74      this.createTableLine(obj);
75    }
76  }
77
78  initDefaultSetting() {
79    if (!CheckCpuSetting.init_setting) {
80      CheckCpuSetting.mid_cores = [];
81      CheckCpuSetting.big_cores = [];
82      CheckCpuSetting.small_cores = [];
83      for (let i = 0; i < SpSchedulingAnalysis.cpuCount; i++) {
84        CheckCpuSetting.mid_cores.push(i);
85      }
86    }
87  }
88
89  createTableLine(cpuSetting: CpuSetting) {
90    let div = document.createElement('div');
91    div.className = 'setting_line';
92    div.textContent = cpuSetting.cpu + '';
93    let bigCheckBox: LitCheckBox = new LitCheckBox();
94    bigCheckBox.checked = cpuSetting.big;
95    let midCheckBox: LitCheckBox = new LitCheckBox();
96    midCheckBox.checked = cpuSetting.middle;
97    let smallCheckBox: LitCheckBox = new LitCheckBox();
98    smallCheckBox.checked = cpuSetting.small;
99    bigCheckBox.addEventListener('change', (e) => {
100      midCheckBox.checked = false;
101      smallCheckBox.checked = false;
102      cpuSetting.big = true;
103      CheckCpuSetting.big_cores.push(cpuSetting.cpu);
104      CheckCpuSetting.mid_cores = CheckCpuSetting.mid_cores.filter((it) => it !== cpuSetting.cpu);
105      CheckCpuSetting.small_cores = CheckCpuSetting.small_cores.filter((it) => it !== cpuSetting.cpu);
106    });
107    midCheckBox.addEventListener('change', (e) => {
108      bigCheckBox.checked = false;
109      smallCheckBox.checked = false;
110      cpuSetting.middle = true;
111      CheckCpuSetting.mid_cores.push(cpuSetting.cpu);
112      CheckCpuSetting.big_cores = CheckCpuSetting.big_cores.filter((it) => it !== cpuSetting.cpu);
113      CheckCpuSetting.small_cores = CheckCpuSetting.small_cores.filter((it) => it !== cpuSetting.cpu);
114    });
115    smallCheckBox.addEventListener('change', (e) => {
116      midCheckBox.checked = false;
117      bigCheckBox.checked = false;
118      cpuSetting.small = true;
119      CheckCpuSetting.small_cores.push(cpuSetting.cpu);
120      CheckCpuSetting.mid_cores = CheckCpuSetting.mid_cores.filter((it) => it !== cpuSetting.cpu);
121      CheckCpuSetting.big_cores = CheckCpuSetting.big_cores.filter((it) => it !== cpuSetting.cpu);
122    });
123    this.table?.append(...[div, bigCheckBox, midCheckBox, smallCheckBox]);
124  }
125
126  createHeaderDiv() {
127    let column1 = document.createElement('div');
128    column1.className = 'setting_line';
129    column1.style.fontWeight = 'bold';
130    column1.textContent = 'cpu_id';
131    let column2 = document.createElement('div');
132    column2.className = 'setting_line';
133    column2.style.fontWeight = 'bold';
134    column2.textContent = 'big';
135    let column3 = document.createElement('div');
136    column3.className = 'setting_line';
137    column3.style.fontWeight = 'bold';
138    column3.textContent = 'middle';
139    let column4 = document.createElement('div');
140    column4.className = 'setting_line';
141    column4.style.fontWeight = 'bold';
142    column4.textContent = 'small';
143    this.table?.append(...[column1, column2, column3, column4]);
144  }
145
146  static resetCpuSettings() {
147    CheckCpuSetting.init_setting = false;
148    CheckCpuSetting.big_cores = [];
149    CheckCpuSetting.small_cores = [];
150    CheckCpuSetting.mid_cores = [];
151  }
152
153  initHtml(): string {
154    return CheckCpuSettingHtml;
155  }
156}
157