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 './TabThreadAnalysis'; 18import './TabCpuAnalysis'; 19import { TabCpuAnalysis } from './TabCpuAnalysis'; 20import { TabThreadAnalysis } from './TabThreadAnalysis'; 21import { LitTabs } from '../../../base-ui/tabs/lit-tabs'; 22import { CheckCpuSetting } from './CheckCpuSetting'; 23import { Top20FrequencyThread } from './Top20FrequencyThread'; 24import { procedurePool } from '../../database/Procedure'; 25import { Utils } from '../trace/base/Utils'; 26 27@element('sp-scheduling-analysis') 28export class SpSchedulingAnalysis extends BaseElement { 29 static traceChange: boolean = false; 30 static cpuCount: number = 0; 31 static startTs: number = 0; 32 static endTs: number = 0; 33 static totalDur: number = 0; 34 private tabs: LitTabs | null | undefined; 35 private tabCpuAnalysis: TabCpuAnalysis | null | undefined; 36 private tabThreadAnalysis: TabThreadAnalysis | null | undefined; 37 38 initElements(): void { 39 this.tabs = this.shadowRoot?.querySelector<LitTabs>('#tabs'); 40 this.tabCpuAnalysis = this.shadowRoot?.querySelector<TabCpuAnalysis>('#cpu-analysis'); 41 this.tabThreadAnalysis = this.shadowRoot?.querySelector<TabThreadAnalysis>('#thread-analysis'); 42 } 43 44 static resetCpu(): void { 45 SpSchedulingAnalysis.traceChange = true; 46 CheckCpuSetting.resetCpuSettings(); 47 Top20FrequencyThread.threads = undefined; 48 procedurePool.submitWithName('logic0', 'scheduling-clearData', {}, undefined, (res: unknown): void => {}); 49 } 50 51 init(): void { 52 if (SpSchedulingAnalysis.traceChange) { 53 SpSchedulingAnalysis.traceChange = false; 54 this.tabs!.activekey = '1'; //@ts-ignore 55 SpSchedulingAnalysis.startTs = (window as unknown).recordStartNS; //@ts-ignore 56 SpSchedulingAnalysis.endTs = (window as unknown).recordEndNS; 57 SpSchedulingAnalysis.totalDur = SpSchedulingAnalysis.endTs - SpSchedulingAnalysis.startTs; //@ts-ignore 58 SpSchedulingAnalysis.cpuCount = Utils.getInstance().getWinCpuCount(); 59 this.tabCpuAnalysis?.init(); 60 this.tabThreadAnalysis?.init(); 61 } 62 } 63 64 initHtml(): string { 65 return ` 66 <style> 67 .content{ 68 display: flex; 69 flex-direction: column; 70 background-color: var(--dark-background5,#F6F6F6); 71 position: absolute; 72 width: 100%; 73 height: 100%; 74 top: 0; 75 bottom: 0; 76 left: 0; 77 right: 0; 78 } 79 #tabs{ 80 width: 100%; 81 height: calc(100% - 55px); 82 background-color: var(--dark-background,#FFFFFF); 83 } 84 :host { 85 width: 100%; 86 height: 100%; 87 background: var(--dark-background5,#F6F6F6); 88 } 89 .interval{ 90 height: 55px; 91 width: 100%; 92 background-color: var(--dark-background,#FFFFFF); 93 } 94 </style> 95 <div class="content"> 96 <div class="interval"></div> 97 <lit-tabs id="tabs" position="top-left" activekey="1" mode="card"> 98 <lit-tabpane key="1" tab="CPU Data"> 99 <tab-cpu-analysis id="cpu-analysis"></tab-cpu-analysis> 100 </lit-tabpane> 101 <lit-tabpane key="2" tab="Thread Analysis"> 102 <tab-thread-analysis id="thread-analysis"></tab-thread-analysis> 103 </lit-tabpane> 104 </lit-tabs> 105 </div> 106 `; 107 } 108} 109