1 /* 2 * Copyright (c) 2021 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 16 package ohos.devtools.views.layout; 17 18 import com.intellij.openapi.ui.ComboBox; 19 import com.intellij.openapi.util.IconLoader; 20 import com.intellij.ui.JBColor; 21 import com.intellij.ui.components.JBCheckBox; 22 import com.intellij.ui.components.JBLabel; 23 import com.intellij.ui.components.JBPanel; 24 import com.intellij.ui.components.JBRadioButton; 25 import com.intellij.ui.components.JBScrollPane; 26 import com.intellij.ui.components.JBTabbedPane; 27 import java.awt.BorderLayout; 28 import java.awt.Color; 29 import java.awt.Cursor; 30 import java.awt.Dimension; 31 import java.awt.Font; 32 import java.awt.Toolkit; 33 import java.awt.datatransfer.Clipboard; 34 import java.awt.datatransfer.ClipboardOwner; 35 import java.awt.datatransfer.StringSelection; 36 import java.awt.datatransfer.Transferable; 37 import java.awt.event.ActionEvent; 38 import java.awt.event.ActionListener; 39 import java.awt.event.ItemEvent; 40 import java.awt.event.ItemListener; 41 import java.awt.event.MouseAdapter; 42 import java.awt.event.MouseEvent; 43 import java.awt.event.MouseListener; 44 import java.text.SimpleDateFormat; 45 import java.util.ArrayList; 46 import java.util.Arrays; 47 import java.util.Date; 48 import java.util.List; 49 import java.util.Locale; 50 import java.util.Objects; 51 import java.util.Optional; 52 import java.util.Vector; 53 import java.util.concurrent.CompletableFuture; 54 import javax.swing.BorderFactory; 55 import javax.swing.ButtonGroup; 56 import javax.swing.DefaultComboBoxModel; 57 import javax.swing.JButton; 58 import javax.swing.JScrollPane; 59 import javax.swing.JSeparator; 60 import javax.swing.JSlider; 61 import javax.swing.JTextArea; 62 import javax.swing.SwingUtilities; 63 import javax.swing.event.ChangeEvent; 64 import javax.swing.event.ChangeListener; 65 import net.miginfocom.swing.MigLayout; 66 import ohos.devtools.datasources.transport.grpc.SystemTraceHelper; 67 import ohos.devtools.datasources.utils.common.GrpcException; 68 import ohos.devtools.datasources.utils.device.entity.DeviceIPPortInfo; 69 import ohos.devtools.datasources.utils.device.entity.DeviceType; 70 import ohos.devtools.datasources.utils.device.service.MultiDeviceManager; 71 import ohos.devtools.datasources.utils.profilerlog.ProfilerLogManager; 72 import ohos.devtools.datasources.utils.quartzmanager.QuartzManager; 73 import ohos.devtools.services.systemconfig.SystemConfigData; 74 import ohos.devtools.views.common.ColorConstants; 75 import ohos.devtools.views.common.LayoutConstants; 76 import ohos.devtools.views.common.UtConstant; 77 import ohos.devtools.views.layout.dialog.SampleDialog; 78 import ohos.devtools.views.layout.dialog.TraceRecordDialog; 79 import ohos.devtools.views.layout.utils.EventTrackUtils; 80 import ohos.devtools.views.trace.util.Utils; 81 import org.apache.logging.log4j.LogManager; 82 import org.apache.logging.log4j.Logger; 83 84 85 import static ohos.devtools.views.common.Constant.DEVICE_REFRESH; 86 87 /** 88 * SystemConfigPanel 89 * 90 * @since : 2021/10/25 91 */ 92 public class SystemConfigPanel extends JBPanel implements MouseListener, ItemListener, ClipboardOwner { 93 private static final Logger LOGGER = LogManager.getLogger(SystemConfigPanel.class); 94 private static final String IDLE_EVENT = "power"; 95 private static final String SCHED_FREQ_EVENT = "sched"; 96 private static final String HTRACE_AUDIO_STR = "Audio"; 97 private static final String HTRACE_CAMERA_STR = "Camera"; 98 private static final String HTRACE_DATABASE_STR = "Database"; 99 private static final String HTRACE_GRAPHICS_STR = "Graphics"; 100 private static final String HTRACE_INPUT_STR = "Input"; 101 private static final String HTRACE_NETWORK_STR = "NetWork"; 102 private static final String HTRACE_VIDEO_STR = "Video"; 103 private static final String LAST_STEP_BTN = "Last Step"; 104 private static final String START_TASK_BTN = "Start Task"; 105 private static final String SCENE_TITLE_STR = "Device"; 106 private static final String SCENE_TITLE_DES_STR = "Task scene: Connected devices"; 107 private static final String CONFIG_TITLE_STR = "Trace config & Probes"; 108 private static final String CONFIG_TITLE_DES_STR = "Task scene: System tuning"; 109 private static final String TRACE_CONFIG_TITLE_STR = "Trace config"; 110 private static final String PROBES_TITLE_STR = "Probes"; 111 private static final String RECORD_MODEL_STR = "Record Mode"; 112 private static final String MEMORY_CONFIG_STR = "Memory Config"; 113 private static final String KERNEL_MEMORY = "Kernel meminfo"; 114 private static final String VIRTUAL_MEMORY = "Virtual memory stats"; 115 private static final String LOG_LEVEL_CHECKBOX = "Log level"; 116 private static final String LOG_LEVEL_CHECKBOX_DEC = "Set log level"; 117 private static final String HILOG_CONFIG_STR = "hilog Config"; 118 private static final String HILOG_CONFIG_ERROR = "Error"; 119 private static final String HILOG_CONFIG_INFO = "Info"; 120 private static final String HILOG_CONFIG_DEBUG = "Debug"; 121 private static final String HILOG_CONFIG_WARN = "Warn"; 122 private static final String SCHEDULING_STR = "Scheduling details"; 123 private static final String SCHEDULING_DES_STR = "Enables high-detailed tracking of scheduling events"; 124 private static final String CPU_FREQUENCY_STR = "CPU Frequency and idle states"; 125 private static final String CPU_FREQUENCY_DES_STR = "Records cpu frequency and idle state change viaftrace"; 126 private static final String BOARD_STR = "Board voltages & frequency"; 127 private static final String BOARD_DES_STR = "Tracks voltage and frequency changes from board sensors"; 128 private static final String TRACE_CONFIG_MODE_STR = "Record Mode"; 129 private static final String TRACE_CONFIG_MODE_BUTTON_STR = "Stop when full"; 130 private static final String BUFFER_SIZE_TITLE_STR = "In-memory buffer size:"; 131 private static final String DURATION_TITLE_STR = "Max duration:"; 132 private static final String HIGH_FREQUENCY_STR = "High frequency memory"; 133 private static final String HIGH_FREQUENCY_DES_STR = "<html>Allows to track short memory splikes and transitories " 134 + "through ftrace's mm_event. rss_stat and ion events." 135 + " Available only on recent Kernel version >= 4.19" 136 + "</html>"; 137 private static final String HTRACE_USERSPACE_STR = "Bytrace categories"; 138 private static final String HTRACE_USERSPACE_DES_STR = "<html>" 139 + "Enables C++ / Java codebase annotations " 140 + "(HTRACE_BEGIN() / os.Trace())" + "</html>"; 141 private static final String SYSCALLS_STR = "Syscalls"; 142 private static final String SYSCALLS_DES_STR = "Tracks the enter and exit of all syscalls"; 143 private static final String ADVANCED_CONFIG_STR = "Advanced ftrace config"; 144 private static final String ADVANCED_CONFIG_DES_STR = "<html>" 145 + "Enable individual events and tune the kernel-tracng(ftrace) module." 146 + "The events enabled here are in addition to those from" 147 + " enabled by other probes." + "</html>"; 148 private static final String LOW_MEMORY_DES_STR = "<html>" 149 + "Record LMK events. Works both with the old in kernel LMK and" 150 + "the newer userspace Imkd. It also tracks OOM score adjustments " 151 + "</html>"; 152 private static final String RECORD_SETTING_STR = "<html>" 153 + "<p style=\"margin-left:28px;font-size:13px;text-align:left;color:white;\">Record Setting</p>" 154 + "<p style=\"margin-top:0px;margin-left:28px;font-size:9px;text-align:left;color:#757784;\">" 155 + "Buffer mode.size and duration</p>" 156 + "</html>"; 157 private static final String TRACE_COMMAND_STR = "<html>" 158 + "<p style=\"margin-left:8px;font-size:13px;text-align:left;color:white;\">Trace Command</p>" 159 + "<p style=\"margin-top:0px;margin-left:8px;font-size:9px;text-align:left;color:#757784;\">" 160 + "Manually record trace</p>" 161 + "</html>"; 162 private static final String PROBES_CPU_STR = "<html>" 163 + "<p style=\"font-size:13px;text-align:left;color:white;\">probes config</p>" 164 + "<p style=\"margin-top:0px;font-size:9px;text-align:left;color:#757784;\">CPU usage,scheduling" 165 + "<br>wakeups</p>" 166 + "</html>"; 167 private static final String VIRTUAL_MEMOYR_STR = "<html>" 168 + "Periodically polls virtual memory stats from /proc/vmstat." 169 + " Allows to gather statistics about swap," 170 + "eviction, compression and pagecache efficiency" 171 + "</html>"; 172 private static final String MEMOYR_STR = "<html>" 173 + "Polling of /proc/meminfo" 174 + "</html>"; 175 private static final String FULL_HOS_DEVICE_PATH = "cd /data/local/tmp/developtools"; 176 private static final String EXPORT_TO_LIBRARY_PATH = "export LD_LIBRARY_PATH=$PWD"; 177 private static final String TRACE_COMMAND_CHECK_HIPROFILER = 178 "if [ `ps -ef | grep hiprofilerd | grep -v grep | wc -l` -eq 0 ]; then"; 179 private static final String SLEEP = "sleep 1"; 180 private static final String EOF = "fi"; 181 private static final String TRACE_COMMAND_CHECK_HIPROFILER_PLUGINS = 182 "if [ `ps -ef | grep hiprofiler_plugins | grep -v grep | wc -l` -eq 0 ]; then"; 183 private static final String START_HIPROFILER = "./hiprofilerd & >> /dev/null"; 184 private static final String START_STD_HIPROFILER = "hiprofilerd & >> /dev/null"; 185 private static final String START_HIPROFILER_PLUGINS = "./hiprofiler_plugins & >> /dev/null"; 186 private static final String START_STD_HIPROFILER_PLUGINS = "hiprofiler_plugins & >> /dev/null"; 187 private static final String TRACE_COMMAND_HEAD = "./hiprofiler_cmd -c "; 188 private static final String TRACE_STD_COMMAND_HEAD = "hiprofiler_cmd -c "; 189 190 private static final String TRACE_COMMAND_END = "/data/local/tmp/hiprofiler_data"; 191 private static final String JUDGE_STD_HIPROFILER_RESULT = 192 TRACE_COMMAND_CHECK_HIPROFILER.concat(System.lineSeparator()) 193 .concat(START_STD_HIPROFILER).concat(System.lineSeparator()) 194 .concat(SLEEP).concat(System.lineSeparator()).concat(EOF); 195 private static final String JUDGE_STD_HIPROFILER_PLUGIN_RESULT = 196 TRACE_COMMAND_CHECK_HIPROFILER_PLUGINS.concat(System.lineSeparator()) 197 .concat(START_STD_HIPROFILER_PLUGINS).concat(System.lineSeparator()) 198 .concat(SLEEP).concat(System.lineSeparator()).concat(EOF); 199 private static final String JUDGE_HIPROFILER_RESULT = 200 TRACE_COMMAND_CHECK_HIPROFILER.concat(System.lineSeparator()) 201 .concat(START_HIPROFILER).concat(System.lineSeparator()) 202 .concat(SLEEP).concat(System.lineSeparator()).concat(EOF); 203 private static final String JUDGE_HIPROFILER_PLUGIN_RESULT = 204 TRACE_COMMAND_CHECK_HIPROFILER_PLUGINS.concat(System.lineSeparator()) 205 .concat(START_HIPROFILER_PLUGINS).concat(System.lineSeparator()) 206 .concat(SLEEP).concat(System.lineSeparator()).concat(EOF); 207 208 JSeparator separator = new JSeparator(); 209 JSeparator memorySeparator = new JSeparator(); 210 JSeparator hilogSeparator = new JSeparator(); 211 ButtonGroup hilogButtonGroup = new ButtonGroup(); 212 213 ArrayList<String> schedulingEvents = new ArrayList<String>(Arrays.asList( 214 "sched/sched_switch", 215 "power/suspend_resume", 216 "sched/sched_wakeup", 217 "sched/sched_wakeup_new", 218 "sched/sched_waking", 219 "sched/sched_process_exit", 220 "sched/sched_process_free", 221 "task/task_newtask", 222 "task/task_rename")); 223 ArrayList<String> powerEvents = new ArrayList<String>(Arrays.asList( 224 "regulator/regulator_set_voltage", 225 "regulator/regulator_set_voltage_complete", 226 "power/clock_enable", 227 "power/clock_disable", 228 "power/clock_set_rate", 229 "power/suspend_resume")); 230 231 ArrayList<String> cpuFreqEvents = new ArrayList<String>(Arrays.asList( 232 "power/cpu_frequency", 233 "power/cpu_idle", 234 "power/suspend_resume" 235 )); 236 ArrayList<String> sysCallsEvents = new ArrayList<String>(Arrays.asList( 237 "raw_syscalls/sys_enter", 238 "raw_syscalls/sys_exit" 239 )); 240 ArrayList<String> highFrequencyEvents = new ArrayList<String>(Arrays.asList( 241 "mm_event/mm_event_record", 242 "kmem/rss_stat", 243 "ion/ion_stat", 244 "dmabuf_heap/dma_heap_stat", 245 "kmem/ion_heap_grow", 246 "kmem/ion_heap_shrink" 247 )); 248 ArrayList<String> advancedConfigEvents = new ArrayList<String>(Arrays.asList( 249 "sched/sched_switch", 250 "sched/sched_wakeup", 251 "sched/sched_wakeup_new", 252 "sched/sched_waking", 253 "sched/sched_process_exit", 254 "sched/sched_process_free", 255 "irq/irq_handler_entry", 256 "irq/irq_handler_exit", 257 "irq/softirq_entry", 258 "irq/softirq_exit", 259 "irq/softirq_raise", 260 "power/clock_disable", 261 "power/clock_enable", 262 "power/clock_set_rate", 263 "power/cpu_frequency", 264 "power/cpu_idle", 265 "clk/clk_disable", 266 "clk/clk_disable_complete", 267 "clk/clk_enable", 268 "clk/clk_enable_complete", 269 "clk/clk_set_rate", 270 "clk/clk_set_rate_complete", 271 "binder/binder_transaction", 272 "binder/binder_transaction_alloc_buf", 273 "binder/binder_transaction_received", 274 "binder/binder_lock", 275 "binder/binder_locked", 276 "binder/binder_unlock", 277 "workqueue/workqueue_execute_start", 278 "workqueue/workqueue_execute_end", 279 "oom/oom_score_adj_update", 280 "ftrace/print" 281 )); 282 ArrayList<String> hTraceAudioEvents = new ArrayList<String>(Arrays.asList( 283 "audio" 284 )); 285 ArrayList<String> hTraceCameraEvents = new ArrayList<String>(Arrays.asList( 286 "camera" 287 )); 288 ArrayList<String> hTraceDatabaseEvents = new ArrayList<String>(Arrays.asList( 289 "database" 290 )); 291 ArrayList<String> hTraceGraphicsEvents = new ArrayList<String>(Arrays.asList( 292 "gfx" 293 )); 294 ArrayList<String> hTraceInputEvents = new ArrayList<String>(Arrays.asList( 295 "input" 296 )); 297 ArrayList<String> hTraceNetWorkEvents = new ArrayList<String>(Arrays.asList( 298 "network" 299 )); 300 ArrayList<String> hTraceVideoEvents = new ArrayList<String>(Arrays.asList( 301 "video" 302 )); 303 private Clipboard clipboard; 304 private JBCheckBox hTraceAudio; 305 private JBCheckBox hTraceCamera; 306 private JBCheckBox hTraceDatabase; 307 private JBCheckBox hTraceGraphics; 308 private JBCheckBox hTraceInput; 309 private JBCheckBox hTraceNetWork; 310 private JBCheckBox hTraceVideo; 311 private TaskPanel contentPanel; 312 private JBPanel sceneTitlePanel; 313 private JBLabel sceneTitle; 314 private JBLabel sceneTitleDes; 315 316 private JBRadioButton hilogLevelError; 317 private JBRadioButton hilogLevelInfo; 318 private JBRadioButton hilogLevelDebug; 319 private JBRadioButton hilogLevelWarn; 320 321 private JBCheckBox memoyrCheckBox; 322 private JBLabel memoyrTitleDes; 323 private JBCheckBox virtualMemoryCheckBox; 324 private JBLabel virtualMemoryTitleDes; 325 private JBCheckBox hilogCheckBox; 326 private JBLabel hilogTitleDes; 327 328 private ComboBox<String> connectTypeComboBox; 329 private ComboBox<String> deviceComboBox; 330 private JBPanel configTitlePanel; 331 private JBLabel configTitle; 332 private JBLabel configTitleDes; 333 private JBPanel traceConfigTab; 334 private JBLabel traceConfigTitle; 335 private JBPanel probesTab; 336 private JBLabel probesTitle; 337 private JBTabbedPane configTabbedPane; 338 private JBPanel traceConfigWestPanel; 339 private JBPanel traceConfigCenterPanel; 340 private JBLabel recordSettingLabel; 341 private JBLabel traceCommandLabel; 342 private JBPanel probesWestPanel; 343 private JBPanel probesCenterPanel; 344 private JBLabel probesCpu; 345 private JButton lastStepBtn; 346 private JButton startTaskBtn; 347 private JBLabel recordModelTitle; 348 private JBLabel memoryConfigTitle; 349 private JBLabel hilogConfigTitle; 350 private JBCheckBox schedulingCheckBox; 351 private JBLabel schedulingCheckBoxDes; 352 private JBCheckBox cpuFrequencyCheckBox; 353 private JBLabel cpuFrequencyCheckBoxDes; 354 private JBCheckBox boardCheckBox; 355 private JBLabel boardCheckBoxDes; 356 private JBCheckBox highFrequencyCheckBox; 357 private JBLabel highFrequencyCheckBoxDes; 358 private JBCheckBox hTraceUserspaceCheckBox; 359 private JBLabel hTraceUserspaceCheckBoxDes; 360 private JBCheckBox syscallsCheckBox; 361 private JBLabel syscallsCheckBoxDes; 362 private JBCheckBox advancedConfigCheckBox; 363 private JBLabel advancedConfigCheckBoxDes; 364 private JBLabel durationValue; 365 private JSlider bufferSizeSlider; 366 private JBPanel buttonPanel; 367 private JBLabel bufferSizeValue; 368 private JSlider durationSlider; 369 private JBScrollPane probesCenterScrollPane; 370 private JBPanel panelIncludeScrollPane; 371 private int inMemoryValue = 10; 372 private int maxDuration = 10; 373 private String eventStr = ""; 374 private boolean chooseMode = false; 375 private List<DeviceIPPortInfo> deviceInfoList = null; 376 private DeviceIPPortInfo deviceIPPortInfo = null; 377 private Vector<String> deviceInfo = new Vector<>(); 378 private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); 379 380 /** 381 * SystemConfigPanel 382 * 383 * @param taskPanel taskPanel 384 */ SystemConfigPanel(TaskPanel taskPanel)385 public SystemConfigPanel(TaskPanel taskPanel) { 386 EventTrackUtils.getInstance().trackSystemConfig(); 387 contentPanel = taskPanel; 388 setLayout(new MigLayout("inset 0", "15[grow,fill]", "15[fill,fill]")); 389 setOpaque(true); 390 setBackground(JBColor.background().darker()); 391 initComponents(); 392 addEventListener(); 393 } 394 395 /** 396 * initComponents 397 */ initComponents()398 private void initComponents() { 399 // init the sceneTitlePanel 400 initSceneTitlePanel(); 401 // init the device ComboBox 402 initDeviceComboBox(); 403 // init the configTitlePanel 404 initConfigTitlePanel(); 405 // init the ConfigTabbedPane 406 initConfigTabbedPane(); 407 // init the buttonPanel 408 initButtonPanel(); 409 } 410 initSceneTitlePanel()411 private void initSceneTitlePanel() { 412 if (ProfilerLogManager.isInfoEnabled()) { 413 LOGGER.info("initSceneTitlePanel"); 414 } 415 sceneTitlePanel = new JBPanel(new MigLayout("insets 0", "[]15[]push", "[fill,fill]")); 416 sceneTitlePanel.setOpaque(false); 417 sceneTitle = new JBLabel(SCENE_TITLE_STR); 418 sceneTitle.setFont(new Font(Font.DIALOG, Font.BOLD, 24)); 419 sceneTitle.setForeground(JBColor.foreground().brighter()); 420 sceneTitleDes = new JBLabel(SCENE_TITLE_DES_STR); 421 sceneTitleDes.setFont(new Font(Font.DIALOG, Font.PLAIN, 14)); 422 sceneTitlePanel.add(sceneTitle); 423 sceneTitlePanel.add(sceneTitleDes); 424 this.add(sceneTitlePanel, "wrap, span"); 425 } 426 initDeviceComboBox()427 private void initDeviceComboBox() { 428 if (ProfilerLogManager.isInfoEnabled()) { 429 LOGGER.info("initDeviceComboBox"); 430 } 431 connectTypeComboBox = new ComboBox<String>(); 432 connectTypeComboBox.setName(UtConstant.UT_SYSTEM_TUNING_CONNECT_TYPE); 433 connectTypeComboBox.addItem(LayoutConstants.USB); 434 deviceComboBox = new ComboBox<String>(); 435 deviceComboBox.setName(UtConstant.UT_SYSTEM_TUNING_DEVICE_NAME); 436 this.add(connectTypeComboBox, "width 20%"); 437 this.add(deviceComboBox, "wrap, width 50%"); 438 } 439 initConfigTitlePanel()440 private void initConfigTitlePanel() { 441 if (ProfilerLogManager.isInfoEnabled()) { 442 LOGGER.info("initConfigTitlePanel"); 443 } 444 configTitlePanel = new JBPanel(new MigLayout("insets 0", "[]15[]push", "15[fill,fill]")); 445 configTitlePanel.setOpaque(false); 446 configTitle = new JBLabel(CONFIG_TITLE_STR); 447 configTitle.setFont(new Font(Font.DIALOG, Font.BOLD, 24)); 448 configTitle.setForeground(JBColor.foreground().brighter()); 449 configTitleDes = new JBLabel(CONFIG_TITLE_DES_STR); 450 configTitleDes.setFont(new Font(Font.DIALOG, Font.PLAIN, 14)); 451 configTitlePanel.add(configTitle); 452 configTitlePanel.add(configTitleDes); 453 this.add(configTitlePanel, "wrap, span"); 454 } 455 initConfigTabbedPane()456 private void initConfigTabbedPane() { 457 if (ProfilerLogManager.isInfoEnabled()) { 458 LOGGER.info("initConfigTabbedPane"); 459 } 460 // initTabPanel 461 initTabPanel(); 462 traceConfigTabDetail(); 463 // initTraceConfigTabItems 464 initTraceConfigTabItems(); 465 // initProbesTabItems 466 initProbesTabItems(); 467 // initProbesHtraceTabItem 468 initProbesHTraceTabItem(); 469 // initMemoryitems 470 initMemoryitems(); 471 // initProbesTabHilogItem 472 initProbesTabHilogItem(); 473 } 474 initTabPanel()475 private void initTabPanel() { 476 if (ProfilerLogManager.isInfoEnabled()) { 477 LOGGER.info("initTabPanel"); 478 } 479 // init the traceConfigTab 480 traceConfigTab = new JBPanel(new BorderLayout()); 481 traceConfigTitle = new JBLabel(TRACE_CONFIG_TITLE_STR, JBLabel.CENTER); 482 traceConfigTitle.setFont(new Font(Font.DIALOG, Font.BOLD, 16)); 483 traceConfigTitle.setPreferredSize(new Dimension(100, 40)); 484 traceConfigTab.add(traceConfigTitle); 485 // init the probesTab 486 probesTab = new JBPanel(new BorderLayout()); 487 probesTitle = new JBLabel(PROBES_TITLE_STR, JBLabel.CENTER); 488 probesTitle.setName(UtConstant.UT_SYSTEM_TUNING_LABEL); 489 probesTitle.setFont(new Font(Font.DIALOG, Font.BOLD, 16)); 490 probesTitle.setPreferredSize(new Dimension(100, 40)); 491 // init the configTabbedPane 492 configTabbedPane = new JBTabbedPane(); 493 configTabbedPane.addTab("", traceConfigTab); 494 configTabbedPane.addTab("", probesTab); 495 configTabbedPane.setTabComponentAt(configTabbedPane.indexOfComponent(traceConfigTab), traceConfigTitle); 496 configTabbedPane.setTabComponentAt(configTabbedPane.indexOfComponent(probesTab), probesTitle); 497 this.add(configTabbedPane, "wrap, span"); 498 } 499 500 /** 501 * traceConfigTabDetail 502 */ traceConfigTabDetail()503 public void traceConfigTabDetail() { 504 if (ProfilerLogManager.isInfoEnabled()) { 505 LOGGER.info("traceConfigTabDetail"); 506 } 507 // traceConfigPanel 508 traceConfigWestPanel = new JBPanel(null); 509 traceConfigCenterPanel = new JBPanel(null); 510 recordSettingLabel = new JBLabel(RECORD_SETTING_STR, JBLabel.CENTER); 511 recordSettingLabel.setOpaque(true); 512 recordSettingLabel.setBorder(BorderFactory.createLineBorder(new Color(0, 117, 255), 1)); 513 recordSettingLabel.setBounds(0, 50, 200, 70); 514 recordSettingLabel.setVisible(true); 515 traceConfigWestPanel.add(recordSettingLabel); 516 traceCommandLabel = new JBLabel(TRACE_COMMAND_STR, JBLabel.CENTER); 517 traceCommandLabel.setOpaque(true); 518 traceCommandLabel.setBounds(0, 120, 200, 70); 519 traceCommandLabel.setVisible(true); 520 traceConfigWestPanel.add(traceCommandLabel); 521 traceConfigTab.add(traceConfigWestPanel, BorderLayout.WEST); 522 traceConfigTab.add(traceConfigCenterPanel, BorderLayout.CENTER); 523 recordSettingLabel.addMouseListener(new MouseAdapter() { 524 @Override 525 public void mouseClicked(MouseEvent mouseEvent) { 526 traceCommandLabel.setBorder(null); 527 recordSettingLabel.setBorder(BorderFactory.createLineBorder(new Color(0, 117, 255), 1)); 528 recordSettingLabel.setOpaque(true); 529 traceCommandLabel.setOpaque(false); 530 initTraceConfigTabItems(); 531 traceConfigCenterPanel.updateUI(); 532 traceConfigCenterPanel.repaint(); 533 } 534 }); 535 traceCommandLabel.addMouseListener(new MouseAdapter() { 536 @Override 537 public void mouseClicked(MouseEvent mouseEvent) { 538 recordSettingLabel.setBorder(null); 539 traceCommandLabel.setBorder(BorderFactory.createLineBorder(new Color(0, 117, 255), 1)); 540 recordSettingLabel.setOpaque(false); 541 traceCommandLabel.setOpaque(true); 542 try { 543 traceCommandLabelRightShow(); 544 } catch (GrpcException grpcException) { 545 grpcException.printStackTrace(); 546 } 547 traceConfigCenterPanel.updateUI(); 548 traceConfigCenterPanel.repaint(); 549 } 550 }); 551 } 552 553 /** 554 * traceCommandLabelRightShow 555 * 556 * @throws GrpcException grpcException 557 */ traceCommandLabelRightShow()558 public void traceCommandLabelRightShow() throws GrpcException { 559 if (ProfilerLogManager.isInfoEnabled()) { 560 LOGGER.info("traceCommandLabelRightShow"); 561 } 562 traceConfigCenterPanel.removeAll(); 563 ArrayList<String> eventsList = new ArrayList(); 564 ArrayList<ArrayList<String>> atraceEventsList = new ArrayList(); 565 getEvent(eventsList, atraceEventsList); 566 String commandString = SystemTraceHelper.getSingleton().showHtraceCommand(deviceIPPortInfo, 567 constructRequestParam()); 568 String commandFormatString = commandString.replace("\\\"", "") 569 .replace("\\n", System.lineSeparator() + "\t\t"); 570 // load html 571 JTextArea textArea = new JTextArea(commandFormatString); 572 textArea.setFocusable(false); 573 // Sets the text in the text field to wrap 574 textArea.setLineWrap(true); 575 textArea.setForeground(Color.gray); 576 textArea.setEditable(false); 577 textArea.setBackground(ColorConstants.BLACK_COLOR); 578 JScrollPane scrollPane = new JScrollPane(textArea); 579 scrollPane.setBounds(40, 40, 600, 400); 580 traceConfigCenterPanel.add(scrollPane); 581 JButton jButtonSave = new JButton(); 582 jButtonSave.setIcon(IconLoader.getIcon("/images/copy.png", getClass())); 583 jButtonSave.setOpaque(true); 584 jButtonSave.setCursor(new Cursor(12)); 585 jButtonSave.setBounds(900, 40, 64, 64); 586 jButtonSave.setBorderPainted(false); 587 jButtonSave.addActionListener(new ActionListener() { 588 @Override 589 public void actionPerformed(ActionEvent event) { 590 CompletableFuture.runAsync(() -> { 591 StringSelection contents = new StringSelection(getCopyCommandStr()); 592 SwingUtilities.invokeLater(() -> { 593 clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 594 clipboard.setContents(contents, SystemConfigPanel.this); 595 }); 596 }, Utils.getPool()).whenComplete((unused, throwable) -> { 597 if (Objects.nonNull(throwable)) { 598 throwable.printStackTrace(); 599 } 600 }); 601 } 602 }); 603 traceConfigCenterPanel.add(jButtonSave); 604 traceConfigCenterPanel.repaint(); 605 } 606 getCopyCommandStr()607 private String getCopyCommandStr() { 608 String commandStr = null; 609 if (deviceIPPortInfo != null) { 610 Date date = new Date(); 611 String commandParameterStr = SystemTraceHelper.getSingleton() 612 .getHtraceExecuteCommand(deviceIPPortInfo, constructRequestParam()); 613 String commandFilePath = SystemTraceHelper.getSingleton() 614 .pushHtraceCommandFile(commandParameterStr, sdf.format(date), deviceIPPortInfo); 615 String path = ""; 616 String recordTrace; 617 if (deviceIPPortInfo.getDeviceType() == DeviceType.FULL_HOS_DEVICE) { 618 path = FULL_HOS_DEVICE_PATH; 619 path = path.concat(System.lineSeparator()) 620 .concat(JUDGE_HIPROFILER_RESULT).concat(System.lineSeparator()) 621 .concat(JUDGE_HIPROFILER_PLUGIN_RESULT).concat(System.lineSeparator()) 622 .concat(EXPORT_TO_LIBRARY_PATH); 623 recordTrace = TRACE_COMMAND_HEAD.concat(commandFilePath).concat(" -o ").concat(TRACE_COMMAND_END) 624 .concat(sdf.format(date)).concat(".htrace"); 625 } else { 626 path = path.concat(System.lineSeparator()) 627 .concat(JUDGE_STD_HIPROFILER_RESULT).concat(System.lineSeparator()) 628 .concat(JUDGE_STD_HIPROFILER_PLUGIN_RESULT).concat(System.lineSeparator()); 629 recordTrace = TRACE_STD_COMMAND_HEAD.concat(commandFilePath).concat(" -o ").concat(TRACE_COMMAND_END) 630 .concat(sdf.format(date)).concat(".htrace"); 631 } 632 commandStr = path.concat(System.lineSeparator()).concat(recordTrace); 633 } 634 return commandStr; 635 } 636 initTraceConfigTabItems()637 private void initTraceConfigTabItems() { 638 if (ProfilerLogManager.isInfoEnabled()) { 639 LOGGER.info("initTraceConfigTabItems"); 640 } 641 traceConfigCenterPanel.removeAll(); 642 // init trace config items 643 JBLabel traceConfigRecordMode = new JBLabel(TRACE_CONFIG_MODE_STR); 644 JBRadioButton traceConfigModeButton = new JBRadioButton(TRACE_CONFIG_MODE_BUTTON_STR, true); 645 traceConfigRecordMode.setBounds(50, 13, 200, 50); 646 traceConfigModeButton.setBounds(50, 50, 160, 50); 647 traceConfigCenterPanel.add(traceConfigRecordMode); 648 traceConfigCenterPanel.add(traceConfigModeButton); 649 // bufferSizeTitle 650 JBLabel bufferSizeTitle = new JBLabel(BUFFER_SIZE_TITLE_STR); 651 bufferSizeTitle.setBounds(50, 100, 200, 50); 652 traceConfigCenterPanel.add(bufferSizeTitle); 653 // bufferSizeValue 654 bufferSizeValue = new JBLabel("" + 10 + " MB", JBLabel.CENTER); 655 bufferSizeValue.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14)); 656 bufferSizeValue.setVerticalTextPosition(JBLabel.CENTER); 657 bufferSizeValue.setHorizontalTextPosition(JBLabel.CENTER); 658 bufferSizeValue.setOpaque(true); 659 bufferSizeValue.setBounds(700, 135, 110, 45); 660 traceConfigCenterPanel.add(bufferSizeValue); 661 // bufferSizeSlider 662 bufferSizeSlider = new JSlider(0, 110); 663 bufferSizeSlider.setValue(10); 664 bufferSizeSlider.setPreferredSize(new Dimension(200, 0)); 665 bufferSizeSlider.setBounds(45, 140, 600, 30); 666 traceConfigCenterPanel.add(bufferSizeSlider); 667 // durationTitle 668 JBLabel durationTitle = new JBLabel(DURATION_TITLE_STR); 669 durationTitle.setBounds(50, 190, 200, 50); 670 traceConfigCenterPanel.add(durationTitle); 671 // durationValue 672 durationValue = new JBLabel("00:00:" + 10 + " h:m:s ", JBLabel.CENTER); 673 durationValue.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14)); 674 durationValue.setVerticalTextPosition(JBLabel.CENTER); 675 durationValue.setHorizontalTextPosition(JBLabel.CENTER); 676 durationValue.setOpaque(true); 677 durationValue.setBounds(700, 225, 110, 45); 678 traceConfigCenterPanel.add(durationValue); 679 // durationSlider 680 durationSlider = new JSlider(10, 600); 681 durationSlider.setValue(10); 682 durationSlider.setPreferredSize(new Dimension(200, 0)); 683 durationSlider.setBounds(45, 230, 600, 30); 684 traceConfigCenterPanel.add(durationSlider); 685 traceConfigWestPanel.add(recordSettingLabel); 686 traceConfigWestPanel.setPreferredSize(new Dimension(200, 500)); 687 // bufferSizeSlider addChangeListener 688 changeListener(); 689 } 690 691 /** 692 * changeListener 693 */ changeListener()694 public void changeListener() { 695 bufferSizeSlider.addChangeListener(new ChangeListener() { 696 @Override 697 public void stateChanged(ChangeEvent changeEvent) { 698 bufferSizeValue.setText("" + bufferSizeSlider.getValue() + " MB"); 699 bufferSizeValue.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14)); 700 bufferSizeValue.setVerticalTextPosition(JBLabel.CENTER); 701 bufferSizeValue.setHorizontalTextPosition(JBLabel.CENTER); 702 inMemoryValue = bufferSizeSlider.getValue(); 703 } 704 }); 705 // durationSlider addChangeListener 706 durationSlider.addChangeListener(new ChangeListener() { 707 /** 708 * stateChanged 709 * 710 * @param changeEvent changeEvent 711 */ 712 @Override 713 public void stateChanged(ChangeEvent changeEvent) { 714 int seconds = durationSlider.getValue() % 60; 715 int minutes = (durationSlider.getValue() / 60) % 60; 716 int hours = durationSlider.getValue() / (60 * 60); 717 durationValue.setText(" " + String.format(Locale.ENGLISH, "%02d", hours) + ":" + String 718 .format(Locale.ENGLISH, "%02d", minutes) + ":" + String.format(Locale.ENGLISH, "%02d", seconds) 719 + " h:m:s "); 720 durationValue.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 14)); 721 durationValue.setVerticalTextPosition(JBLabel.CENTER); 722 durationValue.setHorizontalTextPosition(JBLabel.CENTER); 723 maxDuration = durationSlider.getValue(); 724 } 725 }); 726 } 727 initProbesHTraceTabItem()728 private void initProbesHTraceTabItem() { 729 if (ProfilerLogManager.isInfoEnabled()) { 730 LOGGER.info("initProbesHTraceTabItem"); 731 } 732 hTraceUserspaceCheckBox = new JBCheckBox(HTRACE_USERSPACE_STR, false); 733 hTraceUserspaceCheckBoxDes = new JBLabel(HTRACE_USERSPACE_DES_STR, JBLabel.LEFT); 734 hTraceUserspaceCheckBox.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 735 hTraceUserspaceCheckBox.setName(UtConstant.UT_SYSTEM_TUNING_CATEGORIES); 736 hTraceUserspaceCheckBox.setBounds(50, 350, 250, 50); 737 hTraceUserspaceCheckBoxDes.setBounds(70, 380, 350, 80); 738 hTraceAudio = new JBCheckBox(HTRACE_AUDIO_STR, false); 739 hTraceCamera = new JBCheckBox(HTRACE_CAMERA_STR, false); 740 hTraceDatabase = new JBCheckBox(HTRACE_DATABASE_STR, false); 741 hTraceGraphics = new JBCheckBox(HTRACE_GRAPHICS_STR, false); 742 hTraceInput = new JBCheckBox(HTRACE_INPUT_STR, false); 743 hTraceNetWork = new JBCheckBox(HTRACE_NETWORK_STR, false); 744 hTraceVideo = new JBCheckBox(HTRACE_VIDEO_STR, false); 745 hTraceAudio.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 746 hTraceAudio.setBounds(500, 350, 90, 40); 747 hTraceCamera.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 748 hTraceCamera.setBounds(590, 350, 90, 40); 749 hTraceDatabase.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 750 hTraceDatabase.setBounds(680, 350, 90, 40); 751 hTraceGraphics.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 752 hTraceGraphics.setBounds(770, 350, 90, 40); 753 hTraceInput.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 754 hTraceInput.setBounds(500, 380, 90, 40); 755 hTraceNetWork.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 756 hTraceNetWork.setBounds(590, 380, 90, 40); 757 hTraceVideo.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 758 hTraceVideo.setBounds(680, 380, 90, 40); 759 hTraceAddActionListener(hTraceUserspaceCheckBox); 760 addActionListener(hTraceAudio); 761 addActionListener(hTraceCamera); 762 addActionListener(hTraceDatabase); 763 addActionListener(hTraceGraphics); 764 addActionListener(hTraceInput); 765 addActionListener(hTraceNetWork); 766 addActionListener(hTraceVideo); 767 probesCenterPanel.add(hTraceUserspaceCheckBox); 768 probesCenterPanel.add(hTraceUserspaceCheckBoxDes); 769 probesCenterPanel.add(hTraceAudio); 770 probesCenterPanel.add(hTraceCamera); 771 probesCenterPanel.add(hTraceDatabase); 772 probesCenterPanel.add(hTraceGraphics); 773 probesCenterPanel.add(hTraceInput); 774 probesCenterPanel.add(hTraceNetWork); 775 probesCenterPanel.add(hTraceVideo); 776 } 777 778 /** 779 * hTraceAddActionListener 780 * 781 * @param checkBoxObject checkBoxObject 782 */ hTraceAddActionListener(JBCheckBox checkBoxObject)783 public void hTraceAddActionListener(JBCheckBox checkBoxObject) { 784 checkBoxObject.addActionListener(new ActionListener() { 785 @Override 786 public void actionPerformed(ActionEvent event) { 787 if (hTraceUserspaceCheckBox.isSelected()) { 788 hTraceAudio.setSelected(true); 789 hTraceCamera.setSelected(true); 790 hTraceDatabase.setSelected(true); 791 hTraceGraphics.setSelected(true); 792 hTraceInput.setSelected(true); 793 hTraceNetWork.setSelected(true); 794 hTraceVideo.setSelected(true); 795 } else { 796 hTraceAudio.setSelected(false); 797 hTraceCamera.setSelected(false); 798 hTraceDatabase.setSelected(false); 799 hTraceGraphics.setSelected(false); 800 hTraceInput.setSelected(false); 801 hTraceNetWork.setSelected(false); 802 hTraceVideo.setSelected(false); 803 } 804 } 805 }); 806 } 807 808 /** 809 * addActionListener 810 * 811 * @param checkBoxObject checkBoxObject 812 */ addActionListener(JBCheckBox checkBoxObject)813 public void addActionListener(JBCheckBox checkBoxObject) { 814 checkBoxObject.addActionListener(new ActionListener() { 815 @Override 816 public void actionPerformed(ActionEvent event) { 817 boolean isSelect = 818 hTraceGraphics.isSelected() && hTraceInput.isSelected() && hTraceNetWork.isSelected() && hTraceVideo 819 .isSelected(); 820 if (hTraceAudio.isSelected() && hTraceCamera.isSelected() && hTraceDatabase.isSelected() && isSelect) { 821 hTraceUserspaceCheckBox.setSelected(true); 822 } else { 823 hTraceUserspaceCheckBox.setSelected(false); 824 } 825 } 826 }); 827 } 828 initProbesTabItems()829 private void initProbesTabItems() { 830 if (ProfilerLogManager.isInfoEnabled()) { 831 LOGGER.info("initProbesTabItems"); 832 } 833 // init the probes items 834 probesWestPanel = new JBPanel(null); 835 probesCenterPanel = new JBPanel(null); 836 probesCpu = new JBLabel(PROBES_CPU_STR, JBLabel.CENTER); 837 probesCpu.setOpaque(true); 838 probesCpu.setBorder(BorderFactory.createLineBorder(new Color(0, 117, 255), 1)); 839 probesCpu.setBounds(0, 50, 200, 70); 840 probesWestPanel.add(probesCpu); 841 probesCpu.setVisible(false); 842 probesWestPanel.setPreferredSize(new Dimension(200, 800)); 843 // init the component 844 recordModelTitle = new JBLabel(RECORD_MODEL_STR); 845 schedulingCheckBox = new JBCheckBox(SCHEDULING_STR, true); 846 schedulingCheckBoxDes = new JBLabel(SCHEDULING_DES_STR, JBLabel.LEFT); 847 cpuFrequencyCheckBox = new JBCheckBox(CPU_FREQUENCY_STR, false); 848 cpuFrequencyCheckBoxDes = new JBLabel(CPU_FREQUENCY_DES_STR, JBLabel.LEFT); 849 boardCheckBox = new JBCheckBox(BOARD_STR, false); 850 boardCheckBoxDes = new JBLabel(BOARD_DES_STR, JBLabel.LEFT); 851 highFrequencyCheckBox = new JBCheckBox(HIGH_FREQUENCY_STR, false); 852 highFrequencyCheckBoxDes = new JBLabel(HIGH_FREQUENCY_DES_STR, JBLabel.LEFT); 853 854 syscallsCheckBox = new JBCheckBox(SYSCALLS_STR, false); 855 syscallsCheckBoxDes = new JBLabel(SYSCALLS_DES_STR, JBLabel.LEFT); 856 advancedConfigCheckBox = new JBCheckBox(ADVANCED_CONFIG_STR, false); 857 advancedConfigCheckBoxDes = new JBLabel(ADVANCED_CONFIG_DES_STR, JBLabel.LEFT); 858 // set the font 859 schedulingCheckBox.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 860 cpuFrequencyCheckBox.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 861 boardCheckBox.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 862 highFrequencyCheckBox.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 863 864 syscallsCheckBox.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 865 advancedConfigCheckBox.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 866 // set the bounds 867 recordModelTitle.setBounds(50, 13, 200, 50); 868 schedulingCheckBox.setBounds(50, 50, 250, 50); 869 schedulingCheckBoxDes.setBounds(70, 80, 350, 50); 870 cpuFrequencyCheckBox.setBounds(50, 140, 250, 50); 871 cpuFrequencyCheckBoxDes.setBounds(70, 170, 350, 50); 872 advancedConfigCheckBox.setBounds(50, 240, 250, 50); 873 advancedConfigCheckBoxDes.setBounds(70, 270, 350, 90); 874 875 boardCheckBox.setBounds(500, 50, 250, 50); 876 boardCheckBoxDes.setBounds(520, 80, 350, 60); 877 highFrequencyCheckBox.setBounds(500, 140, 250, 50); 878 highFrequencyCheckBoxDes.setBounds(520, 170, 350, 80); 879 syscallsCheckBox.setBounds(500, 240, 250, 50); 880 syscallsCheckBoxDes.setBounds(520, 270, 350, 50); 881 addProbesCenterPanel(); 882 } 883 initMemoryitems()884 private void initMemoryitems() { 885 // memory 886 memorySeparator.setBounds(50, 450, 850, 10); 887 memorySeparator.setBackground(new Color(255, 255, 255)); 888 memoryConfigTitle = new JBLabel(MEMORY_CONFIG_STR); 889 memoryConfigTitle.setBounds(50, 460, 200, 40); 890 memoyrCheckBox = new JBCheckBox(KERNEL_MEMORY, true); 891 memoyrTitleDes = new JBLabel(MEMOYR_STR); 892 virtualMemoryCheckBox = new JBCheckBox(VIRTUAL_MEMORY); 893 virtualMemoryTitleDes = new JBLabel(VIRTUAL_MEMOYR_STR); 894 memoyrCheckBox.setBounds(50, 490, 250, 50); 895 memoyrTitleDes.setBounds(70, 520, 250, 60); 896 virtualMemoryCheckBox.setBounds(500, 490, 250, 50); 897 virtualMemoryTitleDes.setBounds(520, 520, 350, 90); 898 // set font size 899 memoyrCheckBox.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 900 virtualMemoryCheckBox.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 901 // add all items to probesCenterPanel 902 probesCenterPanel.add(memorySeparator); 903 probesCenterPanel.add(memoryConfigTitle); 904 probesCenterPanel.add(memoyrCheckBox); 905 probesCenterPanel.add(memoyrTitleDes); 906 probesCenterPanel.add(virtualMemoryCheckBox); 907 probesCenterPanel.add(virtualMemoryTitleDes); 908 } 909 initProbesTabHilogItem()910 private void initProbesTabHilogItem() { 911 if (ProfilerLogManager.isInfoEnabled()) { 912 LOGGER.info("initProbesTabHilogItem"); 913 } 914 // hilog 915 hilogSeparator.setBounds(50, 600, 850, 10); 916 hilogSeparator.setBackground(new Color(255, 255, 255)); 917 hilogConfigTitle = new JBLabel(HILOG_CONFIG_STR); 918 hilogConfigTitle.setBounds(50, 610, 200, 40); 919 hilogCheckBox = new JBCheckBox(LOG_LEVEL_CHECKBOX, true); 920 hilogCheckBox.addActionListener(new ActionListener() { 921 @Override 922 public void actionPerformed(ActionEvent event) { 923 hilogLinkageSetting(); 924 } 925 }); 926 hilogTitleDes = new JBLabel(LOG_LEVEL_CHECKBOX_DEC); 927 hilogCheckBox.setBounds(50, 640, 250, 50); 928 hilogTitleDes.setBounds(70, 680, 250, 60); 929 hilogLevelError = new JBRadioButton(HILOG_CONFIG_ERROR, false); 930 hilogLevelInfo = new JBRadioButton(HILOG_CONFIG_INFO, true); 931 hilogLevelDebug = new JBRadioButton(HILOG_CONFIG_DEBUG, false); 932 hilogLevelWarn = new JBRadioButton(HILOG_CONFIG_WARN, false); 933 hilogButtonGroup.add(hilogLevelError); 934 hilogButtonGroup.add(hilogLevelInfo); 935 hilogButtonGroup.add(hilogLevelDebug); 936 hilogButtonGroup.add(hilogLevelWarn); 937 hilogLevelError.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 938 hilogLevelError.setBounds(500, 640, 90, 50); 939 hilogLevelInfo.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 940 hilogLevelInfo.setBounds(590, 640, 90, 50); 941 hilogLevelDebug.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 942 hilogLevelDebug.setBounds(680, 640, 90, 50); 943 hilogLevelWarn.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); 944 hilogLevelWarn.setBounds(770, 640, 90, 50); 945 probesCenterPanel.add(hilogSeparator); 946 probesCenterPanel.add(hilogConfigTitle); 947 probesCenterPanel.add(hilogCheckBox); 948 probesCenterPanel.add(hilogTitleDes); 949 probesCenterPanel.add(hilogLevelError); 950 probesCenterPanel.add(hilogLevelInfo); 951 probesCenterPanel.add(hilogLevelDebug); 952 probesCenterPanel.add(hilogLevelWarn); 953 } 954 hilogLinkageSetting()955 private void hilogLinkageSetting() { 956 if (hilogCheckBox.isSelected()) { 957 hilogLevelInfo.setSelected(true); 958 hilogLevelError.setEnabled(true); 959 hilogLevelInfo.setEnabled(true); 960 hilogLevelDebug.setEnabled(true); 961 hilogLevelWarn.setEnabled(true); 962 } else { 963 hilogLevelError.setSelected(false); 964 hilogLevelError.setEnabled(false); 965 hilogLevelInfo.setSelected(false); 966 hilogLevelInfo.setEnabled(false); 967 hilogLevelDebug.setSelected(false); 968 hilogLevelDebug.setEnabled(false); 969 hilogLevelWarn.setSelected(false); 970 hilogLevelWarn.setEnabled(false); 971 hilogButtonGroup.clearSelection(); 972 } 973 } 974 975 /** 976 * addProbesCenterPanel 977 */ addProbesCenterPanel()978 private void addProbesCenterPanel() { 979 if (ProfilerLogManager.isInfoEnabled()) { 980 LOGGER.info("addProbesCenterPanel"); 981 } 982 // add component 983 probesCenterPanel.add(recordModelTitle); 984 probesCenterPanel.add(schedulingCheckBox); 985 probesCenterPanel.add(schedulingCheckBoxDes); 986 probesCenterPanel.add(cpuFrequencyCheckBox); 987 probesCenterPanel.add(cpuFrequencyCheckBoxDes); 988 probesCenterPanel.add(boardCheckBox); 989 probesCenterPanel.add(boardCheckBoxDes); 990 probesCenterPanel.add(highFrequencyCheckBox); 991 probesCenterPanel.add(highFrequencyCheckBoxDes); 992 probesCenterPanel.add(syscallsCheckBox); 993 probesCenterPanel.add(syscallsCheckBoxDes); 994 probesCenterPanel.add(advancedConfigCheckBox); 995 probesCenterPanel.add(advancedConfigCheckBoxDes); 996 probesCenterPanel.add(separator); 997 // checkBoxState 998 probesTab.add(probesWestPanel, BorderLayout.WEST); 999 probesCenterPanel.setPreferredSize(new Dimension(1100, 800)); 1000 probesCenterScrollPane = new JBScrollPane(probesCenterPanel); 1001 probesCenterScrollPane.setBounds(0, 0, 1100, 500); 1002 panelIncludeScrollPane = new JBPanel(null); 1003 panelIncludeScrollPane.add(probesCenterScrollPane); 1004 probesTab.add(panelIncludeScrollPane, BorderLayout.CENTER); 1005 } 1006 initButtonPanel()1007 private void initButtonPanel() { 1008 if (ProfilerLogManager.isInfoEnabled()) { 1009 LOGGER.info("initButtonPanel"); 1010 } 1011 buttonPanel = new JBPanel(new MigLayout("insets 0", "push[]20[]20", "[fill,fill]")); 1012 buttonPanel.setOpaque(false); 1013 lastStepBtn = new JButton(LAST_STEP_BTN); 1014 lastStepBtn.setName(LAST_STEP_BTN); 1015 lastStepBtn.setFocusPainted(false); 1016 lastStepBtn.setOpaque(false); 1017 lastStepBtn.setPreferredSize(new Dimension(140, 40)); 1018 startTaskBtn = new JButton(START_TASK_BTN); 1019 startTaskBtn.setName(START_TASK_BTN); 1020 startTaskBtn.setFocusPainted(false); 1021 startTaskBtn.setOpaque(false); 1022 startTaskBtn.setPreferredSize(new Dimension(140, 40)); 1023 buttonPanel.add(lastStepBtn); 1024 buttonPanel.add(startTaskBtn); 1025 this.add(buttonPanel, "wrap, span, height 40!"); 1026 } 1027 1028 /** 1029 * addEventListener 1030 */ addEventListener()1031 private void addEventListener() { 1032 addDeviceRefresh(); 1033 lastStepBtn.addMouseListener(this); 1034 startTaskBtn.addMouseListener(this); 1035 deviceComboBox.addItemListener(this); 1036 } 1037 1038 /** 1039 * addDeviceRefresh 1040 */ addDeviceRefresh()1041 public void addDeviceRefresh() { 1042 QuartzManager.getInstance().addExecutor(DEVICE_REFRESH, new Runnable() { 1043 /** 1044 * run 1045 */ 1046 @Override 1047 public void run() { 1048 deviceInfoList = MultiDeviceManager.getInstance().getOnlineDeviceInfoList(); 1049 Vector<String> items = new Vector<>(); 1050 deviceInfoList.forEach(deviceInfo -> { 1051 items.add(deviceInfo.getDeviceName()); 1052 }); 1053 if (!deviceInfo.equals(items)) { 1054 deviceInfo = items; 1055 deviceComboBox.setModel(new DefaultComboBoxModel(items)); 1056 for (DeviceIPPortInfo deviceIPInfo : deviceInfoList) { 1057 if (deviceIPInfo.getDeviceName().equals(deviceComboBox.getSelectedItem())) { 1058 deviceIPPortInfo = deviceIPInfo; 1059 } else { 1060 deviceIPPortInfo = deviceInfoList.get(0); 1061 } 1062 } 1063 } 1064 } 1065 }); 1066 QuartzManager.getInstance() 1067 .startExecutor(DEVICE_REFRESH, LayoutConstants.DEFAULT_NUMBER, LayoutConstants.NUMBER_THREAD); 1068 } 1069 1070 @Override mouseClicked(MouseEvent mouseEvent)1071 public void mouseClicked(MouseEvent mouseEvent) { 1072 } 1073 1074 @Override mousePressed(MouseEvent mouseEvent)1075 public void mousePressed(MouseEvent mouseEvent) { 1076 } 1077 1078 @Override mouseReleased(MouseEvent mouseEvent)1079 public void mouseReleased(MouseEvent mouseEvent) { 1080 String name = mouseEvent.getComponent().getName(); 1081 if (name.equals(LAST_STEP_BTN)) { 1082 contentPanel.getTabContainer().remove(this); 1083 contentPanel.getTabItem().setVisible(true); 1084 contentPanel.getTabContainer().repaint(); 1085 } 1086 if (name.equals(START_TASK_BTN)) { 1087 int itemCount = deviceComboBox.getItemCount(); 1088 // create system tuning load dialog object 1089 if (itemCount == 0) { 1090 new SampleDialog("prompt", "Device list is empty !").show(); 1091 return; 1092 } 1093 if (deviceIPPortInfo == null) { 1094 new SampleDialog("prompt", "Please select the device !").show(); 1095 return; 1096 } 1097 QuartzManager.getInstance().deleteExecutor(DEVICE_REFRESH); 1098 loadTraceRecordDialog(); 1099 contentPanel.getTabContainer().repaint(); 1100 } 1101 } 1102 1103 /** 1104 * loadTraceRecordDialog 1105 */ loadTraceRecordDialog()1106 private void loadTraceRecordDialog() { 1107 if (ProfilerLogManager.isInfoEnabled()) { 1108 LOGGER.info("loadTraceRecordDialog"); 1109 } 1110 try { 1111 if (!getClassificationSelect()) { 1112 new SampleDialog("prompt", "Please select the classification !").show(); 1113 } else { 1114 String sessionId; 1115 if (chooseMode) { 1116 if (cpuFrequencyCheckBox.isSelected() || boardCheckBox.isSelected()) { 1117 eventStr = eventStr.concat(";").concat(IDLE_EVENT); 1118 } 1119 if (schedulingCheckBox.isSelected()) { 1120 eventStr = eventStr.concat(";").concat(SCHED_FREQ_EVENT); 1121 } 1122 sessionId = SystemTraceHelper.getSingleton() 1123 .createSessionByTraceRequest(deviceIPPortInfo, eventStr, maxDuration, inMemoryValue, 1124 "/data/local/tmp/hiprofiler_data.bytrace", true); 1125 } else { 1126 sessionId = SystemTraceHelper.getSingleton() 1127 .executeHtraceRecording(deviceIPPortInfo, constructRequestParam()); 1128 } 1129 if (Optional.ofNullable(sessionId).isPresent()) { 1130 new TraceRecordDialog().load(contentPanel, maxDuration, sessionId, deviceIPPortInfo, chooseMode); 1131 } else { 1132 new SampleDialog("prompt", "The corresponding file is missing!").show(); 1133 } 1134 1135 } 1136 } catch (GrpcException grpcException) { 1137 grpcException.printStackTrace(); 1138 } 1139 } 1140 constructRequestParam()1141 private SystemConfigData constructRequestParam() { 1142 SystemConfigData systemConfigData = new SystemConfigData(); 1143 ArrayList<String> eventsList = new ArrayList(); 1144 ArrayList<ArrayList<String>> hTraceEventsList = new ArrayList(); 1145 getEvent(eventsList, hTraceEventsList); 1146 systemConfigData.setEventsList(eventsList); 1147 systemConfigData.sethTraceEventsList(hTraceEventsList); 1148 systemConfigData.setInMemoryValue(inMemoryValue); 1149 systemConfigData.setMaxDuration(maxDuration); 1150 systemConfigData.setMemoryInfo(memoyrCheckBox.isSelected()); 1151 systemConfigData.setVmemoryInfo(virtualMemoryCheckBox.isSelected()); 1152 if (hilogLevelError.isSelected()) { 1153 systemConfigData.setHilogLevel("ERROR"); 1154 } 1155 if (hilogLevelInfo.isSelected()) { 1156 systemConfigData.setHilogLevel("INFO"); 1157 } 1158 if (hilogLevelDebug.isSelected()) { 1159 systemConfigData.setHilogLevel("DEBUG"); 1160 } 1161 if (hilogLevelWarn.isSelected()) { 1162 systemConfigData.setHilogLevel("WARN"); 1163 } 1164 return systemConfigData; 1165 } 1166 1167 /** 1168 * getClassificationSelect 1169 * 1170 * @return boolean 1171 */ getClassificationSelect()1172 public boolean getClassificationSelect() { 1173 if (!schedulingCheckBox.isSelected() && !cpuFrequencyCheckBox.isSelected() && !boardCheckBox.isSelected() 1174 && !syscallsCheckBox.isSelected() && !highFrequencyCheckBox.isSelected() && !hTraceAudio.isSelected() 1175 && !advancedConfigCheckBox.isSelected() && !hTraceCamera.isSelected() && !hTraceDatabase.isSelected() 1176 && !hTraceGraphics.isSelected() && !hTraceInput.isSelected() && !hTraceNetWork.isSelected() && !hTraceVideo 1177 .isSelected() && !memoyrCheckBox.isSelected() && !virtualMemoryCheckBox.isSelected() && !hilogCheckBox 1178 .isSelected()) { 1179 return false; 1180 } else { 1181 return true; 1182 } 1183 } 1184 1185 /** 1186 * getEvent 1187 * 1188 * @param eventsList eventsList 1189 * @param hTraceEventsList hTraceEventsList 1190 */ getEvent(ArrayList<String> eventsList, ArrayList<ArrayList<String>> hTraceEventsList)1191 public void getEvent(ArrayList<String> eventsList, ArrayList<ArrayList<String>> hTraceEventsList) { 1192 if (schedulingCheckBox.isSelected()) { 1193 schedulingEvents.stream().forEach(event -> eventsList.add(event)); 1194 } 1195 if (boardCheckBox.isSelected()) { 1196 powerEvents.stream().forEach(event -> eventsList.add(event)); 1197 } 1198 if (cpuFrequencyCheckBox.isSelected()) { 1199 cpuFreqEvents.stream().forEach(event -> eventsList.add(event)); 1200 } 1201 if (syscallsCheckBox.isSelected()) { 1202 sysCallsEvents.stream().forEach(event -> eventsList.add(event)); 1203 } 1204 if (advancedConfigCheckBox.isSelected()) { 1205 advancedConfigEvents.stream().forEach(event -> eventsList.add(event)); 1206 } 1207 if (highFrequencyCheckBox.isSelected()) { 1208 highFrequencyEvents.stream().forEach(event -> eventsList.add(event)); 1209 } 1210 if (hTraceAudio.isSelected()) { 1211 hTraceEventsList.add(hTraceAudioEvents); 1212 } 1213 if (hTraceCamera.isSelected()) { 1214 hTraceEventsList.add(hTraceCameraEvents); 1215 } 1216 if (hTraceDatabase.isSelected()) { 1217 hTraceEventsList.add(hTraceDatabaseEvents); 1218 } 1219 if (hTraceGraphics.isSelected()) { 1220 hTraceEventsList.add(hTraceGraphicsEvents); 1221 } 1222 if (hTraceInput.isSelected()) { 1223 hTraceEventsList.add(hTraceInputEvents); 1224 } 1225 if (hTraceNetWork.isSelected()) { 1226 hTraceEventsList.add(hTraceNetWorkEvents); 1227 } 1228 if (hTraceVideo.isSelected()) { 1229 hTraceEventsList.add(hTraceVideoEvents); 1230 } 1231 } 1232 1233 @Override mouseEntered(MouseEvent mouseEvent)1234 public void mouseEntered(MouseEvent mouseEvent) { 1235 } 1236 1237 @Override mouseExited(MouseEvent mouseEvent)1238 public void mouseExited(MouseEvent mouseEvent) { 1239 } 1240 1241 @Override itemStateChanged(ItemEvent itemEvent)1242 public void itemStateChanged(ItemEvent itemEvent) { 1243 if (deviceInfoList != null && deviceInfoList.size() > 0) { 1244 for (DeviceIPPortInfo deviceIPInfo : deviceInfoList) { 1245 if (deviceIPInfo.getDeviceName().equals(deviceComboBox.getSelectedItem())) { 1246 deviceIPPortInfo = deviceIPInfo; 1247 } 1248 } 1249 } 1250 } 1251 1252 @Override lostOwnership(Clipboard clipboard, Transferable contents)1253 public void lostOwnership(Clipboard clipboard, Transferable contents) { 1254 1255 } 1256 } 1257