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 './Top20ThreadCpuUsage'; 18fb726d48Sopenharmony_ciimport './Top20ThreadRunTime'; 19fb726d48Sopenharmony_ciimport './Top20ProcessSwitchCount'; 20fb726d48Sopenharmony_ciimport './Top20ProcessThreadCount'; 21fb726d48Sopenharmony_ciimport './Top20FrequencyThread'; 22fb726d48Sopenharmony_ciimport { Top20ThreadCpuUsage } from './Top20ThreadCpuUsage'; 23fb726d48Sopenharmony_ciimport { Top20ThreadRunTime } from './Top20ThreadRunTime'; 24fb726d48Sopenharmony_ciimport { Top20ProcessThreadCount } from './Top20ProcessThreadCount'; 25fb726d48Sopenharmony_ciimport { Top20ProcessSwitchCount } from './Top20ProcessSwitchCount'; 26fb726d48Sopenharmony_ciimport { Top20FrequencyThread } from './Top20FrequencyThread'; 27fb726d48Sopenharmony_ciimport { SpStatisticsHttpUtil } from '../../../statistics/util/SpStatisticsHttpUtil'; 28fb726d48Sopenharmony_ciimport { TabThreadAnalysisHtml } from './TabThreadAnalysis.html'; 29fb726d48Sopenharmony_ci 30fb726d48Sopenharmony_ci@element('tab-thread-analysis') 31fb726d48Sopenharmony_ciexport class TabThreadAnalysis extends BaseElement { 32fb726d48Sopenharmony_ci private currentTabID: string | undefined; 33fb726d48Sopenharmony_ci private currentTab: BaseElement | undefined; 34fb726d48Sopenharmony_ci private contentDiv: HTMLDivElement | null | undefined; 35fb726d48Sopenharmony_ci private tab1: HTMLDivElement | null | undefined; 36fb726d48Sopenharmony_ci private tab2: HTMLDivElement | null | undefined; 37fb726d48Sopenharmony_ci private tab3: HTMLDivElement | null | undefined; 38fb726d48Sopenharmony_ci private tab4: HTMLDivElement | null | undefined; 39fb726d48Sopenharmony_ci private tab5: HTMLDivElement | null | undefined; 40fb726d48Sopenharmony_ci private top20ThreadCpuUsage: Top20ThreadCpuUsage | undefined | null; 41fb726d48Sopenharmony_ci private top20ThreadRunTime: Top20ThreadRunTime | undefined | null; 42fb726d48Sopenharmony_ci private top20ProcessThreadCount: Top20ProcessThreadCount | undefined | null; 43fb726d48Sopenharmony_ci private top20ProcessSwitchCount: Top20ProcessSwitchCount | undefined | null; 44fb726d48Sopenharmony_ci private top20FrequencyThread: Top20FrequencyThread | undefined | null; 45fb726d48Sopenharmony_ci 46fb726d48Sopenharmony_ci initElements(): void { 47fb726d48Sopenharmony_ci this.contentDiv = this.shadowRoot!.querySelector<HTMLDivElement>('#content'); 48fb726d48Sopenharmony_ci this.tab1 = this.shadowRoot!.querySelector<HTMLDivElement>('#tab1'); 49fb726d48Sopenharmony_ci this.tab2 = this.shadowRoot!.querySelector<HTMLDivElement>('#tab2'); 50fb726d48Sopenharmony_ci this.tab3 = this.shadowRoot!.querySelector<HTMLDivElement>('#tab3'); 51fb726d48Sopenharmony_ci this.tab4 = this.shadowRoot!.querySelector<HTMLDivElement>('#tab4'); 52fb726d48Sopenharmony_ci this.tab5 = this.shadowRoot!.querySelector<HTMLDivElement>('#tab5'); 53fb726d48Sopenharmony_ci this.top20ThreadCpuUsage = this.shadowRoot!.querySelector<Top20ThreadCpuUsage>('#top20_thread_cpu_usage'); 54fb726d48Sopenharmony_ci this.top20ThreadRunTime = this.shadowRoot!.querySelector<Top20ThreadRunTime>('#top20_thread_run_time'); 55fb726d48Sopenharmony_ci this.top20ProcessThreadCount = 56fb726d48Sopenharmony_ci this.shadowRoot!.querySelector<Top20ProcessThreadCount>('#top20_process_thread_count'); 57fb726d48Sopenharmony_ci this.top20ProcessSwitchCount = 58fb726d48Sopenharmony_ci this.shadowRoot!.querySelector<Top20ProcessSwitchCount>('#top20_process_switch_count'); 59fb726d48Sopenharmony_ci this.top20FrequencyThread = this.shadowRoot!.querySelector<Top20FrequencyThread>('#top20_frequency_thread'); 60fb726d48Sopenharmony_ci 61fb726d48Sopenharmony_ci this.tab1!.addEventListener('click', (): void => { 62fb726d48Sopenharmony_ci this.setClickTab(this.tab1!, this.top20ThreadCpuUsage!); 63fb726d48Sopenharmony_ci }); 64fb726d48Sopenharmony_ci this.tab2!.addEventListener('click', (): void => { 65fb726d48Sopenharmony_ci this.setClickTab(this.tab2!, this.top20ThreadRunTime!); 66fb726d48Sopenharmony_ci }); 67fb726d48Sopenharmony_ci this.tab3!.addEventListener('click', (): void => { 68fb726d48Sopenharmony_ci this.setClickTab(this.tab3!, this.top20ProcessThreadCount!); 69fb726d48Sopenharmony_ci }); 70fb726d48Sopenharmony_ci this.tab4!.addEventListener('click', (): void => { 71fb726d48Sopenharmony_ci this.setClickTab(this.tab4!, this.top20ProcessSwitchCount!); 72fb726d48Sopenharmony_ci }); 73fb726d48Sopenharmony_ci this.tab5!.addEventListener('click', (): void => { 74fb726d48Sopenharmony_ci this.setClickTab(this.tab5!, this.top20FrequencyThread!); 75fb726d48Sopenharmony_ci }); 76fb726d48Sopenharmony_ci } 77fb726d48Sopenharmony_ci 78fb726d48Sopenharmony_ci init(): void { 79fb726d48Sopenharmony_ci this.top20FrequencyThread!.clearData(); 80fb726d48Sopenharmony_ci this.top20ThreadCpuUsage!.clearData(); 81fb726d48Sopenharmony_ci this.top20ThreadRunTime!.clearData(); 82fb726d48Sopenharmony_ci this.top20ProcessSwitchCount!.clearData(); 83fb726d48Sopenharmony_ci this.top20ProcessThreadCount!.clearData(); 84fb726d48Sopenharmony_ci this.hideCurrentTab(); 85fb726d48Sopenharmony_ci this.currentTabID = undefined; 86fb726d48Sopenharmony_ci this.setClickTab(this.tab1!, this.top20ThreadCpuUsage!, true); 87fb726d48Sopenharmony_ci } 88fb726d48Sopenharmony_ci 89fb726d48Sopenharmony_ci hideCurrentTab(): void { 90fb726d48Sopenharmony_ci if (this.currentTabID) { 91fb726d48Sopenharmony_ci let clickTab = this.shadowRoot!.querySelector<HTMLDivElement>(`#${this.currentTabID}`); 92fb726d48Sopenharmony_ci if (clickTab) { 93fb726d48Sopenharmony_ci clickTab.className = 'tag_bt'; 94fb726d48Sopenharmony_ci } 95fb726d48Sopenharmony_ci } 96fb726d48Sopenharmony_ci if (this.currentTab) { 97fb726d48Sopenharmony_ci this.currentTab.style.display = 'none'; 98fb726d48Sopenharmony_ci } 99fb726d48Sopenharmony_ci } 100fb726d48Sopenharmony_ci 101fb726d48Sopenharmony_ci setClickTab( 102fb726d48Sopenharmony_ci tab: HTMLDivElement, 103fb726d48Sopenharmony_ci showContent: 104fb726d48Sopenharmony_ci | Top20ThreadCpuUsage 105fb726d48Sopenharmony_ci | Top20ThreadRunTime 106fb726d48Sopenharmony_ci | Top20ProcessSwitchCount 107fb726d48Sopenharmony_ci | Top20ProcessThreadCount 108fb726d48Sopenharmony_ci | Top20FrequencyThread, 109fb726d48Sopenharmony_ci isInit: boolean = false 110fb726d48Sopenharmony_ci ): void { 111fb726d48Sopenharmony_ci if (!isInit) { 112fb726d48Sopenharmony_ci let event = showContent.id 113fb726d48Sopenharmony_ci .replace(/_/g, ' ') 114fb726d48Sopenharmony_ci .toLowerCase() 115fb726d48Sopenharmony_ci .replace(/( |^)[a-z]/g, (L: string) => L.toUpperCase()); 116fb726d48Sopenharmony_ci SpStatisticsHttpUtil.addOrdinaryVisitAction({ 117fb726d48Sopenharmony_ci event: event, 118fb726d48Sopenharmony_ci action: 'scheduling_analysis', 119fb726d48Sopenharmony_ci }); 120fb726d48Sopenharmony_ci } 121fb726d48Sopenharmony_ci if (this.currentTabID) { 122fb726d48Sopenharmony_ci let clickTab = this.shadowRoot!.querySelector<HTMLDivElement>(`#${this.currentTabID}`); 123fb726d48Sopenharmony_ci if (clickTab) { 124fb726d48Sopenharmony_ci clickTab.className = 'tag_bt'; 125fb726d48Sopenharmony_ci } 126fb726d48Sopenharmony_ci } 127fb726d48Sopenharmony_ci tab.className = 'tab_click'; 128fb726d48Sopenharmony_ci if (tab.id !== this.currentTabID) { 129fb726d48Sopenharmony_ci this.currentTabID = tab.id; 130fb726d48Sopenharmony_ci if (this.currentTab) { 131fb726d48Sopenharmony_ci this.currentTab.style.display = 'none'; 132fb726d48Sopenharmony_ci } 133fb726d48Sopenharmony_ci this.currentTab = showContent; 134fb726d48Sopenharmony_ci showContent.style.display = 'inline'; 135fb726d48Sopenharmony_ci showContent.init(); 136fb726d48Sopenharmony_ci } 137fb726d48Sopenharmony_ci } 138fb726d48Sopenharmony_ci 139fb726d48Sopenharmony_ci initHtml(): string { 140fb726d48Sopenharmony_ci return TabThreadAnalysisHtml; 141fb726d48Sopenharmony_ci } 142fb726d48Sopenharmony_ci} 143