CALLSTACK : bug fix - callstack of calltrace item is not shown in runtime 27/25727/1
authorwoojin <woojin2.jung@samsung.com>
Sat, 9 Aug 2014 18:21:35 +0000 (03:21 +0900)
committerwoojin <woojin2.jung@samsung.com>
Sat, 9 Aug 2014 18:21:35 +0000 (03:21 +0900)
If callstackdata is removed from memory before insertion to DB is finished, then the callstackdata is not found.
So, maintain certain amount of callstackdata in memory so that callstackdata is available by either memory or DB at all time.

Change-Id: I922ed54852687bec6c60ff770b3196e6d637126c
Signed-off-by: woojin <woojin2.jung@samsung.com>
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/summary/profiling/FunctionUsageProfiler.java

index 94c69c2..a394106 100644 (file)
@@ -46,6 +46,7 @@ import org.tizen.dynamicanalyzer.swap.logparser.Logs;
 import org.tizen.dynamicanalyzer.swap.logparser.PageDataManager;
 import org.tizen.dynamicanalyzer.swap.model.data.LogData;
 import org.tizen.dynamicanalyzer.swap.model.data.ProfileData;
+import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackData;
 import org.tizen.dynamicanalyzer.ui.toolbar.configuration.ConfigurationDialogDataManager;
 
 public class FunctionUsageProfiler extends PageDataManager {
@@ -56,6 +57,7 @@ public class FunctionUsageProfiler extends PageDataManager {
        public static final String APPLICATION_KEY = "profiling_app_bin_key";//$NON-NLS-1$
        public static final String DEPENDENT_LIB_KEY = "profiling_dependent_lib_key";//$NON-NLS-1$
        public static final String UNKNOWN = CommonConstants.EMPTY;
+       public static final int CALLSTACKDATA_MAX = 5000;
 
        private static FunctionUsageProfiler instance = null;
        private boolean isSetSamplePeriod = false;
@@ -246,26 +248,28 @@ public class FunctionUsageProfiler extends PageDataManager {
                                        getInstance().getProfileDataMakerByPid(
                                                        sample.get(i).getPid())
                                                        .makeFunctionUsageProfileData(sampleLog);
-                                       // remove unnecessary callstackdata from memory
-                                       NavigableMap<Long, Integer> seqByTimeMap = 
-                                                       AnalyzerManager.getCallstackManager()
-                                                       .getSeqTimeByTidMap(sampleLog.getTid());
-                                       // find the time of callstackdata which was made 
-                                       // right before the current sample time
-                                       // callstackdatas made before that time is needless                                             
-                                       Long lastTime = seqByTimeMap
-                                                       .floorKey(sampleLog.getTime());
-                                       if (null != lastTime) {
-                                               SortedMap<Long, Integer> headMap = 
-                                                               seqByTimeMap.headMap(lastTime);
-                                               Iterator<Map.Entry<Long, Integer>> itr = headMap
-                                                               .entrySet().iterator();
-                                               while (itr.hasNext()) {
-                                                       Map.Entry<Long, Integer> entry = itr.next();
-                                                       AnalyzerManager.getCallstackManager()
-                                                               .getCallStackDataBySeqMap()
-                                                               .remove(entry.getValue());
-                                                       itr.remove();
+                                       Map<Integer, CallStackData> callstackDataMap = AnalyzerManager.getCallstackManager()
+                                                       .getCallStackDataBySeqMap();
+                                       if (callstackDataMap.size() > CALLSTACKDATA_MAX) {
+                                               // remove unnecessary callstackdata from memory
+                                               NavigableMap<Long, Integer> seqByTimeMap = 
+                                                               AnalyzerManager.getCallstackManager()
+                                                               .getSeqTimeByTidMap(sampleLog.getTid());
+                                               // find the time of callstackdata which was made 
+                                               // right before the current sample time
+                                               // callstackdatas made before that time is needless                                             
+                                               Long lastTime = seqByTimeMap
+                                                               .floorKey(sampleLog.getTime());
+                                               if (null != lastTime) {
+                                                       SortedMap<Long, Integer> headMap = 
+                                                                       seqByTimeMap.headMap(lastTime);
+                                                       Iterator<Map.Entry<Long, Integer>> itr = headMap
+                                                                       .entrySet().iterator();
+                                                       while (itr.hasNext()) {
+                                                               Map.Entry<Long, Integer> entry = itr.next();
+                                                               callstackDataMap.remove(entry.getValue());
+                                                               itr.remove();
+                                                       }
                                                }
                                        }
                                        // save to DB
@@ -287,8 +291,12 @@ public class FunctionUsageProfiler extends PageDataManager {
                                }
                        }
                } else { // sampling is off, callstackdata is not needed in memory
-                       AnalyzerManager.getCallstackManager()
-                               .getCallStackDataBySeqMap().clear();
+                       // need to maintain callstackdata until insertion to DB is finished
+                       Map<Integer, CallStackData> callstackDataMap = AnalyzerManager.getCallstackManager()
+                                       .getCallStackDataBySeqMap();
+                       if (callstackDataMap.size() > CALLSTACKDATA_MAX) {
+                               callstackDataMap.clear();
+                       }
                }
        }
 }