• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.chartview;
17 
18 import com.intellij.icons.AllIcons;
19 import com.intellij.openapi.util.IconLoader;
20 import com.intellij.ui.JBColor;
21 import com.intellij.ui.components.JBLabel;
22 import com.intellij.ui.components.JBPanel;
23 import com.intellij.ui.components.JBScrollPane;
24 import net.miginfocom.swing.MigLayout;
25 import ohos.devtools.datasources.transport.hdc.HdcWrapper;
26 import ohos.devtools.datasources.utils.device.entity.DeviceProcessInfo;
27 import ohos.devtools.datasources.utils.plugin.service.PlugManager;
28 import ohos.devtools.datasources.utils.profilerlog.ProfilerLogManager;
29 import ohos.devtools.datasources.utils.quartzmanager.QuartzManager;
30 import ohos.devtools.datasources.utils.session.service.SessionManager;
31 import ohos.devtools.services.hiperf.HiperfParse;
32 import ohos.devtools.services.hiperf.ParsePerf;
33 import ohos.devtools.services.hiperf.PerfDAO;
34 import ohos.devtools.views.applicationtrace.AppTracePanel;
35 import ohos.devtools.views.common.ColorConstants;
36 import ohos.devtools.views.common.LayoutConstants;
37 import ohos.devtools.views.common.UtConstant;
38 import ohos.devtools.views.common.customcomp.CustomComboBox;
39 import ohos.devtools.views.common.customcomp.CustomJButton;
40 import ohos.devtools.views.common.customcomp.CustomJLabel;
41 import ohos.devtools.views.common.customcomp.CustomProgressBar;
42 import ohos.devtools.views.layout.HomePanel;
43 import ohos.devtools.views.layout.SystemPanel;
44 import ohos.devtools.views.layout.TaskPanel;
45 import ohos.devtools.views.layout.chartview.memory.nativehook.NativeHookPanel;
46 import ohos.devtools.views.layout.dialog.SampleDialog;
47 import ohos.devtools.views.layout.event.TaskScenePanelChartEvent;
48 import ohos.devtools.views.layout.utils.EventTrackUtils;
49 import ohos.devtools.views.layout.utils.TraceStreamerUtils;
50 import ohos.devtools.views.perftrace.PerfTracePanel;
51 import ohos.devtools.views.trace.component.SysAnalystPanel;
52 import org.apache.logging.log4j.LogManager;
53 import org.apache.logging.log4j.Logger;
54 
55 import javax.swing.BorderFactory;
56 import javax.swing.Icon;
57 import javax.swing.ImageIcon;
58 import javax.swing.JButton;
59 import javax.swing.JSplitPane;
60 import javax.swing.Spring;
61 import javax.swing.SpringLayout;
62 import javax.swing.SwingWorker;
63 import java.awt.BorderLayout;
64 import java.awt.CardLayout;
65 import java.awt.Color;
66 import java.awt.Component;
67 import java.awt.Dimension;
68 import java.awt.FlowLayout;
69 import java.awt.Font;
70 import java.awt.GridLayout;
71 import java.awt.LayoutManager;
72 import java.awt.event.ComponentAdapter;
73 import java.awt.event.ComponentEvent;
74 import java.io.File;
75 import java.io.FileNotFoundException;
76 import java.io.IOException;
77 import java.io.RandomAccessFile;
78 import java.lang.reflect.InvocationTargetException;
79 import java.net.URL;
80 import java.util.ArrayList;
81 import java.util.List;
82 import java.util.Objects;
83 import java.util.Optional;
84 import java.util.concurrent.ExecutionException;
85 import java.util.concurrent.ScheduledExecutorService;
86 import java.util.concurrent.TimeUnit;
87 
88 import static java.awt.Image.SCALE_DEFAULT;
89 import static ohos.devtools.datasources.transport.hdc.HdcCmdList.TRACE_STREAMER_LOAD;
90 import static ohos.devtools.datasources.transport.hdc.HdcWrapper.conversionCommand;
91 import static ohos.devtools.datasources.utils.common.Constant.DEVICE_STAT_OFFLINE;
92 import static ohos.devtools.views.layout.chartview.observer.ProfilerChartsViewPublisher.RUN_NAME;
93 import static ohos.devtools.views.layout.chartview.utils.ChartViewConstants.LOADING_SIZE;
94 
95 /**
96  * TaskScenePanelChart
97  *
98  * @since 2021/10/25
99  */
100 public class TaskScenePanelChart extends JBPanel {
101     private static final Logger LOGGER = LogManager.getLogger(TaskScenePanelChart.class);
102     private static final int SELECTED_INDEX = 4;
103     private static final int DUMP_LABLE_WIDTH = 160;
104     private static final int SESSION_LIST_HEIGHT = 60;
105     private static final int SESSION_LIST_WIDTH = 220;
106     private static final int LABLE_FIRST_ITEM = 0;
107     private static final int LABLE_TWO_ITEM = 1;
108     private static final int LABLE_THREE_ITEM = 2;
109     private static final int SESSION_LABLE_LENGTH = 3;
110     private static final int SESSION_LEFT_LABLE_WIDTH = 8;
111     private static final String BYTRACE_TYPE_VALUE = "TRACE";
112     private static final String SYSTEM_TYPE = "1.System Trace";
113     private static final String APPLICATION_TYPE = "2.Application Trace";
114 
115     private Boolean traceAnalysisResult = true;
116 
117     /**
118      * 整体页面top容器
119      */
120     private JBPanel panelTop;
121 
122     /**
123      * 整体页面center容器
124      */
125     private JBPanel panelMiddle;
126 
127     /**
128      * 整体页面Bottom容器
129      */
130     private JBPanel panelBottom;
131 
132     /**
133      * panelTop中,west容器
134      */
135     private JBPanel jPanelWest;
136 
137     /**
138      * panelTop中,Center容器
139      */
140     private JBPanel jPanelCenter;
141 
142     /**
143      * panelTop中,East容器
144      */
145     private JBPanel jPanelEast;
146 
147     /**
148      * 选项卡标签命名
149      */
150     private JBLabel jLabelSetting;
151 
152     /**
153      * 停止按钮
154      */
155     private CustomJButton jButtonStop;
156 
157     /**
158      * 暂停按钮
159      */
160     private CustomJButton jButtonSuspend;
161 
162     /**
163      * 保存任务按钮
164      */
165     private CustomJButton jButtonSave;
166 
167     /**
168      * 删除任务按钮
169      */
170     private CustomJButton jButtonDelete;
171 
172     /**
173      * 新增配置项按钮
174      */
175     private CustomJButton configButton;
176 
177     /**
178      * 向左扩展页面按钮
179      */
180     private CustomJButton jButtonLeft;
181 
182     /**
183      * 切换上一页按钮
184      */
185     private CustomJButton jButtonUp;
186 
187     /**
188      * 切换下一页按钮
189      */
190     private CustomJButton jButtonNext;
191 
192     /**
193      * Run xx of xx 信息文本
194      */
195     private JBLabel jLabelMidde;
196 
197     /**
198      * 00:24:27 chart计时容器
199      */
200     private JBPanel jPanelLabel;
201 
202     /**
203      * 计时器文字显示
204      */
205     private JBLabel jTextArea;
206 
207     /**
208      * panelMiddle容器中左边容器
209      */
210     private JBPanel jPanelMiddleLeft;
211 
212     /**
213      * panelMiddle容器中右边容器
214      */
215     private JBPanel jPanelMiddleRight;
216 
217     /**
218      * panelMiddle容器分割线
219      */
220     private JSplitPane splitPane;
221 
222     /**
223      * jPanelMiddleLeft容器子容器
224      */
225     private JBPanel jScrollCardsPanel;
226 
227     /**
228      * jScrollCardsPanel容器子容器
229      */
230     private JBPanel jScrollCardsPanelInner;
231 
232     /**
233      * jPanelMiddleLeft滚动条
234      */
235     private JBScrollPane jScrollPane;
236 
237     /**
238      * 卡片式布局的面板,用于多个chart页面
239      */
240     private JBPanel cards;
241 
242     /**
243      * 卡片模型对象
244      */
245     private CardLayout cardLayout;
246 
247     /**
248      * 用于jPanelMiddleLeft布局和内容显示
249      */
250     private int number;
251 
252     private int numberJlabel;
253 
254     private TaskScenePanelChartEvent taskScenePanelChartEvent;
255 
256     private CountingThread counting;
257 
258     private ProfilerChartsView profilerView;
259 
260     private JBPanel jPanelSuspension;
261 
262     private JBPanel jpanelSupen;
263 
264     private CustomComboBox jComboBox;
265 
266     private CustomComboBox timeJComboBox;
267 
268     private int sumInt;
269 
270     private boolean greyFlag;
271 
272     private List<CustomJLabel> sessionList;
273 
274     private List<SubSessionListJBPanel> dumpOrHookSessionList;
275 
276     /**
277      * Task Scene Panel Chart
278      */
TaskScenePanelChart()279     public TaskScenePanelChart() {
280         super();
281     }
282 
283     /**
284      * chart监测页面三级容器
285      *
286      * @param jTaskPanel jTaskPanel
287      * @param hosJLabelList hosJLabelList
288      */
TaskScenePanelChart(TaskPanel jTaskPanel, List<CustomJLabel> hosJLabelList)289     public TaskScenePanelChart(TaskPanel jTaskPanel, List<CustomJLabel> hosJLabelList) {
290         EventTrackUtils.getInstance().trackApplicationChartPage();
291         HomePanel.setTaskIsOpen(true);
292         init();
293         getCardLayout(cards);
294         // 整体页面布局设置
295         setLayAttributes(jTaskPanel, hosJLabelList);
296         // 设置按钮属性
297         setButtonAttributes();
298         // 布局panelTop容器,添加按钮
299         setPanelTopAttributes(hosJLabelList);
300         // 设置标签页标题滚动显示
301         new DynamicThread().start();
302         // 布局panelBigTwo中间容器
303         panelMiddle.setLayout(new BorderLayout());
304         // 创建页面分割事件
305         createSplitPanel();
306         // 布局jPanelMiddleLeft容器
307         setScrollPane();
308         jPanelMiddleRight.add(cards);
309         // 获取有多少个设备开始了任务,并循环设置
310         int numberSum = hosJLabelList.size();
311         setTaskLoop(numberSum, hosJLabelList);
312         // 默认显示第一页
313         cardLayout.show(cards, "card0");
314         // 监听窗体大小使悬浮窗紧贴窗体
315         taskScenePanelChartEvent.setSceneSize(jTaskPanel, this);
316         // 给删除按钮添加点击事件
317         taskScenePanelChartEvent.clickDelete(this);
318         // 给上一个页面按钮,下一个页面按钮添加点击事件
319         taskScenePanelChartEvent.clickUpAndNext(this);
320         // 给jsplitPane添加监听事件
321         taskScenePanelChartEvent.splitPaneChange(this, numberSum);
322         // 给jButtonLeft按钮添加点击事件,向左放大页面
323         taskScenePanelChartEvent.clickLeft(this, hosJLabelList);
324         jButtonLeft.setName(UtConstant.UT_TASK_SCENE_PANEL_CHART_LEFT);
325         // 给jButton按钮添加点击时间,保存trace文件
326         taskScenePanelChartEvent.clickSave(jButtonSave, this);
327         // memory配置项新增点击事件
328         taskScenePanelChartEvent.clickConfig(this, profilerView);
329         // Performance analysis index configuration
330         PerformanceIndexPopupMenu itemMenu =
331             new PerformanceIndexPopupMenu(profilerView, this.getJButtonDelete().getSessionId());
332         taskScenePanelChartEvent.clickIndexConfig(configButton, itemMenu);
333         // trace导入,不需要这些按钮
334         if (!hosJLabelList.get(0).isOnline()) {
335             jPanelWest.removeAll();
336         } else {
337             // 开始计时
338             counting = new CountingThread(jTextArea);
339             counting.start();
340         }
341         // 刷新页面
342         jTaskPanel.getTabContainer().repaint();
343     }
344 
345     /**
346      * getCardLayout
347      *
348      * @param cards cards
349      */
getCardLayout(JBPanel cards)350     private void getCardLayout(JBPanel cards) {
351         if (cards != null) {
352             LayoutManager layout = cards.getLayout();
353             if (layout instanceof CardLayout) {
354                 cardLayout = (CardLayout) layout;
355             }
356         }
357     }
358 
init()359     private void init() {
360         panelTop = new JBPanel(new BorderLayout());
361         panelMiddle = new JBPanel(new BorderLayout());
362         panelBottom = new JBPanel(new BorderLayout());
363         jPanelWest = new JBPanel();
364         jPanelCenter = new JBPanel();
365         jPanelEast = new JBPanel();
366         jLabelSetting = new JBLabel();
367         jButtonStop = new CustomJButton(AllIcons.Debugger.Db_set_breakpoint, "Stop");
368         jButtonSuspend = new CustomJButton(AllIcons.Process.ProgressPauseHover, "Suspend");
369         jButtonSave = new CustomJButton(AllIcons.Actions.Menu_saveall, "Save current task");
370         jButtonDelete = new CustomJButton(IconLoader.getIcon("/images/gc.png", getClass()), "Delete current task");
371         configButton = new CustomJButton(AllIcons.General.Add, "");
372         jButtonLeft = new CustomJButton(AllIcons.Actions.PreviewDetails, "Expand page left");
373         jButtonUp = new CustomJButton(AllIcons.General.ArrowLeft, "Previous page");
374         jButtonNext = new CustomJButton(AllIcons.General.ArrowRight, "Next page");
375         jLabelMidde = new JBLabel();
376         jPanelLabel = new JBPanel(new GridLayout());
377         jTextArea = new JBLabel();
378         jPanelMiddleLeft = new JBPanel();
379         jPanelMiddleRight = new JBPanel();
380         splitPane = new JSplitPane();
381         jScrollCardsPanel = new JBPanel(new BorderLayout());
382         jScrollCardsPanelInner = new JBPanel();
383         jScrollPane = new JBScrollPane(jScrollCardsPanel, JBScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
384             JBScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
385         cards = new JBPanel(new CardLayout());
386         taskScenePanelChartEvent = new TaskScenePanelChartEvent();
387         jPanelSuspension = new JBPanel();
388         jpanelSupen = new JBPanel();
389         jComboBox = new CustomComboBox();
390         timeJComboBox = new CustomComboBox();
391         sessionList = new ArrayList<>();
392         dumpOrHookSessionList = new ArrayList<>();
393     }
394 
395     /**
396      * 创建表格
397      *
398      * @param panelBottom panelBottom
399      * @param jTaskPanel jTaskPanel
400      */
createTable(JBPanel panelBottom, TaskPanel jTaskPanel)401     public void createTable(JBPanel panelBottom, TaskPanel jTaskPanel) {
402         JButton jButtonSuspen = new JButton("Suspension frame");
403         panelBottom.add(jButtonSuspen);
404         taskScenePanelChartEvent.showSuspension(this, jTaskPanel, jButtonSuspen);
405     }
406 
407     /**
408      * chart display
409      *
410      * @param num num
411      * @param jcardsPanel jcardsPanel
412      * @param hosJLabel hosJLabel
413      */
chartDisplay(int num, JBPanel jcardsPanel, CustomJLabel hosJLabel)414     private void chartDisplay(int num, JBPanel jcardsPanel, CustomJLabel hosJLabel) {
415         // sessionId绑定按钮
416         if (num == 0) {
417             jButtonStop.setSessionId(hosJLabel.getSessionId());
418             jButtonSuspend.setSessionId(hosJLabel.getSessionId());
419             jButtonSave.setSessionId(hosJLabel.getSessionId());
420             jButtonSave.setDeviceName(hosJLabel.getDeviceName());
421             jButtonSave.setProcessName(hosJLabel.getProcessName());
422             jButtonDelete.setSessionId(hosJLabel.getSessionId());
423             jButtonDelete.setDeviceName(hosJLabel.getDeviceName());
424             jButtonDelete.setProcessName(hosJLabel.getProcessName());
425             configButton.setSessionId(hosJLabel.getSessionId());
426             jButtonLeft.setSessionId(hosJLabel.getSessionId());
427             jComboBox.setSessionId(hosJLabel.getSessionId());
428             timeJComboBox.setSessionId(hosJLabel.getSessionId());
429         }
430         // 判断是导入还是实时
431         if (!hosJLabel.isOnline()) {
432             // 添加chart
433             profilerView = new ProfilerChartsView(hosJLabel.getSessionId(), true, this);
434             jcardsPanel.add(profilerView);
435             if (hosJLabel.getFileType().equals("nativeHeap")) {
436                 createNativeHook(hosJLabel.getSessionId(), null, hosJLabel.isOnline(),
437                     "nativeHeap" + hosJLabel.getSessionId(), hosJLabel.getMessage());
438             } else if (hosJLabel.getFileType().equals(BYTRACE_TYPE_VALUE) || hosJLabel.getFileType().equals("Perf")) {
439                 LOGGER.info("import trace or perf file");
440             } else {
441                 addMonitorItem(hosJLabel.getSessionId());
442                 profilerView.getPublisher().showTraceResult(hosJLabel.getStartTime(), hosJLabel.getEndTime());
443             }
444             taskScenePanelChartEvent.clickZoomEvery(timeJComboBox, profilerView);
445         } else {
446             // 添加chart
447             profilerView = new ProfilerChartsView(hosJLabel.getSessionId(), false, this);
448             jcardsPanel.add(profilerView);
449             addMonitorItem(hosJLabel.getSessionId());
450             // 显示Loading标识,等数据库初始化完成时再显示chart
451             profilerView.showLoading();
452             taskScenePanelChartEvent.clickZoomEvery(timeJComboBox, profilerView);
453             // 给开始暂停按钮添加点击事件
454             taskScenePanelChartEvent.clickRunAndStop(this, profilerView);
455         }
456     }
457 
addMonitorItem(long sessionId)458     private void addMonitorItem(long sessionId) {
459         List<ProfilerMonitorItem> profilerMonitorItems =
460             PlugManager.getInstance().getProfilerMonitorItemList(sessionId);
461         profilerMonitorItems.forEach(item -> {
462             try {
463                 profilerView.addMonitorItemView(item);
464             } catch (InvocationTargetException | NoSuchMethodException
465                 | InstantiationException | IllegalAccessException exception) {
466                 LOGGER.error("addMonitorItemView failed {} ", item.getName());
467             }
468         });
469     }
470 
setTaskLoop(int numberSum, List<CustomJLabel> hosJLabelList)471     private void setTaskLoop(int numberSum, List<CustomJLabel> hosJLabelList) {
472         for (int index = 0; index < numberSum; index++) {
473             sumInt += LayoutConstants.SIXTY;
474             JBPanel jcardsPanel = new JBPanel(new BorderLayout());
475             jcardsPanel.setOpaque(true);
476             CustomJLabel hosJLabel = hosJLabelList.get(index);
477             // sessionId绑定按钮,判断是导入还是实时
478             chartDisplay(index, jcardsPanel, hosJLabel);
479             String labelText = getLabelText(hosJLabel);
480             // 显示设备进程名称
481             CustomJLabel jLabelRight = new CustomJLabel(labelText);
482             jLabelRight.setName(UtConstant.UT_TASK_SCENE_PANEL_CHART_SESSION_MANAGE);
483             // 绑定sessionid,进程设备信息
484             jLabelRight.setSessionId(hosJLabel.getSessionId());
485             jLabelRight.setDeviceName(hosJLabel.getDeviceName());
486             jLabelRight.setProcessName(hosJLabel.getProcessName());
487             jLabelRight.setOnline(hosJLabel.isOnline());
488             jLabelRight.setCardName(hosJLabel.getCardName());
489             jLabelRight.setOpaque(true);
490             // 判断显示具体颜色布局
491             judge(index, jLabelRight, hosJLabel);
492             // 每个设备进程信息用jpanel包围
493             JBPanel jMultiplePanel = new JBPanel(new FlowLayout(0, 0, 0));
494             jMultiplePanel.setBounds(0, number, LayoutConstants.SESSION_LIST_DIVIDER_WIDTH, LayoutConstants.SIXTY);
495             number += LayoutConstants.SIXTY;
496             numberJlabel += LayoutConstants.INDEX_THREE;
497             sessionList.add(jLabelRight);
498             // margin left lable
499             if (hosJLabel.isOnline()) {
500                 CustomJLabel left = new CustomJLabel("");
501                 left.setOpaque(true);
502                 left.setPreferredSize(new Dimension(SESSION_LEFT_LABLE_WIDTH, LayoutConstants.SIXTY));
503                 left.setBackground(ColorConstants.SELECTED_COLOR);
504                 sessionList.add(left);
505                 jLabelRight.setLeft(left);
506                 jMultiplePanel.add(left);
507             }
508             jMultiplePanel.add(jLabelRight);
509             jScrollCardsPanelInner.add(jMultiplePanel);
510             cards.add(jcardsPanel, "card" + index);
511             // 存放点击选择的进程信息用于标签动态展示
512             String jLabelSelect = hosJLabel.getProcessName() + "(" + hosJLabel.getDeviceName() + ")";
513             // 给每个jpanel添加点击事件
514             taskScenePanelChartEvent.clickEvery(this, jLabelRight, numberSum, jLabelSelect, jMultiplePanel);
515         }
516         if (sumInt > LayoutConstants.SCROPNUM) {
517             jScrollCardsPanelInner.setPreferredSize(new Dimension(LayoutConstants.HEIGHT_Y, sumInt));
518         }
519     }
520 
521     /**
522      * getLabelText
523      *
524      * @param hosJLabel hosJLabel
525      * @return String
526      */
getLabelText(CustomJLabel hosJLabel)527     private String getLabelText(CustomJLabel hosJLabel) {
528         String labelText = "";
529         if (DEVICE_STAT_OFFLINE.equals(hosJLabel.getConnectType())) {
530             String[] strs = hosJLabel.getProcessName().split(";");
531             if (strs.length == SESSION_LABLE_LENGTH) {
532                 labelText = "<html><p style=\"white-space:nowrap;overflow:hidden;margin-top: 0px;"
533                     + "text-overflow:ellipsis;margin-left: 0.5cm;line-height:8px;font-size:10px\">"
534                     + strs[LABLE_FIRST_ITEM] + "<br>" + strs[LABLE_TWO_ITEM] + "<br> <span style=\"color:#A4A4A4;\">"
535                     + strs[LABLE_THREE_ITEM] + "</span></p><html>";
536             }
537         } else {
538             labelText = "<html><p style=\"word-break:keep-all;white-space:nowrap;overflow:hidden;"
539                 + "text-overflow:ellipsis;\">" + "&nbsp;&nbsp;" + hosJLabel.getProcessName() + "<br>" + "(" + hosJLabel
540                 .getDeviceName() + ")" + "</p><html>";
541         }
542         return labelText;
543     }
544 
545     /**
546      * Determine the specific color layout
547      *
548      * @param index index
549      * @param jLabelRight jLabelRight
550      * @param hosJLabel hosJLabel
551      */
judge(int index, JBLabel jLabelRight, CustomJLabel hosJLabel)552     public void judge(int index, JBLabel jLabelRight, CustomJLabel hosJLabel) {
553         if (index == 0) {
554             jLabelRight.setBackground(ColorConstants.SELECTED_COLOR);
555             jLabelRight.setForeground(ColorConstants.FONT_COLOR);
556             jLabelRight.setPreferredSize(new Dimension(LayoutConstants.SESSION_LIST_WIDTH, LayoutConstants.SIXTY));
557             if (!hosJLabel.isOnline()) {
558                 jLabelRight.setPreferredSize(new Dimension(LayoutConstants.NUM_200, LayoutConstants.SIXTY));
559                 splitPane.setDividerLocation(LayoutConstants.NUM_200);
560             }
561         } else {
562             jLabelRight.setForeground(JBColor.gray);
563             jLabelRight.setPreferredSize(new Dimension(LayoutConstants.SESSION_LIST_WIDTH, LayoutConstants.SIXTY));
564         }
565         Icon imageIcon = null;
566         if (LayoutConstants.USB.equals(hosJLabel.getConnectType())) {
567             imageIcon = IconLoader.getIcon("/images/icon_usb.png", getClass());
568         } else if (DEVICE_STAT_OFFLINE.equals(hosJLabel.getConnectType())) {
569             jLabelRight.setIcon(null);
570         } else {
571             imageIcon = IconLoader.getIcon("/images/icon_wifi.png", getClass());
572         }
573         jLabelRight.setIcon(imageIcon);
574     }
575 
576     /**
577      * 布局jPanelMiddleLeft容器
578      */
setScrollPane()579     public void setScrollPane() {
580         jPanelMiddleLeft.setLayout(new BorderLayout());
581         jScrollCardsPanelInner.setOpaque(true);
582         jScrollPane.setBorder(null);
583         jScrollPane.getVerticalScrollBar().setUnitIncrement(LayoutConstants.MEMORY_Y);
584         jScrollPane.setHorizontalScrollBarPolicy(JBScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
585         jScrollPane.setVerticalScrollBarPolicy(JBScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
586         jScrollCardsPanel.add(jScrollCardsPanelInner);
587         jScrollCardsPanelInner.setPreferredSize(new Dimension(LayoutConstants.HEIGHT_Y, LayoutConstants.SCROPNUM));
588         jPanelMiddleLeft.add(jScrollPane);
589         jScrollCardsPanelInner.setLayout(null);
590     }
591 
592     /**
593      * 创建页面分割事件
594      */
createSplitPanel()595     public void createSplitPanel() {
596         jPanelMiddleLeft.setMinimumSize(new Dimension(LayoutConstants.HEIGHT_Y, LayoutConstants.JAVA_WIDTH));
597         jPanelMiddleRight.setMinimumSize(new Dimension(0, LayoutConstants.JAVA_WIDTH));
598         jpanelSupen.setPreferredSize(new Dimension(0, LayoutConstants.HUNDRED));
599         jPanelMiddleLeft.setLayout(new GridLayout());
600         jPanelMiddleRight.setLayout(new GridLayout());
601         jPanelMiddleLeft.setOpaque(true);
602         jPanelMiddleRight.setOpaque(true);
603         jPanelMiddleLeft.setBackground(ColorConstants.BLACK_COLOR);
604         jPanelMiddleRight.setBackground(Color.white);
605         jPanelMiddleLeft.setPreferredSize(new Dimension(LayoutConstants.HEIGHT_Y, LayoutConstants.JAVA_WIDTH));
606         // 让分割线显示出箭头
607         splitPane.setOneTouchExpandable(false);
608         splitPane.setContinuousLayout(true);
609         // 设定分割线的距离左边的位置.
610         splitPane.setDividerLocation(LayoutConstants.SESSION_LIST_DIVIDER_WIDTH);
611         splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
612         splitPane.setDividerSize(1);
613         splitPane.setLeftComponent(jPanelMiddleLeft);
614         splitPane.setRightComponent(jPanelMiddleRight);
615         splitPane.setEnabled(false);
616         panelMiddle.add(splitPane);
617         panelMiddle.add(jpanelSupen, BorderLayout.EAST);
618     }
619 
620     /**
621      * 使用内部类完成标签移动操作
622      */
623     private class DynamicThread extends Thread {
624 
625         /**
626          * DynamicThread con
627          */
DynamicThread()628         public DynamicThread() {
629             super.setName("DynamicThread");
630         }
631 
632         @Override
run()633         public void run() {
634             while (true) {
635                 for (int index = 0; index < 200; index++) {
636                     try {
637                         TimeUnit.MILLISECONDS.sleep(200);
638                     } catch (InterruptedException exception) {
639                         LOGGER.error(exception.getMessage());
640                     }
641                     jLabelSetting.setLocation(-index, 0);
642                 }
643             }
644         }
645     }
646 
647     /**
648      * 布局panelTop容器,添加按钮
649      *
650      * @param hosJLabelList hosJLabelList
651      */
setPanelTopAttributes(List<CustomJLabel> hosJLabelList)652     public void setPanelTopAttributes(List<CustomJLabel> hosJLabelList) {
653         jButtonSuspend.setName(UtConstant.UT_TASK_SCENE_PANEL_CHART_STOP_BUTTON);
654         jButtonStop.setName(UtConstant.UT_TASK_SCENE_PANEL_CHART_RUN_BUTTON);
655         jButtonSave.setName(UtConstant.UT_TASK_SCENE_PANEL_CHART_SAVE_BUTTON);
656         jButtonDelete.setName(UtConstant.UT_TASK_SCENE_PANEL_CHART_DELETE_BUTTON);
657         timeJComboBox.setBorder(BorderFactory.createLineBorder(JBColor.background().brighter()));
658         timeJComboBox.setPreferredSize(new Dimension(LayoutConstants.SE_PANEL_Y_TWO, LayoutConstants.APP_LABEL_X));
659         timeJComboBox.setName(UtConstant.UT_TASK_SCENE_PANEL_CHART_TIME);
660         timeJComboBox.addItem("200ms");
661         timeJComboBox.addItem("400ms");
662         timeJComboBox.addItem("600ms");
663         timeJComboBox.addItem("800ms");
664         timeJComboBox.addItem("1000ms");
665         configButton.setName(UtConstant.UT_TASK_SCENE_PANEL_CHART_CONFIG);
666         timeJComboBox.setSelectedIndex(SELECTED_INDEX);
667         jPanelWest.setLayout(new FlowLayout(FlowLayout.LEADING, 10, 0));
668         jPanelEast.setLayout(new FlowLayout(FlowLayout.LEADING, 10, 0));
669         jPanelWest.add(jButtonStop);
670         jPanelWest.add(jButtonSuspend);
671         jPanelWest.add(jButtonUp);
672         jPanelWest.add(jLabelMidde);
673         jPanelWest.add(jPanelLabel);
674         jPanelWest.add(jButtonNext);
675         jPanelWest.add(jButtonSave);
676         jPanelWest.add(jButtonDelete);
677         jPanelEast.setPreferredSize(new Dimension(50, LayoutConstants.LABEL_NAME_HEIGHT));
678         if (hosJLabelList.get(0).isOnline() || hosJLabelList.get(0).getFileType().equals(UtConstant.FILE_TYPE_TRACE)) {
679             jPanelEast.add(timeJComboBox);
680             jPanelEast.add(configButton);
681             jPanelEast.setPreferredSize(
682                 new Dimension(LayoutConstants.TOP_PANEL_EAST_WIDTH, LayoutConstants.LABEL_NAME_HEIGHT));
683         }
684         jPanelEast.add(jButtonLeft);
685     }
686 
687     /**
688      * 设置按钮属性
689      */
setButtonAttributes()690     public void setButtonAttributes() {
691         this.setButtonStyle(jButtonUp, "Previous page");
692         this.setButtonStyle(jButtonNext, "Next page");
693         this.setButtonStyle(jButtonStop, "Stop");
694         this.setButtonStyle(jButtonSuspend, "Suspend");
695         this.setButtonStyle(jButtonSave, "Save current task");
696         this.setButtonStyle(jButtonDelete, "Delete current task");
697         this.setButtonStyle(configButton, "Data Source");
698         this.setButtonStyle(jButtonLeft, "Expand page left");
699     }
700 
701     /**
702      * set HosJButton Style
703      *
704      * @param button button
705      * @param tipText tipText
706      */
setButtonStyle(CustomJButton button, String tipText)707     private void setButtonStyle(CustomJButton button, String tipText) {
708         button.setOpaque(false);
709         button.setFocusPainted(false);
710         button.setBorderPainted(false);
711         button.setToolTipText(tipText);
712     }
713 
714     /**
715      * Overall page layout settings
716      *
717      * @param jTaskPanel jTaskPanel
718      * @param hosJLabelList hosJLabelList
719      */
setLayAttributes(TaskPanel jTaskPanel, List<CustomJLabel> hosJLabelList)720     public void setLayAttributes(TaskPanel jTaskPanel, List<CustomJLabel> hosJLabelList) {
721         this.setLayout(new BorderLayout());
722         panelTop.setBackground(JBColor.background());
723         panelTop.setPreferredSize(new Dimension(LayoutConstants.DEVICES_WIDTH, LayoutConstants.TOP_PANEL_HEIGHT));
724         // 页面中间部分
725         panelMiddle.setBackground(JBColor.WHITE);
726         panelMiddle.setPreferredSize(new Dimension(LayoutConstants.DEVICES_WIDTH, LayoutConstants.JAVA_WIDTH));
727         // 页面下面部分
728         panelBottom.setBackground(ColorConstants.BLACK_COLOR);
729         panelBottom.setPreferredSize(new Dimension(LayoutConstants.DEVICES_WIDTH, LayoutConstants.LABEL_NAME_WIDTH));
730         this.add(panelTop, BorderLayout.NORTH);
731         setPanelTop(panelTop);
732         this.add(panelMiddle, BorderLayout.CENTER);
733         jPanelWest.setOpaque(false);
734         jPanelCenter.setOpaque(false);
735         jPanelEast.setOpaque(false);
736         jPanelWest.setPreferredSize(new Dimension(LayoutConstants.EAST_LABEL_WIDTH, LayoutConstants.LABEL_NAME_HEIGHT));
737         jPanelCenter.setPreferredSize(new Dimension(LayoutConstants.DEVICES_WIDTH, LayoutConstants.LABEL_NAME_HEIGHT));
738         panelTop.add(jPanelWest, BorderLayout.WEST);
739         panelTop.add(jPanelCenter, BorderLayout.CENTER);
740         panelTop.add(jPanelEast, BorderLayout.EAST);
741         CustomJLabel hosJLabel = hosJLabelList.get(0);
742         if (DEVICE_STAT_OFFLINE.equals(hosJLabel.getConnectType())
743             && hosJLabel.getProcessName().split(";").length == SESSION_LABLE_LENGTH) {
744             jLabelSetting = new JBLabel(hosJLabel.getProcessName().split(";")[LABLE_TWO_ITEM]);
745         } else {
746             jLabelSetting = new JBLabel(hosJLabel.getProcessName() + "(" + hosJLabel.getDeviceName() + ")");
747         }
748         jLabelSetting.setBounds(0, 0, LayoutConstants.EAST_LABEL_WIDTH, LayoutConstants.LABEL_NAME_HEIGHT);
749         jTaskPanel.getTabLeftPanel().removeAll();
750         jTaskPanel.getTabRightPanel().removeAll();
751         jTaskPanel.getTabLeftPanel().add(jLabelSetting);
752         jTaskPanel.getTabRightPanel().add(jTaskPanel.getTabCloseBtn());
753         jTextArea.setOpaque(true);
754         jTextArea.setBackground(JBColor.background());
755         jPanelLabel.add(jTextArea);
756     }
757 
758     /**
759      * createNativeHook
760      *
761      * @param name Native Hook Recoding name
762      * @param startTime Native Hook Recoding Time
763      * @param sessionId Native Hook Session Id
764      * @param dbPath dbPath
765      */
createSessionList(String name, String startTime, long sessionId, String dbPath)766     public void createSessionList(String name, String startTime, long sessionId, String dbPath) {
767         JBPanel jScrollCardsPanelSession = this.getJScrollCardsPanelInner();
768         Component[] innerPanel = jScrollCardsPanelSession.getComponents();
769         SubSessionListJBPanel sessionListPanel = null;
770         CustomJLabel labelSave = new CustomJLabel();
771         labelSave.setIcon(IconLoader.getIcon("/images/menu-saveall.png", getClass()));
772         for (Component inner : innerPanel) {
773             Component[] innerLable;
774             if (inner instanceof JBPanel) {
775                 innerLable = ((JBPanel) inner).getComponents();
776                 for (Component item : innerLable) {
777                     if (item instanceof CustomJLabel && ((CustomJLabel) item).getSessionId() == sessionId) {
778                         // 添加Dump
779                         sessionListPanel = new SubSessionListJBPanel();
780                         addDump(name, startTime, labelSave, sessionListPanel, jScrollCardsPanelSession);
781                     }
782                 }
783             }
784         }
785         if (sessionListPanel != null) {
786             sessionListPanel.setBackground(ColorConstants.SELECTED_COLOR);
787         }
788         String cardName;
789         if (name.contains(LayoutConstants.TRACE_SYSTEM_CALLS)) {
790             cardName = "traceApp" + startTime;
791             Objects.requireNonNull(sessionListPanel).setPanelName(cardName);
792             sessionListPanel.setDbPath(dbPath);
793             showAppTrace(dbPath, sessionId);
794         } else if (name.contains(LayoutConstants.SAMPLE_PERF_DATA)) {
795             cardName = "nativePerf" + startTime;
796             Objects.requireNonNull(sessionListPanel).setPanelName(cardName);
797             sessionListPanel.setDbPath(dbPath);
798             showPerfTrace(dbPath);
799         } else if (name.contains("Native Heap")) {
800             // load Native Hook
801             cardName = "nativeHeap" + startTime;
802             Objects.requireNonNull(sessionListPanel).setPanelName(cardName);
803             createNativeHook(sessionId, labelSave, true, cardName, "");
804         } else {
805             // load Heap Dump
806             cardName = "";
807         }
808         // set Button disabled
809         greyFlag = true;
810         setButtonEnable(greyFlag, cardName);
811     }
812 
813     /**
814      * createImportFileSessionList
815      *
816      * @param name Native Hook Recoding name
817      * @param hosJLabel hosJLabel
818      * @param selectedFile selectedFile
819      */
createImportFileSessionList(String name, CustomJLabel hosJLabel, File selectedFile)820     public void createImportFileSessionList(String name, CustomJLabel hosJLabel, File selectedFile) {
821         JBPanel jScrollCardsPanelSession = this.getJScrollCardsPanelInner();
822         Component[] innerPanel = jScrollCardsPanelSession.getComponents();
823         SubSessionListJBPanel sessionListPanel = null;
824         String labelText = getLabelText(hosJLabel);
825         hosJLabel.setText(labelText);
826         int addNum = 1;
827         for (Component inner : innerPanel) {
828             Component[] innerLable;
829             if (inner instanceof JBPanel) {
830                 innerLable = ((JBPanel) inner).getComponents();
831                 for (Component item : innerLable) {
832                     if (item instanceof CustomJLabel && addNum == 1) {
833                         sessionListPanel = new SubSessionListJBPanel();
834                         addImportFile(name, hosJLabel, sessionListPanel, jScrollCardsPanelSession);
835                         addNum++;
836                     }
837                 }
838             }
839         }
840         if (sessionListPanel != null) {
841             sessionListPanel.setBackground(ColorConstants.SELECTED_COLOR);
842         }
843         handImportScene(name, hosJLabel, selectedFile, sessionListPanel);
844     }
845 
handImportScene(String name, CustomJLabel hosJLabel, File selectedFile, SubSessionListJBPanel sessionListPanel)846     private void handImportScene(String name, CustomJLabel hosJLabel, File selectedFile,
847         SubSessionListJBPanel sessionListPanel) {
848         String cardName = "";
849         long sessionId = hosJLabel.getSessionId();
850         if (name.contains(UtConstant.FILE_TYPE_TRACE)) {
851             JBPanel jcardsPanel = new JBPanel(new BorderLayout());
852             cardName = "trace" + sessionId;
853             Objects.requireNonNull(sessionListPanel).setPanelName(cardName);
854             createImportTrace(selectedFile, hosJLabel, jcardsPanel, cardName);
855             cards.add(jcardsPanel, cardName);
856             cardLayout.show(cards, cardName);
857         } else if (name.contains(BYTRACE_TYPE_VALUE)) {
858             cardName = "Trace" + sessionId;
859             createImportSystemTrace(cardName, hosJLabel, selectedFile);
860             Objects.requireNonNull(sessionListPanel).setPanelName(cardName);
861         } else if (name.contains("NativeHeap")) {
862             cardName = "NativeHeap" + sessionId;
863             createImportNativeHook(hosJLabel.getSessionId(), null, hosJLabel.isOnline(),
864                 "NativeHeap" + hosJLabel.getSessionId(), hosJLabel.getMessage());
865             Objects.requireNonNull(sessionListPanel).setPanelName(cardName);
866         } else if (name.contains("PERF")) {
867             cardName = "Perf" + sessionId;
868             PerfTracePanel component = new PerfTracePanel();
869             loadPerf(selectedFile, name, cardName, component);
870             Objects.requireNonNull(sessionListPanel).setPanelName(cardName);
871             cards.add(component, cardName);
872             cardLayout.show(cards, cardName);
873         } else {
874             // load Heap Dump
875             cardName = "";
876         }
877         disSelectOtherList(cardName);
878     }
879 
createImportTrace(File selectedFile, CustomJLabel hosJLabel, JBPanel jcardsPanel, String cardName)880     private void createImportTrace(File selectedFile, CustomJLabel hosJLabel, JBPanel jcardsPanel, String cardName) {
881         SwingWorker<Optional<DeviceProcessInfo>, Object> task = new SwingWorker<Optional<DeviceProcessInfo>, Object>() {
882             JBLabel loadingLabel = new JBLabel();
883 
884             /**
885              * doInBackground
886              *
887              * @return Optional<DeviceProcessInfo>
888              */
889             @Override
890             protected Optional<DeviceProcessInfo> doInBackground() {
891                 loadingLabel = showLoading(jcardsPanel);
892                 CustomProgressBar progressBar = new CustomProgressBar(new JBPanel<>());
893                 return SessionManager.getInstance().localSessionDataFromFile(progressBar, selectedFile);
894             }
895 
896             /**
897              * done
898              */
899             @Override
900             protected void done() {
901                 try {
902                     Optional<DeviceProcessInfo> deviceProcessInfo = get();
903                     if (deviceProcessInfo.isPresent()) {
904                         DeviceProcessInfo deviceInfo = deviceProcessInfo.get();
905                         buildHosLabel(deviceInfo, hosJLabel, selectedFile);
906                         ProfilerChartsView chartsView =
907                             new ProfilerChartsView(deviceInfo.getLocalSessionId(), true, TaskScenePanelChart.this);
908                         List<ProfilerMonitorItem> profilerMonitorItems =
909                             PlugManager.getInstance().getProfilerMonitorItemList(deviceInfo.getLocalSessionId());
910                         profilerMonitorItems.forEach(item -> {
911                             try {
912                                 chartsView.addMonitorItemView(item);
913                             } catch (InvocationTargetException | NoSuchMethodException
914                                 | InstantiationException | IllegalAccessException exception) {
915                                 LOGGER.error("addMonitorItemView failed {} ", item.getName());
916                             }
917                         });
918                         chartsView.getPublisher().showTraceResult(hosJLabel.getStartTime(), hosJLabel.getEndTime());
919                         jcardsPanel.setOpaque(true);
920                         jcardsPanel.add(chartsView);
921                         chartsView.addComponentListener(new ComponentAdapter() {
922                             @Override
923                             public void componentResized(ComponentEvent event) {
924                                 super.componentResized(event);
925                                 chartsView
926                                     .setPreferredSize(new Dimension(jcardsPanel.getWidth(), jcardsPanel.getHeight()));
927                             }
928                         });
929                         taskScenePanelChartEvent.clickZoomEvery(timeJComboBox, chartsView);
930                         jcardsPanel.remove(loadingLabel);
931                     }
932                 } catch (InterruptedException | ExecutionException exception) {
933                     exception.printStackTrace();
934                 }
935             }
936         };
937         task.execute();
938     }
939 
buildHosLabel(DeviceProcessInfo deviceInfo, CustomJLabel hosJLabel, File selectedFile)940     private void buildHosLabel(DeviceProcessInfo deviceInfo, CustomJLabel hosJLabel, File selectedFile) {
941         hosJLabel.setProcessName(deviceInfo.getProcessName() + ";" + selectedFile.getName());
942         hosJLabel.setSessionId(deviceInfo.getLocalSessionId());
943         hosJLabel.setDeviceName(deviceInfo.getDeviceName());
944         hosJLabel.setOnline(false);
945         hosJLabel.setFileType(UtConstant.FILE_TYPE_TRACE);
946         hosJLabel.setStartTime(deviceInfo.getStartTime());
947         hosJLabel.setEndTime(deviceInfo.getEndTime());
948     }
949 
createImportSystemTrace(String cardName, CustomJLabel hosJLabel, File selectedFile)950     private void createImportSystemTrace(String cardName, CustomJLabel hosJLabel, File selectedFile) {
951         JBPanel component;
952         String value = hosJLabel.getMessage();
953         if (value.equals(SYSTEM_TYPE)) {
954             component = new SysAnalystPanel();
955             loadTrace(component, selectedFile, cards, false, cardName);
956         }
957         if (value.equals(APPLICATION_TYPE)) {
958             component = new AppTracePanel();
959             loadTrace(component, selectedFile, cards, true, cardName);
960             cards.add(component, cardName);
961         }
962         cardLayout.show(cards, cardName);
963     }
964 
loadTrace(JBPanel component, File selectedFile, JBPanel optionJPanel, boolean isAppTrace, String cardName)965     private void loadTrace(JBPanel component, File selectedFile, JBPanel optionJPanel, boolean isAppTrace,
966         String cardName) {
967         SwingWorker<String, Object> task = new SwingWorker<String, Object>() {
968 
969             JBLabel loadingLabel = new JBLabel();
970 
971             @Override
972             protected String doInBackground() throws Exception {
973                 traceAnalysisResult = true;
974                 loadingLabel = showLoading(component);
975                 String logPath = TraceStreamerUtils.getInstance().getLogPath("trace_streamer.db");
976                 File logFile = new File(logPath);
977                 if (logFile.exists()) {
978                     logFile.delete();
979                 }
980                 String baseDir = TraceStreamerUtils.getInstance().getBaseDir();
981                 String dbPath = TraceStreamerUtils.getInstance().getDbPath();
982                 HdcWrapper.getInstance().getHdcStringResult(conversionCommand(TRACE_STREAMER_LOAD,
983                     baseDir + TraceStreamerUtils.getInstance().getTraceStreamerApp(), selectedFile.getPath(), dbPath));
984                 randomFile(logFile);
985                 return dbPath;
986             }
987 
988             /**
989              * done
990              */
991             @Override
992             protected void done() {
993                 if (!traceAnalysisResult) {
994                     new SampleDialog("Warring",
995                         "The system cannot parse the file properly. Please import the legal file.").show();
996                 }
997                 try {
998                     if (traceAnalysisResult) {
999                         String dbPath = get();
1000                         addOptionJPanel(dbPath, optionJPanel, isAppTrace, component, cardName);
1001                         component.remove(loadingLabel);
1002                     }
1003                 } catch (InterruptedException interruptedException) {
1004                     LOGGER.error(interruptedException.getMessage());
1005                 } catch (ExecutionException executionException) {
1006                     LOGGER.error(executionException.getMessage());
1007                 }
1008             }
1009         };
1010         task.execute();
1011     }
1012 
addOptionJPanel(String dbPath, JBPanel optionJPanel, boolean isAppTrace, JBPanel component, String cardName)1013     private void addOptionJPanel(String dbPath, JBPanel optionJPanel, boolean isAppTrace, JBPanel component,
1014         String cardName) {
1015         if (isAppTrace) {
1016             ((AppTracePanel) component).load(dbPath, null, null, true);
1017             optionJPanel.add(component, cardName);
1018         } else {
1019             JBPanel tabContainer = new JBPanel(new BorderLayout());
1020             ((SysAnalystPanel) component).load(dbPath, true);
1021             SystemPanel systemTuningPanel = new SystemPanel(tabContainer, ((SysAnalystPanel) component));
1022             tabContainer.add(systemTuningPanel, BorderLayout.NORTH);
1023             tabContainer.add(component, BorderLayout.CENTER);
1024             ((SysAnalystPanel) component).getAnalystPanel()
1025                 .setPreferredSize(new Dimension(optionJPanel.getWidth() - 20, optionJPanel.getHeight()));
1026             optionJPanel.add(tabContainer, cardName);
1027         }
1028         cardLayout.show(optionJPanel, cardName);
1029     }
1030 
randomFile(File logFile)1031     private void randomFile(File logFile) throws IOException {
1032         RandomAccessFile randomFile = null;
1033         try {
1034             if (logFile.exists()) {
1035                 randomFile = new RandomAccessFile(logFile, "r");
1036                 String tmp = null;
1037                 while ((tmp = randomFile.readLine()) != null) {
1038                     if (tmp.startsWith("last")) {
1039                         continue;
1040                     }
1041                     if (Integer.valueOf(tmp.split(":")[1]) != 0) {
1042                         traceAnalysisResult = false;
1043                     }
1044                 }
1045             }
1046         } catch (FileNotFoundException fileNotFoundException) {
1047             LOGGER.error("randomFile exception:{}", fileNotFoundException.getMessage());
1048         } catch (IOException iOException) {
1049             LOGGER.error("randomFile exception:{}", iOException.getMessage());
1050         } finally {
1051             if (randomFile != null) {
1052                 randomFile.close();
1053             }
1054         }
1055     }
1056 
loadPerf(File selectedFile, String readLineStr, String cardName, PerfTracePanel component)1057     private void loadPerf(File selectedFile, String readLineStr, String cardName, PerfTracePanel component) {
1058         SwingWorker<String, Object> task = new SwingWorker<>() {
1059             JBLabel loadingLabel = new JBLabel();
1060 
1061             @Override
1062             protected String doInBackground() {
1063                 ParsePerf traceParser = new HiperfParse();
1064                 loadingLabel = showLoading(component);
1065                 try {
1066                     traceParser.parseFile(selectedFile);
1067                     PerfDAO.getInstance().createTable(null);
1068                     traceParser.insertSample();
1069                 } catch (IOException exception) {
1070                     exception.printStackTrace();
1071                 }
1072                 return SessionManager.getInstance().tempPath() + "perf.db";
1073             }
1074 
1075             @Override
1076             protected void done() {
1077                 try {
1078                     String dbPath = get();
1079                     if (dbPath != null) {
1080                         component.load(dbPath, null, true);
1081                         component.remove(loadingLabel);
1082                     }
1083                 } catch (InterruptedException | ExecutionException exception) {
1084                     exception.printStackTrace();
1085                 }
1086             }
1087         };
1088         task.execute();
1089     }
1090 
1091     /**
1092      * showLoading
1093      *
1094      * @param panel panel
1095      * @return JBLabel
1096      */
showLoading(JBPanel panel)1097     public JBLabel showLoading(JBPanel panel) {
1098         if (ProfilerLogManager.isInfoEnabled()) {
1099             LOGGER.info("showLoading");
1100         }
1101         SpringLayout spring = new SpringLayout();
1102         panel.setLayout(spring);
1103         JBLabel loadingLabel = new JBLabel();
1104         URL url = TaskScenePanelChart.class.getClassLoader().getResource("/images/loading.gif");
1105         if (url != null) {
1106             ImageIcon icon = new ImageIcon(url);
1107             icon.setImage(icon.getImage().getScaledInstance(LOADING_SIZE, LOADING_SIZE, SCALE_DEFAULT));
1108             loadingLabel.setIcon(icon);
1109         }
1110         panel.add(loadingLabel);
1111         // 增加约束,保持Loading图在组件中间
1112         SpringLayout.Constraints loadingCons = spring.getConstraints(loadingLabel);
1113         loadingCons.setX(Spring.constant((this.getjPanelMiddleRight().getWidth() - LOADING_SIZE) / 2));
1114         loadingCons.setY(Spring.constant((this.getjPanelMiddleRight().getHeight() - LOADING_SIZE) / 2));
1115         return loadingLabel;
1116     }
1117 
disSelectOtherList(String panelName)1118     private void disSelectOtherList(String panelName) {
1119         for (CustomJLabel customJLabel : sessionList) {
1120             customJLabel.setBackground(JBColor.background().brighter());
1121         }
1122         for (SubSessionListJBPanel tempsubSession : dumpOrHookSessionList) {
1123             if (!tempsubSession.getPanelName().equals(panelName)) {
1124                 tempsubSession.setBackground(JBColor.background().brighter());
1125             }
1126         }
1127     }
1128 
1129     /**
1130      * addDump
1131      *
1132      * @param name name
1133      * @param startTime startTime
1134      * @param labelSave labelSave
1135      * @param sessionListPanel sessionListPanel
1136      * @param jScrollCardsPanelSession jScrollCardsPanelSession
1137      */
addDump(String name, String startTime, CustomJLabel labelSave, SubSessionListJBPanel sessionListPanel, JBPanel jScrollCardsPanelSession)1138     public void addDump(String name, String startTime, CustomJLabel labelSave, SubSessionListJBPanel sessionListPanel,
1139         JBPanel jScrollCardsPanelSession) {
1140         CustomJLabel nameLable = new CustomJLabel(name);
1141         nameLable.setPreferredSize(new Dimension(DUMP_LABLE_WIDTH, LayoutConstants.THIRTY));
1142         String btnStr = "Save Heap Dump";
1143         if (name.contains("Native Heap")) {
1144             btnStr = "Save Native Heap Recording";
1145         }
1146         MigLayout layout = new MigLayout();
1147         sessionListPanel.setLayout(layout);
1148         if (name.contains(LayoutConstants.TRACE_SYSTEM_CALLS)) {
1149             nameLable.setIcon(IconLoader.getIcon("/images/cpu.png", getClass()));
1150             sessionListPanel.add(nameLable, "gapleft 15,wrap 5");
1151         } else if (name.contains(LayoutConstants.SAMPLE_PERF_DATA)) {
1152             nameLable.setIcon(IconLoader.getIcon("/images/cpu.png", getClass()));
1153             sessionListPanel.add(nameLable, "gapleft 15,wrap 5");
1154         } else {
1155             nameLable.setIcon(IconLoader.getIcon("/images/icon_heap_dump_normal.png", getClass()));
1156             labelSave.setToolTipText(btnStr);
1157             sessionListPanel.add(nameLable, "gapleft 15");
1158             sessionListPanel.add(labelSave, "wrap 5,width 15:15:15,height 15:15:15");
1159             taskScenePanelChartEvent.saveButtonAddClick(labelSave, name);
1160         }
1161         CustomJLabel timeLabel = new CustomJLabel(" " + startTime);
1162         timeLabel.setBounds(LayoutConstants.TIMELABLE_XY, LayoutConstants.TIMELABLE_XY, LayoutConstants.HUNDRED_EIGHTY,
1163             LayoutConstants.THIRTY);
1164         Font font = new Font(Font.DIALOG, Font.PLAIN, LayoutConstants.OPTION_FONT);
1165         timeLabel.setFont(font);
1166         sessionListPanel.add(timeLabel, "gapleft 28");
1167         sessionListPanel.setHosJLabel(nameLable);
1168         sessionListPanel.setStartTime(startTime);
1169         sessionListPanel.setTimeJLabel(timeLabel);
1170         dumpOrHookSessionList.add(sessionListPanel);
1171         sessionListPanel.setBounds(0, number, SESSION_LIST_WIDTH, SESSION_LIST_HEIGHT);
1172         jScrollCardsPanelSession.add(sessionListPanel);
1173         if (number > LayoutConstants.LEFT_TOP_WIDTH) {
1174             jScrollCardsPanelSession.setPreferredSize(new Dimension(SESSION_LIST_WIDTH, number + SESSION_LIST_HEIGHT));
1175         }
1176         taskScenePanelChartEvent.sessionListPanelAddClick(sessionListPanel, this);
1177         number += SESSION_LIST_HEIGHT;
1178     }
1179 
1180     /**
1181      * addImportFile
1182      *
1183      * @param name name
1184      * @param labelSave labelSave
1185      * @param sessionListPanel sessionListPanel
1186      * @param jScrollCardsPanelSession jScrollCardsPanelSession
1187      */
addImportFile(String name, CustomJLabel labelSave, SubSessionListJBPanel sessionListPanel, JBPanel jScrollCardsPanelSession)1188     public void addImportFile(String name, CustomJLabel labelSave, SubSessionListJBPanel sessionListPanel,
1189         JBPanel jScrollCardsPanelSession) {
1190         MigLayout layout = new MigLayout();
1191         sessionListPanel.setLayout(layout);
1192         sessionListPanel.setHosJLabel(labelSave);
1193         sessionListPanel.add(labelSave);
1194         dumpOrHookSessionList.add(sessionListPanel);
1195         sessionListPanel.setBounds(0, number, SESSION_LIST_WIDTH, SESSION_LIST_HEIGHT);
1196         jScrollCardsPanelSession.add(sessionListPanel);
1197         if (number > LayoutConstants.LEFT_TOP_WIDTH) {
1198             jScrollCardsPanelSession.setPreferredSize(new Dimension(SESSION_LIST_WIDTH, number + SESSION_LIST_HEIGHT));
1199         }
1200         taskScenePanelChartEvent.sessionListPanelAddClick(sessionListPanel, this);
1201         number += SESSION_LIST_HEIGHT;
1202     }
1203 
1204     /**
1205      * showAppTrace
1206      *
1207      * @param dbPathParam dbPathParam
1208      * @param sessionId sessionId
1209      */
showAppTrace(String dbPathParam, long sessionId)1210     public void showAppTrace(String dbPathParam, long sessionId) {
1211         this.remove(panelTop);
1212         AppTracePanel component = new AppTracePanel();
1213         component.load(dbPathParam, SessionManager.getInstance().tempPath() + "cpuDb",
1214             (int) SessionManager.getInstance().getPid(sessionId), true);
1215         cards.add(component, dbPathParam);
1216         cardLayout.show(cards, dbPathParam);
1217     }
1218 
1219     /**
1220      * showPerfTrace
1221      *
1222      * @param dbPathParam dbPathParam
1223      */
showPerfTrace(String dbPathParam)1224     public void showPerfTrace(String dbPathParam) {
1225         PerfTracePanel component = new PerfTracePanel();
1226         this.remove(panelTop);
1227         component.load(dbPathParam, SessionManager.getInstance().tempPath() + "cpuDb", true);
1228         cards.add(component, dbPathParam);
1229         cardLayout.show(cards, dbPathParam);
1230     }
1231 
createNativeHook(long sessionId, CustomJLabel labelSave, boolean isOnline, String cardName, String filePath)1232     private void createNativeHook(long sessionId, CustomJLabel labelSave, boolean isOnline, String cardName,
1233         String filePath) {
1234         NativeHookPanel nativeHookPanel = new NativeHookPanel(this);
1235         nativeHookPanel.load(sessionId, labelSave, isOnline, filePath);
1236         if (!isOnline) {
1237             profilerView.add(nativeHookPanel);
1238         } else {
1239             cards.add(nativeHookPanel, cardName);
1240             cardLayout.show(cards, cardName);
1241         }
1242     }
1243 
createImportNativeHook(long sessionId, CustomJLabel labelSave, boolean isOnline, String cardName, String filePath)1244     private void createImportNativeHook(long sessionId, CustomJLabel labelSave, boolean isOnline, String cardName,
1245         String filePath) {
1246         NativeHookPanel nativeHookPanel = new NativeHookPanel(this);
1247         nativeHookPanel.load(sessionId, labelSave, isOnline, filePath);
1248         cards.add(nativeHookPanel, cardName);
1249         cardLayout.show(cards, cardName);
1250     }
1251 
1252     /**
1253      * handleFailed
1254      *
1255      * @param sessionListPanel sessionListPanel
1256      */
handleFailed(SubSessionListJBPanel sessionListPanel)1257     public void handleFailed(SubSessionListJBPanel sessionListPanel) {
1258         if (sessionListPanel != null && sessionList.size() >= 1) {
1259             this.getJScrollCardsPanelInner().remove(sessionListPanel);
1260             cardLayout.show(cards, "card0");
1261             sessionList.get(0).setBackground(ColorConstants.SELECTED_COLOR);
1262             number -= SESSION_LIST_HEIGHT;
1263         }
1264     }
1265 
1266     /**
1267      * showSubSessionList
1268      *
1269      * @param list list
1270      */
showSubSessionList(List<SubSessionListJBPanel> list)1271     public void showSubSessionList(List<SubSessionListJBPanel> list) {
1272         SubSessionListJBPanel tempSub;
1273         for (int index = 0; index < list.size(); index++) {
1274             tempSub = list.get(index);
1275             if (index == 0) {
1276                 number = 0;
1277                 tempSub.setBounds(0, 0, SESSION_LIST_WIDTH, SESSION_LIST_HEIGHT);
1278                 if (tempSub.getPanelName().contains("heapDump") || (tempSub.getPanelName().contains("nativeHook"))) {
1279                     cardLayout.show(cards, tempSub.getPanelName());
1280                     setButtonEnable(true, "");
1281                 } else {
1282                     cardLayout.show(cards, tempSub.getDbPath());
1283                     this.remove(panelTop);
1284                 }
1285                 tempSub.setBackground(ColorConstants.SELECTED_COLOR);
1286             } else {
1287                 number += SESSION_LIST_HEIGHT;
1288                 tempSub.setBounds(0, number, SESSION_LIST_WIDTH, SESSION_LIST_HEIGHT);
1289             }
1290         }
1291     }
1292 
1293     /**
1294      * Set button available or not  and set sessionList not selected background
1295      *
1296      * @param flag flag
1297      * @param panelName panelName
1298      */
setButtonEnable(boolean flag, String panelName)1299     public void setButtonEnable(boolean flag, String panelName) {
1300         if (flag) {
1301             jButtonStop.setIcon(IconLoader.getIcon("/images/db_set_breakpoint_grey.png", getClass()));
1302             if (!panelName.contains("nativeHeap")) {
1303                 jButtonSuspend.setIcon(AllIcons.Process.ProgressPause);
1304             }
1305             jButtonDelete.setIcon(IconLoader.getIcon("/images/gc_grey.png", getClass()));
1306             for (CustomJLabel customJLabel : sessionList) {
1307                 customJLabel.setBackground(JBColor.background().brighter());
1308             }
1309             for (SubSessionListJBPanel tempsubSession : dumpOrHookSessionList) {
1310                 if (!tempsubSession.getPanelName().equals(panelName)) {
1311                     tempsubSession.setBackground(JBColor.background().brighter());
1312                 }
1313                 if (tempsubSession.getDbPath() != null && !tempsubSession.getDbPath().equals(panelName) && panelName
1314                     .contains(".db")) {
1315                     tempsubSession.setBackground(JBColor.background().brighter());
1316                 }
1317             }
1318         } else {
1319             Optional<ScheduledExecutorService> scheduledExecutorService =
1320                 QuartzManager.getInstance().checkService(RUN_NAME);
1321             if (!scheduledExecutorService.isPresent()) {
1322                 profilerView.getPublisher().restartRefresh();
1323                 profilerView.setPause(false);
1324             }
1325             jButtonStop.setIcon(AllIcons.Debugger.Db_set_breakpoint);
1326             jButtonSuspend.setIcon(AllIcons.Process.ProgressPause);
1327             jButtonDelete.setIcon(IconLoader.getIcon("/images/gc.png", getClass()));
1328             // disable all dump or native hook
1329             for (SubSessionListJBPanel subSessionListJBPanel : dumpOrHookSessionList) {
1330                 subSessionListJBPanel.setBackground(JBColor.background().brighter());
1331             }
1332         }
1333     }
1334 
1335     /**
1336      * getJButtonDelete
1337      *
1338      * @return CustomJButton
1339      */
getJButtonDelete()1340     public CustomJButton getJButtonDelete() {
1341         return jButtonDelete;
1342     }
1343 
1344     /**
1345      * getjButtonRun
1346      *
1347      * @return CustomJButton
1348      */
getjButtonRun()1349     public CustomJButton getjButtonRun() {
1350         return jButtonStop;
1351     }
1352 
1353     /**
1354      * getjButtonStop
1355      *
1356      * @return CustomJButton
1357      */
getjButtonStop()1358     public CustomJButton getjButtonStop() {
1359         return jButtonSuspend;
1360     }
1361 
1362     /**
1363      * getjButtonSave
1364      *
1365      * @return CustomJButton
1366      */
getjButtonSave()1367     public CustomJButton getjButtonSave() {
1368         return jButtonSave;
1369     }
1370 
1371     /**
1372      * getConfigButton
1373      *
1374      * @return CustomJButton
1375      */
getConfigButton()1376     public CustomJButton getConfigButton() {
1377         return configButton;
1378     }
1379 
1380     /**
1381      * getjButtonLeft
1382      *
1383      * @return CustomJButton
1384      */
getjButtonLeft()1385     public CustomJButton getjButtonLeft() {
1386         return jButtonLeft;
1387     }
1388 
1389     /**
1390      * getjButtonUp
1391      *
1392      * @return JButton
1393      */
getjButtonUp()1394     public JButton getjButtonUp() {
1395         return jButtonUp;
1396     }
1397 
1398     /**
1399      * getjButtonNext
1400      *
1401      * @return JButton
1402      */
getjButtonNext()1403     public JButton getjButtonNext() {
1404         return jButtonNext;
1405     }
1406 
1407     /**
1408      * getSplitPane
1409      *
1410      * @return JSplitPane
1411      */
getSplitPane()1412     public JSplitPane getSplitPane() {
1413         return splitPane;
1414     }
1415 
1416     /**
1417      * getJScrollCardsPanelInner
1418      *
1419      * @return JBPanel
1420      */
getJScrollCardsPanelInner()1421     public JBPanel getJScrollCardsPanelInner() {
1422         return jScrollCardsPanelInner;
1423     }
1424 
1425     /**
1426      * getCards
1427      *
1428      * @return JBPanel
1429      */
getCards()1430     public JBPanel getCards() {
1431         return cards;
1432     }
1433 
1434     /**
1435      * CardLayout
1436      *
1437      * @return CardLayout
1438      */
getCardLayout()1439     public CardLayout getCardLayout() {
1440         return cardLayout;
1441     }
1442 
1443     /**
1444      * getjPanelSuspension
1445      *
1446      * @return JBPanel
1447      */
getjPanelSuspension()1448     public JBPanel getjPanelSuspension() {
1449         return jPanelSuspension;
1450     }
1451 
1452     /**
1453      * getjComboBox
1454      *
1455      * @return CustomComboBox
1456      */
getjComboBox()1457     public CustomComboBox getjComboBox() {
1458         return jComboBox;
1459     }
1460 
1461     /**
1462      * getTimeJComboBox
1463      *
1464      * @return CustomComboBox
1465      */
getTimeJComboBox()1466     public CustomComboBox getTimeJComboBox() {
1467         return timeJComboBox;
1468     }
1469 
1470     /**
1471      * getCounting
1472      *
1473      * @return CountingThread
1474      */
getCounting()1475     public CountingThread getCounting() {
1476         return counting;
1477     }
1478 
1479     /**
1480      * setCounting
1481      *
1482      * @param counting counting
1483      */
setCounting(CountingThread counting)1484     public void setCounting(CountingThread counting) {
1485         this.counting = counting;
1486     }
1487 
1488     /**
1489      * getjTextArea
1490      *
1491      * @return JBLabel
1492      */
getjTextArea()1493     public JBLabel getjTextArea() {
1494         return jTextArea;
1495     }
1496 
1497     /**
1498      * isGreyFlag
1499      *
1500      * @return boolean
1501      */
isGreyFlag()1502     public boolean isGreyFlag() {
1503         return greyFlag;
1504     }
1505 
1506     /**
1507      * setGreyFlag
1508      *
1509      * @param greyFlag greyFlag
1510      */
setGreyFlag(boolean greyFlag)1511     public void setGreyFlag(boolean greyFlag) {
1512         this.greyFlag = greyFlag;
1513     }
1514 
1515     /**
1516      * getjPanelMiddleRight
1517      *
1518      * @return JBPanel
1519      */
getjPanelMiddleRight()1520     public JBPanel getjPanelMiddleRight() {
1521         return jPanelMiddleRight;
1522     }
1523 
1524     /**
1525      * getPanelTop
1526      *
1527      * @return JBPanel
1528      */
getPanelTop()1529     public JBPanel getPanelTop() {
1530         return panelTop;
1531     }
1532 
1533     /**
1534      * setPanelTop
1535      *
1536      * @param panelTop panelTop
1537      */
setPanelTop(JBPanel panelTop)1538     public void setPanelTop(JBPanel panelTop) {
1539         this.panelTop = panelTop;
1540     }
1541 
setjButtonStop(CustomJButton jButtonStop)1542     public void setjButtonStop(CustomJButton jButtonStop) {
1543         this.jButtonStop = jButtonStop;
1544     }
1545 
setjButtonSuspend(CustomJButton jButtonSuspend)1546     public void setjButtonSuspend(CustomJButton jButtonSuspend) {
1547         this.jButtonSuspend = jButtonSuspend;
1548     }
1549 
1550     /**
1551      * getDumpOrHookSessionList
1552      *
1553      * @return List <SubSessionListJBPanel>
1554      */
getDumpOrHookSessionList()1555     public List<SubSessionListJBPanel> getDumpOrHookSessionList() {
1556         return dumpOrHookSessionList;
1557     }
1558 }