SRADA-782 Tracing time value now is got directly from TracingProcessManager.
authorp.privalov <p.privalov@partner.samsung.com>
Mon, 11 Jul 2016 09:10:37 +0000 (12:10 +0300)
committerMaria Guseva <m.guseva@samsung.com>
Fri, 29 Jul 2016 15:46:29 +0000 (18:46 +0300)
Now tracing time is got without unzip of zipped trace.
In TracingProcess unneeded comment deleted.

In TracingProcessManager and TracingProcess implemented communication threads.
To that moment there are 4 types of messages
 * STOP_TRACING message - is sent from TracingProcessManager to TracingProcess
   to stop it.
 * STOP_DONE message - TracingProcess sends this message to inform that it is
   stopped successfully.
 * REQUEST_TRACING_TIME message - TracingProcessManager requests for tracing
   time value.
 * INFO_TRACING_TIME message - message that contains tracing time value.
List of message types may be extended further.

Change-Id: I43c0f49414d13c141dbc8714ca5eb1a174e7ec34

org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/CliInternals.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/commands/StopCommand.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/manager/ProcessManager.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/manager/ProcessManagerMBean.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/manager/TracingProcessManager.java
org.tizen.dynamicanalyzer.cli/src/org/tizen/dynamicanalyzer/cli/tracing/TracingProcess.java

