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