1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ci 16fb726d48Sopenharmony_ciimport { BaseElement, element } from '../../../base-ui/BaseElement'; 17fb726d48Sopenharmony_ciimport { LitCheckBox } from '../../../base-ui/checkbox/LitCheckBox'; 18fb726d48Sopenharmony_ciimport '../../../base-ui/checkbox/LitCheckBox'; 19fb726d48Sopenharmony_ciimport { SpSchedulingAnalysis } from './SpSchedulingAnalysis'; 20fb726d48Sopenharmony_ciimport { SpStatisticsHttpUtil } from '../../../statistics/util/SpStatisticsHttpUtil'; 21fb726d48Sopenharmony_ciimport { CheckCpuSettingHtml } from './CheckCpuSetting.html'; 22fb726d48Sopenharmony_ci 23fb726d48Sopenharmony_ciexport class CpuSetting { 24fb726d48Sopenharmony_ci cpu: number = 0; 25fb726d48Sopenharmony_ci big: boolean = false; 26fb726d48Sopenharmony_ci middle: boolean = true; 27fb726d48Sopenharmony_ci small: boolean = false; 28fb726d48Sopenharmony_ci} 29fb726d48Sopenharmony_ci 30fb726d48Sopenharmony_ci@element('check-cpu-setting') 31fb726d48Sopenharmony_ciexport class CheckCpuSetting extends BaseElement { 32fb726d48Sopenharmony_ci static mid_cores: number[] = []; 33fb726d48Sopenharmony_ci static big_cores: number[] = []; 34fb726d48Sopenharmony_ci static small_cores: number[] = []; 35fb726d48Sopenharmony_ci static init_setting: boolean = false; 36fb726d48Sopenharmony_ci 37fb726d48Sopenharmony_ci private table: HTMLDivElement | null | undefined; 38fb726d48Sopenharmony_ci private setUpload: HTMLDivElement | null | undefined; 39fb726d48Sopenharmony_ci private listener?: () => void | undefined; 40fb726d48Sopenharmony_ci 41fb726d48Sopenharmony_ci initElements(): void { 42fb726d48Sopenharmony_ci this.table = this.shadowRoot!.querySelector<HTMLDivElement>('#tb_cpu_setting'); 43fb726d48Sopenharmony_ci this.setUpload = this.shadowRoot!.querySelector<HTMLDivElement>('#set_upload'); 44fb726d48Sopenharmony_ci this.setUpload!.addEventListener('click', (): void => { 45fb726d48Sopenharmony_ci SpStatisticsHttpUtil.addOrdinaryVisitAction({ 46fb726d48Sopenharmony_ci event: 'Analysis Upload', 47fb726d48Sopenharmony_ci action: 'scheduling_analysis', 48fb726d48Sopenharmony_ci }); 49fb726d48Sopenharmony_ci CheckCpuSetting.init_setting = true; 50fb726d48Sopenharmony_ci this.listener?.(); 51fb726d48Sopenharmony_ci }); 52fb726d48Sopenharmony_ci } 53fb726d48Sopenharmony_ci 54fb726d48Sopenharmony_ci set cpuSetListener(listener: () => void | undefined) { 55fb726d48Sopenharmony_ci this.listener = listener; 56fb726d48Sopenharmony_ci } 57fb726d48Sopenharmony_ci 58fb726d48Sopenharmony_ci init(): void { 59fb726d48Sopenharmony_ci this.initDefaultSetting(); 60fb726d48Sopenharmony_ci let data: unknown[] = []; 61fb726d48Sopenharmony_ci this.table!.innerHTML = ''; 62fb726d48Sopenharmony_ci this.createHeaderDiv(); 63fb726d48Sopenharmony_ci for (let i = 0; i < SpSchedulingAnalysis.cpuCount; i++) { 64fb726d48Sopenharmony_ci let obj = { 65fb726d48Sopenharmony_ci cpu: i, 66fb726d48Sopenharmony_ci // @ts-ignore 67fb726d48Sopenharmony_ci big: CheckCpuSetting.big_cores.includes(i), 68fb726d48Sopenharmony_ci // @ts-ignore 69fb726d48Sopenharmony_ci middle: CheckCpuSetting.mid_cores.includes(i), 70fb726d48Sopenharmony_ci // @ts-ignore 71fb726d48Sopenharmony_ci small: CheckCpuSetting.small_cores.includes(i), 72fb726d48Sopenharmony_ci }; 73fb726d48Sopenharmony_ci data.push(obj); 74fb726d48Sopenharmony_ci this.createTableLine(obj); 75fb726d48Sopenharmony_ci } 76fb726d48Sopenharmony_ci } 77fb726d48Sopenharmony_ci 78fb726d48Sopenharmony_ci initDefaultSetting(): void { 79fb726d48Sopenharmony_ci if (!CheckCpuSetting.init_setting) { 80fb726d48Sopenharmony_ci CheckCpuSetting.mid_cores = []; 81fb726d48Sopenharmony_ci CheckCpuSetting.big_cores = []; 82fb726d48Sopenharmony_ci CheckCpuSetting.small_cores = []; 83fb726d48Sopenharmony_ci for (let i = 0; i < SpSchedulingAnalysis.cpuCount; i++) { 84fb726d48Sopenharmony_ci CheckCpuSetting.mid_cores.push(i); 85fb726d48Sopenharmony_ci } 86fb726d48Sopenharmony_ci } 87fb726d48Sopenharmony_ci } 88fb726d48Sopenharmony_ci 89fb726d48Sopenharmony_ci createTableLine(cpuSetting: CpuSetting): void { 90fb726d48Sopenharmony_ci let div = document.createElement('div'); 91fb726d48Sopenharmony_ci div.className = 'setting_line'; 92fb726d48Sopenharmony_ci div.textContent = `${cpuSetting.cpu}`; 93fb726d48Sopenharmony_ci let bigCheckBox: LitCheckBox = new LitCheckBox(); 94fb726d48Sopenharmony_ci bigCheckBox.checked = cpuSetting.big; 95fb726d48Sopenharmony_ci let midCheckBox: LitCheckBox = new LitCheckBox(); 96fb726d48Sopenharmony_ci midCheckBox.checked = cpuSetting.middle; 97fb726d48Sopenharmony_ci let smallCheckBox: LitCheckBox = new LitCheckBox(); 98fb726d48Sopenharmony_ci smallCheckBox.checked = cpuSetting.small; 99fb726d48Sopenharmony_ci bigCheckBox.addEventListener('change', (): void => { 100fb726d48Sopenharmony_ci midCheckBox.checked = false; 101fb726d48Sopenharmony_ci smallCheckBox.checked = false; 102fb726d48Sopenharmony_ci cpuSetting.big = true; 103fb726d48Sopenharmony_ci CheckCpuSetting.big_cores.push(cpuSetting.cpu); 104fb726d48Sopenharmony_ci CheckCpuSetting.mid_cores = CheckCpuSetting.mid_cores.filter((it): boolean => it !== cpuSetting.cpu); 105fb726d48Sopenharmony_ci CheckCpuSetting.small_cores = CheckCpuSetting.small_cores.filter((it): boolean => it !== cpuSetting.cpu); 106fb726d48Sopenharmony_ci }); 107fb726d48Sopenharmony_ci midCheckBox.addEventListener('change', (): void => { 108fb726d48Sopenharmony_ci bigCheckBox.checked = false; 109fb726d48Sopenharmony_ci smallCheckBox.checked = false; 110fb726d48Sopenharmony_ci cpuSetting.middle = true; 111fb726d48Sopenharmony_ci CheckCpuSetting.mid_cores.push(cpuSetting.cpu); 112fb726d48Sopenharmony_ci CheckCpuSetting.big_cores = CheckCpuSetting.big_cores.filter((it): boolean => it !== cpuSetting.cpu); 113fb726d48Sopenharmony_ci CheckCpuSetting.small_cores = CheckCpuSetting.small_cores.filter((it): boolean => it !== cpuSetting.cpu); 114fb726d48Sopenharmony_ci }); 115fb726d48Sopenharmony_ci smallCheckBox.addEventListener('change', (): void => { 116fb726d48Sopenharmony_ci midCheckBox.checked = false; 117fb726d48Sopenharmony_ci bigCheckBox.checked = false; 118fb726d48Sopenharmony_ci cpuSetting.small = true; 119fb726d48Sopenharmony_ci CheckCpuSetting.small_cores.push(cpuSetting.cpu); 120fb726d48Sopenharmony_ci CheckCpuSetting.mid_cores = CheckCpuSetting.mid_cores.filter((it): boolean => it !== cpuSetting.cpu); 121fb726d48Sopenharmony_ci CheckCpuSetting.big_cores = CheckCpuSetting.big_cores.filter((it): boolean => it !== cpuSetting.cpu); 122fb726d48Sopenharmony_ci }); 123fb726d48Sopenharmony_ci this.table?.append(...[div, bigCheckBox, midCheckBox, smallCheckBox]); 124fb726d48Sopenharmony_ci } 125fb726d48Sopenharmony_ci 126fb726d48Sopenharmony_ci createHeaderDiv(): void { 127fb726d48Sopenharmony_ci let column1 = document.createElement('div'); 128fb726d48Sopenharmony_ci column1.className = 'setting_line'; 129fb726d48Sopenharmony_ci column1.style.fontWeight = 'bold'; 130fb726d48Sopenharmony_ci column1.textContent = 'cpu_id'; 131fb726d48Sopenharmony_ci let column2 = document.createElement('div'); 132fb726d48Sopenharmony_ci column2.className = 'setting_line'; 133fb726d48Sopenharmony_ci column2.style.fontWeight = 'bold'; 134fb726d48Sopenharmony_ci column2.textContent = 'big'; 135fb726d48Sopenharmony_ci let column3 = document.createElement('div'); 136fb726d48Sopenharmony_ci column3.className = 'setting_line'; 137fb726d48Sopenharmony_ci column3.style.fontWeight = 'bold'; 138fb726d48Sopenharmony_ci column3.textContent = 'middle'; 139fb726d48Sopenharmony_ci let column4 = document.createElement('div'); 140fb726d48Sopenharmony_ci column4.className = 'setting_line'; 141fb726d48Sopenharmony_ci column4.style.fontWeight = 'bold'; 142fb726d48Sopenharmony_ci column4.textContent = 'small'; 143fb726d48Sopenharmony_ci this.table?.append(...[column1, column2, column3, column4]); 144fb726d48Sopenharmony_ci } 145fb726d48Sopenharmony_ci 146fb726d48Sopenharmony_ci static resetCpuSettings(): void { 147fb726d48Sopenharmony_ci CheckCpuSetting.init_setting = false; 148fb726d48Sopenharmony_ci CheckCpuSetting.big_cores = []; 149fb726d48Sopenharmony_ci CheckCpuSetting.small_cores = []; 150fb726d48Sopenharmony_ci CheckCpuSetting.mid_cores = []; 151fb726d48Sopenharmony_ci } 152fb726d48Sopenharmony_ci 153fb726d48Sopenharmony_ci initHtml(): string { 154fb726d48Sopenharmony_ci return CheckCpuSettingHtml; 155fb726d48Sopenharmony_ci } 156fb726d48Sopenharmony_ci} 157