From: greatim Date: Wed, 17 Sep 2014 17:20:49 +0000 (+0900) Subject: COMM: uncommented getting process name by request X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e3c50f4747ae844211ee87da9354c6dd8dfc0cbb;p=sdk%2Ftools%2Fdynamic-analyzer.git COMM: uncommented getting process name by request uncommented getting process name by request. swap manager is applied to recent SDK Change-Id: Ib8f2520e0be7e03ff8fbb05fa7ba27666059349a Signed-off-by: greatim --- diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerConstants.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerConstants.java index e3419b0..a792bfb 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerConstants.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerConstants.java @@ -106,6 +106,7 @@ public class AnalyzerConstants { public static final int SOCKET_CHECK_INTERVAL = 10; public static final int DATA_SOCKET_TIMEOUT = 50000; public static final int CONTROL_SOCKET_TIMEOUT = 10000; + public static final int PROC_ADD_INFO_TIMEOUT = 1000; public static final int SOCKET_FORWARD_INTERVAL = 1000; public static final int LOG_CHECK_INTERVAL = 1000; diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/HostResult.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/HostResult.java index bc2d50e..ba6331e 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/HostResult.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/HostResult.java @@ -72,6 +72,8 @@ public enum HostResult { ERR_KEEP_ALIVE(-506, "keep alive message ack fail..."), ERR_BIN_INFO_GET_FAIL(-507, "binary info get fail..."), + + ERR_RECEIVE_ACK_FAIL(-508, "receiving ack message fail..."), ERR_DA_IS_EXIT(-901, "Dynamic Analyzer is closing"), diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/BaseCommunicator.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/BaseCommunicator.java index 53bffd1..13570b9 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/BaseCommunicator.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/BaseCommunicator.java @@ -51,8 +51,6 @@ public abstract class BaseCommunicator { public abstract void clear(); - public abstract HostResult handleControlMessage(String message); - public boolean isBlocked() { return blocked; } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/DACommunicator.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/DACommunicator.java index 06d3412..cdb3416 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/DACommunicator.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/DACommunicator.java @@ -675,10 +675,6 @@ public class DACommunicator { GlobalInformation.getCurrentDeviceInfo().getCommunicator().closeSock(); } - public static HostResult handleControlMessage(String msg) { - return GlobalInformation.getCurrentDeviceInfo().getCommunicator().handleControlMessage(msg); - } - public static Map sendProcessAddInfoMessage(List pids) { DeviceInfo dev = GlobalInformation.getCurrentDeviceInfo(); if (dev != null) { diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/ProcessInformation.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/ProcessInformation.java index 4a1c640..396ee94 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/ProcessInformation.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/ProcessInformation.java @@ -83,27 +83,26 @@ public class ProcessInformation { } public String getProcessName() { -// if (processNameByRequest == null) { -// synchronized (processNameRequestLock) { -// if (processNameByRequest == null) { -// List pids = new ArrayList(); -// pids.add(Integer.valueOf(pid)); -// Map nameMap = DACommunicator -// .sendProcessAddInfoMessage(pids); -// if (nameMap != null) { -// String name = nameMap.get(Integer.valueOf(pid)); -// if (name != null) { -// int index = name.lastIndexOf("/"); -// if(index > 0) { -// processNameByRequest = name.substring(index + 1); -// } else { -// processNameByRequest = name; -// } -// } -// } -// } -// } -// } + if (processNameByRequest == null) { + synchronized (processNameRequestLock) { + if (processNameByRequest == null) { + List pids = new ArrayList(); + pids.add(Integer.valueOf(pid)); + Map nameMap = DACommunicator.sendProcessAddInfoMessage(pids); + if (nameMap != null) { + String name = nameMap.get(Integer.valueOf(pid)); + if (name != null) { + int index = name.lastIndexOf("/"); + if (index > 0) { + processNameByRequest = name.substring(index + 1); + } else { + processNameByRequest = name; + } + } + } + } + } + } if (processNameByRequest != null && !processNameByRequest.isEmpty()) return processNameByRequest; diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java index 498bc71..eebbb02 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java @@ -42,6 +42,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; @@ -104,6 +105,10 @@ import org.tizen.sdblib.exception.SdbCommandRejectedException; import org.tizen.sdblib.exception.TimeoutException; import org.tizen.sdblib.service.SyncResult; +/** + * @author greatim + * + */ public class Communicator30 extends BaseCommunicator { static final boolean PRINT_CONTROL_LOG_TOFILE = true; @@ -182,6 +187,11 @@ public class Communicator30 extends BaseCommunicator { @Override public HostResult startTrace() { + DeviceInfo curDev = GlobalInformation.getCurrentDeviceInfo(); + if (curDev == null) { + return HostResult.ERR_DEVICE_IS_NULL; + } + DACommunicator.setRunning(true); UserSpaceInst userSpaceInst = getUserSpaceInst(); Logger.performance("TEST", "Start Trace", "Set application inst"); @@ -224,7 +234,7 @@ public class Communicator30 extends BaseCommunicator { Thread dataThread = new Thread(null, new DataChannelThread(), AnalyzerConstants.COMMUNICATOR_RECEIVE_THREAD); // start message send - HostResult result = handleControlMessage(GlobalInformation.getCurrentDeviceInfo(), ret); + HostResult result = handleControlMessage(curDev, ret); Logger.performance("TEST", "Start Trace", "Make and Send start message"); // FIX @@ -403,6 +413,9 @@ public class Communicator30 extends BaseCommunicator { byte[] preMsg = null; DeviceInfo curDevice = GlobalInformation.getCurrentDeviceInfo(); + if (curDevice == null) { + return HostResult.ERR_DEVICE_IS_NULL; + } if (AnalyzerConstants.RUNNING_PROCESS.equals(selectedPkg.getPackageId())) { Map selProcess = selectedPkg.getMainApp().getRunningProcesses(); @@ -490,19 +503,21 @@ public class Communicator30 extends BaseCommunicator { // send config message byte[] config = ByteUtil.toBytes(AnalyzerConstants.MSG_CONFIG); RunTimeConfiguration rt = new RunTimeConfiguration(); - rt.setFeatures(SettingDataManager.getInstance().getConfiguration(devInfo), SettingDataManager - .getInstance().getPreConfiguration(devInfo)); -// TODO : check and remove -// rt.setSystemTracePeriod(ConfigureManager.getInstance().getSystemPeriod()); -// rt.setSamplingPeriod(ConfigureManager.getInstance().getSamplingPeriod()); - + rt.setFeatures(SettingDataManager.getInstance().getConfiguration(devInfo), + SettingDataManager.getInstance().getPreConfiguration(devInfo)); + // TODO : check and remove + // rt.setSystemTracePeriod(ConfigureManager.getInstance().getSystemPeriod()); + // rt.setSamplingPeriod(ConfigureManager.getInstance().getSamplingPeriod()); + TargetData target = SettingDataManager.getInstance().getConnectedTarget(); - int systemPeriod = target.getSelectedFeatureValue(ConfigureLabels.SYSTEM_INFOMATION_SAMPLING_PERIODIC); + int systemPeriod = target + .getSelectedFeatureValue(ConfigureLabels.SYSTEM_INFOMATION_SAMPLING_PERIODIC); if (systemPeriod < 0) { systemPeriod = target.getAvailableFeature( ConfigureLabels.SYSTEM_INFOMATION_SAMPLING_PERIODIC).getDefaultValue(); } - int samplingPeriod = target.getSelectedFeatureValue(ConfigureLabels.FUNCTION_PROFILING_SAMPLING_PERIODIC); + int samplingPeriod = target + .getSelectedFeatureValue(ConfigureLabels.FUNCTION_PROFILING_SAMPLING_PERIODIC); if (samplingPeriod < 0) { samplingPeriod = target.getAvailableFeature( ConfigureLabels.FUNCTION_PROFILING_SAMPLING_PERIODIC).getDefaultValue(); @@ -550,8 +565,7 @@ public class Communicator30 extends BaseCommunicator { byte[] stop = ByteUtil.toBytes(AnalyzerConstants.MSG_STOP_SWAP); int length = 0; byte[] stopMsg = ByteUtil.getByte(stop, length); - HostResult result = handleControlMessage(GlobalInformation.getCurrentDeviceInfo(), - stopMsg); + HostResult result = handleControlMessage(stopMsg); if (result.isSuccess()) { if (isCorrectAck(MSG_STOP_ACK, result)) { @@ -583,12 +597,39 @@ public class Communicator30 extends BaseCommunicator { } } - @Override - public HostResult handleControlMessage(String message) { - return HostResult.SUCCESS; + public HostResult handleControlMessage(byte[] message) { + DeviceInfo curDev = GlobalInformation.getCurrentDeviceInfo(); + if (curDev != null) { + return handleControlMessage(curDev, message); + } else { + return HostResult.ERR_DEVICE_IS_NULL; + } } public HostResult handleControlMessage(DeviceInfo device, byte[] message) { + if (device != null) { + return handleControlMessage(device, message, true, + AnalyzerConstants.CONTROL_SOCKET_TIMEOUT); + } else { + return HostResult.ERR_DEVICE_IS_NULL; + } + } + + /** + * send host message to manager by control socket, and receive ack message. + * + * @param device + * target device to send message + * @param message + * message to send + * @param waitack + * whether receive ack message or not + * @param timeout + * when wait for ack message, time limit of waiting by millisec + * @return HostResult + */ + public HostResult handleControlMessage(DeviceInfo device, byte[] message, boolean waitack, + int timeout) { HostResult result = null; Socket controlSock = device.getControlSock(); @@ -600,60 +641,72 @@ public class Communicator30 extends BaseCommunicator { printWriter.printf("%02x ", message[k]); printWriter.printf("\n"); } - controlSock.getOutputStream().write(message); - Logger.debug("wait for ack... [send message : " + ByteUtil.toInt(message) + " ]"); - int readsize = -1; - byte[] cbuf = new byte[DACommunicator.READ_BUFFER_SIZE]; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + synchronized (controlSock) { + controlSock.getOutputStream().write(message); + if (!waitack) { + return HostResult.SUCCESS; + } + + Logger.debug("wait for ack of message [" + ByteUtil.toInt(message) + "]"); - Logger.debug("blocked"); - blocked = true; + int readsize = -1; + byte[] cbuf = new byte[DACommunicator.READ_BUFFER_SIZE]; - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - readsize = controlSock.getInputStream().read(cbuf, 0, CONTROL_HEADER_SIZE); - if (readsize == CONTROL_HEADER_SIZE) { - baos.write(cbuf, 0, readsize); - int payloadsize = ByteUtil.toInt(cbuf, INT_SIZE); + Logger.debug("blocked"); + blocked = true; + + int oldtimeout = controlSock.getSoTimeout(); + controlSock.setSoTimeout(timeout); + InputStream in = controlSock.getInputStream(); - do { - readsize = controlSock.getInputStream().read(cbuf); + readsize = in.read(cbuf, 0, CONTROL_HEADER_SIZE); + if (readsize == CONTROL_HEADER_SIZE) { baos.write(cbuf, 0, readsize); + int payloadsize = ByteUtil.toInt(cbuf, INT_SIZE); - payloadsize -= readsize; - } while (payloadsize > 0); - blocked = false; - - readsize = baos.size(); - cbuf = baos.toByteArray(); - if (PRINT_CONTROL_LOG_TOFILE && printWriter != null) { - printWriter.printf("recv :"); - for (int k = 0; k < readsize; k++) - printWriter.printf("%02x ", cbuf[k]); - printWriter.printf("\n"); + do { + readsize = in.read(cbuf); + baos.write(cbuf, 0, readsize); + + payloadsize -= readsize; + } while (payloadsize > 0); + blocked = false; + Logger.debug("unblocked"); } - Logger.debug("unblocked"); - if (readsize > 0) { - byte[] buf = new byte[readsize]; - System.arraycopy(cbuf, 0, buf, 0, readsize); - result = HostResult.SUCCESS; - int ackId = ByteUtil.toInt(buf); + controlSock.setSoTimeout(oldtimeout); + } - // for debug - System.out.print("ack id : "); - AnalyzerUtil.printHexdecimal(ackId); - Logger.debug(); + int readsize = baos.size(); + byte[] cbuf = baos.toByteArray(); + if (PRINT_CONTROL_LOG_TOFILE && printWriter != null) { + printWriter.printf("recv :"); + for (int k = 0; k < readsize; k++) + printWriter.printf("%02x ", cbuf[k]); + printWriter.printf("\n"); + } - result.setRet(buf); - } else { - result = HostResult.ERR_CONTROL_SOCKET_CONNECTION_CLOSED; - result.setMessage(result.getMessage()); - } + if (readsize > 0) { + byte[] buf = new byte[readsize]; + System.arraycopy(cbuf, 0, buf, 0, readsize); + result = HostResult.SUCCESS; + int ackId = ByteUtil.toInt(buf); + + // for debug + System.out.print("ack id : "); + AnalyzerUtil.printHexdecimal(ackId); + Logger.debug(); + + result.setRet(buf); } else { - blocked = false; - result = HostResult.ERR_EXCEPTION_OCCURRED; - result.setMessage("Failed to read Ack Header"); + result = HostResult.ERR_RECEIVE_ACK_FAIL; + result.setMessage(result.getMessage()); } + } else { + result = HostResult.ERR_CONTROL_SOCKET_CONNECTION_CLOSED; + result.setMessage("Control socket connection is closed"); } } catch (SocketException e) { result = HostResult.ERR_EXCEPTION_OCCURRED; @@ -928,38 +981,16 @@ public class Communicator30 extends BaseCommunicator { public HostResult sendScreenShotRequest() { byte[] msg = ByteUtil.getByte(AnalyzerConstants.MSG_GET_SCREENSHOT, 0); - HostResult result = HostResult.SUCCESS; - Socket controlSock = GlobalInformation.getCurrentDeviceInfo().getControlSock(); - try { - if (null != controlSock && !controlSock.isClosed()) { - controlSock.getOutputStream().write(msg); - } else { - Logger.debug("control socket is closed"); - result = HostResult.ERR_CONTROL_SOCKET_CONNECTION_CLOSED; - } - } catch (SocketException e) { - result = HostResult.ERR_EXCEPTION_OCCURRED; - result.setMessage(e.getMessage()); - e.printStackTrace(); - return result; - } catch (SocketTimeoutException e) { - result = HostResult.ERR_EXCEPTION_OCCURRED; - result.setMessage(e.getMessage()); - e.printStackTrace(); - return result; - } catch (IOException e) { - result = HostResult.ERR_EXCEPTION_OCCURRED; - result.setMessage(e.getMessage()); - e.printStackTrace(); - return result; - } finally { - blocked = false; - } - return result; + return handleControlMessage(GlobalInformation.getCurrentDeviceInfo(), msg, false, 0); } public HostResult sendSWAPMessage(int messageId, List settings) { + DeviceInfo curDev = GlobalInformation.getCurrentDeviceInfo(); + if (curDev == null) { + return HostResult.ERR_DEVICE_IS_NULL; + } + byte[] msg = new byte[0]; int count = settings.size(); int failedCount = 0; @@ -1017,7 +1048,7 @@ public class Communicator30 extends BaseCommunicator { msg = ByteUtil.getByte(msg, length, libInst); // ByteUtils.printByteArrayForStart(msg); - HostResult result = handleControlMessage(GlobalInformation.getCurrentDeviceInfo(), msg); + HostResult result = handleControlMessage(curDev, msg); int ackMsg = AnalyzerConstants.MSG_SWAP_INST_ADD_ACK; if (messageId == AnalyzerConstants.MSG_SWAP_INST_REMOVE) { @@ -1031,6 +1062,11 @@ public class Communicator30 extends BaseCommunicator { } public Map sendProcessAddInfoMessage(List pids) { + DeviceInfo curDev = GlobalInformation.getCurrentDeviceInfo(); + if (curDev == null) { + return null; + } + Map infoMap = null; int pidcount = pids.size(); @@ -1046,7 +1082,8 @@ public class Communicator30 extends BaseCommunicator { int length = sendbin.length; byte[] msg = ByteUtil.getByte(AnalyzerConstants.MSG_GET_PROCESS_ADD_INFO, length, sendbin); - HostResult result = handleControlMessage(GlobalInformation.getCurrentDeviceInfo(), msg); + HostResult result = handleControlMessage(curDev, msg, true, + AnalyzerConstants.PROC_ADD_INFO_TIMEOUT); if (result.isSuccess() && isCorrectAck(AnalyzerConstants.MSG_GET_PROCESS_ADD_INFO_ACK, result)) { @@ -1093,7 +1130,7 @@ public class Communicator30 extends BaseCommunicator { int length = sendBin.length; byte[] msg = ByteUtil.getByte(AnalyzerConstants.MSG_BINARY_INFO, length, sendBin); - HostResult result = handleControlMessage(GlobalInformation.getCurrentDeviceInfo(), msg); + HostResult result = handleControlMessage(msg); if (!result.isSuccess() || !isCorrectAck(MSG_BINARY_INFO_ACK, result)) { return HostResult.ERR_BIN_INFO_GET_FAIL;