index f2f5ef6..a7e6565 100644 (file)
@@ -364,6 +364,19 @@ public final class CliInternals {
        }
 
        /**
+        * Return tracing time of process, that is being running on device or zero
+        * if it not finished yet
+        *
+        * @param device string definition of device
+        * @return Tracing time in ms. Not in human readable form by now.
+        * @throws ConnectException if not able to connect with ProcessManager
+        */
+       public static long getTracingTime(String device) throws ConnectException {
+               ProcessManagerMBean pmProxy = getPMProxyInstance();
+               return pmProxy.getTracingTime(device);
+       }
+
+       /**
         * Get information about last tracing process on specified device.
         *
         * @param device target device
index a2ca0b8..21dd118 100644 (file)
@@ -50,9 +50,10 @@ public class StopCommand extends Command {
                }
 
                Duration duration = new Duration(ctx.getStartTime(), ctx.getFinishTime());
-               String totalStopTime = "";
+               long tracingTime;
                try{
-                       totalStopTime = getTotalStopTime(ctx);
+                       tracingTime = CliInternals.getTracingTime(
+                                       ctx.getArgs().getDevice());
                }catch(Exception e){
                        System.err.println("Can't get time from TracingProcessManager");
                        return ExitCode.EX_OPERATION_FAILED;
@@ -63,35 +64,12 @@ public class StopCommand extends Command {
                                "Total time:   %s%n" +
                                "Tracing time: %s%n" +
                                "Output:       %s%n",
-                               duration, totalStopTime, ctx.getArgs().getOutput()+".zip");
+                               duration, tracingTime, ctx.getArgs().getOutput()+".zip");
                                // TODO check if output was created
 
                return ExitCode.EX_SUCCESS;
        }
 
-       private String getTotalStopTime(TracingProcessContext ctx) throws Exception {
-               long diff_ms = 0;
-               String src = CommandAction.loadFromZip(PathManager.DA_SAVE_PATH + File.separator
-                                               + ctx.getArgs().getOutput().getName() + ".zip");
-               if (src == null) {
-                       throw new Exception();
-               }
-               Project project = Project.getProjectFromFile(src);
-               if (project == null)
-                       throw new Exception();
-
-               diff_ms = project.getTotalStopTime();
-
-               String result = "";
-
-               long seconds = diff_ms / 1000;
-               diff_ms %= 1000;
-
-               result += String.format("%.3f", seconds + (float) diff_ms / 1000) + "s";
-
-               return result.trim();
-       }
-
        @Override
        public ExitCode processCommand(String[] args) {
                try {
index f428a48..08b39a0 100644 (file)
@@ -138,6 +138,11 @@ public class ProcessManager implements ProcessManagerMBean {
        }
 
        @Override
+       public synchronized long getTracingTime(String device) {
+               return mTracingMap.get(device).getTracingTime();
+       }
+
+       @Override
        public synchronized DAResult stopAll() {
                Logger.warning("Requested stop tracing on all devices.");
 
index 6a77610..9459c4a 100644 (file)
@@ -50,6 +50,15 @@ public interface ProcessManagerMBean {
        DAResult stopTracing(String device);
 
        /**
+        * Return tracing time of process in milliseconds or zero if process is
+        * still running
+        *
+        * @param device String definition of device serial or ip:port
+        * @return time in milliseconds or zero
+        */
+       long getTracingTime(String device);
+
+       /**
         * Stop all tracing processes.
         *
         * @return {@link ErrorCode#SUCCESS} if tracing processes finished
index a5baf3b..68de458 100644 (file)
@@ -116,12 +116,22 @@ public class TracingProcessManager {
        private volatile Thread monitoringThread;
 
        /**
-        * Thread, that encapsulated all communication with TracingProcess, starts
+        * Tracing time of Tracing process, initialized during stopTracing execution
+        */
+       private volatile long tracingTime;
+
+       /**
+        * Object, that encapsulated all communication with TracingProcess, starts
         * in constructor
         */
        private ServerConnection serverConnection;
 
        /**
+        * Communication thread.
+        */
+       private Thread commThread;
+
+       /**
         * Launch asynchronous monitoring of tracing process state.
         */
        private void startMonitoring() {
@@ -158,7 +168,7 @@ public class TracingProcessManager {
                        Socket socket = ss.accept();
                        // start processing in separate thread
                        serverConnection = new ServerConnection(socket);
-                       Thread commThread = new Thread(serverConnection,
+                       commThread = new Thread(serverConnection,
                                        "Communication thread");
                        commThread.start();
                        // finally we should close server socket
@@ -239,6 +249,28 @@ public class TracingProcessManager {
        }
 
        /**
+        * Returns tracing time of process in milliseconds, or zero if it still
+        * running
+        *
+        * @return time value in milliseconds
+        */
+       public long getTracingTime() {
+               if (tracingTime > 0)
+                       return tracingTime;
+               else {
+                       try {
+                               serverConnection.sendMessage(MessageType.REQUEST_TRACING_TIME);
+                               while (commThread.isAlive()) {
+                                       serverConnection.wait();
+                               }
+                       } catch (IOException | InterruptedException e) {
+                               Logger.error("Communication failed");
+                       }
+                       return tracingTime;
+               }
+       }
+
+       /**
         * Forcibly terminate underlying tracing process.
         */
        public synchronized void forceStopTracing() {
@@ -276,7 +308,7 @@ public class TracingProcessManager {
                return ctx.isFinished();
        }
 
-       private static class ServerConnection implements Runnable {
+       private class ServerConnection implements Runnable {
                ObjectOutputStream oos;
                ObjectInputStream ois;
 
@@ -333,7 +365,7 @@ public class TracingProcessManager {
                                                bw.close();
                                                break;
                                        case INFO_TRACING_TIME:
-
+                                               tracingTime = Long.parseLong(message.args[0]);
                                                break;
                                        // Wrong requests
                                        case REQUEST_TRACING_TIME:
@@ -342,11 +374,14 @@ public class TracingProcessManager {
                                                Logger.warning("wrong request type for TracingProcessManager");
                                                break;
                                        }
+                                       this.notifyAll();
                                }
                        } catch (ClassNotFoundException e) {
                                Logger.error("Error while communicating with TracingProcess. Message type can't be resolved.");
+                               this.notifyAll();
                        } catch (IOException e) {
                                Logger.info("Communication stopped, stream closed");
+                               this.notifyAll();
                        }
                }
        }
index 03b61cc..57da32b 100644 (file)
@@ -194,7 +194,6 @@ public class TracingProcess {
                        return result;
                }
 
-               // async start stop monitor thread
                try {
                        // block until tracing will be finished
                        tracingProcess.waitForCompletion();