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