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 { LitMainMenuGroup } from '../../base-ui/menu/LitMainMenuGroup'; 18import { LitMainMenu, MenuItem } from '../../base-ui/menu/LitMainMenu'; 19import { LitMainMenuItem } from '../../base-ui/menu/LitMainMenuItem'; 20import { SpStatisticsHttpUtil } from '../../statistics/util/SpStatisticsHttpUtil'; 21 22@element('sp-help') 23export class SpHelp extends BaseElement { 24 private appContent: HTMLElement | undefined | null; 25 26 get dark() { 27 return this.hasAttribute('dark'); 28 } 29 30 set dark(dark: boolean) { 31 if (dark) { 32 this.setAttribute('dark', `${dark}`); 33 } else { 34 this.removeAttribute('dark'); 35 } 36 this.appContent!.innerHTML = 37 '<object type="text/html" data=' + 38 `/application/doc/quickstart_device_record.html?${dark} width="100%" height="100%"></object>`; 39 } 40 41 initElements(): void { 42 let that = this; 43 let parentElement = this.parentNode as HTMLElement; 44 parentElement.style.overflow = 'hidden'; 45 this.appContent = this.shadowRoot?.querySelector('#app-content') as HTMLElement; 46 let mainMenu = this.shadowRoot?.querySelector('#main-menu') as LitMainMenu; 47 let header = mainMenu.shadowRoot?.querySelector('.header') as HTMLDivElement; 48 let color = mainMenu.shadowRoot?.querySelector('.customColor') as HTMLDivElement; 49 let version = mainMenu.shadowRoot?.querySelector('.version') as HTMLDivElement; 50 color.style.display = 'none'; 51 header.style.display = 'none'; 52 version.style.display = 'none'; 53 this.setupMainMenu(mainMenu, that); 54 mainMenu.style.width = '330px'; 55 let body = mainMenu.shadowRoot?.querySelector('.menu-body') as HTMLDivElement; 56 let groups = body.querySelectorAll<LitMainMenuGroup>('lit-main-menu-group'); 57 groups.forEach((value) => { 58 let items = value.querySelectorAll<LitMainMenuItem>('lit-main-menu-item'); 59 items.forEach((item) => { 60 item.style.width = '330px'; 61 }); 62 if (value.title == 'TraceStreamer') { 63 let items = value.querySelectorAll<LitMainMenuItem>('lit-main-menu-item'); 64 items.forEach((i) => { 65 if (i.title != 'TraceStreamer数据库说明') { 66 i.style.display = 'none'; 67 } 68 }); 69 } 70 if (value.title == 'SmartPerf') { 71 value.style.display = 'none'; 72 } 73 }); 74 } 75 76 private setupMainMenu(mainMenu: LitMainMenu, that: this): void { 77 mainMenu.menus = [ 78 { 79 collapsed: false, 80 title: 'QuickStart', 81 second: false, 82 icon: 'caret-down', 83 describe: '', 84 children: [ 85 this.setupCaptureAndImportMenu(that), 86 this.setupMemoryMenu(that), 87 this.setupNativeMenu(that), 88 this.setupTsMenu(that), 89 this.setupAnalysisTemplateMenu(that), 90 this.setupFileMenu(that), 91 this.setupOtherMenu(that), 92 ], 93 }, 94 { 95 collapsed: false, 96 title: 'TraceStreamer', 97 second: false, 98 icon: 'caret-down', 99 describe: '', 100 children: [ 101 this.setupDatabaseMenu(that), 102 this.setupCompileMenu(that), 103 this.setupAnalysisMenu(that), 104 this.setupEventListMenu(that), 105 this.setupToolDescriptionMenu(that), 106 this.setupBinderMenu(that), 107 this.setupWakeUpMenu(that), 108 ], 109 }, 110 { 111 collapsed: false, 112 title: 'SmartPerf', 113 second: false, 114 icon: 'caret-down', 115 describe: '', 116 children: [ 117 this.setupSmartPerfMenu(that), 118 ], 119 }, 120 ]; 121 } 122 123 private setupCaptureAndImportMenu(that: this) { 124 return { 125 collapsed: false, 126 title: '抓取和导入', 127 describe: '', 128 second: true, 129 icon: 'caret-down', 130 children: [ 131 { 132 title: '设备端抓取trace说明', 133 icon: '', 134 clickHandler: function (item: MenuItem) { 135 that.handleMemoryMenuItemClick(that, 'record', 'quickstart_device_record'); 136 }, 137 }, 138 { 139 title: 'web端抓取trace说明', 140 icon: '', 141 clickHandler: function (item: MenuItem) { 142 that.handleMemoryMenuItemClick(that, 'online_record', 'quickstart_web_record'); 143 }, 144 }, 145 { 146 title: 'web端加载trace说明', 147 icon: '', 148 clickHandler: function (item: MenuItem) { 149 that.handleMemoryMenuItemClick(that, 'load', 'quickstart_systemtrace'); 150 }, 151 }, 152 ], 153 }; 154 } 155 156 private setupOtherMenu(that: this) { 157 return { 158 collapsed: false, 159 title: '其他', 160 describe: '', 161 icon: 'caret-down', 162 second: true, 163 children: this.setupOtherMenuItems(that), 164 }; 165 } 166 private setupOtherMenuItems(that: this): MenuItem[] { 167 return [ 168 this.createSubMenuItem('Sql分析和Metrics说明', 'sql', 'quickstart_sql_metrics', that), 169 this.createSubMenuItem('HiSystemEvent抓取和展示说明', 'hisys', 'quickstart_hisystemevent', that), 170 this.createSubMenuItem('sdk抓取和展示说明', 'sdk_record', 'quickstart_sdk', that), 171 this.createSubMenuItem('调用栈可视化和不同库函数调用占比说明', 'import_so', 'quickstart_Import_so', that), 172 this.createSubMenuItem('Hilog抓取和展示说明', 'hilog', 'quickstart_hilog', that), 173 this.createSubMenuItem('Ability Monitor抓取和展示说明', 'ability', 'quickstart_ability_monitor', that), 174 this.createSubMenuItem('Trace解析能力增强', 'trace_parsing', 'quickstart_parsing_ability', that), 175 this.createSubMenuItem('应用操作技巧', 'operation_skills', 'quickstart_Application_operation_skills', that), 176 this.createSubMenuItem('快捷键说明', 'keywords_shortcuts', 'quickstart_keywords_shortcuts', that), 177 ]; 178 } 179 180 private createSubMenuItem(title: string, event: string, docName: string, that: this): MenuItem { 181 return { 182 title: title, 183 icon: '', 184 clickHandler: (item: MenuItem) => { 185 that.handleMemoryMenuItemClick(that, event, docName); 186 }, 187 }; 188 } 189 190 191 private setupMemoryMenu(that: this) { 192 return { 193 collapsed: false, 194 title: '内存', 195 describe: '', 196 icon: 'caret-down', 197 second: true, 198 children: [ 199 { 200 title: 'Js Memory抓取和展示说明', 201 icon: '', 202 clickHandler: function (item: MenuItem) { 203 that.handleMemoryMenuItemClick(that, 'js_memory', 'quickstart_Js_memory'); 204 }, 205 }, 206 { 207 title: 'Native Memory抓取和展示说明', 208 icon: '', 209 clickHandler: function (item: MenuItem) { 210 that.handleMemoryMenuItemClick(that, 'native', 'quickstart_native_memory'); 211 }, 212 }, 213 { 214 title: '页内存抓取和展示说明', 215 icon: '', 216 clickHandler: function (item: MenuItem) { 217 that.handleMemoryMenuItemClick(that, 'virtual_memory', 'quickstart_page_fault'); 218 }, 219 }, 220 { 221 title: '系统内存抓取和展示说明', 222 icon: '', 223 clickHandler: function (item: MenuItem) { 224 that.handleMemoryMenuItemClick(that, 'memory_template', 'quickstart_memory_template'); 225 }, 226 }, 227 ], 228 }; 229 } 230 231 private handleMemoryMenuItemClick(that: this, event: string, docName: string): void { 232 SpStatisticsHttpUtil.addOrdinaryVisitAction({ 233 event: event, 234 action: 'help_doc', 235 }); 236 that.appContent!.innerHTML = 237 `<object type="text/html" data='/application/doc/${docName}.html?${that.dark}' width="100%" height="100%"></object>`; 238 } 239 240 private setupNativeMenu(that: this) { 241 return { 242 collapsed: false, 243 title: 'Native栈', 244 describe: '', 245 second: true, 246 icon: 'caret-down', 247 children: [ 248 { 249 title: 'HiPerf的抓取和展示说明', 250 icon: '', 251 clickHandler: function (item: MenuItem) { 252 that.handleMemoryMenuItemClick(that, 'perf', 'quickstart_hiperf'); 253 }, 254 }, 255 ], 256 } 257 } 258 259 private setupTsMenu(that: this) { 260 return { 261 collapsed: false, 262 title: 'TS栈', 263 describe: '', 264 second: true, 265 icon: 'caret-down', 266 children: [ 267 { 268 title: 'Cpuprofiler抓取和展示说明', 269 icon: '', 270 clickHandler: function (item: MenuItem) { 271 that.handleMemoryMenuItemClick(that, 'arkts', 'quickstart_arkts'); 272 }, 273 }, 274 ], 275 } 276 } 277 278 private setupAnalysisTemplateMenu(that: this) { 279 return { 280 collapsed: false, 281 title: '分析模板', 282 describe: '', 283 second: true, 284 icon: 'caret-down', 285 children: [ 286 { 287 title: 'Frame timeline抓取和展示说明', 288 icon: '', 289 clickHandler: function (item: MenuItem) { 290 that.handleMemoryMenuItemClick(that, 'frame_record', 'quickstart_Frametimeline'); 291 }, 292 }, 293 { 294 title: 'Animation的抓取和展示说明', 295 icon: '', 296 clickHandler: function (item: MenuItem) { 297 that.handleMemoryMenuItemClick(that, 'animation', 'quickstart_animation'); 298 }, 299 }, 300 { 301 title: 'TaskPool抓取和展示说明', 302 icon: '', 303 clickHandler: function (item: MenuItem) { 304 that.handleMemoryMenuItemClick(that, 'taskpool', 'quickstart_taskpool'); 305 }, 306 }, 307 { 308 title: 'App startup的抓取和展示说明', 309 icon: '', 310 clickHandler: function (item: MenuItem) { 311 that.handleMemoryMenuItemClick(that, 'app_startup', 'quickstart_app_startup'); 312 }, 313 }, 314 { 315 title: 'Scheduling analysis抓取和展示说明', 316 icon: '', 317 clickHandler: function (item: MenuItem) { 318 that.handleMemoryMenuItemClick(that, 'scheduling_record', 'quickstart_schedulinganalysis'); 319 }, 320 }, 321 ], 322 } 323 } 324 325 private setupFileMenu(that: this) { 326 return { 327 collapsed: false, 328 title: '文件', 329 describe: '', 330 second: true, 331 icon: 'caret-down', 332 children: [ 333 { 334 title: 'FileSystem抓取和展示说明', 335 icon: '', 336 clickHandler: function (item: MenuItem) { 337 that.handleMemoryMenuItemClick(that, 'file_system', 'quickstart_filesystem'); 338 }, 339 }, 340 { 341 title: 'Bio抓取和展示说明', 342 icon: '', 343 clickHandler: function (item: MenuItem) { 344 that.handleMemoryMenuItemClick(that, 'bio', 'quickstart_bio'); 345 }, 346 }, 347 ], 348 } 349 } 350 351 private setupDatabaseMenu(that: this) { 352 return { 353 title: 'TraceStreamer数据库说明', 354 icon: '', 355 clickHandler: function (item: MenuItem) { 356 that.handleMemoryMenuItemClick(that, 'trace_streamer_explain', 'des_tables'); 357 }, 358 }; 359 } 360 361 private setupCompileMenu(that: this) { 362 return { 363 title: '编译Trace_streamer', 364 icon: '', 365 clickHandler: function (item: MenuItem) { 366 that.handleMemoryMenuItemClick(that, 'trace_streamer_compile', 'compile_trace_streamer'); 367 }, 368 }; 369 } 370 371 private setupAnalysisMenu(that: this) { 372 return { 373 title: 'TraceStreamer 解析数据状态表', 374 icon: '', 375 clickHandler: function (item: MenuItem) { 376 that.handleMemoryMenuItemClick(that, 'trace_streamer_des', 'des_stat'); 377 }, 378 }; 379 } 380 381 private setupSmartPerfMenu(that: this) { 382 return { 383 title: 'SmartPerf 编译指导', 384 icon: '', 385 clickHandler: function (item: MenuItem) { 386 that.handleMemoryMenuItemClick(that, 'smartperf_guide', 'quickstart_smartperflinux_compile_guide'); 387 }, 388 }; 389 } 390 391 private setupEventListMenu(that: this) { 392 return { 393 title: 'TraceStreamer支持解析事件列表', 394 icon: '', 395 clickHandler: function (item: MenuItem) { 396 that.handleMemoryMenuItemClick(that, 'support_event', 'des_support_event'); 397 }, 398 } 399 } 400 401 private setupToolDescriptionMenu(that: this) { 402 return { 403 title: 'trace_streamer工具说明', 404 icon: '', 405 clickHandler: function (item: MenuItem) { 406 that.handleMemoryMenuItemClick(that, 'quickstart_trace_streamer', 'quickstart_trace_streamer'); 407 }, 408 }; 409 } 410 411 private setupBinderMenu(that: this) { 412 return { 413 title: 'binder事件上下文如何关联', 414 icon: '', 415 clickHandler: function (item: MenuItem) { 416 that.handleMemoryMenuItemClick(that, 'binder', 'des_binder'); 417 }, 418 }; 419 } 420 421 private setupWakeUpMenu(that: this) { 422 return { 423 title: 'wakeup唤醒说明', 424 icon: '', 425 clickHandler: function (item: MenuItem) { 426 that.handleMemoryMenuItemClick(that, 'wakeup', 'des_wakup'); 427 }, 428 }; 429 } 430 431 initHtml(): string { 432 return ` 433 <style> 434 .sp-help-vessel { 435 min-height: 100%; 436 display: grid; 437 grid-template-columns: 1fr; 438 grid-template-rows:1fr; 439 background-color: var(--dark-background5,#F6F6F6); 440 } 441 :host{ 442 width: 100%; 443 display: block; 444 height: 100%; 445 background-color: var(--dark-background5,#F6F6F6); 446 } 447 .body{ 448 width: 90%; 449 margin-left: 3%; 450 margin-top: 2%; 451 margin-bottom: 2%; 452 display: grid; 453 grid-template-columns: min-content 1fr; 454 background-color: var(--dark-background3,#FFFFFF); 455 border-radius: 16px 16px 16px 16px; 456 } 457 458 .content{ 459 background: var(--dark-background3,#FFFFFF); 460 border-style: none none none solid; 461 border-width: 1px; 462 border-color: rgba(166,164,164,0.2); 463 border-radius: 0px 16px 16px 0px; 464 padding: 40px 20px 40px 20px; 465 display: flex; 466 } 467 468 </style> 469 <div class="sp-help-vessel"> 470 <div class="body"> 471 <lit-main-menu id="main-menu" class="menugroup" data=''></lit-main-menu> 472 <div id="app-content" class="content"> 473 </div> 474 </div> 475 </div> 476 `; 477 } 478} 479