From 550a225e29957992acb6e570eca985f960e6264b Mon Sep 17 00:00:00 2001 From: woojin Date: Sat, 9 Aug 2014 09:18:27 +0900 Subject: [PATCH] INTERNAL : get actual path of application 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 --- .../dynamicanalyzer/common/path/PathConstants.java | 1 + .../common/AnalyzerShellCommands.java | 1 + .../dynamicanalyzer/common/SymbolManager.java | 5 +- .../dynamicanalyzer/handlers/OpenTraceHandler.java | 26 +++------- .../org/tizen/dynamicanalyzer/project/AppInfo.java | 58 ++++++++++++++++------ .../dynamicanalyzer/project/DeviceStatusInfo.java | 1 + .../project/FunctionNameManager.java | 5 +- .../swap/callstack/SWAPCallStackManager.java | 2 +- .../swap/logparser/SWAPLogParser.java | 2 +- .../ui/info/callstack/CallStackUnit.java | 4 +- 10 files changed, 65 insertions(+), 40 deletions(-) diff --git a/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/common/path/PathConstants.java b/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/common/path/PathConstants.java index 4739702..ed88872 100644 --- a/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/common/path/PathConstants.java +++ b/org.tizen.dynamicanalyzer.workbench/src/org/tizen/dynamicanalyzer/common/path/PathConstants.java @@ -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 diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerShellCommands.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerShellCommands.java index 770f942..b7571f8 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerShellCommands.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/AnalyzerShellCommands.java @@ -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$ diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/SymbolManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/SymbolManager.java index 66e048a..2b5c899 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/SymbolManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/common/SymbolManager.java @@ -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; diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/OpenTraceHandler.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/OpenTraceHandler.java index d9dad86..8b7d6e8 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/OpenTraceHandler.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/OpenTraceHandler.java @@ -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() diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java index 267d371..76814d6 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/AppInfo.java @@ -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 localPackagePath = null; private Map runningProcesses = null; - + private String execPath = null; + + private static List readlinkResult = new ArrayList(); private List properties = new ArrayList(); // 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() { diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/DeviceStatusInfo.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/DeviceStatusInfo.java index 3221270..9fe2942 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/DeviceStatusInfo.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/DeviceStatusInfo.java @@ -64,6 +64,7 @@ public class DeviceStatusInfo { private List binaryInfoArray = new ArrayList(); public DeviceStatusInfo(List functionList) { + // TODO: add first, then add apiMap list this.functionList = functionList; } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/FunctionNameManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/FunctionNameManager.java index f9e969e..af08719 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/FunctionNameManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/FunctionNameManager.java @@ -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(); } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/callstack/SWAPCallStackManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/callstack/SWAPCallStackManager.java index 4a9a8d5..f08f8f6 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/callstack/SWAPCallStackManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/callstack/SWAPCallStackManager.java @@ -290,7 +290,7 @@ public class SWAPCallStackManager extends BaseCallstackManager { .getInstance().getTargetBinInfoMap(); List binPaths = new ArrayList(); binPaths.addAll(binInfoMap.keySet()); - + // TODO: performance improvement int size = binPaths.size(); for (int i = 0; i < size; i++) { String binPath = binPaths.get(i); diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/SWAPLogParser.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/SWAPLogParser.java index bd52c02..f730493 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/SWAPLogParser.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/SWAPLogParser.java @@ -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 : check with apiId if (apiId == -1 || apiName.equals("")) { continue; } else { diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/info/callstack/CallStackUnit.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/info/callstack/CallStackUnit.java index 01d3807..42c43fd 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/info/callstack/CallStackUnit.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/info/callstack/CallStackUnit.java @@ -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$ -- 2.7.4