COMM: bug fix for trace cancel 25/26825/1
authorgreatim <jaewon81.lim@samsung.com>
Fri, 29 Aug 2014 00:30:16 +0000 (09:30 +0900)
committergreatim <jaewon81.lim@samsung.com>
Fri, 29 Aug 2014 00:30:16 +0000 (09:30 +0900)
When tracing is canceled, Message receive thread still be blocked,
Set the socket timeout time to 5sec, and do not show the disconnect popup when tracing is canceled

Change-Id: I4d5340020e802905d6b35539f7ca84a0029b6456
Signed-off-by: greatim <jaewon81.lim@samsung.com>
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/MessageParser.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/TraceStartStopThread.java

index c17007b..76ee115 100755 (executable)
@@ -123,8 +123,8 @@ public class MessageParser {
 
        public void startTimer() {
                timer = new Timer();
-               timer.scheduleAtFixedRate(new AddBufferTimerTask(),
-                               MSG_BUFFER_TIMER_DELAY, MSG_BUFFER_TIMER_PERIOD);
+               timer.scheduleAtFixedRate(new AddBufferTimerTask(), MSG_BUFFER_TIMER_DELAY,
+                               MSG_BUFFER_TIMER_PERIOD);
        }
 
        public void stopTimer() {
@@ -203,8 +203,7 @@ public class MessageParser {
                        pinfo.setDropLog(true);
                }
 
-               ProcessMemoryMap pMap = new ProcessMemoryMap(pinfo.getPid(),
-                               subTime.getLongTime());
+               ProcessMemoryMap pMap = new ProcessMemoryMap(pinfo.getPid(), subTime.getLongTime());
                pinfo.addProcessMemoryMap(pMap);
 
                for (int i = 0; i < dependantLibCount; i++) {
@@ -214,25 +213,23 @@ public class MessageParser {
                        index += LONG_SIZE;
                        String libPath = ByteUtil.getString(data, index);
 
-                       LibraryObject libObj = new LibraryObject(project
-                                       .getDeviceStatusInfo().getBinaryInfo(libPath).getID(),
-                                       lowestAddr, highestAddr);
+                       LibraryObject libObj = new LibraryObject(project.getDeviceStatusInfo()
+                                       .getBinaryInfo(libPath).getID(), lowestAddr, highestAddr);
 
                        index += ByteUtil.getStringLength(data, index);
 
                        pMap.addLibraryMap(libObj);
                }
 
-               Logger.debug("process info start time : " + capturedTime.getSec()
-                               + "  " + capturedTime.getNano());
+               Logger.debug("process info start time : " + capturedTime.getSec() + "  "
+                               + capturedTime.getNano());
 
                pMap.setMainBinary(new LibraryObject(project.getDeviceStatusInfo()
                                .getBinaryInfo(targetBinaryPath).getID(), lowAddr, highAddr));
 
                AnalyzerManager.setProcessInfoArrived(true);
 
-               ThreadChartManager.getInstance().getThreadDataManager()
-                               .createMainThreadItem(pid);
+               ThreadChartManager.getInstance().getThreadDataManager().createMainThreadItem(pid);
        }
 
        private void memoryMapChanged(byte[] data) {
@@ -270,8 +267,7 @@ public class MessageParser {
                DATime subTime = changeTime.subtract(profileStartTime);
 
                ProcessMemoryMap lastMap = pinfo.getLastProcessMemoryMap();
-               ProcessMemoryMap newMap = new ProcessMemoryMap(pinfo.getPid(),
-                               subTime.getLongTime());
+               ProcessMemoryMap newMap = new ProcessMemoryMap(pinfo.getPid(), subTime.getLongTime());
                pinfo.addProcessMemoryMap(newMap);
                newMap.copy(lastMap);
 
@@ -279,10 +275,8 @@ public class MessageParser {
                        String libPath = LogDataUtils.getString(index, data);
                        index += LogDataUtils.getStringLength(index, data);
 
-                       BinaryInfo bininfo = project.getDeviceStatusInfo().getBinaryInfo(
-                                       libPath);
-                       LibraryObject libObj = new LibraryObject(bininfo.getID(), lowAddr,
-                                       highAddr);
+                       BinaryInfo bininfo = project.getDeviceStatusInfo().getBinaryInfo(libPath);
+                       LibraryObject libObj = new LibraryObject(bininfo.getID(), lowAddr, highAddr);
                        newMap.addLibraryMap(libObj);
                } else {
                        newMap.removeLibrary(lowAddr, highAddr);
@@ -307,8 +301,7 @@ public class MessageParser {
                        }
 
                        try {
-                               printWriter = new PrintWriter(new BufferedWriter(
-                                               new FileWriter(logPath)), true);
+                               printWriter = new PrintWriter(new BufferedWriter(new FileWriter(logPath)), true);
                        } catch (IOException e) {
                                e.printStackTrace();
                        }
@@ -319,14 +312,14 @@ public class MessageParser {
                try {
                        byte[] header = new byte[MSG_HEADER_SIZE];
 
+                       dataSocket.setSoTimeout(5000);
                        inputStream = dataSocket.getInputStream();
 
                        while (true) {
                                int readSize = 0;
                                int toRead = MSG_HEADER_SIZE;
                                while (toRead > 0) {
-                                       readSize = inputStream.read(header, MSG_HEADER_SIZE
-                                                       - toRead, toRead);
+                                       readSize = inputStream.read(header, MSG_HEADER_SIZE - toRead, toRead);
                                        toRead -= readSize;
                                        if (!DACommunicator.isRunning() && readSize == -1) {
                                                // manager socket closed!!
@@ -351,8 +344,7 @@ public class MessageParser {
                                // AnalyzerUtil.printHexdecimal(id);
                                // System.out.println();
 
-                               int payloadSize = ByteUtil
-                                               .toInt(header, MSG_PAYLOAD_SIZE_INDEX);
+                               int payloadSize = ByteUtil.toInt(header, MSG_PAYLOAD_SIZE_INDEX);
                                byte[] payload = null;
 
                                try {
@@ -363,8 +355,7 @@ public class MessageParser {
 
                                toRead = payloadSize;
                                while (toRead > 0) {
-                                       readSize = inputStream.read(payload, payloadSize - toRead,
-                                                       toRead);
+                                       readSize = inputStream.read(payload, payloadSize - toRead, toRead);
                                        toRead -= readSize;
                                        if (!DACommunicator.isRunning() && readSize == -1) {
                                                // manager socket closed!!
@@ -379,14 +370,11 @@ public class MessageParser {
 
                                byte[] buffer = new byte[MSG_HEADER_SIZE + payloadSize];
                                System.arraycopy(header, 0, buffer, 0, MSG_HEADER_SIZE);
-                               System.arraycopy(payload, 0, buffer, MSG_HEADER_SIZE,
-                                               payloadSize);
+                               System.arraycopy(payload, 0, buffer, MSG_HEADER_SIZE, payloadSize);
 
                                if (PRINT_DATA_LOG_TOFILE && printWriter != null) {
-                                       printWriter.printf("%d %d %d %d %d :", id,
-                                                       ByteUtil.toInt(header, 4),
-                                                       ByteUtil.toInt(header, 8),
-                                                       ByteUtil.toInt(header, 12), payloadSize);
+                                       printWriter.printf("%d %d %d %d %d :", id, ByteUtil.toInt(header, 4),
+                                                       ByteUtil.toInt(header, 8), ByteUtil.toInt(header, 12), payloadSize);
                                        for (int k = 0; k < payloadSize; k++)
                                                printWriter.printf("%02x ", payload[k]);
                                        printWriter.printf("\n");
@@ -395,8 +383,7 @@ public class MessageParser {
                                processMessage(buffer);
                                if (id == DataChannelConstants.MSG_DATA_TERMINATE) {
                                        Logger.debug("message data terminate arrived!!!");
-                                       Logger.performance("TEST", "While tracing",
-                                                       "Terminate Application");
+                                       Logger.performance("TEST", "While tracing", "Terminate Application");
                                        if (AnalyzerManager.getProcessCount() == 0) {
                                                break;
                                        }
@@ -409,10 +396,8 @@ public class MessageParser {
                                Display.getDefault().asyncExec(new Runnable() {
                                        @Override
                                        public void run() {
-                                               StopProcessManager
-                                                               .getInstance()
-                                                               .stopProcessStart(
-                                                                               AnalyzerLabels.STOP_PROCESS_DLG_SUMMARIZING_DATA); // socket
+                                               StopProcessManager.getInstance().stopProcessStart(
+                                                               AnalyzerLabels.STOP_PROCESS_DLG_SUMMARIZING_DATA); // socket
                                                // timeout
                                        }
                                });
@@ -421,16 +406,16 @@ public class MessageParser {
                } catch (IOException e) {
                        Logger.debug("### socket timeout - TODO: show this as a dialog."); //$NON-NLS-1$
 
-                       Display.getDefault().asyncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       StopProcessManager
-                                                       .getInstance()
-                                                       .stopProcessStart(
-                                                                       AnalyzerLabels.STOP_PROCESS_DLG_DEVICE_DISCONNECTED); // socket
-                                       // timeout
-                               }
-                       });
+                       if (AnalyzerManager.isRunning()) {
+                               Display.getDefault().asyncExec(new Runnable() {
+                                       @Override
+                                       public void run() {
+                                               StopProcessManager.getInstance().stopProcessStart(
+                                                               AnalyzerLabels.STOP_PROCESS_DLG_DEVICE_DISCONNECTED); // socket
+                                               // timeout
+                                       }
+                               });
+                       }
                        endingSteps();
                } finally {
                        if (printWriter != null) {
@@ -446,8 +431,7 @@ public class MessageParser {
                Display.getDefault().syncExec(new Runnable() {
                        @Override
                        public void run() {
-                               ToolbarArea.getInstance().setToolbarState(
-                                               ToolbarArea.TOOLBAR_STATE_READY);
+                               ToolbarArea.getInstance().setToolbarState(ToolbarArea.TOOLBAR_STATE_READY);
                        }
                });
                stopTimer();
@@ -488,16 +472,13 @@ public class MessageParser {
 
                case DataChannelConstants.MSG_DATA_SYSTEM:
                        Runtime runtime = Runtime.getRuntime();
-                       if ((runtime.totalMemory() - runtime.freeMemory()) >= runtime
-                                       .maxMemory() * 0.8) {
+                       if ((runtime.totalMemory() - runtime.freeMemory()) >= runtime.maxMemory() * 0.8) {
                                ToolbarArea.getInstance().stopTrace();
                                Display.getDefault().asyncExec(new Runnable() {
                                        @Override
                                        public void run() {
-                                               final Shell shell = WorkbenchUtil.getWorkbenchWindow()
-                                                               .getShell();
-                                               DADialog dialog = new DADialog(shell, SWT.NONE, 550,
-                                                               153);
+                                               final Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell();
+                                               DADialog dialog = new DADialog(shell, SWT.NONE, 550, 153);
                                                dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
                                                dialog.setMessage(AnalyzerLabels.HEAP_MEMORY_WARNING_PRE
                                                                + PathManager.DA_INSTALL_PATH
@@ -530,8 +511,7 @@ public class MessageParser {
                        String name = ByteUtil.getString(data, index);
                        index += ByteUtil.getStringLength(data, index);
 
-                       ProcessInformation process = AnalyzerManager.getProject()
-                                       .getProcessInformation(pid);
+                       ProcessInformation process = AnalyzerManager.getProject().getProcessInformation(pid);
 
                        if (null != process) {
                                process.setProcessName(name);
@@ -539,8 +519,7 @@ public class MessageParser {
                }
                        break;
                default: // MSG_PROBE
-                       if (AnalyzerManager.isProcessInfoArrived() && id > 0x0100
-                                       && id < 0x0200) {
+                       if (AnalyzerManager.isProcessInfoArrived() && id > 0x0100 && id < 0x0200) {
                                log = LogDataFactory.createInstance(data);
                                if (null != log) {
                                        buffer.add(log);
index 7d3813e..27148df 100644 (file)
@@ -89,10 +89,15 @@ public class TraceStartStopThread implements Runnable {
 
        private void traceCancel(String message) {
                AnalyzerManager.setRunningState(false);
+               DACommunicator.stopTrace();
                final String msg = message;
                Display.getDefault().syncExec(new Runnable() {
                        @Override
                        public void run() {
+                               if (!AnalyzerManager.isExit()) {
+                                       ToolbarArea.getInstance().stopTimer();
+                               }
+                               
                                final Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell();
                                DADialog dialog = new DADialog(shell, SWT.NONE);
                                dialog.setIcon(ImageResources.DIALOG_WARNING_ICON);
@@ -103,10 +108,6 @@ public class TraceStartStopThread implements Runnable {
                                ToolbarArea.getInstance().setStartButtonEnablement(true);
                                ToolbarArea.getInstance().setSettingsButtonEnablement(true);
                                ShortCutManager.getInstance().setEnabled(true);
-
-                               if (!AnalyzerManager.isExit()) {
-                                       ToolbarArea.getInstance().stopTimer();
-                               }
                        }
                });
        }