• 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 '../../../base-ui/select/LitAllocationSelect';
18
19import '../../../base-ui/switch/lit-switch';
20import { LitAllocationSelect } from '../../../base-ui/select/LitAllocationSelect';
21import { SpRecordTrace } from '../SpRecordTrace';
22import { Cmd } from '../../../command/Cmd';
23import { LitRadioBox } from '../../../base-ui/radiobox/LitRadioBox';
24import { SpCheckDesBox } from './SpCheckDesBox';
25import LitSwitch from '../../../base-ui/switch/lit-switch';
26import { SpApplication } from '../../SpApplication';
27import { SpArkTsHtml } from './SpArkTs.html';
28
29@element('sp-ark-ts')
30export class SpArkTs extends BaseElement {
31  private processInput: LitAllocationSelect | undefined | null;
32  private spCheckDesBox: SpCheckDesBox | undefined | null;
33  private radioBox: LitRadioBox | undefined | null;
34  private interval: HTMLInputElement | undefined | null;
35  private memorySwitch: LitSwitch | undefined | null;
36  private cpuSwitch: LitSwitch | undefined | null;
37  private litSwitch: LitSwitch | undefined | null;
38
39  set startSamp(jsHeapStart: boolean) {
40    if (jsHeapStart) {
41      this.setAttribute('startSamp', '');
42    } else {
43      this.removeAttribute('startSamp');
44    }
45  }
46
47  get startSamp(): boolean {
48    return this.hasAttribute('startSamp');
49  }
50
51  get process(): string {
52    if (this.processInput!.value.length > 0) {
53      return this.processInput!.value;
54    }
55    return '';
56  }
57
58  get radioBoxType(): number {
59    let memorySwitch = this.shadowRoot?.querySelector('#memory-switch');
60    let type: string;
61    if (memorySwitch!.getAttribute('checked') !== null) {
62      this.radioBox = this.shadowRoot?.querySelector('lit-radio[checked]');
63      type = this.radioBox?.getAttribute('type') || '';
64    } else {
65      type = '-1';
66    }
67    return Number(type);
68  }
69
70  get grabNumeric(): boolean {
71    if (this.radioBoxType === 0) {
72      this.spCheckDesBox = this.shadowRoot?.querySelector('#snapshot');
73      let isChecked = this.spCheckDesBox?.getAttribute('checked');
74      return isChecked === 'true';
75    } else {
76      return false;
77    }
78  }
79
80  get grabAllocations(): boolean {
81    if (this.radioBoxType === 1) {
82      this.spCheckDesBox = this.shadowRoot?.querySelector('#timeline');
83      let isChecked = this.spCheckDesBox?.getAttribute('checked');
84      return isChecked === 'true';
85    } else {
86      return false;
87    }
88  }
89
90  get intervalValue(): number {
91    if (this.radioBoxType === 0) {
92      return Number(this.interval!.value);
93    } else {
94      return 0;
95    }
96  }
97
98  get grabCpuProfiler(): boolean {
99    let isChecked = this.cpuSwitch?.getAttribute('checked');
100    return isChecked !== null;
101  }
102
103  get intervalCpuValue(): number {
104    let interval = this.shadowRoot?.querySelector<HTMLInputElement>('#cpuInterval');
105    if (interval) {
106      return Number(interval!.value);
107    } else {
108      return 0;
109    }
110  }
111
112  initElements(): void {
113    this.interval = this.shadowRoot?.querySelector('#interval');
114    this.processInput = this.shadowRoot?.querySelector<LitAllocationSelect>('lit-allocation-select');
115    let processInput = this.processInput?.shadowRoot?.querySelector('.multipleSelect') as HTMLDivElement;
116    this.cpuSwitch = this.shadowRoot?.querySelector('#cpu-switch') as LitSwitch;
117    processInput!.addEventListener('mousedown', () => {
118      if (SpRecordTrace.serialNumber === '') {
119        this.processInput!.processData = [];
120        this.processInput!.initData();
121      }
122    });
123    processInput!.addEventListener('mouseup', () => {
124      if (SpRecordTrace.serialNumber === '') {
125        this.processInput!.processData = [];
126        this.processInput!.initData();
127      } else {
128        Cmd.getDebugProcess().then((processList) => {
129          this.processInput!.processData = processList;
130          this.processInput!.initData();
131        });
132      }
133    });
134    this.litSwitch = this.shadowRoot?.querySelector('lit-switch') as LitSwitch;
135    this.memorySwitch = this.shadowRoot?.querySelector('#memory-switch') as LitSwitch;
136    this.cpuSwitch = this.shadowRoot?.querySelector('#cpu-switch') as LitSwitch;
137    this.disable();
138    this.memoryDisable();
139  }
140
141  intervalFocusoutHandler = (): void => {
142    if (this.interval!.value === '') {
143      this.interval!.value = '10';
144    }
145  };
146
147  litSwitchChangeHandler = (event: Event): void => {
148    // @ts-ignore
149    let detail = event.detail;
150    if (detail.checked) {
151      this.unDisable();
152      this.unMemoryDisable();
153    } else {
154      this.disable();
155      this.memoryDisable();
156    }
157  };
158
159  memorySwitchChangeHandler = (event: Event): void => {
160    // @ts-ignore
161    let detail = event.detail;
162    if (detail.checked) {
163      this.unMemoryDisable();
164    } else {
165      if (!this.cpuSwitch?.checked) {
166        this.litSwitch!.checked = false;
167        this.disable();
168      }
169      this.memoryDisable();
170    }
171  };
172
173  cpuSwitchChangeHandler = (event: Event): void => {
174    // @ts-ignore
175    let detail = event.detail;
176    let interval = this.shadowRoot?.querySelectorAll<HTMLInputElement>('#cpuInterval');
177    if (!detail.checked && !this.memorySwitch?.checked) {
178      this.litSwitch!.checked = false;
179      this.disable();
180    } else if (detail.checked) {
181      interval!.forEach((item) => {
182        item.disabled = false;
183        item.style.background = 'var(--dark-background5,#FFFFFF)';
184      });
185    } else {
186      interval!.forEach((item) => {
187        item.disabled = true;
188        item.style.color = '#b7b7b7';
189        item.style.background = 'var(--dark-background1,#f5f5f5)';
190      });
191      this.litSwitch!.checked = true;
192      this.startSamp = true;
193    }
194  };
195
196  private memoryDisable(): void {
197    let interval = this.shadowRoot?.querySelectorAll<HTMLInputElement>('#interval');
198    interval!.forEach((item) => {
199      item.disabled = true;
200      item.style.color = '#b7b7b7';
201      item.style.background = 'var(--dark-background1,#f5f5f5)';
202    });
203    let radioBoxes = this.shadowRoot?.querySelectorAll<LitRadioBox>('lit-radio');
204    radioBoxes!.forEach((item) => {
205      item.disabled = true;
206    });
207    let checkBoxes = this.shadowRoot?.querySelectorAll<SpCheckDesBox>('check-des-box');
208    checkBoxes!.forEach((item) => {
209      item.disabled = true;
210    });
211  }
212
213  private unMemoryDisable(): void {
214    let interval = this.shadowRoot?.querySelectorAll<HTMLInputElement>('#interval');
215    interval!.forEach((item) => {
216      item.disabled = false;
217      item.style.background = 'var(--dark-background5,#FFFFFF)';
218    });
219    let radioBoxes = this.shadowRoot?.querySelectorAll<LitRadioBox>('lit-radio');
220    radioBoxes!.forEach((item) => {
221      item.disabled = false;
222    });
223    let checkBoxes = this.shadowRoot?.querySelectorAll<SpCheckDesBox>('check-des-box');
224    checkBoxes!.forEach((item) => {
225      item.disabled = false;
226    });
227  }
228
229  private disable(): void {
230    this.startSamp = false;
231    this.processInput!.setAttribute('disabled', '');
232    let heapConfigs = this.shadowRoot?.querySelectorAll<HTMLInputElement>('.select');
233    heapConfigs!.forEach((item) => {
234      item.disabled = true;
235    });
236    let switches = this.shadowRoot?.querySelectorAll<LitSwitch>('.switch');
237    switches!.forEach((item) => {
238      item.disabled = true;
239      item.checked = false;
240    });
241    let interval = this.shadowRoot?.querySelectorAll<HTMLInputElement>('.inputstyle');
242    interval!.forEach((item) => {
243      item.disabled = true;
244      item.style.color = '#b7b7b7';
245      item.style.background = 'var(--dark-background1,#f5f5f5)';
246    });
247  }
248
249  private unDisable(): void {
250    this.startSamp = true;
251    this.processInput!.removeAttribute('disabled');
252    let heapConfigs = this.shadowRoot?.querySelectorAll<HTMLInputElement>('.select');
253    heapConfigs!.forEach((item) => {
254      item.disabled = false;
255    });
256    let switches = this.shadowRoot?.querySelectorAll<LitSwitch>('.switch');
257    switches!.forEach((item) => {
258      item.disabled = false;
259      item.checked = true;
260    });
261    let interval = this.shadowRoot?.querySelectorAll<HTMLInputElement>('.inputstyle');
262    interval!.forEach((item) => {
263      item.disabled = false;
264      item.style.background = 'var(--dark-background5,#FFFFFF)';
265    });
266  }
267
268  connectedCallback(): void {
269    let traceMode = this.shadowRoot!.querySelector('#traceMode') as HTMLDivElement;
270    let isLongTrace = SpApplication.isLongTrace;
271    if (isLongTrace) {
272      traceMode!.style.display = 'block';
273    } else {
274      traceMode!.style.display = 'none';
275    }
276    this.interval!.addEventListener('focusout', this.intervalFocusoutHandler);
277    this.litSwitch!.addEventListener('change', this.litSwitchChangeHandler);
278    this.memorySwitch!.addEventListener('change', this.memorySwitchChangeHandler);
279    this.cpuSwitch!.addEventListener('change', this.cpuSwitchChangeHandler);
280  }
281
282  disconnectedCallback(): void {
283    super.disconnectedCallback();
284    this.interval!.removeEventListener('focusout', this.intervalFocusoutHandler);
285    this.litSwitch!.removeEventListener('change', this.litSwitchChangeHandler);
286    this.memorySwitch!.removeEventListener('change', this.memorySwitchChangeHandler);
287    this.cpuSwitch!.removeEventListener('change', this.cpuSwitchChangeHandler);
288  }
289
290  initHtml(): string {
291    return SpArkTsHtml;
292  }
293}
294