[Title] ProfileDataMaker class added
authorLee <jy.exe.lee@samsung.com>
Tue, 27 Nov 2012 11:06:04 +0000 (20:06 +0900)
committerLee <jy.exe.lee@samsung.com>
Tue, 27 Nov 2012 11:06:04 +0000 (20:06 +0900)
[Desc.] for divide profiling and ui profiling
[Issue] -

org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/OpenTraceHandler.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/project/Project.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/sql/SqlManager.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/file/FileDataMaker.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/info/callstack/CallStackManager.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/summary/profiling/FunctionUsageProfiler.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/summary/profiling/ProfileDataMaker.java [new file with mode: 0644]
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/summary/profiling/ProfilingData.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/summary/profiling/ProfilingTable.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/userinterface/profiling/UIFunctionProfilingDataChecker.java

index 1d7731e..d93f930 100644 (file)
@@ -59,6 +59,7 @@ import org.tizen.dynamicanalyzer.ui.summary.failed.FailedData;
 import org.tizen.dynamicanalyzer.ui.summary.leaks.LeakData;\r
 import org.tizen.dynamicanalyzer.ui.summary.leaks.LeakDetector;\r
 import org.tizen.dynamicanalyzer.ui.summary.profiling.FunctionUsageProfiler;\r
+import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfileDataMaker;\r
 import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingChildData;\r
 import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingData;\r
 import org.tizen.dynamicanalyzer.ui.toolbar.ToolbarArea;\r
@@ -397,7 +398,7 @@ public class OpenTraceHandler extends AbstractHandler {
                                DBTableManager.TABLE_INDEX_PROFILING_DATA);\r
                String tableName = profilingData.getTableName();\r
                ResultSet rs = SqlManager.selectAllFromTable(tableName);\r
-               FunctionUsageProfiler profiler = FunctionUsageProfiler.getInstance();\r
+               ProfileDataMaker profiler = FunctionUsageProfiler.getInstance().getProfileDataMaker();\r
                if (null == rs || profiler == null) {\r
                        return false;\r
                }\r
