[SRADA-203]When StopTrace, quickly shows the result data
authorggh1933.go <ggh1933.go@samsung.com>
Thu, 17 Mar 2016 09:25:18 +0000 (18:25 +0900)
committerggh1933.go <ggh1933.go@samsung.com>
Fri, 18 Mar 2016 02:09:08 +0000 (11:09 +0900)
 - Make Thread running, when "stopNormal" progress
 - thread.join take long times in stopNormal
 - ToolBar disabled, while Datathreads join completed.
 - Thread Progress changed.
 - "stopForce" make Thread running too.
 - change Boolean type and make synchronized "stopThreadCompleted" used each thread.

Change-Id: I26436c72b41088ce43745b32e7412a9199ea2887

org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/ProgressTable.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StopTraceManager.java

index 8683564..c8d0157 100644 (file)
@@ -58,11 +58,14 @@ public class ProgressTable {
                STOP_SCREENSHOT_TIMER(2),
                STOP_UPDATE_TIMER(2),
                SEND_STOPMSG(15),
+               /*
                STOP_DATATHREAD(10),
                STOP_MESSAGEPARSER(8),
                STOP_LOGPARSER(8),
                STOP_PAGEMANAGER(17),
                STOP_CALLSTACK_INSERTER(5),
+               */
+               STOP_DATATHREADS(48),
                SUMMARIZE_UI(5),
                FINAL(0);
 
@@ -106,9 +109,8 @@ public class ProgressTable {
                        STAGE.CREATE_DATATHREAD, STAGE.CREATE_PROJECT, STAGE.FINAL };
        private static STAGE[] traceEndProgress = new STAGE[] { STAGE.STOP_RESOURCE_MONITOR,
                        STAGE.SEND_STOPMSG, STAGE.STOP_CLOCK, STAGE.STOP_REPLAY_TIMER,
-                       STAGE.STOP_SCREENSHOT_TIMER, STAGE.STOP_UPDATE_TIMER, STAGE.STOP_DATATHREAD,
-                       STAGE.STOP_MESSAGEPARSER, STAGE.STOP_LOGPARSER, STAGE.STOP_PAGEMANAGER,
-                       STAGE.STOP_CALLSTACK_INSERTER, STAGE.SUMMARIZE_UI, STAGE.FINAL };
+                       STAGE.STOP_SCREENSHOT_TIMER, STAGE.STOP_UPDATE_TIMER, STAGE.STOP_DATATHREADS,
+                       STAGE.SUMMARIZE_UI, STAGE.FINAL };
        private static STAGE[] rangeAnalysisProgress = new STAGE[] { STAGE.FINAL };
 
        public static int getPercent(PHASE phase, STAGE stage) {
index b95ffff..e06958c 100644 (file)
@@ -61,7 +61,7 @@ public class StopTraceManager implements Runnable {
        private ProgressDialog progressDlg = null;
        private DAResult error;
        private boolean stopFromTarget = false;
-
+       private Boolean stopThreadCompleted = false;
        public StopTraceManager(DAResult err, boolean stopFromTarget) {
                this.error = err;
                this.stopFromTarget = stopFromTarget;
@@ -98,7 +98,7 @@ public class StopTraceManager implements Runnable {
                        }
                });
        }
