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.js"; 17import {log} from "../../../log/Log.js"; 18import {HdcDeviceManager} from "../../../hdc/HdcDeviceManager.js"; 19import {LitAllocationSelect} from "../../../base-ui/select/LitAllocationSelect.js"; 20import "../../../base-ui/select/LitAllocationSelect.js"; 21import {SpApplication} from "../../SpApplication.js"; 22import {LitSearch} from "../trace/search/Search.js"; 23import {SpRecordTrace} from "../SpRecordTrace.js"; 24import {Cmd} from "../../../command/Cmd.js"; 25import {CmdConstant} from "../../../command/CmdConstant.js"; 26import LitSwitch from "../../../base-ui/switch/lit-switch.js"; 27 28@element('sp-allocations') 29export class SpAllocations extends BaseElement { 30 private processId: LitAllocationSelect | null | undefined; 31 private unwindEL: HTMLInputElement | null | undefined; 32 private shareMemory: HTMLInputElement | null | undefined; 33 private shareMemoryUnit: HTMLSelectElement | null | undefined; 34 private filterMemory: HTMLInputElement | null | undefined; 35 private filterMemoryUnit: HTMLSelectElement | null | undefined; 36 private fpUnWind: LitSwitch | null | undefined; 37 38 get appProcess(): string { 39 return this.processId!.value || ""; 40 } 41 42 get unwind(): number { 43 log("unwind value is :" + this.unwindEL!.value) 44 return Number(this.unwindEL!.value); 45 } 46 47 get shared(): number { 48 let value = this.shareMemory?.value || ""; 49 log("shareMemory value is :" + value) 50 if (value != "") { 51 let unit = Number(this.shareMemory?.value) || 16384; 52 return unit; 53 } 54 return 16384; 55 } 56 57 get filter(): number { 58 let value = this.filterMemory?.value || ""; 59 log("filter value is :" + value) 60 if (value != "") { 61 return Number(value); 62 } 63 return 4096; 64 } 65 66 get fp_unwind(): boolean { 67 let value = this.fpUnWind?.checked 68 if (value != undefined) { 69 return value; 70 } 71 return true 72 } 73 74 initElements(): void { 75 this.processId = this.shadowRoot?.getElementById("pid") as LitAllocationSelect 76 let input = this.processId.shadowRoot?.querySelector('.multipleSelect') as HTMLDivElement 77 let sp = document.querySelector("sp-application") as SpApplication; 78 let litSearch = sp?.shadowRoot?.querySelector('#lit-search') as LitSearch; 79 let processData: Array<string> = [] 80 input.addEventListener('mousedown', ev => { 81 if (SpRecordTrace.serialNumber == '') { 82 this.processId!.processData = [] 83 } 84 }) 85 input.addEventListener('valuable', ev => { 86 this.dispatchEvent(new CustomEvent('addProbe', {})); 87 }) 88 input.addEventListener('inputClick', () => { 89 processData = [] 90 if (SpRecordTrace.serialNumber != '') { 91 if (SpRecordTrace.isVscode) { 92 let cmd = Cmd.formatString(CmdConstant.CMD_GET_PROCESS_DEVICES, [SpRecordTrace.serialNumber]) 93 Cmd.execHdcCmd(cmd, (res: string) => { 94 let lineValues: string[] = res.replace(/\r\n/g, "\r").replace(/\n/g, "\r").split(/\r/); 95 for (let lineVal of lineValues) { 96 if (lineVal.indexOf("__progname") != -1 || lineVal.indexOf("PID CMD") != -1) { 97 continue; 98 } 99 let process: string[] = lineVal.trim().split(" "); 100 if (process.length == 2) { 101 let processId = process[0] 102 let processName = process[1] 103 processData.push(processName + "(" + processId + ")") 104 } 105 } 106 this.processId!.processData = processData 107 this.processId!.initData() 108 }) 109 } else { 110 HdcDeviceManager.connect(SpRecordTrace.serialNumber).then(rr => { 111 if (sp.search) { 112 sp.search = false; 113 litSearch.clear(); 114 } 115 if (rr) { 116 HdcDeviceManager.shellResultAsString(CmdConstant.CMD_GET_PROCESS, false).then(res => { 117 if (res) { 118 let lineValues: string[] = res.replace(/\r\n/g, "\r").replace(/\n/g, "\r").split(/\r/); 119 for (let lineVal of lineValues) { 120 if (lineVal.indexOf("__progname") != -1 || lineVal.indexOf("PID CMD") != -1) { 121 continue; 122 } 123 let process: string[] = lineVal.trim().split(" "); 124 if (process.length == 2) { 125 let processId = process[0] 126 let processName = process[1] 127 processData.push(processName + "(" + processId + ")") 128 } 129 } 130 } 131 this.processId!.processData = processData 132 this.processId!.initData() 133 }) 134 } else { 135 sp.search = true; 136 litSearch.clear(); 137 litSearch.setPercent("please kill other hdc-server! ", -1); 138 } 139 }) 140 } 141 } 142 }) 143 this.unwindEL = this.shadowRoot?.getElementById("unwind") as HTMLInputElement 144 this.shareMemory = this.shadowRoot?.getElementById("shareMemory") as HTMLInputElement 145 this.shareMemoryUnit = this.shadowRoot?.getElementById("shareMemoryUnit") as HTMLSelectElement 146 this.filterMemory = this.shadowRoot?.getElementById("filterSized") as HTMLInputElement 147 this.filterMemoryUnit = this.shadowRoot?.getElementById("filterSizedUnit") as HTMLSelectElement 148 this.fpUnWind = this.shadowRoot?.getElementById("use_fp_unwind") as LitSwitch 149 } 150 151 initHtml(): string { 152 return ` 153 <style> 154 :host{ 155 display: block; 156 width: 100%; 157 height: 100%; 158 border-radius: 0px 16px 16px 0px; 159 } 160 .root { 161 display: grid; 162 grid-template-columns: repeat(2, 1fr); 163 grid-template-rows: min-content 1fr min-content; 164 padding-top: 45px; 165 margin-left: 40px; 166 width: 90%; 167 border-radius: 0px 16px 16px 0px; 168 } 169 .title { 170 grid-column: span 2 / auto; 171 } 172 173 .font-style{ 174 font-family: Helvetica-Bold; 175 font-size: 1em; 176 color: var(--dark-color1,#000000); 177 line-height: 28px; 178 font-weight: 700; 179 } 180 .inner-font-style { 181 font-family: Helvetica,serif; 182 font-size: 1em; 183 color: var(--dark-color1,#000000); 184 text-align: left; 185 line-height: 20px; 186 font-weight: 400; 187 } 188 input { 189 width: 72%; 190 height: 25px; 191 border:0; 192 outline:none; 193 border-radius: 16px; 194 text-indent:2% 195 } 196 input::-webkit-input-placeholder{ 197 color:var(--bark-prompt,#999999); 198 } 199 .select { 200 height: 30px; 201 border:0; 202 border-radius: 3px; 203 outline:none; 204 border: 1px solid var(--dark-border,#B3B3B3); 205 width: 60px; 206 background-color:var(--dark-background5, #FFFFFF) 207 font-family: Helvetica; 208 font-size: 14px; 209 color:var(--dark-color,#212121) 210 text-align: center; 211 line-height: 16px; 212 font-weight: 400; 213 border-radius: 16px; 214 } 215 .application{ 216 display: flex; 217 flex-direction: column; 218 grid-gap: 15px; 219 margin-top: 40px; 220 } 221 .switchstyle{ 222 margin-top: 40px; 223 display: flex; 224 } 225 #fp-unwind { 226 display:flex; 227 width:25%; 228 margin-top: 3px; 229 } 230 .inputstyle{ 231 background: var(--dark-background5,#FFFFFF); 232 border: 1px solid var(--dark-background5,#999999); 233 font-family: Helvetica; 234 font-size: 14px; 235 color: var(--dark-color1,#212121); 236 text-align: left; 237 line-height: 16px; 238 font-weight: 400; 239 } 240 .inputstyle::-webkit-input-placeholder { 241 background: var(--dark-background5,#FFFFFF); 242 } 243 #one_mb{ 244 background-color:var(--dark-background5, #FFFFFF) 245 } 246 #one_kb{ 247 background-color:var(--dark-background5, #FFFFFF) 248 } 249 #two_mb{ 250 background-color:var(--dark-background5, #FFFFFF) 251 } 252 #two_kb{ 253 background-color:var(--dark-background5, #FFFFFF) 254 } 255 .processSelect { 256 border-radius: 15px; 257 width: 84%; 258 } 259 </style> 260 <div class="root"> 261 <div class = "title"> 262 <span class="font-style">Native Memory</span> 263 </div> 264 <div class="application"> 265 <span class="inner-font-style">ProcessId or ProcessName :</span> 266 <lit-allocation-select show-search class="processSelect" rounded default-value="" id="pid" placement="bottom" title="process" placeholder="please select process"> 267 </lit-allocation-select> 268 </div> 269 <div class="application"> 270 <span class="inner-font-style" >Max unwind level :</span> 271 <input id= "unwind" class="inputstyle" type="text" placeholder="Enter the Max Unwind Level" oninput="if(this.value > 30) this.value = '30'" onkeyup="this.value=this.value.replace(/\\D/g,'')" value="10"> 272 </div> 273 <div class="application"> 274 <span class="inner-font-style">Shared Memory Size (One page equals 4 KB) :</span> 275 <div> 276 <input id = "shareMemory" class="inputstyle" type="text" placeholder="Enter the Shared Memory Size" oninput="if(this.value > 2147483647) this.value = ''" onkeyup="this.value=this.value.replace(/\\D/g,'')" value="16384"> 277 <span>Page</span> 278 </div> 279 </div> 280 <div class="application"> 281 <span class="inner-font-style" >Filter Memory Size :</span> 282 <div> 283 <input id = "filterSized" class="inputstyle" type="text" placeholder="Enter the Filter Memory Size" oninput="if(this.value > 65535) this.value = ''" onkeyup="this.value=this.value.replace(/\\\\D/g,'')" value="4096"> 284 <span>Byte</span> 285 </div> 286 </div> 287 <div class="switchstyle"> 288 <span class="inner-font-style" id="fp-unwind">Use Fp Unwind :</span> 289 <lit-switch id="use_fp_unwind" title="fp unwind" checked="true"></lit-switch> 290 </div> 291 </div> 292 `; 293 } 294 295 private convertToValue(input: string, unit: string): number { 296 let value: number; 297 switch (unit) { 298 case "MB": 299 value = Number(input) * 1024 * 1024; 300 break; 301 case "KB": 302 value = Number(input) * 1024; 303 break; 304 default: 305 value = 0; 306 } 307 let number = value / 4096; 308 if (number > 0 && number < 1) { 309 return 16384; 310 } 311 return parseInt(String(number)); 312 } 313}