@@ -415,7 +416,7 @@ public class OpenTraceHandler extends AbstractHandler {
                                String seq = data.get(ProfilingData.SEQUENCE_INDEX);\r
                                profiler.getProfilingDataMap().put(seq, fupData);\r
                                String symbol = data.get(ProfilingData.KEY_INDEX);\r
-                               profiler.getSymbolSeqHash().put(symbol, seq);\r
+                               FunctionUsageProfiler.getSymbolSeqHash().put(symbol, seq);\r
                        }\r
                        rs.close();\r
                } catch (SQLException e) {\r
@@ -439,7 +440,8 @@ public class OpenTraceHandler extends AbstractHandler {
                ResultSet rs = SqlManager.selectAllFromTable(tableName);\r
                // FunctionUsageProfiler profiler = AnalyzerManager\r
                // .getFunctionUserProfiler();\r
-               FunctionUsageProfiler profiler = FunctionUsageProfiler.getInstance();\r
+               ProfileDataMaker profiler = FunctionUsageProfiler.getInstance()\r
+                               .getProfileDataMaker();\r
                if (null == rs || profiler == null) {\r
                        return false;\r
                }\r
index c44cc4e..0d2dfb7 100755 (executable)
@@ -346,13 +346,12 @@ public class Project {
        }
 
        public void setTotalProfilingSampleCount(int count) {
-               // AnalyzerManager.getFunctionUserProfiler().setTotalSampleCount(count);
-               FunctionUsageProfiler.getInstance().setTotalSampleCount(count);
+               FunctionUsageProfiler.getInstance().getProfileDataMaker()
+                               .setTotalSampleCount(count);
        }
 
        public int getTotalProfilingSampleCount() {
-               return FunctionUsageProfiler.getInstance().getTotalSampleCount();
-               // return
-               // AnalyzerManager.getFunctionUserProfiler().getTotalSampleCount();
+               return FunctionUsageProfiler.getInstance().getProfileDataMaker()
+                               .getTotalSampleCount();
        }
 }
index c30211d..6a03e0f 100755 (executable)
@@ -51,6 +51,7 @@ import org.tizen.dynamicanalyzer.ui.summary.failed.FailedData;
 import org.tizen.dynamicanalyzer.ui.summary.leaks.LeakData;
 import org.tizen.dynamicanalyzer.ui.summary.leaks.LeakDetector;
 import org.tizen.dynamicanalyzer.ui.summary.profiling.FunctionUsageProfiler;
+import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfileDataMaker;
 import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingChildData;
 import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingData;
 import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
@@ -896,9 +897,8 @@ public class SqlManager {
                        unlockDB();
                        return;
                }
-               // FunctionUsageProfiler profiler = AnalyzerManager
-               // .getFunctionUserProfiler();
-               FunctionUsageProfiler profiler = FunctionUsageProfiler.getInstance();
+               ProfileDataMaker profiler = FunctionUsageProfiler.getInstance()
+                               .getProfileDataMaker();
                HashMap<String, ProfilingData> profilingDataMap = profiler
                                .getProfilingDataMap();
                List<ProfilingData> pDataList = new ArrayList<ProfilingData>();
@@ -945,7 +945,8 @@ public class SqlManager {
                }
                // FunctionUsageProfiler profiler = AnalyzerManager
                // .getFunctionUserProfiler();
-               FunctionUsageProfiler profiler = FunctionUsageProfiler.getInstance();
+               ProfileDataMaker profiler = FunctionUsageProfiler.getInstance()
+                               .getProfileDataMaker();
                HashMap<String, ProfilingChildData> profilingDataMap = profiler
                                .getChildListMap();
                List<ProfilingChildData> pDataList = new ArrayList<ProfilingChildData>();
index 3e41bfb..effa96f 100644 (file)
@@ -94,7 +94,6 @@ public class FileDataMaker {
                int size = inputs.size();
                for (int i = 0; i < size; i++) {
                        List<String> input = inputs.get(i);
-       //              System.out.println("file b : "+input);
                        if (AnalyzerUtil.isInternal(input, false)) {
                                continue;
                        }
@@ -256,9 +255,6 @@ public class FileDataMaker {
                                // read / write
                        } else if (fdApiType.equals(LogCenterConstants.FD_API_TYPE_READ)
                                        || fdApiType.equals(LogCenterConstants.FD_API_TYPE_WRITE)) {
-
-                               System.out.print("Read Write " + input + "\n");
-
                                if (printCalledFunctionChart(input) == false) {
                                        continue;
                                }
@@ -292,7 +288,6 @@ public class FileDataMaker {
                                }
                        } else // / Other
                        {
-                               // System.out.print(" Other "+input+"\n");
                                if (printCalledFunctionChart(input) == false) {
                                        continue;
                                }
index 6c59f21..1e80b35 100644 (file)
@@ -39,6 +39,7 @@ import org.tizen.dynamicanalyzer.logparser.LogCenterConstants;
 import org.tizen.dynamicanalyzer.logparser.LogParser;
 import org.tizen.dynamicanalyzer.nl.InformationViewLabels;
 import org.tizen.dynamicanalyzer.ui.summary.profiling.FunctionUsageProfiler;
+import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfileDataMaker;
 
 public class CallStackManager {
        class DuplicateUserCall {
@@ -119,7 +120,7 @@ public class CallStackManager {
                // insert call count
 //             FunctionUsageProfiler profiler = AnalyzerManager
 //                             .getFunctionUserProfiler();
-               FunctionUsageProfiler profiler = FunctionUsageProfiler.getInstance();
+               ProfileDataMaker profiler = FunctionUsageProfiler.getInstance().getProfileDataMaker();
                profiler.makeFupDataForCallTrace(selfCallstackUnit, input);
 
                List<CallStackUnit> userCallstack = getUserCallstack(tid);
index 76470ab..71676ed 100644 (file)
@@ -32,55 +32,11 @@ import java.util.HashMap;
 import java.util.List;
 
 import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
-import org.tizen.dynamicanalyzer.common.AnalyzerPaths;
-import org.tizen.dynamicanalyzer.common.CommonConstants;
 import org.tizen.dynamicanalyzer.communicator.DACommunicator;
-import org.tizen.dynamicanalyzer.logparser.LogCenterConstants;
 import org.tizen.dynamicanalyzer.nl.SummaryLabels;
-import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackManager;
-import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackUnit;
-import org.tizen.dynamicanalyzer.ui.userinterface.UIDataManager;
-import org.tizen.dynamicanalyzer.utils.Formatter;
 
 public class FunctionUsageProfiler implements Runnable {
 
-       class CallstackTree {
-               ProfilingData me;
-               CallstackTree parent;
-               List<CallstackTree> children = null;
-               int childExeTime = 0;
-
-               public CallstackTree(ProfilingData me, CallstackTree parent) {
-                       this.me = me;
-                       this.parent = parent;
-                       children = new ArrayList<FunctionUsageProfiler.CallstackTree>();
-               }
-
-               public void addChild(CallstackTree child) {
-                       children.add(child);
-               }
-
-               public void addChildExeTime(int time) {
-                       childExeTime += time;
-               }
-
-               public int getInclusiveExeTime() {
-                       // int cTime = 0;
-                       // for (int i = 0; i < children.size(); i++) {
-                       // cTime += children.get(i).getThis().getLastExeTime();
-                       // }
-                       return me.getLastElapsedTime() - childExeTime;
-               }
-
-               public ProfilingData getThis() {
-                       return me;
-               }
-
-               public CallstackTree getParent() {
-                       return parent;
-               }
-       }
-
        // 0.01 second = 10 ms
        public static final long SAMPLE_TIME = 10;
        public static final String APPLICATION = SummaryLabels.FUNCTION_USAGE_PROFILER_APPLICATION;
@@ -89,31 +45,24 @@ public class FunctionUsageProfiler implements Runnable {
        public static final String DEPENDENT_LIB_KEY = "profiling_dependent_lib_key";//$NON-NLS-1$
        public static final String UNKNOWN = "";//$NON-NLS-1$
 
-       private int totalSampleCount = 0;
-       private CallstackTree current = null;
        private static FunctionUsageProfiler instance = null;
 
-       /**
-        * key: seq - value : function usage profiling data hash map all function
-        * usage profiling data are in this hash map
-        **/
-       private HashMap<String, ProfilingData> profilingDataMap = null;
-
-       /**
-        * key : seq - value : child seq list // all child lists are in this hash
-        */
-       private HashMap<String, ProfilingChildData> childListMap = null;
+       private ProfileDataMaker profileDataMaker = null;
        /**
         * key: symbol(child) or file path (parent) - value : sequence num of
         * profiling data. all parent and child data is in
         */
-       private HashMap<String, String> symbolSeqHash = null;
+       private static HashMap<String, String> symbolSeqHash = null;
        private List<String> sampleInputs = null;
        private static Thread profiler = null;
 
-       private ProfilingData appBin = null;
-       private ProfilingData dependentLib = null;
-       private String appBinName = null;
+       public FunctionUsageProfiler() {
+               profileDataMaker = new ProfileDataMaker();
+       }
+
+       public ProfileDataMaker getProfileDataMaker() {
+               return profileDataMaker;
+       }
 
        public static FunctionUsageProfiler getInstance() {
                if (null == instance) {
@@ -122,21 +71,7 @@ public class FunctionUsageProfiler implements Runnable {
                return instance;
        }
 
-       public HashMap<String, ProfilingData> getProfilingDataMap() {
-               if (null == profilingDataMap) {
-                       profilingDataMap = new HashMap<String, ProfilingData>();
-               }
-               return profilingDataMap;
-       }
-
-       public HashMap<String, ProfilingChildData> getChildListMap() {
-               if (null == childListMap) {
-                       childListMap = new HashMap<String, ProfilingChildData>();
-               }
-               return childListMap;
-       }
-
-       public HashMap<String, String> getSymbolSeqHash() {
+       public static HashMap<String, String> getSymbolSeqHash() {
                if (null == symbolSeqHash) {
                        symbolSeqHash = new HashMap<String, String>();
                }
@@ -160,337 +95,6 @@ public class FunctionUsageProfiler implements Runnable {
                getSampleInputs().add(sample);
        }
 
-       public String getAppBinName() {
-               return appBinName;
-       }
-
-       public ProfilingData getAppBin() {
-               return appBin;
-       }
-
-       public ProfilingData getDependentLib() {
-               return dependentLib;
-       }
-
-       public void makeFupDataForCallTrace(CallStackUnit inputCallstackApiData,
-                       String[] inputLog) {
-               int exeTime = 0;
-               String strType = inputLog[LogCenterConstants.USER_FUNCTION_TYPE_INDEX];
-               int type = Integer.parseInt(strType);
-               if (type == LogCenterConstants.USER_FUNCTION_EVENT_TYPE_EXIT) {
-                       String strExeTime = inputLog[LogCenterConstants.USER_FUNCTION_ELAPSED_TIME_INDEX];
-                       exeTime += Integer.parseInt(strExeTime);
-               }
-
-               ProfilingData parent = getProfilingDataByKey(inputCallstackApiData
-                               .getPath());
-               if (null == parent) {
-                       parent = makeNewProfilingData(inputCallstackApiData, true);
-                       checkUserCall(inputCallstackApiData, parent, null);
-
-                       ProfilingData child = makeNewProfilingData(inputCallstackApiData,
-                                       false);
-                       parent.addChild(child);
-                       child.addExCount();
-                       child.addElpasedTime(exeTime);
-                       child.setParent(parent.getName());
-
-                       if (type != LogCenterConstants.USER_FUNCTION_EVENT_TYPE_EXIT) {
-                               child.addCallCount();
-                       }
-               } else {
-                       ProfilingData child = getProfilingDataByKey(inputCallstackApiData
-                                       .getSymbol());
-                       if (null == child) {
-                               child = makeNewProfilingData(inputCallstackApiData, false);
-                               parent.addChild(child);
-                               child.setParent(parent.getName());
-                       }
-                       child.addElpasedTime(exeTime);
-                       if (type != LogCenterConstants.USER_FUNCTION_EVENT_TYPE_EXIT) {
-                               child.addCallCount();
-                       }
-
-                       // calculate internal time
-                       if (type == LogCenterConstants.USER_FUNCTION_EVENT_TYPE_EXIT) {
-                               if (null == current) {
-                                       // bug
-                                       System.out
-                                                       .println("bug found!!" + inputCallstackApiData.getFunctionName()); //$NON-NLS-1$
-                               } else {
-                                       CallstackTree parentCt = current.getParent();
-                                       if (null != parentCt) {
-                                               parentCt.addChildExeTime(current.getThis()
-                                                               .getLastElapsedTime());
-                                       }
-                                       child.addExclusiveElapsedTime(current.getInclusiveExeTime());
-                                       current = current.getParent();
-                                       UIDataManager.getInstance()
-                                                       .getfunctionProfilingDataChecker()
-                                                       .addProfilingData(child);
-                               }
-                       } else {
-                               if (null == current) {
-                                       CallstackTree ct = new CallstackTree(child, null);
-                                       current = ct;
-                               } else {
-                                       CallstackTree ct = new CallstackTree(child, current);
-                                       current.addChild(ct);
-                                       current = ct;
-                               }
-                       }
-               }
-       }
-
-       public void makeFunctionUsageProfileData(String sampleLog) {
-               totalSampleCount++;
-               String[] splitSampleLog = sampleLog.split(CommonConstants.NEW_LINE);
-               String[] selfAddrLog = splitSampleLog[0]
-                               .split(AnalyzerConstants.DATA_PARSING_TOKEN);
-               String[] splitCallstack = splitSampleLog[1]
-                               .split(AnalyzerConstants.DATA_PARSING_TOKEN);
-               List<String> sampleCallstack = new ArrayList<String>();
-
-               for (int i = 0; i < splitCallstack.length; i++) {
-                       sampleCallstack.add(new String(splitCallstack[i]));
-               }
-
-               List<Long> addrs = makeCallstackHashAndList(sampleCallstack);
-               HashMap<Long, CallStackUnit> addrMap = CallStackManager.getInstance()
-                               .getCallStackApiByAddrMap();
-               String selfAddrStr = selfAddrLog[0];
-               long selfAddr = Long.parseLong(selfAddrStr);
-               CallStackUnit inputData = addrMap.get(selfAddr);
-               if (null == inputData) {
-                       return;
-               }
-
-               // drop samples of probe library
-               if (inputData.getPath().startsWith(AnalyzerPaths.DA_REMOTE_PROBE_PATH)) {
-                       return;
-               }
-
-               String inputPath = inputData.getPath();
-               String inputFuncName = inputData.getFunctionName();
-
-               ProfilingData parent = getProfilingDataByKey(inputPath);
-               // exclusive cpu time
-               if (null == parent) {
-                       parent = makeNewProfilingData(inputData, true);
-                       checkUserCall(inputData, parent, null);
-                       if (inputFuncName.equals(UNKNOWN)) {
-                               parent.addExCount();
-                       } else {
-                               ProfilingData child = makeNewProfilingData(inputData, false);
-                               parent.addChild(child);
-                               child.addExCount();
-                               child.setParent(parent.getName());
-                       }
-               } else {
-                       if (inputFuncName.isEmpty()) {
-                               parent.addExCount();
-                       } else {
-                               ProfilingData child = getProfilingDataByKey(inputData
-                                               .getSymbol());
-                               if (null == child) {
-                                       child = makeNewProfilingData(inputData, false);
-                                       parent.addChild(child);
-                                       child.setParent(parent.getName());
-                               }
-                               child.addExCount();
-                       }
-               }
-
-               // inclusive cpu time
-               for (int i = 0; i < addrs.size(); i++) {
-                       CallStackUnit callstackCsa = addrMap.get(addrs.get(i));
-                       // disable inclusive cpu time of dependent library
-                       if (!CallStackManager.getInstance().checkUserCall(
-                                       callstackCsa.getPath())) {
-                               continue;
-                       }
-
-                       if (callstackCsa.getFunctionName().equals(UNKNOWN)) {
-                               ProfilingData inParent = getProfilingDataByKey(callstackCsa
-                                               .getPath());
-                               ProfilingData pp = null;
-                               if (null == inParent) {
-                                       inParent = makeNewProfilingData(callstackCsa, true);
-                                       checkUserCall(callstackCsa, inParent, pp);
-                               }
-                               inParent.addInCount(totalSampleCount);
-
-                               if (null != inParent.getParent()) {
-                                       String pInParentName = inParent.getParent();
-                                       pp = getProfilingDataByKey(pInParentName);
-                                       pp.addInCount(totalSampleCount);
-                               }
-                       } else {
-                               ProfilingData fupData = getProfilingDataByKey(callstackCsa
-                                               .getSymbol());
-                               if (null == fupData) {
-                                       ProfilingData inParent = getProfilingDataByKey(callstackCsa
-                                                       .getPath());
-                                       if (null == inParent) {
-                                               inParent = makeNewProfilingData(callstackCsa, true);
-                                               checkUserCall(callstackCsa, inParent, null);
-                                       }
-                                       fupData = makeNewProfilingData(callstackCsa, false);
-                                       fupData.setParent(inParent.getName());
-
-                                       inParent.addChild(fupData);
-                                       inParent.addInCount(totalSampleCount);
-                                       if (null != inParent.getParent()) {
-                                               String pInParentName = inParent.getParent();
-                                               ProfilingData pp = getProfilingDataByKey(pInParentName);
-                                               pp.addInCount(totalSampleCount);
-                                       }
-                               } else {
-                                       String pName = fupData.getParent();
-                                       ProfilingData inParent = getProfilingDataByKey(pName);
-                                       inParent.addInCount(totalSampleCount);
-
-                                       if (null != inParent.getParent()) {
-                                               String pInParentName = inParent.getParent();
-                                               ProfilingData ppData = getProfilingDataByKey(pInParentName);
-                                               ppData.addInCount(totalSampleCount);
-                                       }
-                               }
-                               fupData.addInCount(totalSampleCount);
-                       }
-               }
-       }
-
-       private void checkUserCall(CallStackUnit csa, ProfilingData parent,
-                       ProfilingData pp) {
-               if (CallStackManager.getInstance().checkUserCall(csa.getPath())) {
-                       if (null == appBin) {
-                               CallStackUnit appBinCsa = new CallStackUnit(-1,
-                                               FunctionUsageProfiler.APPLICATION);
-                               appBin = makeNewProfilingData(appBinCsa, true);
-                               appBin.setKey(APPLICATION_KEY);
-                               appBinName = csa.getPath();
-                       }
-                       parent.setParent(appBin.getName());
-                       appBin.addChild(parent);
-                       if (null != pp) {
-                               pp = appBin;
-                       }
-               } else {
-                       if (null == dependentLib) {
-                               CallStackUnit dependentLibBinCsa = new CallStackUnit(-2,
-                                               FunctionUsageProfiler.DEPENDENT_LIB);
-                               dependentLib = makeNewProfilingData(dependentLibBinCsa, true);
-                               dependentLib.setKey(DEPENDENT_LIB_KEY);
-                       }
-                       parent.setParent(dependentLib.getName());
-                       dependentLib.addChild(parent);
-                       if (null != pp) {
-                               pp = dependentLib;
-                       }
-               }
-       }
-
-       private List<Long> makeCallstackHashAndList(List<String> callstackLog) {
-               HashMap<Long, CallStackUnit> addrMap = CallStackManager.getInstance()
-                               .getCallStackApiByAddrMap();
-               List<Long> addrs = new ArrayList<Long>();
-               int size = callstackLog.size();
-               for (int i = 1; i + 1 < size; i += 2) {
-                       if (callstackLog.get(i).equals(AnalyzerConstants.CALLSTACK_END)
-                                       || callstackLog.get(i + 1).equals(
-                                                       AnalyzerConstants.CALLSTACK_END)) {
-                               break;
-                       }
-                       String addrStr = callstackLog.get(i);
-                       if (addrStr.isEmpty()) {
-                               return null;
-                       }
-                       long addr = 0;
-                       try {
-                               addr = Long.parseLong(addrStr);
-                       } catch (NumberFormatException e) {
-                               e.printStackTrace();
-                       }
-                       addrs.add(addr);
-
-                       CallStackUnit funcName = addrMap.get(addr);
-                       if (null == funcName) {
-                               String funcSymbol = callstackLog.get(i + 1);
-                               CallStackUnit cas = new CallStackUnit(addr, funcSymbol);
-                               if (null == addrMap.get(addr)) {
-                                       addrMap.put(addr, cas);
-                               }
-                       }
-               }
-               return addrs;
-       }
-
-       public String getCpuRate(ProfilingData data, boolean exclusive) {
-               int count = 0;
-               double rate = 0.;
-               if (exclusive) {
-                       count = data.getExCount();
-                       rate = count / (double) totalSampleCount * 100;
-               } else {
-                       count = data.getInCount();
-                       rate = count / (double) totalSampleCount * 100;
-               }
-
-               return Formatter.toDoubleFormat2(Double.toString(rate));
-       }
-
-       public String getCpuTime(ProfilingData data, boolean exclusive) {
-               int count = 0;
-               if (exclusive) {
-                       count = data.getExCount();
-               } else {
-                       count = data.getInCount();
-               }
-
-               return Long.toString(count * SAMPLE_TIME);
-       }
-
-       public ProfilingData getProfilingDataByKey(String key) {
-               String seq = getSymbolSeqHash().get(key);
-               if (null == seq) {
-                       return null;
-               }
-
-               return getProfilingDataMap().get(seq);
-       }
-
-       private ProfilingData makeNewProfilingData(CallStackUnit inputData,
-                       boolean isParent) {
-               ProfilingData newProfilingData = new ProfilingData(inputData, isParent);
-               getProfilingDataMap().put(newProfilingData.getSequence(),
-                               newProfilingData);
-               if (isParent) {
-                       getSymbolSeqHash().put(inputData.getPath(),
-                                       newProfilingData.getSequence());
-               } else {
-                       getSymbolSeqHash().put(inputData.getSymbol(),
-                                       newProfilingData.getSequence());
-               }
-               return newProfilingData;
-       }
-
-       public void setAppBin(ProfilingData appBin) {
-               this.appBin = appBin;
-       }
-
-       public void setDependentLib(ProfilingData dependentLib) {
-               this.dependentLib = dependentLib;
-       }
-
-       public void setTotalSampleCount(int count) {
-               totalSampleCount = count;
-       }
-
-       public int getTotalSampleCount() {
-               return totalSampleCount;
-       }
-
        public static void startProfiler() {
                if (null == profiler || !profiler.isAlive()) {
                        profiler = new Thread(null, getInstance(),
@@ -513,7 +117,8 @@ public class FunctionUsageProfiler implements Runnable {
                        try {
                                if (!getInstance().getSampleInputs().isEmpty()) {
                                        String sample = getInstance().getFirstSample();
-                                       getInstance().makeFunctionUsageProfileData(sample);
+                                       getInstance().getProfileDataMaker()
+                                                       .makeFunctionUsageProfileData(sample);
                                } else if (DACommunicator.isRunning()) {
                                        Thread.sleep(AnalyzerConstants.LOG_CHECK_INTERVAL);
                                } else {
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/summary/profiling/ProfileDataMaker.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/summary/profiling/ProfileDataMaker.java
new file mode 100644 (file)
index 0000000..907a2ea
--- /dev/null
@@ -0,0 +1,414 @@
+package org.tizen.dynamicanalyzer.ui.summary.profiling;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
+import org.tizen.dynamicanalyzer.common.AnalyzerPaths;
+import org.tizen.dynamicanalyzer.common.CommonConstants;
+import org.tizen.dynamicanalyzer.logparser.LogCenterConstants;
+import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackManager;
+import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackUnit;
+import org.tizen.dynamicanalyzer.ui.userinterface.UIDataManager;
+import org.tizen.dynamicanalyzer.utils.Formatter;
+
+public class ProfileDataMaker {
+
+       class CallstackTree {
+               ProfilingData me;
+               CallstackTree parent;
+               List<CallstackTree> children = null;
+               int childExeTime = 0;
+
+               public CallstackTree(ProfilingData me, CallstackTree parent) {
+                       this.me = me;
+                       this.parent = parent;
+                       children = new ArrayList<ProfileDataMaker.CallstackTree>();
+               }
+
+               public void addChild(CallstackTree child) {
+                       children.add(child);
+               }
+
+               public void addChildExeTime(int time) {
+                       childExeTime += time;
+               }
+
+               public int getInclusiveExeTime() {
+                       return me.getLastElapsedTime() - childExeTime;
+               }
+
+               public ProfilingData getThis() {
+                       return me;
+               }
+
+               public CallstackTree getParent() {
+                       return parent;
+               }
+       }
+
+       private CallstackTree current = null;
+       private int totalSampleCount = 0;
+
+       /**
+        * key: seq - value : function usage profiling data hash map all function
+        * usage profiling data are in this hash map
+        **/
+       private HashMap<String, ProfilingData> profilingDataMap = null;
+
+       /**
+        * key : seq - value : child seq list // all child lists are in this hash
+        */
+       private HashMap<String, ProfilingChildData> childListMap = null;
+
+       private ProfilingData appBin = null;
+       private ProfilingData dependentLib = null;
+       private String appBinName = null;
+
+       public String getAppBinName() {
+               return appBinName;
+       }
+
+       public ProfilingData getAppBin() {
+               return appBin;
+       }
+
+       public ProfilingData getDependentLib() {
+               return dependentLib;
+       }
+
+       public void setAppBin(ProfilingData appBin) {
+               this.appBin = appBin;
+       }
+
+       public void setDependentLib(ProfilingData dependentLib) {
+               this.dependentLib = dependentLib;
+       }
+
+       public void setTotalSampleCount(int count) {
+               totalSampleCount = count;
+       }
+
+       public int getTotalSampleCount() {
+               return totalSampleCount;
+       }
+
+       public ProfilingData getProfilingDataByKey(String key) {
+               String seq = FunctionUsageProfiler.getSymbolSeqHash().get(key);
+               if (null == seq) {
+                       return null;
+               }
+
+               return getProfilingDataMap().get(seq);
+       }
+
+       public HashMap<String, ProfilingData> getProfilingDataMap() {
+               if (null == profilingDataMap) {
+                       profilingDataMap = new HashMap<String, ProfilingData>();
+               }
+               return profilingDataMap;
+       }
+
+       public HashMap<String, ProfilingChildData> getChildListMap() {
+               if (null == childListMap) {
+                       childListMap = new HashMap<String, ProfilingChildData>();
+               }
+               return childListMap;
+       }
+
+       public String getCpuRate(ProfilingData data, boolean exclusive) {
+               int count = 0;
+               double rate = 0.;
+               if (exclusive) {
+                       count = data.getExCount();
+                       rate = count / (double) totalSampleCount * 100;
+               } else {
+                       count = data.getInCount();
+                       rate = count / (double) totalSampleCount * 100;
+               }
+
+               return Formatter.toDoubleFormat2(Double.toString(rate));
+       }
+
+       public String getCpuTime(ProfilingData data, boolean exclusive) {
+               int count = 0;
+               if (exclusive) {
+                       count = data.getExCount();
+               } else {
+                       count = data.getInCount();
+               }
+
+               return Long.toString(count * FunctionUsageProfiler.SAMPLE_TIME);
+       }
+
+       private void checkUserCall(CallStackUnit csa, ProfilingData parent,
+                       ProfilingData pp) {
+               if (CallStackManager.getInstance().checkUserCall(csa.getPath())) {
+                       if (null == appBin) {
+                               CallStackUnit appBinCsa = new CallStackUnit(-1,
+                                               FunctionUsageProfiler.APPLICATION);
+                               appBin = makeNewProfilingData(appBinCsa, true);
+                               appBin.setKey(FunctionUsageProfiler.APPLICATION_KEY);
+                               appBinName = csa.getPath();
+                       }
+                       parent.setParent(appBin.getName());
+                       appBin.addChild(parent);
+                       if (null != pp) {
+                               pp = appBin;
+                       }
+               } else {
+                       if (null == dependentLib) {
+                               CallStackUnit dependentLibBinCsa = new CallStackUnit(-2,
+                                               FunctionUsageProfiler.DEPENDENT_LIB);
+                               dependentLib = makeNewProfilingData(dependentLibBinCsa, true);
+                               dependentLib.setKey(FunctionUsageProfiler.DEPENDENT_LIB_KEY);
+                       }
+                       parent.setParent(dependentLib.getName());
+                       dependentLib.addChild(parent);
+                       if (null != pp) {
+                               pp = dependentLib;
+                       }
+               }
+       }
+
+       public void makeFunctionUsageProfileData(String sampleLog) {
+               totalSampleCount++;
+               String[] splitSampleLog = sampleLog.split(CommonConstants.NEW_LINE);
+               String[] selfAddrLog = splitSampleLog[0]
+                               .split(AnalyzerConstants.DATA_PARSING_TOKEN);
+               String[] splitCallstack = splitSampleLog[1]
+                               .split(AnalyzerConstants.DATA_PARSING_TOKEN);
+               List<String> sampleCallstack = new ArrayList<String>();
+
+               for (int i = 0; i < splitCallstack.length; i++) {
+                       sampleCallstack.add(new String(splitCallstack[i]));
+               }
+
+               List<Long> addrs = makeCallstackHashAndList(sampleCallstack);
+               HashMap<Long, CallStackUnit> addrMap = CallStackManager.getInstance()
+                               .getCallStackApiByAddrMap();
+               String selfAddrStr = selfAddrLog[0];
+               long selfAddr = Long.parseLong(selfAddrStr);
+               CallStackUnit inputData = addrMap.get(selfAddr);
+               if (null == inputData) {
+                       return;
+               }
+
+               // drop samples of probe library
+               if (inputData.getPath().startsWith(AnalyzerPaths.DA_REMOTE_PROBE_PATH)) {
+                       return;
+               }
+
+               String inputPath = inputData.getPath();
+               String inputFuncName = inputData.getFunctionName();
+
+               ProfilingData parent = getProfilingDataByKey(inputPath);
+               // exclusive cpu time
+               if (null == parent) {
+                       parent = makeNewProfilingData(inputData, true);
+                       checkUserCall(inputData, parent, null);
+                       if (inputFuncName.equals(FunctionUsageProfiler.UNKNOWN)) {
+                               parent.addExCount();
+                       } else {
+                               ProfilingData child = makeNewProfilingData(inputData, false);
+                               parent.addChild(child);
+                               child.addExCount();
+                               child.setParent(parent.getName());
+                       }
+               } else {
+                       if (inputFuncName.isEmpty()) {
+                               parent.addExCount();
+                       } else {
+                               ProfilingData child = getProfilingDataByKey(inputData
+                                               .getSymbol());
+                               if (null == child) {
+                                       child = makeNewProfilingData(inputData, false);
+                                       parent.addChild(child);
+                                       child.setParent(parent.getName());
+                               }
+                               child.addExCount();
+                       }
+               }
+
+               // inclusive cpu time
+               for (int i = 0; i < addrs.size(); i++) {
+                       CallStackUnit callstackCsa = addrMap.get(addrs.get(i));
+                       // disable inclusive cpu time of dependent library
+                       if (!CallStackManager.getInstance().checkUserCall(
+                                       callstackCsa.getPath())) {
+                               continue;
+                       }
+
+                       if (callstackCsa.getFunctionName().equals(
+                                       FunctionUsageProfiler.UNKNOWN)) {
+                               ProfilingData inParent = getProfilingDataByKey(callstackCsa
+                                               .getPath());
+                               ProfilingData pp = null;
+                               if (null == inParent) {
+                                       inParent = makeNewProfilingData(callstackCsa, true);
+                                       checkUserCall(callstackCsa, inParent, pp);
+                               }
+                               inParent.addInCount(totalSampleCount);
+
+                               if (null != inParent.getParent()) {
+                                       String pInParentName = inParent.getParent();
+                                       pp = getProfilingDataByKey(pInParentName);
+                                       pp.addInCount(totalSampleCount);
+                               }
+                       } else {
+                               ProfilingData fupData = getProfilingDataByKey(callstackCsa
+                                               .getSymbol());
+                               if (null == fupData) {
+                                       ProfilingData inParent = getProfilingDataByKey(callstackCsa
+                                                       .getPath());
+                                       if (null == inParent) {
+                                               inParent = makeNewProfilingData(callstackCsa, true);
+                                               checkUserCall(callstackCsa, inParent, null);
+                                       }
+                                       fupData = makeNewProfilingData(callstackCsa, false);
+                                       fupData.setParent(inParent.getName());
+
+                                       inParent.addChild(fupData);
+                                       inParent.addInCount(totalSampleCount);
+                                       if (null != inParent.getParent()) {
+                                               String pInParentName = inParent.getParent();
+                                               ProfilingData pp = getProfilingDataByKey(pInParentName);
+                                               pp.addInCount(totalSampleCount);
+                                       }
+                               } else {
+                                       String pName = fupData.getParent();
+                                       ProfilingData inParent = getProfilingDataByKey(pName);
+                                       inParent.addInCount(totalSampleCount);
+
+                                       if (null != inParent.getParent()) {
+                                               String pInParentName = inParent.getParent();
+                                               ProfilingData ppData = getProfilingDataByKey(pInParentName);
+                                               ppData.addInCount(totalSampleCount);
+                                       }
+                               }
+                               fupData.addInCount(totalSampleCount);
+                       }
+               }
+       }
+
+       private List<Long> makeCallstackHashAndList(List<String> callstackLog) {
+               HashMap<Long, CallStackUnit> addrMap = CallStackManager.getInstance()
+                               .getCallStackApiByAddrMap();
+               List<Long> addrs = new ArrayList<Long>();
+               int size = callstackLog.size();
+               for (int i = 1; i + 1 < size; i += 2) {
+                       if (callstackLog.get(i).equals(AnalyzerConstants.CALLSTACK_END)
+                                       || callstackLog.get(i + 1).equals(
+                                                       AnalyzerConstants.CALLSTACK_END)) {
+                               break;
+                       }
+                       String addrStr = callstackLog.get(i);
+                       if (addrStr.isEmpty()) {
+                               return null;
+                       }
+                       long addr = 0;
+                       try {
+                               addr = Long.parseLong(addrStr);
+                       } catch (NumberFormatException e) {
+                               e.printStackTrace();
+                       }
+                       addrs.add(addr);
+
+                       CallStackUnit funcName = addrMap.get(addr);
+                       if (null == funcName) {
+                               String funcSymbol = callstackLog.get(i + 1);
+                               CallStackUnit cas = new CallStackUnit(addr, funcSymbol);
+                               if (null == addrMap.get(addr)) {
+                                       addrMap.put(addr, cas);
+                               }
+                       }
+               }
+               return addrs;
+       }
+
+       private ProfilingData makeNewProfilingData(CallStackUnit inputData,
+                       boolean isParent) {
+               ProfilingData newProfilingData = new ProfilingData(inputData, isParent);
+               getProfilingDataMap().put(newProfilingData.getSequence(),
+                               newProfilingData);
+               if (isParent) {
+                       FunctionUsageProfiler.getSymbolSeqHash().put(inputData.getPath(),
+                                       newProfilingData.getSequence());
+               } else {
+                       FunctionUsageProfiler.getSymbolSeqHash().put(inputData.getSymbol(),
+                                       newProfilingData.getSequence());
+               }
+               return newProfilingData;
+       }
+
+       public void makeFupDataForCallTrace(CallStackUnit inputCallstackApiData,
+                       String[] inputLog) {
+               int exeTime = 0;
+               String strType = inputLog[LogCenterConstants.USER_FUNCTION_TYPE_INDEX];
+               int type = Integer.parseInt(strType);
+               if (type == LogCenterConstants.USER_FUNCTION_EVENT_TYPE_EXIT) {
+                       String strExeTime = inputLog[LogCenterConstants.USER_FUNCTION_ELAPSED_TIME_INDEX];
+                       exeTime += Integer.parseInt(strExeTime);
+               }
+
+               ProfilingData parent = getProfilingDataByKey(inputCallstackApiData
+                               .getPath());
+               if (null == parent) {
+                       parent = makeNewProfilingData(inputCallstackApiData, true);
+                       checkUserCall(inputCallstackApiData, parent, null);
+
+                       ProfilingData child = makeNewProfilingData(inputCallstackApiData,
+                                       false);
+                       parent.addChild(child);
+                       child.addExCount();
+                       child.addElpasedTime(exeTime);
+                       child.setParent(parent.getName());
+
+                       if (type != LogCenterConstants.USER_FUNCTION_EVENT_TYPE_EXIT) {
+                               child.addCallCount();
+                       }
+               } else {
+                       ProfilingData child = getProfilingDataByKey(inputCallstackApiData
+                                       .getSymbol());
+                       if (null == child) {
+                               child = makeNewProfilingData(inputCallstackApiData, false);
+                               parent.addChild(child);
+                               child.setParent(parent.getName());
+                       }
+                       child.addElpasedTime(exeTime);
+                       if (type != LogCenterConstants.USER_FUNCTION_EVENT_TYPE_EXIT) {
+                               child.addCallCount();
+                       }
+
+                       // calculate internal time
+                       if (type == LogCenterConstants.USER_FUNCTION_EVENT_TYPE_EXIT) {
+                               if (null == current) {
+                                       // bug
+                                       System.out
+                                                       .println("bug found!!" + inputCallstackApiData.getFunctionName()); //$NON-NLS-1$
+                               } else {
+                                       CallstackTree parentCt = current.getParent();
+                                       if (null != parentCt) {
+                                               parentCt.addChildExeTime(current.getThis()
+                                                               .getLastElapsedTime());
+                                       }
+                                       child.addExclusiveElapsedTime(current.getInclusiveExeTime());
+                                       current = current.getParent();
+                                       UIDataManager.getInstance()
+                                                       .getfunctionProfilingDataChecker()
+                                                       .addProfilingData(child);
+                               }
+                       } else {
+                               if (null == current) {
+                                       CallstackTree ct = new CallstackTree(child, null);
+                                       current = ct;
+                               } else {
+                                       CallstackTree ct = new CallstackTree(child, current);
+                                       current.addChild(ct);
+                                       current = ct;
+                               }
+                       }
+               }
+       }
+}
index 2d27ee0..2b7301e 100644 (file)
@@ -74,7 +74,7 @@ public class ProfilingData {
                        children = new ProfilingChildData(Integer.toString(seq));
                        // AnalyzerManager.getFunctionUserProfiler().getChildListMap()
                        // .put(Integer.toString(seq), children);
-                       FunctionUsageProfiler.getInstance().getChildListMap()
+                       FunctionUsageProfiler.getInstance().getProfileDataMaker().getChildListMap()
                                        .put(Integer.toString(seq), children);
                }
                return children;
@@ -155,9 +155,7 @@ public class ProfilingData {
                        return exCount;
                }
 
-               // FunctionUsageProfiler profiler = AnalyzerManager
-               // .getFunctionUserProfiler();
-               FunctionUsageProfiler profiler = FunctionUsageProfiler.getInstance();
+               ProfileDataMaker profiler = FunctionUsageProfiler.getInstance().getProfileDataMaker();
                int size = seqs.size();
                int count = 0;
                for (int i = 0; i < size; i++) {
@@ -238,14 +236,12 @@ public class ProfilingData {
        }
 
        public List<ProfilingData> getChildList() {
-               // FunctionUsageProfiler profiler = AnalyzerManager
-               // .getFunctionUserProfiler();
                FunctionUsageProfiler profiler = FunctionUsageProfiler.getInstance();
                List<ProfilingData> output = new ArrayList<ProfilingData>();
                List<String> seqs = getChildData().getChildren();
 
                for (int i = 0; i < seqs.size(); i++) {
-                       ProfilingData child = profiler.getProfilingDataMap().get(
+                       ProfilingData child = profiler.getProfileDataMaker().getProfilingDataMap().get(
                                        seqs.get(i));
                        if (null != child) {
                                output.add(child);
index 4418583..1817a24 100644 (file)
@@ -198,9 +198,8 @@ public class ProfilingTable extends DATreeComposite {
                }
 
                tableData.setObject(input.getName());
-               FunctionUsageProfiler profiler = FunctionUsageProfiler.getInstance();
-               // FunctionUsageProfiler profiler = AnalyzerManager
-               // .getFunctionUserProfiler();
+               ProfileDataMaker profiler = FunctionUsageProfiler.getInstance()
+                               .getProfileDataMaker();
                String exTime = "0", exRate = "0.00", inTime = "0", inRate = "0.00", callCount = "0", exeTime = "0", inExeTime = "0"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
 
                try {
@@ -276,9 +275,7 @@ public class ProfilingTable extends DATreeComposite {
        @Override
        public List<TreeInput> makeTreeInput() {
                List<TreeInput> output = new ArrayList<TreeInput>();
-               // FunctionUsageProfiler profiler = AnalyzerManager
-               // .getFunctionUserProfiler();
-               FunctionUsageProfiler profiler = FunctionUsageProfiler.getInstance();
+               ProfileDataMaker profiler = FunctionUsageProfiler.getInstance().getProfileDataMaker();
                ProfilingData appBin = profiler.getAppBin();
                if (null != appBin) {
                        TreeInput appBinInput = makeInput(appBin,
index b5f3100..48e3b1a 100644 (file)
@@ -38,6 +38,7 @@ import java.util.TreeSet;
 import org.tizen.dynamicanalyzer.common.AnalyzerPaths;
 import org.tizen.dynamicanalyzer.nl.AnalyzerLabels;
 import org.tizen.dynamicanalyzer.ui.summary.profiling.FunctionUsageProfiler;
+import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfileDataMaker;
 import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingData;
 import org.tizen.dynamicanalyzer.ui.userinterface.UIDataManager;
 import org.tizen.dynamicanalyzer.utils.Formatter;
@@ -52,7 +53,6 @@ public class UIFunctionProfilingDataChecker {
                if (userInterfaceFunctionTree.size() == 0) {
                        return;
                }
-//             System.out.println("input.getName() : " + input.getName());
                boolean bTreeSearch = userInterfaceFunctionTree
                                .contains(makeTreeSetData(input.getName()));
                if (bTreeSearch) { // Find Same Api name
@@ -63,7 +63,6 @@ public class UIFunctionProfilingDataChecker {
 
                        int nListSize = getDataList().size();
                        for (int i = 0; i < nListSize; i++) {
-                               
                                if (getDataList().get(i).getSequence()
                                                .equals(input.getSequence())) {
                                        getDataList().remove(i);
@@ -71,7 +70,14 @@ public class UIFunctionProfilingDataChecker {
                                        bUpdateData = true;
                                        break;
                                }
-                               if (getDataList().get(i).getAPIName().equals(input.getParent())) {                                                                                                                      
+                       }
+
+                       nListSize = getDataList().size();
+                       for (int i = 0; i < nListSize; i++) {
+                               if (getDataList().get(i).getAPIName().equals(input.getParent())) { // Check,
+                                                                                                                                                                       // Exist
+                                                                                                                                                                       // Parent
+                                                                                                                                                                       // Node
                                        bExistParentData = true;
                                        break;
                                }
@@ -81,8 +87,8 @@ public class UIFunctionProfilingDataChecker {
                        }
 
                        UIFunctionProfilingData pd = new UIFunctionProfilingData();
-                       FunctionUsageProfiler profiler = FunctionUsageProfiler
-                                       .getInstance();
+                       ProfileDataMaker profiler = FunctionUsageProfiler.getInstance()
+                                       .getProfileDataMaker();
                        String exTime = "-", inTime = "-", exeTime = "-", inExeTime = "-", exAvgTime = "-", inAvgTime = "-", exeAvgTime = "-", inExeAvgTime = "-"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
                        try {
                                exTime = profiler.getCpuTime(input, true);