From 495960a64e4ef5e3d0ff40772b4825f7537ab81f Mon Sep 17 00:00:00 2001 From: dongkyu6 lee Date: Mon, 30 May 2016 16:26:02 +0900 Subject: [PATCH] [SRADA-XXX] Add DB for dlog Change-Id: Ic3a7ebf2f23fd048d5cc39654756cafd173550fa --- .../dynamicanalyzer/control/StartTraceManager.java | 5 +- .../dynamicanalyzer/control/StopTraceManager.java | 5 +- .../org/tizen/dynamicanalyzer/project/Project.java | 46 ++- .../tizen/dynamicanalyzer/ui/page/LoadDAFile.java | 392 +++++++++++++++++++++ .../dynamicanalyzer/ui/timeline/TimelinePage.java | 2 + .../ui/timeline/calltrace/CallTraceTable.java | 1 - .../ui/timeline/dlog/DADlogReceiver.java | 148 -------- .../ui/timeline/dlog/DLogDBTable.java | 116 ++++++ .../ui/timeline/dlog/DLogDataManager.java | 231 ++++++++++++ .../ui/timeline/dlog/DlogTable.java | 78 ++-- .../dynamicanalyzer/ui/timeline/dlog/DlogView.java | 50 ++- 11 files changed, 861 insertions(+), 213 deletions(-) create mode 100644 org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/LoadDAFile.java delete mode 100755 org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DADlogReceiver.java create mode 100644 org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DLogDBTable.java create mode 100644 org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DLogDataManager.java diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StartTraceManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StartTraceManager.java index ed42b8e..189418f 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StartTraceManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StartTraceManager.java @@ -57,7 +57,7 @@ import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackInserter; import org.tizen.dynamicanalyzer.ui.info.screenshot.ScreenshotTimer; import org.tizen.dynamicanalyzer.ui.page.MenuBar; import org.tizen.dynamicanalyzer.ui.page.UpdateViewTimer; -import org.tizen.dynamicanalyzer.ui.timeline.dlog.DADlogReceiver; +import org.tizen.dynamicanalyzer.ui.timeline.dlog.DLogDataManager; import org.tizen.dynamicanalyzer.ui.toolbar.Toolbar; import org.tizen.dynamicanalyzer.util.Logger; import org.tizen.dynamicanalyzer.util.WorkbenchUtil; @@ -425,8 +425,7 @@ public class StartTraceManager implements Runnable { private void startDlog(){ Thread DlogThread = new Thread(new Runnable() { public void run() { - DADlogReceiver dlogRecv = new DADlogReceiver(); - dlogRecv.startDlog(); + DLogDataManager.getInstance().startDlog(); } }); DlogThread.start(); diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StopTraceManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StopTraceManager.java index d3c79a5..4297d10 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StopTraceManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StopTraceManager.java @@ -47,7 +47,7 @@ import org.tizen.dynamicanalyzer.ui.memory.data.HeapDataManager; import org.tizen.dynamicanalyzer.ui.page.BaseView; import org.tizen.dynamicanalyzer.ui.page.MenuBar; import org.tizen.dynamicanalyzer.ui.page.UpdateViewTimer; -import org.tizen.dynamicanalyzer.ui.timeline.dlog.DADlogReceiver; +import org.tizen.dynamicanalyzer.ui.timeline.dlog.DLogDataManager; import org.tizen.dynamicanalyzer.ui.toolbar.Toolbar; import org.tizen.dynamicanalyzer.util.Logger; import org.tizen.dynamicanalyzer.util.WorkbenchUtil; @@ -59,7 +59,6 @@ public class StopTraceManager implements Runnable { private DAResult error; private boolean stopFromTarget = false; private Boolean stopThreadCompleted = false; - private DADlogReceiver dlogRecv = new DADlogReceiver(); public StopTraceManager(DAResult err, boolean stopFromTarget) { this.error = err; this.stopFromTarget = stopFromTarget; @@ -157,7 +156,7 @@ public class StopTraceManager implements Runnable { // change summary UI // change to summary page UIAction.applyStopTraceUI(); - dlogRecv.stopDlog(); + DLogDataManager.getInstance().stopDlog(); Display.getDefault().syncExec(new Runnable() { @Override public void run() { diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java index dcc08b3..6d97d70 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java @@ -117,6 +117,9 @@ public class Project { private static final String PROFILE_START_TIME = "profilingStartTime"; private static final String PAGE_TAB_LIST = "pageTabList"; private static final String TIMELINE_CHART_LIST = "timelineChartList"; + + private static final String MEMPS_DATA_AVAILABLE = "availableMemps"; + private static final String DA_START_TIME = "daStartTime"; private ProjectVersion version = ProjectVersion.VERSION_UNKNOWN; private String protocolVersion = null; @@ -151,6 +154,10 @@ public class Project { private int seqRotation = 0; private int activeProcessCount = 0; + + private boolean availableMemps = false; + private String daStartTime = ""; + private boolean isSavedData = false; static { // register DB table @@ -665,7 +672,11 @@ public class Project { writer.write(CommonConstants.NEW_LINE); writer.write(CREATE_TIME + CommonConstants.EQUAL + getCreateTime()); writer.write(CommonConstants.NEW_LINE); - writer.write(TOTAL_STOP_TIME + CommonConstants.EQUAL + getTotalStopTime()); + writer.write(TOTAL_STOP_TIME + CommonConstants.EQUAL + getTotalStopTime()); + writer.write(CommonConstants.NEW_LINE); + writer.write(DA_START_TIME + CommonConstants.EQUAL + getDAStartTime()); + writer.write(CommonConstants.NEW_LINE); + writer.write(MEMPS_DATA_AVAILABLE + CommonConstants.EQUAL + (getMempsAvailable() ? "true" : "false")); writer.write(CommonConstants.NEW_LINE); writer.write(REPLAY_STOP_TIME + CommonConstants.EQUAL + getReplayStopTime()); writer.write(CommonConstants.NEW_LINE); @@ -849,6 +860,15 @@ public class Project { pageTabList = val.split(CommonConstants.COMMA); } else if (infoKey.equals(TIMELINE_CHART_LIST)) { timelineChartList = val.split(CommonConstants.COMMA); + } else if (infoKey.equals(MEMPS_DATA_AVAILABLE)) { + if(val.equals("true")) { + setMempsAvailable(true); + } + else { + setMempsAvailable(false); + } + } else if (infoKey.equals(DA_START_TIME)) { + setDAStartTime(val); } } } else { @@ -1186,4 +1206,28 @@ public class Project { timelineChartList = chartList.toArray(new String[0]); } + + public void setMempsAvailable(boolean available) { + this.availableMemps = available; + } + + public boolean getMempsAvailable() { + return this.availableMemps; + } + + public void setDAStartTime(String timestring) { + this.daStartTime = timestring; + } + + public String getDAStartTime() { + return this.daStartTime; + } + + public void setSavedProject (boolean save) { + this.isSavedData = save; + } + + public boolean isSaveProject() { + return this.isSavedData; + } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/LoadDAFile.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/LoadDAFile.java new file mode 100644 index 0000000..16612ef --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/LoadDAFile.java @@ -0,0 +1,392 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Dongkye Lee + * Jaeyong Lee + * Gihun Chang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.tizen.dynamicanalyzer.ui.page; + +import java.io.File; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.tizen.dynamicanalyzer.common.AnalyzerConstants; +import org.tizen.dynamicanalyzer.common.AnalyzerManager; +import org.tizen.dynamicanalyzer.common.DAResult; +import org.tizen.dynamicanalyzer.common.Global; +import org.tizen.dynamicanalyzer.database.SqlConnectionManager; +import org.tizen.dynamicanalyzer.database.compatible.DBConverter; +import org.tizen.dynamicanalyzer.handlers.CommandAction; +import org.tizen.dynamicanalyzer.handlers.CommonAction; +import org.tizen.dynamicanalyzer.handlers.UIAction; +import org.tizen.dynamicanalyzer.nl.AnalyzerLabels; +import org.tizen.dynamicanalyzer.project.BinaryInfo; +import org.tizen.dynamicanalyzer.project.Project; +import org.tizen.dynamicanalyzer.resources.ImageResources; +import org.tizen.dynamicanalyzer.setting.UILayoutDataManager; +import org.tizen.dynamicanalyzer.swap.logparser.DataManagerRegistry; +import org.tizen.dynamicanalyzer.ui.range.RangeDataManager; +import org.tizen.dynamicanalyzer.ui.range.RangePage; +import org.tizen.dynamicanalyzer.ui.summary.profiling.FunctionUsageProfiler; +import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfileDataMaker; +import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingChildData; +import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingChildDataDBTable; +import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingData; +import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingDataDBTable; +import org.tizen.dynamicanalyzer.ui.summary.profiling.WebProfileDataMaker; +import org.tizen.dynamicanalyzer.ui.summary.profiling.WebProfilingData; +import org.tizen.dynamicanalyzer.ui.summary.profiling.WebProfilingDataDBTable; +import org.tizen.dynamicanalyzer.ui.timeline.TimelinePage; +import org.tizen.dynamicanalyzer.ui.toolbar.Toolbar; +import org.tizen.dynamicanalyzer.ui.userinterface.UIDataManager; +import org.tizen.dynamicanalyzer.util.Logger; +import org.tizen.dynamicanalyzer.util.WorkbenchUtil; +import org.tizen.dynamicanalyzer.utils.AnalyzerUtil; +import org.tizen.dynamicanalyzer.widgets.da.base.DADialog; +import org.tizen.dynamicanalyzer.widgets.da.base.ProgressDialog; +import org.tizen.dynamicanalyzer.widgets.da.view.DAPageComposite; +import org.tizen.dynamicanalyzer.workbench.LayoutManager; + +public class LoadDAFile implements Runnable { + private ProgressDialog progressDialog; + private String filepath = ""; + + public LoadDAFile() { + + } + + @Override + public void run() { + //startProgress(); + boolean ret = false; + String decompresspath = CommandAction.loadFromZip(this.filepath); + if (decompresspath != null && !decompresspath.isEmpty()) { + Project project = Project.getProjectFromFile(decompresspath); + project.setSavedProject(true); + if (project != null) { + Global.setProject(project); + if (openTraceFile(decompresspath)) { + ret = true; + Logger.debug("Open File Success : " + this.filepath); + } else { + Logger.debug("Open File Fail : " + this.filepath); + } + } + } + + //stopProgress(ret); + } + + public void setZipFilePath(String path) { + this.filepath = path; + } + + private boolean openTraceFile(String tracePath) { + + final Project project = Global.getProject(); + + // establish db connection with new path + SqlConnectionManager.closeConnection(); + SqlConnectionManager + .establishConnection(project.getSavePath() + File.separator + AnalyzerConstants.DATABASE_NAME); + + // convert save file for compatible database + DBConverter converter = new DBConverter(project.getVersion()); + if (!converter.convert()) { + // failed to convert for compatible database + UIAction.showWarning(AnalyzerLabels.OPEN_TRACE_PROGRESS_INVALID); + CommonAction.clear(); + return false; + } else { + // converting is succeeded + // change version of save file to current version + project.upgrade(); + } + + boolean bsuccess = project.openDetail(); + if (!bsuccess) { + UIAction.showWarning(AnalyzerLabels.OPEN_TRACE_PROGRESS_VERSION_INVALID_REMOVE); + CommonAction.clear(); + return false; + } + + if (loadProfilingData(project) && loadProfilingChildData() && loadWebProfilingData()) { + + } else { + UIAction.showWarning(AnalyzerLabels.OPEN_TRACE_PROGRESS_INVALID_REMOVE); + CommonAction.clear(); + return false; + } + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + Toolbar.INSTANCE.setTime(project.getTotalStopTime()); + Toolbar.INSTANCE.setAllControlState(true); + } + }); + + // change tab list and page to be shown + UIAction.setPages(project.getPageTabList()); + + // change chart list in timeline page + UIAction.setCharts(project.getTimelineChartList()); + + // change page + if (RangeDataManager.getInstance().isBeingAnalyzed()) { + DAPageComposite page = AnalyzerManager.getCurrentPage(); + if (page instanceof RangePage) { + AnalyzerUtil.changePage(TimelinePage.pageID); + } + } + + // set dirty of UI layout + UILayoutDataManager.INSTANCE.setDirty(true); + + // open for each PageDataManager + DataManagerRegistry.openData(); + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + UIAction.applyWebProfilingUI(Global.getProject().isWebApplication()); + + DAPageComposite page = AnalyzerManager.getCurrentPage(); + page.updateView(); + } + }); + + return true; + } + + private boolean loadProfilingData(Project project) { + boolean isSuccess = true; + List> profilingDatas = FunctionUsageProfiler.getInstance().getProfilingDataTable() + .getProfilingDataFromDB(); + if (null == profilingDatas) { + Logger.debug("failed - loadProfilingData"); + isSuccess = false; + } else { + for (int i = 0; i < profilingDatas.size(); i++) { + List profilingData = profilingDatas.get(i); + int pid = (Integer) profilingData.get(ProfilingDataDBTable.COLUMN.PID.index); + // possibility of extensions - network, efl, db, etc... + ProfileDataMaker profiler = FunctionUsageProfiler.getInstance().getProfileDataMakerByPid(pid); + int profilingDataID = (Integer) profilingData.get(ProfilingDataDBTable.COLUMN.PROFILING_DATA_ID.index); + byte type = (Byte) profilingData.get(ProfilingDataDBTable.COLUMN.TYPE.index); + int exCount = (Integer) profilingData.get(ProfilingDataDBTable.COLUMN.EXCLUSIVE_COUNT.index); + int inCount = (Integer) profilingData.get(ProfilingDataDBTable.COLUMN.INCLUSIVE_COUNT.index); + int callCount = (Integer) profilingData.get(ProfilingDataDBTable.COLUMN.CALL_COUNT.index); + long inElapsedTime = (Long) profilingData + .get(ProfilingDataDBTable.COLUMN.INCLUSIVE_EXECUTION_TIME.index); + long exElapsedTime = (Long) profilingData + .get(ProfilingDataDBTable.COLUMN.EXCLUSIVE_EXECUTION_TIME.index); + String name; + ProfilingData fupData = null; + int binaryId; + BinaryInfo bInfo = null; + switch (type) { + case ProfilingData.TYPE_APPLICATION: + case ProfilingData.TYPE_DEPENDENTLIBRARY: + case ProfilingData.TYPE_LIBRARY: + binaryId = (Integer) profilingData.get(ProfilingDataDBTable.COLUMN.BINARY_ID.index); + bInfo = project.getDeviceStatusInfo().getBinaryInfo(binaryId); + name = bInfo.getTargetBinaryPath(); + fupData = new ProfilingData(profilingDataID, name, exCount, inCount, callCount, inElapsedTime, + exElapsedTime, profiler); + break; + case ProfilingData.TYPE_FUNCTION: + int functionId = (Integer) profilingData.get(ProfilingDataDBTable.COLUMN.FUNCTION_ID.index); + name = project.getFunctionName(functionId); + fupData = new ProfilingData(profilingDataID, name, exCount, inCount, callCount, inElapsedTime, + exElapsedTime, profiler); + break; + default: // never goes here + Logger.error("invalid profiling data type"); + break; + } + + if (null == fupData) { + isSuccess = false; + } else { + if (type == ProfilingData.TYPE_APPLICATION) { + profiler.setAppBin(fupData); + } else if (type == ProfilingData.TYPE_DEPENDENTLIBRARY) { + profiler.setDependentLib(fupData); + } + + profiler.getProfilingDataMap().put(profilingDataID, fupData); + UIDataManager.getInstance().getfunctionProfilingDataChecker().addProfilingData(fupData); + // restore total sample count + profiler.setTotalSampleCount(profiler.getTotalSampleCount() + fupData.getExCount()); + } + } + } + return isSuccess; + } + + private boolean loadProfilingChildData() { + boolean isSuccess = true; + List> profilingChilds = FunctionUsageProfiler.getInstance().getProfilingChildDataTable() + .getProfilingChildDataFromDB(); + if (null == profilingChilds) { + Logger.debug("failed - loadProfilingChildData"); + isSuccess = false; + } else { + int size = profilingChilds.size(); + for (int i = 0; i < size; i++) { + List data = profilingChilds.get(i); + int parentID = (Integer) data.get(ProfilingChildDataDBTable.COLUMN.PROFILING_DATA_ID.index); + int pid = (Integer) data.get(ProfilingChildDataDBTable.COLUMN.PID.index); + + @SuppressWarnings("unchecked") + List childSeqList = (List) data + .get(ProfilingChildDataDBTable.COLUMN.CHILD_SEQUENCE_ARRAY.index); + + ProfileDataMaker profiler = FunctionUsageProfiler.getInstance().getProfileDataMakerByPid(pid); + ProfilingData parent = profiler.getProfilingDataMap().get(parentID); + ProfilingChildData child = parent.getChildData(); + child.getChildren().addAll(childSeqList); + } + } + return isSuccess; + } + + private boolean loadWebProfilingData() { + boolean isSuccess = true; + List> profilingDatas = FunctionUsageProfiler.getInstance().getWebProfilingDataTable() + .getWebProfilingDataFromDB(); + if (null == profilingDatas) { + Logger.debug("failed - loadWebProfilingData"); + isSuccess = false; + } else { + for (int i = 0; i < profilingDatas.size(); i++) { + List profilingData = profilingDatas.get(i); + + int profilingDataID = (Integer) profilingData + .get(WebProfilingDataDBTable.COLUMN.PROFILING_DATA_ID.getIndex()); + int pid = (Integer) profilingData.get(WebProfilingDataDBTable.COLUMN.PID.getIndex()); + int functionLineNumber = (Integer) profilingData + .get(WebProfilingDataDBTable.COLUMN.FUNCTION_LINE_NUMBER.getIndex()); + String functionName = (String) profilingData + .get(WebProfilingDataDBTable.COLUMN.FUNCTION_NAME.getIndex()); + String functionURL = (String) profilingData.get(WebProfilingDataDBTable.COLUMN.FUNCTION_URL.getIndex()); + int callCount = (Integer) profilingData.get(WebProfilingDataDBTable.COLUMN.CALL_COUNT.getIndex()); + long inElapsedTime = (Long) profilingData + .get(WebProfilingDataDBTable.COLUMN.INCLUSIVE_EXECUTION_TIME.getIndex()); + long exElapsedTime = (Long) profilingData + .get(WebProfilingDataDBTable.COLUMN.EXCLUSIVE_EXECUTION_TIME.getIndex()); + + @SuppressWarnings("unchecked") + List childSeqList = (List) profilingData + .get(WebProfilingDataDBTable.COLUMN.CHILD_SEQUENCE_ARRAY.getIndex()); + + // create WebProfilingData + WebProfilingData fupData = new WebProfilingData(profilingDataID, functionLineNumber, functionName, + functionURL, callCount, inElapsedTime, exElapsedTime, childSeqList); + + // get WebProfileDataMaker + WebProfileDataMaker profiler = FunctionUsageProfiler.getInstance().getWebProfileDataMakerByPid(pid); + + // set WebProfilingData + if (functionName.equals(FunctionUsageProfiler.APPLICATION)) { + profiler.setAppBin(fupData); + } + profiler.webProfilingDataMap().put(profilingDataID, fupData); + } + } + return isSuccess; + } + + private void startProgress() { + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell(); + progressDialog = new ProgressDialog(shell, LayoutManager.getBaseComposite()); + progressDialog.setProgressStyle(ProgressDialog.PROGRESS_STYLE_INDETERMINATE); + progressDialog.setProgressMessage("Loading saved file..."); + progressDialog.setProgressInfo(AnalyzerLabels.DLG_PLEASE_WAIT); + progressDialog.setCancelListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + cancelProgress(); + } + }); + + progressDialog.open(); + } + }); + } + + public void stopProgress(final boolean isSuccess) { + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + if (progressDialog != null) { + progressDialog.close(); + progressDialog = null; + } + if (isSuccess) { + + } else { + Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell(); + DADialog dialog = new DADialog(shell, SWT.NONE); + dialog.setIcon(ImageResources.DIALOG_ERROR_ICON); + dialog.setMessage("Failed loading zip file."); + dialog.setDialog(false); + dialog.open(); + } + } + }); + } + + private void cancelProgress() { + try { + //DAResult result = DACommunicator.cancelRequestUIHierarchy(); + DAResult result = DAResult.SUCCESS; + if (result.isSuccess() != false) { + Logger.warning(result); + } + } catch (Exception e) { + Logger.exception(e); + } + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + if (progressDialog != null) { + progressDialog.close(); + progressDialog = null; + } + } + }); + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/TimelinePage.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/TimelinePage.java index 4f6d7f7..aedb313 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/TimelinePage.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/TimelinePage.java @@ -45,6 +45,7 @@ import org.tizen.dynamicanalyzer.ui.timeline.calltrace.CallTraceView; import org.tizen.dynamicanalyzer.ui.timeline.common.TimelineChartManager; import org.tizen.dynamicanalyzer.ui.timeline.common.TimelineChartView; import org.tizen.dynamicanalyzer.ui.timeline.common.TimelineTableView; +import org.tizen.dynamicanalyzer.ui.timeline.dlog.DLogDataManager; import org.tizen.dynamicanalyzer.ui.toolbar.replay.data.ReplayDataManager; import org.tizen.dynamicanalyzer.widgets.da.view.DAPageComposite; import org.tizen.dynamicanalyzer.widgets.da.view.DATabComposite; @@ -112,6 +113,7 @@ public class TimelinePage extends DAPageComposite { DataManagerRegistry.registerPageDataManager(InteractiveDataManager.getInstance()); DataManagerRegistry.registerPageDataManager(ScreenshotDataManager.getInstance()); DataManagerRegistry.registerPageDataManager(MemoryDataManager.getInstance()); + DataManagerRegistry.registerPageDataManager(DLogDataManager.getInstance()); } public TimelineChartView getTimelineChartView() { diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/calltrace/CallTraceTable.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/calltrace/CallTraceTable.java index 475e080..f840c3a 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/calltrace/CallTraceTable.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/calltrace/CallTraceTable.java @@ -39,7 +39,6 @@ import org.tizen.dynamicanalyzer.common.AnalyzerConstants; import org.tizen.dynamicanalyzer.common.AnalyzerManager; import org.tizen.dynamicanalyzer.common.DASelectionData; import org.tizen.dynamicanalyzer.common.Global; -import org.tizen.dynamicanalyzer.model.FilterProperty; import org.tizen.dynamicanalyzer.model.TableInput; import org.tizen.dynamicanalyzer.nl.TimelinePageLabels; import org.tizen.dynamicanalyzer.project.BinaryInfo; diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DADlogReceiver.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DADlogReceiver.java deleted file mode 100755 index b8ddf28..0000000 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DADlogReceiver.java +++ /dev/null @@ -1,148 +0,0 @@ -package org.tizen.dynamicanalyzer.ui.timeline.dlog; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.regex.Pattern; -import org.tizen.dynamicanalyzer.common.Global; -import org.tizen.dynamicanalyzer.communicator.CommunicatorUtils; -import org.tizen.dynamicanalyzer.communicator.DeviceInfo; -import org.tizen.sdblib.receiver.MultiLineReceiver; -import org.tizen.sdblib.util.StringUtil; - -public class DADlogReceiver { - - - static List Dlogs = new ArrayList(); - - private static final Pattern pattern = Pattern.compile("\\d{2}-\\d{2}\\s(\\d{2}:\\d{2}:\\d{2}\\.?\\d*)\\+?\\d*\\s+" //time - + "(\\d+)\\s+" //pid - + "(\\d+)\\s+" //tid - + "(V|D|I|W|E|F)\\s+" //level - + "(\\S+)\\s*\\:\\s+" //tag - + "(.*)"); //message - - static boolean start = false; - static boolean dlogKill = false; - static String[] daStartTime = null; - public DADlogReceiver() { - // TODO Auto-generated constructor stub - } - - public boolean startDlog(){ - - Pattern timeregex = Pattern.compile("\\S+\\s+" //day - + "\\S+\\s+" //month - + "\\d+\\s+" //date - + "(\\d{2}\\:\\d{2}\\:\\d{2})\\s+" //hour:min:sec - + ".*"); //year - - DeviceInfo curDev = Global.getCurrentDeviceInfo(); - - Dlogs.clear(); - dlogKill = false; - - - if (curDev == null) { - return false; - } - - CommunicatorUtils.execShellCommand(curDev.getIDevice(), - "date", new MultiLineReceiver() { - @Override - public void processNewLines(String[] appLines) { - for (int i = 0; i < appLines.length; i++) { - daStartTime = appLines; - } - } - }); - - String[] TmpdaStartTime = daStartTime; - daStartTime = StringUtil.split(TmpdaStartTime[0], timeregex); - - CommunicatorUtils.execShellCommand(curDev.getIDevice(), - "/usr/bin/dlogutil -c"); - - CommunicatorUtils.execShellCommand(curDev.getIDevice(), - "/usr/bin/dlogutil -v threadtime", new MultiLineReceiver() { - @Override - public void processNewLines(String[] appLines) { - start = true; - for (int i = 0; i < appLines.length; i++) { - if(dlogKill){ - break; - } - /* Dlog don't show swap_start always... - if(appLines[i].contains("swap_start")){ - daStartTime = StringUtil.split(appLines[i], StartTimepattern); - } - */ - Dlogs.add(appLines[i]); - //System.out.println(appLines[i]); - } - } - }); - - return true; - } - - public void stopDlog(){ - dlogKill = true; - } - public List getDlogs(){ - return Dlogs; - } - - public List parserDlogs(){ - - List dlogList = new ArrayList(); - - for (int i=0;i + * GwangHo Go + * Gihun Chang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.tizen.dynamicanalyzer.ui.timeline.dlog; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import org.tizen.dynamicanalyzer.database.DBColumn; +import org.tizen.dynamicanalyzer.database.DBConstants; +import org.tizen.dynamicanalyzer.database.DBTable; +import org.tizen.dynamicanalyzer.util.Logger; + +public class DLogDBTable extends DBTable { + public static final String TABLENAME = "DLOG_DB"; + + public enum COLUMN { + TIME(0, "TIME"), + LEVEL(1, "LEVEL"), + PID(2, DBConstants.DBCOLUMN_PID), + TID(3, DBConstants.DBCOLUMN_TID), + TAG(4, "TAG"), + MESSAGE(5, "MESSAGE"); + + public final int index; + public final String name; + + COLUMN(int index, String name) { + this.index = index; + this.name = name; + } + } + + @Override + public String getTableName() { + return TABLENAME; + } + + public DLogDBTable() { + addColumn(new DBColumn(COLUMN.TIME.name, DBConstants.NOT_NULL, DBConstants.DBTYPE_VARCHAR, 20)); + addColumn(new DBColumn(COLUMN.LEVEL.name, DBConstants.NOT_NULL, DBConstants.DBTYPE_VARCHAR, 10)); + addColumn(new DBColumn(COLUMN.PID.name, DBConstants.NOT_NULL, DBConstants.DBTYPE_VARCHAR, 10)); + addColumn(new DBColumn(COLUMN.TID.name, DBConstants.NOT_NULL, DBConstants.DBTYPE_VARCHAR, 10)); + addColumn(new DBColumn(COLUMN.TAG.name, DBConstants.NOT_NULL, DBConstants.DBTYPE_VARCHAR, 64)); + addColumn(new DBColumn(COLUMN.MESSAGE.name, DBConstants.NOT_NULL, DBConstants.DBTYPE_VARCHAR, 4096)); + } + + @Override + public boolean prepare(PreparedStatement prep, List rowData) { + boolean isPrepared = true; + + int columnsize = getColumnSize(); + if (columnsize != rowData.size()) { + isPrepared = false; + } else { + try { + int index = 1; + prep.setString(index++, (String) (rowData.get(COLUMN.TIME.index))); + prep.setString(index++, (String) (rowData.get(COLUMN.LEVEL.index))); + prep.setString(index++, (String) (rowData.get(COLUMN.PID.index))); + prep.setString(index++, (String) (rowData.get(COLUMN.TID.index))); + prep.setString(index++, (String) (rowData.get(COLUMN.TAG.index))); + prep.setString(index++, (String) (rowData.get(COLUMN.MESSAGE.index))); + } catch (SQLException e) { + Logger.exception(e); + isPrepared = false; + } + } + + return isPrepared; + } + + @Override + public List extractDataFromResultSet(ResultSet rs) { + List row = new ArrayList(); + try { + int index = 1; + row.add(rs.getString(index++)); + row.add(rs.getString(index++)); + row.add(rs.getString(index++)); + row.add(rs.getString(index++)); + row.add(rs.getString(index++)); + row.add(rs.getString(index++)); + } catch (SQLException e) { + Logger.exception(e); + return null; + } + + return row; + } + +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DLogDataManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DLogDataManager.java new file mode 100644 index 0000000..b7313dd --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DLogDataManager.java @@ -0,0 +1,231 @@ +package org.tizen.dynamicanalyzer.ui.timeline.dlog; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.regex.Pattern; + +import org.tizen.dynamicanalyzer.common.Global; +import org.tizen.dynamicanalyzer.communicator.CommunicatorUtils; +import org.tizen.dynamicanalyzer.communicator.DeviceInfo; +import org.tizen.dynamicanalyzer.database.DBInserter; +import org.tizen.dynamicanalyzer.swap.logparser.LogPackage; +import org.tizen.dynamicanalyzer.swap.logparser.PageDataManager; +import org.tizen.dynamicanalyzer.util.Logger; +import org.tizen.sdblib.receiver.MultiLineReceiver; +import org.tizen.sdblib.util.StringUtil; + +public class DLogDataManager extends PageDataManager { + + private static DLogDataManager instance = new DLogDataManager(); + private Thread dlogthread = null; + + private DLogDBTable dLogDBTable = null; + private DBInserter dLogDBInserter = null; + + public DLogDataManager() { + dLogDBTable = new DLogDBTable(); + dLogDBInserter = makeInserter(dLogDBTable); + } + + public static DLogDataManager getInstance() { + return instance; + } + + public DLogDBTable getDBTable() { + return dLogDBTable; + } + + @Override + protected void makeData(LogPackage pack) { + } + + private static final Pattern pattern = Pattern.compile("\\d{2}-\\d{2}\\s(\\d{2}:\\d{2}:\\d{2}\\.?\\d*)\\+?\\d*\\s+" // time + + "(\\d+)\\s+" // pid + + "(\\d+)\\s+" // tid + + "(V|D|I|W|E|F)\\s+" // level + + "(\\S+)\\s*\\:\\s+" // tag + + "(.*)"); // message + + static boolean start = false; + private boolean dlogKill = false; + static String[] daStartTime = null; + + public boolean getDlogKill() { + return dlogKill; + } + + public void setDlogKill(boolean killed) { + if (dlogthread != null) { + dlogKill = killed; + } + } + + public boolean startDlog() { + final DeviceInfo curDev = Global.getCurrentDeviceInfo(); + + dlogKill = false; + + if (curDev == null) { + return false; + } + + String datecommand = "date +\"%H:%M:%S.%3N\""; + + CommunicatorUtils.execShellCommand(curDev.getIDevice(), datecommand, new MultiLineReceiver() { + @Override + public void processNewLines(String[] appLines) { + for (int i = 0; i < appLines.length; i++) { + daStartTime = appLines; + } + } + }); + + Global.getProject().setDAStartTime(daStartTime[0]); + + CommunicatorUtils.execShellCommand(curDev.getIDevice(), "/usr/bin/dlogutil -c"); + + dlogthread = new Thread(new Runnable() { + + @Override + public void run() { + CommunicatorUtils.execShellCommand(curDev.getIDevice(), "/usr/bin/dlogutil -v threadtime", + new MultiLineReceiver() { + @Override + public void processNewLines(String[] appLines) { + if (dlogKill) { + start = false; + try { + Logger.debug("Dlog receiver joined"); + Thread.currentThread().join(); + } catch (InterruptedException e) { + + } + } + + if (appLines != null) { + makeDlogData(appLines); + } + } + }); + } + }); + + dlogthread.start(); + start = true; + + return true; + } + + public void stopDlog() { + setDlogKill(true); + } + + private void makeDlogData(String[] dlogs) { + if (dlogs.length > 0) { + List> mList = new ArrayList>(); + + for (int i = 0; i < dlogs.length; i++) { + String dlogstring = dlogs[i]; + + List dlog = splitDlog(dlogstring); + + if (dlog != null) { + mList.add(dlog); + } + } + dLogDBInserter.pushData(mList); + } + } + + private List splitDlog(String dlog) { + List splited = new ArrayList(); + + String[] matches = StringUtil.split(dlog, pattern); + if (matches == null || matches.length != 6) + return null; + + if (matches[5].contains("swap_start")) { + if (Global.getProject() != null) { + Global.getProject().setDAStartTime(matches[0]); + } + } + + for (int i = 0; i < matches.length; i++) { + splited.add(String.valueOf(matches[i])); + } + + return splited; + } + + public List parserDlogs() { + List dlogList = new ArrayList(); + + DateFormat formatter = new SimpleDateFormat("hh:mm:ss.SSS"); + + List> Dlogs = getDlogFromDB(); + + String dastart = Global.getProject().getDAStartTime(); + + if (dastart == null || dastart.isEmpty()) { + dastart = (String) Dlogs.get(0).get(0); + } + + Date DAStartTime = null; + try { + DAStartTime = formatter.parse(dastart); + } catch (ParseException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + for (List dlog : Dlogs) { + DADlogData dlogData = new DADlogData(); + try { + Date date = formatter.parse((String) dlog.get(0)); + dlogData.setSyncTime(DAStartTime); + + int compare = date.compareTo(DAStartTime); + + if (compare < 0) { + continue; + } else { + long diffTime = date.getTime() * 1000 - DAStartTime.getTime() * 1000; + + // dlogData.setTime(matches[0]); + dlogData.setTime(Long.toString(diffTime)); + dlogData.setPid((String) dlog.get(1)); + dlogData.setTid((String) dlog.get(2)); + dlogData.setLevel((String) dlog.get(3)); + dlogData.setTag((String) dlog.get(4)); + dlogData.setMessage((String) dlog.get(5)); + dlogList.add(dlogData); + } + + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return dlogList; + } + + public boolean isStart() { + return start; + } + + private List> getDlogFromDB() { + List> dlogdatas = new ArrayList>(); + + List> queryResult = dLogDBTable.selectAllColumnData(null); + if (queryResult == null) { + return dlogdatas; + } + dlogdatas = queryResult; + + return dlogdatas; + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DlogTable.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DlogTable.java index 54f2d7b..210df1e 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DlogTable.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DlogTable.java @@ -1,3 +1,28 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GwangHo Go + * Dongkye Lee + * Gihun Chang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + package org.tizen.dynamicanalyzer.ui.timeline.dlog; import java.util.ArrayList; @@ -18,6 +43,7 @@ import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; import org.tizen.dynamicanalyzer.common.AnalyzerConstants; +import org.tizen.dynamicanalyzer.common.Global; import org.tizen.dynamicanalyzer.model.TableInput; import org.tizen.dynamicanalyzer.ui.common.UICommonConstants; import org.tizen.dynamicanalyzer.ui.page.BaseView; @@ -36,13 +62,12 @@ import org.tizen.dynamicanalyzer.widgets.chartBoard.DAChartBoard; public class DlogTable extends DATableComposite { private String[] columnNames = {"Time", "Level", "Pid", "Tid", "Tag", "Message" }; //6col - private int[] columnSizes = { 80, 80, 80, 80, 300, 1200}; + private int[] columnSizes = { 80, 60, 70, 70, 100, 1200}; private int[] columnAlignment = { SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT }; private boolean[] columnVisibility = { true, true, true, true, true, true }; private int[] sortTypes = { AnalyzerConstants.SORT_TYPE_NONE, AnalyzerConstants.SORT_TYPE_NONE, AnalyzerConstants.SORT_TYPE_NONE, AnalyzerConstants.SORT_TYPE_NONE,AnalyzerConstants.SORT_TYPE_NONE, AnalyzerConstants.SORT_TYPE_NONE }; - private DADlogReceiver dlogRecv = new DADlogReceiver(); private List tableClone = new ArrayList(); private List filteredDlog = new ArrayList(); private static boolean isFilter = false; @@ -195,17 +220,10 @@ public class DlogTable extends DATableComposite { } @Override protected List makeTableInput() { - List output = new ArrayList(); List dlogData = new ArrayList(); - if(dlogRecv.getDlogs()!=null){ - dlogData = dlogRecv.parserDlogs(); - } - else { - tableClone = output; - return output; - } + dlogData = DLogDataManager.getInstance().parserDlogs(); int seqnum = 0; @@ -253,37 +271,15 @@ public class DlogTable extends DATableComposite { tableClone = output; return output; } - /* - protected void addTableData() { - - List dlogData = dlogRecv.parserDlogs(); - - for(DADlogData data : dlogData){ - GridItem item = new GridItem(table, SWT.LEFT); - item.setText(data.getTime()); - item.setText(data.getTag()); - item.setText(data.getPid()); - item.setText(data.getMessage()); - } - - } - */ + @Override public void updateTable() { - if(!DADlogReceiver.dlogKill){ - return; - } - int itemCount = 0; - if(dlogRecv.isStart() == true){ - itemCount = dlogRecv.parserDlogs().size(); - } - else { - return; - } - if (itemCount <= 0) { - return; + if(Global.getProject().isSaveProject() == false) { + if(!DLogDataManager.getInstance().getDlogKill()){ + return; + } } - + List output = null; output = makeTableInput(); @@ -354,12 +350,6 @@ public class DlogTable extends DATableComposite { if(tableClone != null){ for(TableInput table : tableClone){ if(table.getText().get(4).contains(input)){ - //private String time; - //private String pid; - //private String tid; - //private String level; - //private String tag; - //private String message; filteredDlog.add(table); isFilter = true; } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DlogView.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DlogView.java index 5151e9b..ecc6156 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DlogView.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/dlog/DlogView.java @@ -1,3 +1,28 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GwangHo Go + * Dongkye Lee + * Gihun Chang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + + package org.tizen.dynamicanalyzer.ui.timeline.dlog; import org.eclipse.swt.layout.FillLayout; @@ -15,39 +40,38 @@ public class DlogView extends DAViewComposite { Composite contents = null; private DATableComposite DlogTable = null; - + public DlogView(Composite parent, int style) { super(parent, style, false); this.setLayout(new FillLayout()); - + setTitle(InformationViewLabels.DLOG_VIEW_TITLE); contents = getContentArea(); contents.setBackground(ColorResources.WINDOW_BG_COLOR); contents.setLayout(new FillLayout()); - - DlogTable = new DlogTable(contents, SWT.NONE, SWT.SINGLE - | SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); - - DlogTable.setTableToolTipEnable(false); - } - + + DlogTable = new DlogTable(contents, SWT.NONE, + SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); + + DlogTable.setTableToolTipEnable(false); } + @Override public void updateView() { if (!AnalyzerManager.isVisibleView(this.getID())) { return; } + if (null == DlogTable) { return; } - if(DADlogReceiver.dlogKill){ - DlogTable.updateTable(); - } + + DlogTable.updateTable(); } @Override public void clear() { DlogTable.clear(); - DADlogReceiver.dlogKill = false; + DLogDataManager.getInstance().setDlogKill(false); } @Override -- 2.7.4