/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import {BaseElement, element} from "../../../base-ui/BaseElement.js"; @element('sp-allocations') export class SpAllocations extends BaseElement { private processId: HTMLInputElement | null | undefined; private unwindEL: HTMLInputElement | null | undefined; private shareMemory: HTMLInputElement | null | undefined; private shareMemoryUnit: HTMLSelectElement | null | undefined; private filterMemory: HTMLInputElement | null | undefined; private filterMemoryUnit: HTMLSelectElement | null | undefined; get pid(): number { return Number(this.processId!.value) || -1; } get unwind(): number { return Number(this.unwindEL!.value) || 10; } get shared(): number { let value = this.shareMemory?.value || ""; if (value != "") { let unit = this.shareMemoryUnit?.value || ""; return this.convertToValue(value, unit); } return 1024; } get filter(): number { let value = this.filterMemory?.value || ""; if (value != "") { let unit = this.filterMemoryUnit?.value || ""; return this.convertToValue(value, unit); } return 0; } initElements(): void { this.processId = this.shadowRoot?.getElementById("pid") as HTMLInputElement this.unwindEL = this.shadowRoot?.getElementById("unwind") as HTMLInputElement this.shareMemory = this.shadowRoot?.getElementById("shareMemory") as HTMLInputElement this.shareMemoryUnit = this.shadowRoot?.getElementById("shareMemoryUnit") as HTMLSelectElement this.filterMemory = this.shadowRoot?.getElementById("filterSized") as HTMLInputElement this.filterMemoryUnit = this.shadowRoot?.getElementById("filterSizedUnit") as HTMLSelectElement } initHtml(): string { return `
Allocations
Process Identifier :
Max unwind level :
Shared Memory Size :
Filter Memory Size :
`; } private convertToValue(input: string, unit: string): number { let value: number; switch (unit) { case "MB": value = Number(input) * 1024 * 1024; break; case "KB": value = Number(input) * 1024; break; default: value = 0; } let number = value / 4096; if (number > 0 && number < 1) { return 1; } return parseInt(String(number)); } }