-
+       
        @Override
        public void run() {
                // DAResult result = DAResult.SUCCESS;
@@ -113,71 +113,95 @@ public class StopTraceManager implements Runnable {
                                DACommunicator.stopTrace();
                        }
                        setStageComplete(STAGE.SEND_STOPMSG);
-
-                       // stop clock
-                       Toolbar.INSTANCE.stopTimer();
-                       setStageComplete(STAGE.STOP_CLOCK);
-
-                       // stop replay timer
-                       ReplayManager.resetStopAlarm();
-                       setStageComplete(STAGE.STOP_REPLAY_TIMER);
-
-                       // stop screenshot timer
-                       ScreenshotTimer.stop();
-                       setStageComplete(STAGE.STOP_SCREENSHOT_TIMER);
-
-                       // stop update timer
-                       UpdateViewTimer.stop();
-                       setStageComplete(STAGE.STOP_UPDATE_TIMER);
-
+                       
+                       Thread stopTimers = new Thread(new Runnable() {
+                               public void run() {
+                               // stop clock
+                                       try{
+                                       Toolbar.INSTANCE.stopTimer();
+                                       setStageComplete(STAGE.STOP_CLOCK);
+               
+                                       // stop replay timer
+                                       ReplayManager.resetStopAlarm();
+                                       setStageComplete(STAGE.STOP_REPLAY_TIMER);
+               
+                                       // stop screenshot timer
+                                       ScreenshotTimer.stop();
+                                       setStageComplete(STAGE.STOP_SCREENSHOT_TIMER);
+               
+                                       // stop update timer
+                                       UpdateViewTimer.stop();
+                                       setStageComplete(STAGE.STOP_UPDATE_TIMER);
+                                       }
+                                       catch(InterruptedException e){
+                                               Logger.debug(); // for new line
+                                               Logger.debug("Interrupt occurred while stopTimers");
+                                       }
+                               }
+                       });
+                       
+                       stopTimers.start();
+                       
                        // if error code equals with canceling then stop threads by force
                        if (error.equals(DAResult.ErrorCode.ERR_BY_USER_CANCEL)) {
-                               // stop data channel
-                               DataChannelThread.getInstance().stopForced();
-                               setStageComplete(STAGE.STOP_DATATHREAD);
-
-                               // stop message parser
-                               MessageParser.getInstance().stopForced();
-                               setStageComplete(STAGE.STOP_MESSAGEPARSER);
-
-                               // stop log parser
-                               LogParser.getInstance().stopForced();
-                               setStageComplete(STAGE.STOP_LOGPARSER);
-
-                               // stop page data manager
-                               DataManagerRegistry.stopThreadsForced();
-                               setStageComplete(STAGE.STOP_PAGEMANAGER);
-
-                               // stop other db inserters
-                               CallStackInserter.getInstance().stopForced();
-                               setStageComplete(STAGE.STOP_CALLSTACK_INSERTER);
+                               Thread stopForcedThread = new Thread(new Runnable() {
+                                       public void run() {
+                                               synchronized(stopThreadCompleted){
+                                                       stopThreadCompleted=false;
+                                               }
+                                               // stop data channel
+                                               DataChannelThread.getInstance().stopForced();           
+                                               // stop message parser
+                                               MessageParser.getInstance().stopForced();               
+                                               // stop log parser
+                                               LogParser.getInstance().stopForced();           
+                                               // stop page data manager
+                                               DataManagerRegistry.stopThreadsForced();                
+                                               // stop other db inserters
+                                               CallStackInserter.getInstance().stopForced();
+                                               synchronized(stopThreadCompleted){
+                                                       stopThreadCompleted=true;
+                                               }
+                                       }
+                               });
+                               
+                               stopForcedThread.start();
+                               setStageComplete(STAGE.STOP_DATATHREADS);
+                               
                        } else {
-                               // stop data channel
-                               DataChannelThread.getInstance().stopNormal();
-                               setStageComplete(STAGE.STOP_DATATHREAD);
-
-                               // stop message parser
-                               MessageParser.getInstance().stopNormal();
-                               setStageComplete(STAGE.STOP_MESSAGEPARSER);
-
-                               // stop log parser
-                               LogParser.getInstance().stopNormal();
-                               setStageComplete(STAGE.STOP_LOGPARSER);
-
-                               // stop page data manager
-                               DataManagerRegistry.stopThreadsNormal();
-                               setStageComplete(STAGE.STOP_PAGEMANAGER);
-
-                               // stop other db inserters
-                               CallStackInserter.getInstance().stopNormal();
-
+                               
+                               Thread stopNormalThread = new Thread(new Runnable() {
+                                       public void run() {
+                                               synchronized(stopThreadCompleted){
+                                                       stopThreadCompleted=false;
+                                               }
+                                               // stop data channel
+                                               DataChannelThread.getInstance().stopNormal();   
+                                               // stop message parser
+                                               MessageParser.getInstance().stopNormal();
+                                               // stop log parser
+                                               LogParser.getInstance().stopNormal();           
+                                               // stop page data manager
+                                               DataManagerRegistry.stopThreadsNormal();
+                                               // stop other db inserters
+                                               CallStackInserter.getInstance().stopNormal();
+                                               synchronized(stopThreadCompleted){
+                                                       stopThreadCompleted=true;
+                                               }
+                                       }
+                               });
+                               
+                               stopNormalThread.start();
+                               
+                               setStageComplete(STAGE.STOP_DATATHREADS);
+                               
                                Project project = Global.getProject();
                                if (project != null && project.isValid()) {
                                        project.setTotalStopTime(Toolbar.INSTANCE.getTime());
                                } else {
                                        Logger.error("project is not valid to save");
                                }
-                               setStageComplete(STAGE.STOP_CALLSTACK_INSERTER);
+                               
                        }
 
                        // change summary UI
@@ -215,10 +239,34 @@ public class StopTraceManager implements Runnable {
                        // if (!result.isSuccess()) {
                        // showError(result);
                        // }
-
-                       // set shortcut and toolbar UI as DA state
-                       ShortCutManager.getInstance().setEnabled(true);
-                       Toolbar.INSTANCE.changeUIState(DAState.getCurrentState());
+                       
+                       // Enable ToolBar wait DataThreads clear completed.
+                       Thread enableToolBar = new Thread(new Runnable() {
+                               public void run() {
+                                       boolean checkCompleted = false;
+                                       
+                                       synchronized(stopThreadCompleted){
+                                               checkCompleted = stopThreadCompleted;
+                                       }
+                                       
+                                       while(checkCompleted==false){
+                                               try {
+                                                       Thread.sleep(10);
+                                               } catch (InterruptedException e) {
+                                                       // TODO Auto-generated catch block
+                                                       break;
+                                               }
+                                               
+                                               synchronized(stopThreadCompleted){
+                                                       checkCompleted = stopThreadCompleted;
+                                               }
+                                       }
+                                       // set shortcut and toolbar UI as DA state
+                                       ShortCutManager.getInstance().setEnabled(true);
+                                       Toolbar.INSTANCE.changeUIState(DAState.getCurrentState());
+                               }
+                       });
+                       enableToolBar.start();
                }
        }