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 {checkDesBean, SpCheckDesBox} from "./SpCheckDesBox.js"; 18import {LitCheckBox} from "../../../base-ui/checkbox/LitCheckBox.js"; 19import {LitRadioGroup} from "../../../base-ui/radiobox/LitRadioGroup.js"; 20import {info, log} from "../../../log/Log.js"; 21 22@element('probes-config') 23export class SpProbesConfig extends BaseElement { 24 private traceConfigList: Array<checkDesBean> | undefined 25 private memoryConfigList: Array<checkDesBean> | undefined 26 private hitraceConfigList: Array<any> | undefined; 27 private hitrace: SpCheckDesBox | undefined 28 29 private _traceConfig: HTMLElement | undefined; 30 private _memoryConfig: HTMLElement | undefined | null; 31 32 get traceConfig() { 33 let selectedTrace = this._traceConfig?.querySelectorAll<SpCheckDesBox>(`check-des-box[checked]`) || []; 34 let values = [] 35 for (const litCheckBoxElement of selectedTrace) { 36 values.push(litCheckBoxElement.value) 37 } 38 if (this.hitrace && this.hitrace.checked) { 39 values.push(this.hitrace.value) 40 } 41 info("traceConfig is :", values) 42 return values; 43 } 44 45 get memoryConfig() { 46 let values = [] 47 let selectedMemory = this._memoryConfig?.querySelectorAll<SpCheckDesBox>(`check-des-box[checked]`) as NodeListOf<SpCheckDesBox> 48 for (const litCheckBoxElement of selectedMemory) { 49 values.push(litCheckBoxElement.value) 50 } 51 log("memoryConfig size is :" + values.length) 52 return values 53 } 54 55 get traceEvents() { 56 let values = [] 57 if (this.hitrace && this.hitrace.checked) { 58 let parent = this.shadowRoot?.querySelector('.user-events') as Element 59 const siblingNode = parent?.querySelectorAll<LitCheckBox>(`lit-check-box[name=userEvents][checked]`); 60 for (const litCheckBoxElement of siblingNode) { 61 values.push(litCheckBoxElement.value) 62 } 63 } 64 log("traceEvents size is :" + values.length) 65 return values; 66 } 67 68 get hilogConfig() { 69 let logLevel = this.shadowRoot?.getElementById('logLevel') as LitCheckBox; 70 if (logLevel.checked) { 71 let logRadio = this.shadowRoot?.getElementById('log-radio') as LitRadioGroup; 72 return logRadio.value; 73 } else { 74 return [] 75 } 76 } 77 78 initElements(): void { 79 this.traceConfigList = [ 80 {value: 'Scheduling details', isSelect: false, des: "enables high-detailed tracking of scheduling events"}, 81 { 82 value: "CPU Frequency and idle states", isSelect: false, 83 des: "Records cpu frequency and idle state change viaftrace" 84 }, 85 { 86 value: "Advanced ftrace config", isSelect: false, 87 des: "Enable individual events and tune the kernel-tracng(ftrace) module." 88 + "The events enabled here are in addition to those from" 89 + " enabled by other probes." 90 }, 91 { 92 value: "AbilityMonitor", 93 isSelect: false, 94 des: "Tracks the AbilityMonitor" 95 }, 96 { 97 value: "HiSystemEvent", 98 isSelect: false, 99 des: "Tracks the HiSystemEvent" 100 }] 101 this._traceConfig = this.shadowRoot?.querySelector(".trace-config") as HTMLElement 102 this.traceConfigList.forEach(configBean => { 103 let checkDesBox = new SpCheckDesBox(); 104 checkDesBox.value = configBean.value; 105 checkDesBox.checked = configBean.isSelect; 106 checkDesBox.des = configBean.des; 107 checkDesBox.addEventListener("onchange", (ev: any) => { 108 this.dispatchEvent(new CustomEvent('addProbe', {})); 109 }) 110 this._traceConfig?.appendChild(checkDesBox) 111 }) 112 this.memoryConfigList = [ 113 {value: 'Kernel meminfo', isSelect: false, des: "polling of /proc/meminfo"}, 114 { 115 value: 'Virtual memory stats', 116 isSelect: false, 117 des: "Periodically polls virtual memory stats from /proc/vmstat." 118 + " Allows to gather statistics about swap," 119 + "eviction, compression and pagecache efficiency" 120 }] 121 this._memoryConfig = this.shadowRoot?.querySelector(".memory-config") 122 this.memoryConfigList.forEach(configBean => { 123 let checkDesBox = new SpCheckDesBox(); 124 checkDesBox.value = configBean.value; 125 checkDesBox.checked = configBean.isSelect; 126 checkDesBox.des = configBean.des; 127 checkDesBox.addEventListener("onchange", (ev: any) => { 128 this.dispatchEvent(new CustomEvent('addProbe', {})); 129 }) 130 this._memoryConfig?.appendChild(checkDesBox) 131 }) 132 this.hitraceConfigList = ["ability", "ace", "app", "ark", "binder", "disk", "distributeddatamgr" 133 , "dsoftbus", "freq", "graphic", "i2c", "idle", "irq", "mdfs", "memory", "memreclaim", "misc", "mmc", 134 "msdp", "multimodalinput", "notification", "ohos", "pagecache", "regulators", "rpc", "sched", "sensors", "sync" 135 , "window", "workq", "zaudio", "zcamera", "zimage", "zmedia"] 136 this.hitrace = this.shadowRoot?.getElementById("hitrace") as SpCheckDesBox 137 let parent = this.shadowRoot?.querySelector('.user-events') as Element 138 this.hitraceConfigList?.forEach(value => { 139 let litCheckBox = new LitCheckBox(); 140 litCheckBox.setAttribute("name", "userEvents") 141 litCheckBox.value = value; 142 litCheckBox.addEventListener("change", (ev: any) => { 143 let detail = ev.detail; 144 if (this.hitrace?.checked == false) { 145 this.hitrace.checked = detail.checked 146 } 147 if (detail.checked == false && this.hitrace?.checked == true) { 148 let hasChecked = false; 149 const nodes = parent?.querySelectorAll<LitCheckBox>(`lit-check-box[name=userEvents]`); 150 nodes.forEach(vv => { 151 if (vv.checked) { 152 hasChecked = true; 153 } 154 }) 155 if (!hasChecked) { 156 this.hitrace.checked = hasChecked 157 } 158 } 159 this.dispatchEvent(new CustomEvent('addProbe', {})); 160 }) 161 parent.append(litCheckBox) 162 }) 163 } 164 165 initHtml(): string { 166 return ` 167 <style> 168 :host{ 169 display: inline-block; 170 width: 100%; 171 height: 100%; 172 background: var(--dark-background3,#FFFFFF); 173 border-radius: 0px 16px 16px 0px; 174 } 175 176 .root { 177 padding-top: 30px; 178 padding-left: 54px; 179 margin-right: 30px; 180 font-size:16px; 181 margin-bottom: 30px; 182 } 183 .recordText { 184 font-family: Helvetica-Bold; 185 font-size: 1em; 186 color: var(--dark-color1,#000000); 187 line-height: 28px; 188 font-weight: 700; 189 margin-bottom: 20px; 190 } 191 192 .config-page { 193 height: 95%; 194 font-size: 0.875em; 195 } 196 197 .trace-config{ 198 display: grid; 199 grid-template-columns: repeat(2, 1fr); 200 gap: 10px; 201 margin-bottom: 20px; 202 } 203 204 .memory-config{ 205 display: grid; 206 grid-template-columns: repeat(2, 1fr); 207 border-style: solid none none none; 208 border-color: #D5D5D5; 209 padding-top: 15px; 210 margin-top: 15px; 211 gap: 10px; 212 } 213 214 .span-col-2{ 215 grid-column: span 2 / auto; 216 } 217 218 .log-config{ 219 display: grid; 220 grid-template-columns: repeat(2, 1fr); 221 border-style: solid none none none; 222 border-color: #D5D5D5; 223 padding-top: 15px; 224 gap: 10px; 225 } 226 227 #hitrace-cat{ 228 display: grid; 229 grid-template-columns: 1fr 1fr; 230 } 231 .user-events{ 232 display: grid; 233 grid-template-columns: repeat(4, 1fr); 234 grid-template-rows: repeat(2, 1fr); 235 gap: 10px; 236 margin-left: 15px;; 237 } 238 </style> 239 <div class="root"> 240 <div class="recordText" >Record mode</div> 241 <div class="config-page"> 242 <div> 243 <div class="trace-config"></div> 244 <div class="span-col-2" id="hitrace-cat"> 245 <check-des-box id="hitrace" value ="Hitrace categories" des="Enables C++ codebase annotations (HTRACE_BEGIN() / os.Trace())"> 246 </check-des-box> 247 <div class="user-events"> 248 <slot></slot> 249 </div> 250 </div> 251 </div> 252 <div class="memory-config"> 253 <div class="span-col-2"> 254 <span>Memory Config</span> 255 </div> 256 </div> 257 </div> 258 </div> 259 `; 260 } 261 262 //当 custom element首次被插入文档DOM时,被调用。 263 public connectedCallback() { 264 let parent = this.shadowRoot?.querySelector('.user-events') as Element 265 const siblingNode = parent?.querySelectorAll<LitCheckBox>(`lit-check-box[name=userEvents]`); 266 this.hitrace!.addEventListener('onchange', (ev: any) => { 267 let detail = ev.detail; 268 siblingNode.forEach(node => { 269 node.checked = detail.checked 270 }) 271 this.dispatchEvent(new CustomEvent('addProbe', {})); 272 }) 273 } 274}