INTERNAL : get actual path of application 24/25724/2
authorwoojin <woojin2.jung@samsung.com>
Sat, 9 Aug 2014 00:18:27 +0000 (09:18 +0900)
committerwoojin <woojin2.jung@samsung.com>
Sat, 9 Aug 2014 11:19:03 +0000 (20:19 +0900)
using readlink command in target platform via da_command script, get the actual file path of application executable

Change-Id: If326eff72219706dac67a19a029c254707a5ed9c
Signed-off-by: woojin <woojin2.jung@samsung.com>
org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/common/path/PathConstants.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerShellCommands.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/SymbolManager.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/OpenTraceHandler.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/DeviceStatusInfo.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/FunctionNameManager.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/callstack/SWAPCallStackManager.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/SWAPLogParser.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/info/callstack/CallStackUnit.java

index 4739702..ed88872 100644 (file)
@@ -41,6 +41,7 @@ public class PathConstants {
        public static final String WINDOW_ACTIVATOR_MACOS = "macoswindowactivator.sh";//$NON-NLS-1$
 
        // paths
+       // DA_REMOTE_PROBE_PATH : to drop sample log from probe library [function profiling]
        public static final String DA_REMOTE_PROBE_PATH = "/usr/lib/da_probe"; //$NON-NLS-1$
        public static final String DA_REMOTE_PATH = "/home/developer/sdk_tools/da/"; //$NON-NLS-1$
        public static final String DA_REMOTE_DAEMON_BINARY_PATH = DA_REMOTE_PATH
index 770f942..b7571f8 100755 (executable)
@@ -46,6 +46,7 @@ public class AnalyzerShellCommands {
        public static final String DACOMMAND_FIND_UNITTEST = "da findunittest";
        public static final String DACOMMAND_FIND_IME = "/usr/bin/pkginfo --arg-flt 10 http://tizen.org/category/ime";
        public static final String DACOMMAND_CHECK_VERSION = "da getversion";
+       public static final String DACOMMAND_READLINK = "da readlink ";
 
        public static final String CMD_IS_ARM_ARCH = "uname -m"; //$NON-NLS-1$
        public static final String CMD_CAT_PORT_FILE = "cat /tmp/port.da"; //$NON-NLS-1$
index 66e048a..2b5c899 100644 (file)
@@ -428,7 +428,10 @@ public class SymbolManager {
                // _end indicates end of BSS (uninitialized data) section
                // function entry of _end is considered as bad data
                // TODO: test and remove _end condition
-               if (null == functionName || functionName.isEmpty() || functionName.equals("_end")) { //$NON-NLS-1$
+               if (null == functionName || functionName.isEmpty()) {
+                       functionName = InformationViewLabels.CALLSTACK_TABLE_UNKNOWN_FUNCTION;
+               } else if (functionName.equals("_end")) { //$NON-NLS-1$)
+                       DA_LOG.error("function name : _end occurred!\n");
                        functionName = InformationViewLabels.CALLSTACK_TABLE_UNKNOWN_FUNCTION;
                } else {
                        String prevFunctionName = functionName;
index d9dad86..8b7d6e8 100644 (file)
@@ -246,26 +246,10 @@ public class OpenTraceHandler extends AbstractHandler {
                                BinaryInfo bInfo = null;
                                switch (type) {
                                case ProfilingData.TYPE_APPLICATION:
-                                       binaryId = (Integer) profilingData
-                                                       .get(ProfilingDataDBTable.COLUMN.BINARYID.index);
-                                       bInfo = AnalyzerManager.getProject().getDeviceStatusInfo().getBinaryInfo(binaryId);
-                                       name = bInfo.getTargetBinaryPath();
-                                       fupData = new ProfilingData(seq, name, exCount, inCount, callCount,
-                                                       inElapsedTime, exElapsedTime, profiler);
-                                       profiler.setAppBin(fupData);
-                                       break;
                                case ProfilingData.TYPE_DEPENDENTLIBRARY:
+                               case ProfilingData.TYPE_LIBRARY:                                        
                                        binaryId = (Integer) profilingData
-                                       .get(ProfilingDataDBTable.COLUMN.BINARYID.index);
-                                       bInfo = AnalyzerManager.getProject().getDeviceStatusInfo().getBinaryInfo(binaryId);
-                                       name = bInfo.getTargetBinaryPath();
-                                       fupData = new ProfilingData(seq, name, exCount, inCount, callCount,
-                                                       inElapsedTime, exElapsedTime, profiler);                                        
-                                       profiler.setDependentLib(fupData);
-                                       break;
-                               case ProfilingData.TYPE_LIBRARY:
-                                       binaryId = (Integer) profilingData
-                                       .get(ProfilingDataDBTable.COLUMN.BINARYID.index);
+                                                       .get(ProfilingDataDBTable.COLUMN.BINARYID.index);
                                        bInfo = AnalyzerManager.getProject().getDeviceStatusInfo().getBinaryInfo(binaryId);
                                        name = bInfo.getTargetBinaryPath();
                                        fupData = new ProfilingData(seq, name, exCount, inCount, callCount,
@@ -282,6 +266,12 @@ public class OpenTraceHandler extends AbstractHandler {
                                        System.out.println("invalid profiling data type");
                                        break;
                                }
+                               
+                               if (type == ProfilingData.TYPE_APPLICATION) {
+                                       profiler.setAppBin(fupData);                                    
+                               } else if (type == ProfilingData.TYPE_DEPENDENTLIBRARY) {
+                                       profiler.setDependentLib(fupData);      
+                               }
 
                                profiler.getProfilingDataMap().put(seq, fupData);
                                UIDataManager.getInstance().getfunctionProfilingDataChecker()
index 267d371..76814d6 100644 (file)
@@ -37,12 +37,15 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.tizen.dynamicanalyzer.common.AnalyzerShellCommands;
 import org.tizen.dynamicanalyzer.common.ElfSymbolExtractor;
 import org.tizen.dynamicanalyzer.common.path.PathManager;
+import org.tizen.dynamicanalyzer.communicator.CommunicatorUtils;
 import org.tizen.dynamicanalyzer.constant.CommonConstants;
 import org.tizen.dynamicanalyzer.model.AddrSymbolPair;
 import org.tizen.dynamicanalyzer.util.DALogger;
 import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
+import org.tizen.sdblib.receiver.MultiLineReceiver;
 
 public class AppInfo {
 
@@ -108,7 +111,9 @@ public class AppInfo {
        private String execFileName = null;
        private List<String> localPackagePath = null;
        private Map<Integer, String> runningProcesses = null;
-
+       private String execPath = null;
+       
+       private static List<String> readlinkResult = new ArrayList<String>();
        private List<String> properties = new ArrayList<String>();
 
        // instance initializer
@@ -148,14 +153,16 @@ public class AppInfo {
 
        public String getExecFileName() {
                if (null == execFileName) {
-                       String[] splitPath = properties.get(PROPERTY.EXEC.index).split(
-                                       CommonConstants.SLASH);
-                       if (getAppType().contains(APPTYPE_CPP)) {
-                               execFileName = splitPath[splitPath.length - 1]
-                                               + CommonConstants.EXTENSION_EXEC_FILE;
-                       } else {
-                               execFileName = splitPath[splitPath.length - 1];
-                       }
+//                     String[] splitPath = properties.get(PROPERTY.EXEC.index).split(
+//                                     CommonConstants.SLASH);
+//                     if (getAppType().contains(APPTYPE_CPP)) {
+//                             execFileName = splitPath[splitPath.length - 1]
+//                                             + CommonConstants.EXTENSION_EXEC_FILE;
+//                     } else {
+//                             execFileName = splitPath[splitPath.length - 1];
+//                     }
+                       String[] splitPath = getExecPath().split(CommonConstants.SLASH);
+                       execFileName = splitPath[splitPath.length - 1];         
                }
                return execFileName;
        }
@@ -454,12 +461,35 @@ public class AppInfo {
        }
 
        public String getExecPath() {
-               String exec = properties.get(PROPERTY.EXEC.index);
-               if (getAppType().contains(APPTYPE_CPP)) {
-                       exec = exec.replaceFirst("/opt/apps", "/opt/usr/apps");
-                       exec += CommonConstants.EXTENSION_EXEC_FILE;
+               if (null != execPath) {
+                       return execPath;
+               } else {
+                       String exec = properties.get(PROPERTY.EXEC.index);
+                       String command = AnalyzerShellCommands.DACOMMAND_READLINK + exec;
+                       readlinkResult.clear();
+                       CommunicatorUtils.execHostCommand(command, new MultiLineReceiver() {
+                               @Override
+                               public void processNewLines(String[] appLines) {
+                                       for (int i = 0; i < appLines.length; i++) {
+                                               readlinkResult.add(appLines[i]);
+                                       }
+                               }
+                       }); // get actual file path using da readlink command (inside target platform)
+                       
+                       if (readlinkResult.isEmpty() || readlinkResult.size() > 1) { // fail to get path
+                               if (getAppType().contains(APPTYPE_CPP)) {
+                                       exec = exec.replaceFirst("/opt/apps", "/opt/usr/apps");
+                                       exec += CommonConstants.EXTENSION_EXEC_FILE;
+                               } else if (getAppType().contains(APPTYPE_CAPP)) {
+                                       exec = exec.replaceFirst("/opt/apps", "/opt/usr/apps");                 
+                               }
+                               execPath = exec;
+                       } else {
+                               execPath = readlinkResult.get(0);
+                       }
+                       
+                       return execPath;
                }
-               return exec;
        }
 
        public String getAppType() {
index 3221270..9fe2942 100755 (executable)
@@ -64,6 +64,7 @@ public class DeviceStatusInfo {
        private List<BinaryInfo> binaryInfoArray = new ArrayList<BinaryInfo>();
 
        public DeviceStatusInfo(List<String> functionList) {
+               // TODO: add <unknown function> first, then add apiMap list
                this.functionList = functionList;
        }
 
index f9e969e..af08719 100644 (file)
@@ -31,7 +31,6 @@ import java.util.List;
 
 import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
 import org.tizen.dynamicanalyzer.common.AnalyzerManager;
-import org.tizen.dynamicanalyzer.communicator.DACommunicator;
 import org.tizen.dynamicanalyzer.util.DALogger;
 
 public class FunctionNameManager {
@@ -72,8 +71,6 @@ public class FunctionNameManager {
        }
 
        public static void clear() {
-               if (DACommunicator.isSWAPVersion()) {
-                       getFunctionList().clear();
-               }
+               getFunctionList().clear();
        }
 }
index 4a9a8d5..f08f8f6 100644 (file)
@@ -290,7 +290,7 @@ public class SWAPCallStackManager extends BaseCallstackManager {
                                .getInstance().getTargetBinInfoMap();
                List<String> binPaths = new ArrayList<String>();
                binPaths.addAll(binInfoMap.keySet());
-               
+               // TODO: performance improvement
                int size = binPaths.size();
                for (int i = 0; i < size; i++) {
                        String binPath = binPaths.get(i);
index bd52c02..f730493 100755 (executable)
@@ -190,7 +190,7 @@ public class SWAPLogParser implements Runnable {
                                        int apiId = SymbolManager.getFuncId(pData, pData.getPcAddr(),
                                                        pData.getPid(), pData.getTime());
                                        String apiName = FunctionNameManager.getFunctionName(apiId);
-
+                                       // TODO : <unknown function> check with apiId
                                        if (apiId == -1 || apiName.equals("<unknown function>")) {
                                                continue;
                                        } else {
index 01d3807..42c43fd 100644 (file)
@@ -52,6 +52,7 @@ public class CallStackUnit {
        
        private static final DALogger DA_LOG = DALogger.getInstance();
 
+       // TODO: get path and function name as parameter, not symbol
        public CallStackUnit(long addr, String symbol, LogData log) {
                address = addr;
                functionStartAddress = addr;
@@ -97,7 +98,8 @@ public class CallStackUnit {
        }
 
        private void makeCallstackData() {
-
+               // callstack symbol format : path(functionName
+               // ex. /usr/lib/libpthread.so(pthread_create
                String[] splitPath = originSymbol.split("\\(", 2); //$NON-NLS-1$
                path = splitPath[0];
                if (!path.startsWith("/") && !path.contains(FunctionUsageProfiler.APPLICATION) //$NON-NLS-1$