}
/**
+ * 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
}
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;
"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 {
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() {
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
}
/**
+ * 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() {
return ctx.isFinished();
}
- private static class ServerConnection implements Runnable {
+ private class ServerConnection implements Runnable {
ObjectOutputStream oos;
ObjectInputStream ois;
bw.close();
break;
case INFO_TRACING_TIME:
-
+ tracingTime = Long.parseLong(message.args[0]);
break;
// Wrong requests
case REQUEST_TRACING_TIME:
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();
}
}
}