[Title] before start trace
authorjooyoul_lee <jy.exe.lee@samsung.com>
Fri, 19 Jul 2013 06:16:51 +0000 (15:16 +0900)
committerjooyoul_lee <jy.exe.lee@samsung.com>
Fri, 19 Jul 2013 06:16:51 +0000 (15:16 +0900)
[Desc.]
[Issue]

org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerConstants.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/listeners/AnalyzerPerspectiveListener.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/Communicator30.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/communicator/HeartBeatThread.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/model/ByteUtils.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/model/control/ApplicationInfo.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/model/control/RunTimeConfiguration.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/model/data/ApiNameManager.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/utils/ByteSwapper.java [new file with mode: 0644]

index 1a228be..e63dcc4 100644 (file)
@@ -116,7 +116,7 @@ public class AnalyzerConstants {
 \r
        /* timer intervals */\r
        public static final int SOCKET_CHECK_INTERVAL = 10;\r
-       public static final int SOCKET_TIMEOUT = 5000;\r
+       public static final int SOCKET_TIMEOUT = 50000;\r
        public static final int SOCKET_FORWARD_INTERVAL = 1000;\r
        public static final int LOG_CHECK_INTERVAL = 1000;\r
        public static final int SAVE_PREPARE_TIME = 2000;\r
index 1c3ec19..50aa771 100644 (file)
@@ -33,22 +33,27 @@ import org.tizen.dynamicanalyzer.communicator.DACommunicator;
 import org.tizen.dynamicanalyzer.ui.toolbar.ToolbarArea;
 
 public class AnalyzerPerspectiveListener extends PerspectiveAdapter {
+       private static boolean init = false;
 
        @Override
        public void perspectiveActivated(IWorkbenchPage page,
                        IPerspectiveDescriptor perspective) {
 
-               ToolbarArea.getInstance().initToolbarEnablement();
-               DACommunicator.reload();
-
-               DACommunicator.addDeviceListener();
-               DACommunicator.loadDevices();
-               DACommunicator.checkDevices();
-               if (DACommunicator.checkVersion().isSuccess()) {
-                       DACommunicator.init();
-               } else {
-                       System.out.println("invalid version");
-                       //TODO: error popup and exit 
+               if (!init) {
+                       ToolbarArea.getInstance().initToolbarEnablement();
+                       DACommunicator.reload();
+
+                       DACommunicator.addDeviceListener();
+                       DACommunicator.loadDevices();
+                       DACommunicator.checkDevices();
+                       if (DACommunicator.checkVersion().isSuccess()) {
+                               DACommunicator.init();
+                               init = true;
+                               System.out.println("DA device init complete!!");
+                       } else {
+                               System.out.println("invalid version");
+                               // TODO: error popup and exit
+                       }
                }
        }
 
index d08384e..76704ff 100755 (executable)
@@ -1,6 +1,6 @@
 package org.tizen.dynamicanalyzer.swap.communicator;
 
-import static org.tizen.dynamicanalyzer.common.AnalyzerConstants.MSG_CONFIG_ACK;
+import static org.tizen.dynamicanalyzer.common.AnalyzerConstants.*;
 import static org.tizen.dynamicanalyzer.common.AnalyzerConstants.MSG_KEEP_ALIVE_ACK;
 import static org.tizen.dynamicanalyzer.common.AnalyzerConstants.MSG_START_ACK;
 import static org.tizen.dynamicanalyzer.common.AnalyzerConstants.MSG_STOP_ACK;
@@ -14,6 +14,8 @@ import java.net.SocketException;
 import java.net.SocketTimeoutException;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
@@ -38,6 +40,7 @@ import org.tizen.dynamicanalyzer.ui.toolbar.ConfigureManager;
 import org.tizen.dynamicanalyzer.ui.toolbar.ToolbarArea;
 import org.tizen.dynamicanalyzer.ui.userinterface.UIDataManager;
 import org.tizen.dynamicanalyzer.uirecorder.UIRecorderTool;
+import org.tizen.dynamicanalyzer.utils.ByteSwapper;
 import org.tizen.dynamicanalyzer.utils.UpdateViewTimer;
 
 public class Communicator30 extends BaseCommunicator {
@@ -61,10 +64,12 @@ public class Communicator30 extends BaseCommunicator {
                // get port
                List<DeviceInfo> removeList = new ArrayList<DeviceInfo>();
                for (DeviceInfo devInfo : devices) {
-                       int remotePort = CommunicatorUtils.getRemotePort(devInfo.getIDevice());
+                       int remotePort = CommunicatorUtils.getRemotePort(devInfo
+                                       .getIDevice());
                        if (remotePort < 0) {
                                System.out.println(devInfo.getIDevice().getSerialNumber()
-                                               + " remote port get failed and remove this device");
+                                               + " remote port get failed and remove this device : "
+                                               + devInfo.getIDevice().getSerialNumber());
                                removeList.add(devInfo);
                                // devices.remove(devInfo);
                        } else {
@@ -85,6 +90,7 @@ public class Communicator30 extends BaseCommunicator {
 
                if (!removeList.isEmpty()) {
                        devices.removeAll(removeList);
+                       removeList.clear();
                }
 
                // create control socket
@@ -92,14 +98,26 @@ public class Communicator30 extends BaseCommunicator {
                        HostResult result = createControlSocket(devInfo);
                        if (!result.isSuccess()) {
                                System.out.println(result.toString());
+                               removeList.add(devInfo);
+                       } else {
+                               result = createDataSocket(devInfo);
+                               if (!result.isSuccess()) {
+                                       System.out.println(result.toString());
+                                       removeList.add(devInfo);
+                               }
                        }
                }
                // create data socket - not create data receive thread
-               for (DeviceInfo devInfo : devices) {
-                       HostResult result = createDataSocket(devInfo);
-                       if (!result.isSuccess()) {
-                               System.out.println(result.toString());
-                       }
+               // for (DeviceInfo devInfo : devices) {
+               // HostResult result = createDataSocket(devInfo);
+               // if (!result.isSuccess()) {
+               // System.out.println(result.toString());
+               // }
+               // }
+
+               if (!removeList.isEmpty()) {
+                       devices.removeAll(removeList);
+                       removeList.clear();
                }
 
                // target info get
@@ -107,14 +125,25 @@ public class Communicator30 extends BaseCommunicator {
                        HostResult result = getTargetInfo(devInfo);
                        if (!result.isSuccess()) {
                                System.out.println(result.toString());
+                               removeList.add(devInfo);
                        }
                }
 
+               if (!removeList.isEmpty()) {
+                       devices.removeAll(removeList);
+                       removeList.clear();
+               }
+
+               if (devices.isEmpty()) {
+                       System.out.println("device init faiiled...");
+                       // TODO: close da
+               }
+
                // heart beat thread start
 
-               Thread heartBeat = new Thread(null, new HeartBeatThread(),
-                               AnalyzerConstants.HEART_BEAT_THREAD);
-               heartBeat.start();
+               // Thread heartBeat = new Thread(null, new HeartBeatThread(),
+               // AnalyzerConstants.HEART_BEAT_THREAD);
+               // heartBeat.start();
 
                return HostResult.SUCCESS;
        }
@@ -122,10 +151,15 @@ public class Communicator30 extends BaseCommunicator {
        @Override
        public HostResult startTrace() {
                // binary info message send
+               DACommunicator.setRunning(true);
                ApplicationInfo appInfo = new ApplicationInfo();
                AppInfo selectedApp = DACommunicator.getSelectedApp();
-               appInfo.setAppType(Integer.parseInt(selectedApp
-                               .getInfo(AppInfo.APPTYPE_INDEX))); // tizen native app
+               String appType = selectedApp.getInfo(AppInfo.APPTYPE_INDEX);
+               if (appType.contains(AppInfo.APPTYPE_CPP)) {
+                       appInfo.setAppType(APP_TYPE_TIZEN);
+               } else {
+                       appInfo.setAppType(APP_TYPE_OSP);
+               }
                appInfo.setAppId(selectedApp.getInfo(AppInfo.APPID_INDEX));
                appInfo.setExecPath(selectedApp.getInfo(AppInfo.EXEC_INDEX));
 
@@ -147,7 +181,11 @@ public class Communicator30 extends BaseCommunicator {
 
                if (result.isSuccess()) {
                        if (!isCorrectAck(MSG_START_ACK, result)) {
-                               return HostResult.ERR_MSG_START_FAIL;
+                               HostResult failResult = HostResult.ERR_MSG_START_FAIL;
+                               failResult.setMessage(ErrorCode.getError(
+                                               getReturnId(result.getRet())).toString());
+                               DACommunicator.setRunning(false);
+                               return failResult;
                        }
                } else {
                        DACommunicator.setRunning(false);
@@ -245,16 +283,19 @@ public class Communicator30 extends BaseCommunicator {
 
                        System.out.println("wait for ack... [send message : " + message
                                        + " ]");
-                       while (DACommunicator.isRunning()) {
-                               byte[] cbuf = new byte[64];
-                               blocked = true;
-                               int readsize = controlSock.getInputStream().read(cbuf);
-                               blocked = false;
-                               if (readsize > 0) {
-                                       result = HostResult.SUCCESS;
-                                       result.setRet(cbuf);
-                               }
+                       // while (true) {
+                       byte[] cbuf = new byte[64];
+                       blocked = true;
+                       int readsize = controlSock.getInputStream().read(cbuf);
+                       blocked = false;
+                       if (readsize > 0) {
+                               byte[] buf = new byte[readsize];
+                               System.arraycopy(cbuf, 0, buf, 0, readsize);
+                               result = HostResult.SUCCESS;
+                               result.setRet(buf);
                        }
+
+                       // }
                } catch (SocketException e) {
                        result = HostResult.ERR_EXCEPTION_OCCURRED;
                        result.setMessage(e.getMessage());
@@ -281,7 +322,7 @@ public class Communicator30 extends BaseCommunicator {
                Socket controlSock = null;
                try {
                        controlSock = new Socket(CommonConstants.LOCAL_HOST,
-                                       device.getRemotePort());
+                                       CommunicatorUtils.LOCAL_PORT);
                        controlSock.setSoTimeout(AnalyzerConstants.SOCKET_TIMEOUT);
                        controlSock.setReuseAddress(true);
                        controlSock.setTcpNoDelay(true);
@@ -310,7 +351,7 @@ public class Communicator30 extends BaseCommunicator {
                Socket dataSock = null;
                try {
                        dataSock = new Socket(CommonConstants.LOCAL_HOST,
-                                       device.getRemotePort());
+                                       CommunicatorUtils.LOCAL_PORT);
                        dataSock.setSoTimeout(AnalyzerConstants.SOCKET_TIMEOUT);
                        dataSock.setReuseAddress(true);
                        dataSock.setTcpNoDelay(true);
@@ -336,16 +377,16 @@ public class Communicator30 extends BaseCommunicator {
 
        public HostResult getTargetInfo(DeviceInfo device) {
                System.out.println("Send target info  : "
-                               + ByteUtils.getByte(AnalyzerConstants.MSG_TARGET_INFO));
+                               + ByteUtils.getByte(AnalyzerConstants.MSG_TARGET_INFO, 0));
                HostResult result = handleControlMessage(device,
-                               ByteUtils.getByte(AnalyzerConstants.MSG_TARGET_INFO));
+                               ByteUtils.getByte(AnalyzerConstants.MSG_TARGET_INFO, 0));
                if (result.isSuccess()) {
                        System.out.println("target info message ack :" + result.getRet());
                        // FIXME : log parsing
                        byte[] data = result.getRet();
-                       int index = INT_SIZE * 2;
+                       int index = INT_SIZE * 3;
 
-                       if (isCorrectAck(MSG_KEEP_ALIVE_ACK, result)) {
+                       if (isCorrectAck(MSG_TARGET_INFO_ACK, result)) {
                                TargetInfo info = processTargetInfo(data, index);
                                device.setTargetInfo(info);
                                return result;
@@ -357,7 +398,7 @@ public class Communicator30 extends BaseCommunicator {
        @Override
        public HostResult sendKeepAliveMessage(DeviceInfo device) {
                System.out.println("Send keep alive message  : "
-                               + ByteUtils.getByte(AnalyzerConstants.MSG_KEEP_ALIVE));
+                               + ByteUtils.getByte(AnalyzerConstants.MSG_KEEP_ALIVE, 0));
                HostResult result = handleControlMessage(device,
                                ByteUtils.getByte(AnalyzerConstants.MSG_KEEP_ALIVE, 0));
                if (result.isSuccess()) {
@@ -376,6 +417,8 @@ public class Communicator30 extends BaseCommunicator {
                int index = 0;
                int msgId = ByteUtils.toInt(data, index);
                index += INT_SIZE;
+               int length = ByteUtils.toInt(data, index);
+               index += INT_SIZE;
                int retId = ByteUtils.toInt(data, index);
                index += INT_SIZE;
 
@@ -440,4 +483,14 @@ public class Communicator30 extends BaseCommunicator {
        public void closeSock() {
                DACommunicator.getSelectedDevice().releaseDataSock();
        }
+
+       private int getMessageId(byte[] data) {
+               int index = 0;
+               return ByteUtils.toInt(data, index);
+       }
+
+       private int getReturnId(byte[] data) {
+               int index = INT_SIZE * 2;
+               return ByteUtils.toInt(data, index);
+       }
 }
index 1b7163d..9111a41 100755 (executable)
@@ -15,10 +15,10 @@ public class HeartBeatThread implements Runnable {
                List<DeviceInfo> devices = null;
 
                while (!AnalyzerManager.isExit()) {
-                       devices.clear();
+                       // devices.clear();
                        devices = DACommunicator.getDevices();
                        for (DeviceInfo device : devices) {
-                               System.out.println("Heart Beat!!");
+//                             System.out.println("Heart Beat!!");
                                HostResult result = DACommunicator.sendKeepAliveMessage(device);
                                if (!result.isSuccess()) {
                                        System.out.println(result.toString());
index 915482f..2d3fa4a 100755 (executable)
@@ -3,6 +3,8 @@ package org.tizen.dynamicanalyzer.swap.model;
 import java.nio.ByteBuffer;
 import java.util.List;
 
+import org.tizen.dynamicanalyzer.utils.ByteSwapper;
+
 public class ByteUtils {
        public static byte EOS = '\0';
 
@@ -35,7 +37,8 @@ public class ByteUtils {
                for (int i = 0; i < 4; i++) {
                        dword = (dword << 8) + (src[i + srcPos] & 0xFF);
                }
-               return dword;
+               return ByteSwapper.swap(dword);
+//             return dword;
        }
 
        /**
@@ -60,7 +63,8 @@ public class ByteUtils {
                for (int i = 0; i < 8; i++) {
                        qword = (qword << 8) + (src[i + srcPos] & 0xFF);
                }
-               return qword;
+               return ByteSwapper.swap(qword);
+//             return qword;
        }
 
        /**
@@ -93,6 +97,7 @@ public class ByteUtils {
         * @return
         */
        public static byte[] toBytes(int value) {
+               value = ByteSwapper.swap(value);
                byte[] dest = new byte[4];
                toBytes(value, dest, 0);
                return dest;
@@ -223,7 +228,7 @@ public class ByteUtils {
                byte[] temp = new byte[size];
                System.arraycopy(input, from, temp, 0, size);
                ByteBuffer buf = ByteBuffer.wrap(temp);
-               return buf.getShort();
+               return ByteSwapper.swap(buf.getShort());
        }
 
        public static byte[] floatToBytes(float input) {
@@ -241,7 +246,7 @@ public class ByteUtils {
                byte[] temp = new byte[size];
                System.arraycopy(input, from, temp, 0, size);
                ByteBuffer buf = ByteBuffer.wrap(temp);
-               return buf.getFloat();
+               return ByteSwapper.swap(buf.getFloat());
        }
 
        public static double toDouble(byte[] input, int from) {
@@ -249,7 +254,7 @@ public class ByteUtils {
                byte[] temp = new byte[size];
                System.arraycopy(input, from, temp, 0, size);
                ByteBuffer buf = ByteBuffer.wrap(temp);
-               return buf.getDouble();
+               return ByteSwapper.swap(buf.getDouble());
        }
 
        public static byte[] concatByteArray(byte[] front, byte[] rear) {
index f3d9b46..591825c 100755 (executable)
@@ -4,6 +4,9 @@ import org.tizen.dynamicanalyzer.swap.model.ByteUtils;
 import org.tizen.dynamicanalyzer.swap.model.SWAPModel;
 
 public class ApplicationInfo implements SWAPModel {
+       public static final int APPTYPE_TIZEN = 0x01;
+       public static final int APPTYPE_PROCESS = 0x02;
+       public static final int APPTYPE_COMMON_EXEC = 0x03;
        /***
         * target application type 
         * 01: tizen native application
index 02d8b36..e218ec7 100755 (executable)
@@ -4,15 +4,15 @@ import org.tizen.dynamicanalyzer.swap.model.ByteUtils;
 import org.tizen.dynamicanalyzer.swap.model.SWAPModel;
 
 public class RunTimeConfiguration implements SWAPModel {
-       private int features = 0;
+       private long features = 0;
        private int systemTraceInterval = 1000;
        private int dataMessageInterval = 1000;
 
-       public int getFeatures() {
+       public long getFeatures() {
                return features;
        }
 
-       public void setFeatures(int features) {
+       public void setFeatures(long features) {
                this.features = features;
        }
 
@@ -41,6 +41,6 @@ public class RunTimeConfiguration implements SWAPModel {
        @Override
        public void setByteToValues(byte[] input) {
                // TODO Auto-generated method stub
-               
+
        }
 }
index 4e7c5e9..2a23275 100644 (file)
@@ -25,7 +25,7 @@ public class ApiNameManager {
 
        public static void clear() {
                if (DACommunicator.isSWAPVersion()) {
-                       apiList.clear();
+                       getApiList().clear();
                }
        }
 }
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/utils/ByteSwapper.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/utils/ByteSwapper.java
new file mode 100644 (file)
index 0000000..c0f27fb
--- /dev/null
@@ -0,0 +1,140 @@
+package org.tizen.dynamicanalyzer.utils;
+
+public class ByteSwapper {
+       /**
+        * Byte swap a single short value.
+        * 
+        * @param value
+        *            Value to byte swap.
+        * @return Byte swapped representation.
+        */
+       public static short swap(short value) {
+               int b1 = value & 0xff;
+               int b2 = (value >> 8) & 0xff;
+
+               return (short) (b1 << 8 | b2 << 0);
+       }
+
+       /**
+        * Byte swap a single int value.
+        * 
+        * @param value
+        *            Value to byte swap.
+        * @return Byte swapped representation.
+        */
+       public static int swap(int value) {
+               int b1 = (value >> 0) & 0xff;
+               int b2 = (value >> 8) & 0xff;
+               int b3 = (value >> 16) & 0xff;
+               int b4 = (value >> 24) & 0xff;
+
+               return b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0;
+       }
+
+       /**
+        * Byte swap a single long value.
+        * 
+        * @param value
+        *            Value to byte swap.
+        * @return Byte swapped representation.
+        */
+       public static long swap(long value) {
+               long b1 = (value >> 0) & 0xff;
+               long b2 = (value >> 8) & 0xff;
+               long b3 = (value >> 16) & 0xff;
+               long b4 = (value >> 24) & 0xff;
+               long b5 = (value >> 32) & 0xff;
+               long b6 = (value >> 40) & 0xff;
+               long b7 = (value >> 48) & 0xff;
+               long b8 = (value >> 56) & 0xff;
+
+               return b1 << 56 | b2 << 48 | b3 << 40 | b4 << 32 | b5 << 24 | b6 << 16
+                               | b7 << 8 | b8 << 0;
+       }
+
+       /**
+        * Byte swap a single float value.
+        * 
+        * @param value
+        *            Value to byte swap.
+        * @return Byte swapped representation.
+        */
+       public static float swap(float value) {
+               int intValue = Float.floatToIntBits(value);
+               intValue = swap(intValue);
+               return Float.intBitsToFloat(intValue);
+       }
+
+       /**
+        * Byte swap a single double value.
+        * 
+        * @param value
+        *            Value to byte swap.
+        * @return Byte swapped representation.
+        */
+       public static double swap(double value) {
+               long longValue = Double.doubleToLongBits(value);
+               longValue = swap(longValue);
+               return Double.longBitsToDouble(longValue);
+       }
+
+       /**
+        * Byte swap an array of shorts. The result of the swapping is put back into
+        * the specified array.
+        * 
+        * @param array
+        *            Array of values to swap
+        */
+       public static void swap(short[] array) {
+               for (int i = 0; i < array.length; i++)
+                       array[i] = swap(array[i]);
+       }
+
+       /**
+        * Byte swap an array of ints. The result of the swapping is put back into
+        * the specified array.
+        * 
+        * @param array
+        *            Array of values to swap
+        */
+       public static void swap(int[] array) {
+               for (int i = 0; i < array.length; i++)
+                       array[i] = swap(array[i]);
+       }
+
+       /**
+        * Byte swap an array of longs. The result of the swapping is put back into
+        * the specified array.
+        * 
+        * @param array
+        *            Array of values to swap
+        */
+       public static void swap(long[] array) {
+               for (int i = 0; i < array.length; i++)
+                       array[i] = swap(array[i]);
+       }
+
+       /**
+        * Byte swap an array of floats. The result of the swapping is put back into
+        * the specified array.
+        * 
+        * @param array
+        *            Array of values to swap
+        */
+       public static void swap(float[] array) {
+               for (int i = 0; i < array.length; i++)
+                       array[i] = swap(array[i]);
+       }
+
+       /**
+        * Byte swap an array of doubles. The result of the swapping is put back
+        * into the specified array.
+        * 
+        * @param array
+        *            Array of values to swap
+        */
+       public static void swap(double[] array) {
+               for (int i = 0; i < array.length; i++)
+                       array[i] = swap(array[i]);
+       }
+}