import org.tizen.dynamicanalyzer.annotation.FutureUse;
import org.tizen.dynamicanalyzer.annotation.UIMethod;
-import org.tizen.dynamicanalyzer.project.Project;
-import org.tizen.dynamicanalyzer.swap.callstack.BaseCallstackManager;
-import org.tizen.dynamicanalyzer.swap.callstack.SWAPCallStackManager;
+import org.tizen.dynamicanalyzer.swap.callstack.RuntimeCallstackManager;
import org.tizen.dynamicanalyzer.ui.opengl.data.type.GLSelectionData;
import org.tizen.dynamicanalyzer.ui.page.BaseView;
import org.tizen.dynamicanalyzer.ui.range.RangeDataManager;
import org.tizen.dynamicanalyzer.ui.summary.leaks.NewLeakDetector;
import org.tizen.dynamicanalyzer.ui.summary.profiling.FunctionUsageProfiler;
-import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingData;
import org.tizen.dynamicanalyzer.ui.summary.warning.WarningChecker;
import org.tizen.dynamicanalyzer.util.WorkbenchUtil;
import org.tizen.dynamicanalyzer.widgets.da.view.DABaseComposite;
private static NewLeakDetector newLeakDetector = new NewLeakDetector();
private static WarningChecker warningChecker = new WarningChecker();
- private static SWAPCallStackManager swapCallstackManager = new SWAPCallStackManager(false);
+ private static RuntimeCallstackManager runtimeCallstackManager = new RuntimeCallstackManager();
public static boolean isPlatformSDK() {
return isPlatformSDK;
return warningChecker;
}
- public static BaseCallstackManager getCallstackManager() {
- Project curProject = Global.getProject();
- if (curProject != null) {
- // TODO : protocol version definition
- String pver = curProject.getProtocolVersion();
- if (pver.startsWith("3.")) {
- return swapCallstackManager;
- }
- }
-
- return swapCallstackManager;
+ public static RuntimeCallstackManager getRuntimeCallstackManager() {
+ return runtimeCallstackManager;
}
public static void clear() {
newLeakDetector.clear();
warningChecker.clear();
- swapCallstackManager.clear();
+ runtimeCallstackManager.clear();
// UserFunctionManager.getInstance().clear();
FunctionUsageProfiler.getInstance().stopNormal();
- ProfilingData.clear(); // reset internal sequence number
RangeDataManager.getInstance().initRange();
}
Logger.debug("failed - loadCallStackApis");
isSuccess = false;
} else {
- BaseCallstackManager callstackManager = AnalyzerManager.getCallstackManager();
+ BaseCallstackManager callstackManager = AnalyzerManager.getRuntimeCallstackManager();
int size = callStackUnits.size();
for (int i = 0; i < size; i++) {
List<Object> callStackUnit = callStackUnits.get(i);
import java.util.concurrent.ConcurrentSkipListMap;
import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
-import org.tizen.dynamicanalyzer.common.AnalyzerManager;
import org.tizen.dynamicanalyzer.common.Global;
import org.tizen.dynamicanalyzer.common.SymbolManager;
import org.tizen.dynamicanalyzer.constant.CommonConstants;
import org.tizen.dynamicanalyzer.nl.InformationViewLabels;
-import org.tizen.dynamicanalyzer.project.AppInfo;
import org.tizen.dynamicanalyzer.project.BinaryInfo;
import org.tizen.dynamicanalyzer.project.LibraryObject;
import org.tizen.dynamicanalyzer.project.ProcessInformation;
import org.tizen.dynamicanalyzer.swap.platform.BinarySettingData;
import org.tizen.dynamicanalyzer.swap.platform.BinarySettingManager;
import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackData;
-import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackInserter;
import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackItem;
import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackUnit;
import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfileDataMaker;
import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
public abstract class BaseCallstackManager {
- protected static class DuplicateUserCall {
- private CallStackUnit dupCallstackUnit = null;
- private int dupCallcount = 0;
-
- public DuplicateUserCall(CallStackUnit callStackUnit) {
- dupCallstackUnit = callStackUnit;
- dupCallcount = 1;
- }
-
- public CallStackUnit getDupCallstackUnit() {
- return dupCallstackUnit;
- }
-
- public int getDupCallCount() {
- return dupCallcount;
- }
-
- public void increaseDupCallCount() {
- dupCallcount++;
- }
-
- public void decreaseDupCallCount() {
- dupCallcount--;
- }
- }
-
- protected ConcurrentHashMap<Integer, ConcurrentHashMap<Long, CallStackUnit>> callstackApiAddrByPidMap = new ConcurrentHashMap<Integer, ConcurrentHashMap<Long, CallStackUnit>>();
- protected ConcurrentSkipListMap<Long, CallStackData> callstackDataBySeqMap = new ConcurrentSkipListMap<Long, CallStackData>();
- protected String userFunctionBin = null;
- protected HashMap<Integer, List<CallStackItem>> userCallstackByTidMap = new HashMap<Integer, List<CallStackItem>>();
- protected HashMap<Integer, DuplicateUserCall> dupUserCallByTidMap = new HashMap<Integer, DuplicateUserCall>();
- protected ConcurrentHashMap<Integer, ConcurrentSkipListMap<Long, Long>> seqTimeByTidMap = new ConcurrentHashMap<Integer, ConcurrentSkipListMap<Long, Long>>();
-
- protected CallStackInserter callstackInserter = null;
+ protected Map<Integer, Map<Long, CallStackUnit>> callstackApiAddrByPidMap = new ConcurrentHashMap<Integer, Map<Long, CallStackUnit>>();
+ protected NavigableMap<Long, CallStackData> callstackDataBySeqMap = new ConcurrentSkipListMap<Long, CallStackData>();
+ protected Map<Integer, List<CallStackItem>> userCallstackByTidMap = new HashMap<Integer, List<CallStackItem>>();
abstract public void makeUserCallstack(LogData log, ProfileDataMaker profiler);
- abstract public void makeUserCallstackforRange(LogData log, ProfileDataMaker profiler);
-
- abstract public void makeCallstackWithoutBacktrace(LogData inputData);
- abstract public long getSeqOfUserCallstackForTime(int tid, long time);
- abstract public List<Long> getCallstackAddrListFromSeq(long seq);
- abstract public List<List<Long>> getArrayOfAddrListFromSeq(List<Long> seqs);
-
- public void offerCallStackUnit(CallStackUnit csu) {
- if (callstackInserter != null) {
- CallStackInserter.startInserterThread();
- callstackInserter.offerCallstackUnit(csu);
- }
- return;
- }
- public void offerCallStackData(CallStackData csd) {
- if (callstackInserter != null) {
- CallStackInserter.startInserterThread();
- callstackInserter.offerCallstackData(csd);
- }
- return;
- }
+ abstract public long getSeqOfUserCallstackForTime(int tid, long time);
public Map<Long, CallStackUnit> getCallStackApiAddrByPidMap(int pid) {
- if (null == callstackApiAddrByPidMap) {
- callstackApiAddrByPidMap = new ConcurrentHashMap<Integer, ConcurrentHashMap<Long, CallStackUnit>>();
- }
- ConcurrentHashMap<Long, CallStackUnit> callstackApiByAddrMap = callstackApiAddrByPidMap
- .get(pid);
+ Map<Long, CallStackUnit> callstackApiByAddrMap = callstackApiAddrByPidMap.get(pid);
if (null == callstackApiByAddrMap) {
callstackApiByAddrMap = new ConcurrentHashMap<Long, CallStackUnit>();
callstackApiAddrByPidMap.put(pid, callstackApiByAddrMap);
}
public NavigableMap<Long, CallStackData> getCallStackDataBySeqMap() {
- if (null == callstackDataBySeqMap) {
- callstackDataBySeqMap = new ConcurrentSkipListMap<Long, CallStackData>();
- }
return callstackDataBySeqMap;
}
- public HashMap<Integer, DuplicateUserCall> getDupUserCallByTidMap() {
- if (null == dupUserCallByTidMap) {
- dupUserCallByTidMap = new HashMap<Integer, DuplicateUserCall>();
- }
- return dupUserCallByTidMap;
- }
-
- public NavigableMap<Long, Long> getSeqTimeByTidMap(int tid) {
- if (null == seqTimeByTidMap) {
- seqTimeByTidMap = new ConcurrentHashMap<Integer, ConcurrentSkipListMap<Long, Long>>();
- }
- ConcurrentSkipListMap<Long, Long> seqByTimeMap = seqTimeByTidMap.get(tid);
- if (null == seqByTimeMap) {
- seqByTimeMap = new ConcurrentSkipListMap<Long, Long>();
- seqTimeByTidMap.put(tid, seqByTimeMap);
+ public List<CallStackItem> getUserCallstack(int tid) {
+ List<CallStackItem> userCallstack = userCallstackByTidMap.get(tid);
+ if (null == userCallstack) {
+ userCallstack = new ArrayList<CallStackItem>();
+ userCallstackByTidMap.put(tid, userCallstack);
}
- return seqByTimeMap;
- }
-
- public List<Integer> getTidsOfSeqTimeMap() {
- ArrayList<Integer> tids = new ArrayList<Integer>();
- tids.addAll(seqTimeByTidMap.keySet());
-
- return tids;
+ return userCallstack;
}
- public String getUserFunctionPosition() {
- if (userFunctionBin == null || userFunctionBin.isEmpty()) {
- if (AnalyzerManager.isOsp()) {
- userFunctionBin = new String(Global.getCurrentApplication().getMainApp()
- .getInfo(AppInfo.PROPERTY.EXEC.index)
- + ".exe"); //$NON-NLS-1$
- } else {
- userFunctionBin = new String(Global.getCurrentApplication().getMainApp()
- .getInfo(AppInfo.PROPERTY.EXEC.index));
- }
- }
- return userFunctionBin;
+ public void clear() {
+ callstackApiAddrByPidMap.clear();
+ callstackDataBySeqMap.clear();
+ userCallstackByTidMap.clear();
}
- public String getUserFunctionPosition(int pid, long time) {
+ private String getUserFunctionPosition(int pid, long time) {
Project project = Global.getProject();
ProcessInformation process = project.getProcessInformation(pid);
ProcessMemoryMap pmap = process.getProcessMemoryMap(time);
}
}
- public List<CallStackItem> getUserCallstack(int tid) {
- if (null == userCallstackByTidMap) {
- userCallstackByTidMap = new HashMap<Integer, List<CallStackItem>>();
- }
- List<CallStackItem> userCallstack = userCallstackByTidMap.get(tid);
- if (null == userCallstack) {
- userCallstack = new ArrayList<CallStackItem>();
- userCallstackByTidMap.put(tid, userCallstack);
- }
- return userCallstack;
- }
-
- public boolean checkUserCall(String input) {
- AppInfo appInfo = Global.getProject().getApplicationInfo();
- BinaryInfo binfo = Global.getProject().getDeviceStatusInfo()
- .getBinaryInfo(appInfo.getExecBinaryPath());
- if (binfo.getTargetBinaryPath().equals(input)) {
- return true;
- }
- return false;
- }
-
// callstack symbol format : path(functionName
// ex. /usr/lib/libpthread.so(pthread_create
public String getCallStackSymbol(long addr, int pid, long time) {
return symbol;
}
- abstract public void clear();
+ protected boolean isAddrInBinaryRange(int pid, long time, long addr) {
+ ProcessMemoryMap pmap = Global.getProject().getProcessInformation(pid)
+ .getProcessMemoryMap(time);
+ if (null == pmap) {
+ return false;
+ }
+ // return true when addr is within memory range of main executable
+ // or library which is set in the binary setting
+ if (addr >= pmap.getMainbinary().getLowestAddress()
+ && addr <= pmap.getMainbinary().getHighestAddress()) {
+ return true;
+ }
+
+ List<BinarySettingData> binDataList = BinarySettingManager.getInstance()
+ .getBinarySettingList();
+ List<String> binPaths = new ArrayList<String>();
+ for (BinarySettingData binData : binDataList) {
+ binPaths.add(binData.getBinaryPath());
+ }
+ // TODO: performance improvement
+ int size = binPaths.size();
+ for (int i = 0; i < size; i++) {
+ String binPath = binPaths.get(i);
+ BinaryInfo bininfo = Global.getProject().getDeviceStatusInfo().getBinaryInfo(binPath);
+ LibraryObject libObj = pmap.getLibraryByBinaryID(bininfo.getID());
+ if (null == libObj) {
+ continue;
+ }
+ if (addr >= libObj.getLowestAddress() && addr <= libObj.getHighestAddress()) {
+ return true;
+ }
+ }
+ return false;
+ }
}
--- /dev/null
+/*
+ * Dynamic Analyzer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * WooJin Jung <woojin2.jung@samsung.com>
+ * Jooyoul Lee <jy.exe.lee@samsung.com>
+ * Juyoung Kim <j0.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.dynamicanalyzer.swap.callstack;
+
+import static org.tizen.dynamicanalyzer.swap.channel.data.DataChannelConstants.MSG_FUNCTION_ENTRY;
+import static org.tizen.dynamicanalyzer.swap.channel.data.DataChannelConstants.MSG_FUNCTION_EXIT;
+
+import java.util.List;
+import java.util.Map;
+
+import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
+import org.tizen.dynamicanalyzer.common.Global;
+import org.tizen.dynamicanalyzer.project.BinaryInfo;
+import org.tizen.dynamicanalyzer.swap.model.data.LogData;
+import org.tizen.dynamicanalyzer.swap.model.data.ProfileData;
+import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackItem;
+import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackUnit;
+import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfileDataMaker;
+import org.tizen.dynamicanalyzer.util.Logger;
+
+public class RangeCallstackManager extends BaseCallstackManager {
+
+ @Override
+ public void makeUserCallstack(LogData log, ProfileDataMaker profiler) {
+ ProfileData pData = (ProfileData) log;
+ int pid = pData.getPid();
+ long time = pData.getTime();
+
+ Map<Long, CallStackUnit> addrMap = getCallStackApiAddrByPidMap(pid);
+
+ int tid = pData.getTid();
+ long selfAddr = pData.getPcAddr();
+ long callerAddr = pData.getCallerPcAddr();
+
+ CallStackUnit selfCallstackUnit = addrMap.get(selfAddr);
+ // TODO: use callstackunit made during trace time
+ if (null == selfCallstackUnit) {
+ String strSelfFuncName = Global.getFunctionName(pData.getApiId());
+ BinaryInfo binInfo = Global.getProject().getDeviceStatusInfo()
+ .getBinaryInfo(pData.getBinaryId());
+ String strSelfSymbol = binInfo.getTargetBinaryPath()
+ + AnalyzerConstants.CALLSTACK_API_TOKEN_STRING + strSelfFuncName;
+ selfCallstackUnit = new CallStackUnit(selfAddr, strSelfSymbol, pData.getApiId(), pData);
+ addrMap.put(selfAddr, selfCallstackUnit);
+ }
+
+ // make ProfilingData
+ profiler.makeFupDataForCallTrace(selfCallstackUnit, pData);
+
+ List<CallStackItem> userCallstack = getUserCallstack(tid);
+ int size = userCallstack.size();
+
+ CallStackUnit callerCallstackUnit = addrMap.get(callerAddr);
+ if (null == callerCallstackUnit) {
+ String strCallerSymbol = getCallStackSymbol(callerAddr, pid, time);
+ callerCallstackUnit = new CallStackUnit(callerAddr, strCallerSymbol, pData);
+ addrMap.put(callerAddr, callerCallstackUnit);
+ }
+
+ int eventType = pData.getMsgID();
+ if (eventType == MSG_FUNCTION_ENTRY) {
+ if (size == 0) {
+ userCallstack.add(new CallStackItem(selfCallstackUnit, time));
+ } else {
+ if (isAddrInBinaryRange(pid, time, callerAddr)) {
+ // change previous top callstackunit's address to caller address of this
+ // callstackunit
+ CallStackUnit callerCsa = addrMap.get(callerAddr);
+ if (null == callerCsa) {
+ callerCsa = userCallstack.get(size - 1).getCallStackUnit();
+ callerCsa.setFunctionStartAddr(callerCsa.getAddr());
+ callerCsa.setAddr(callerAddr);
+ } else {
+ CallStackItem topCallstackItem = userCallstack.get(size - 1);
+ callerCsa.setFunctionStartAddr(topCallstackItem.getCallStackUnit()
+ .getAddr());
+ userCallstack.set(size - 1,
+ new CallStackItem(callerCsa, topCallstackItem.getStartTime()));
+ }
+ } // do nothing when call is from library
+ // in range analysis, user callstack is only used to make callstack of sample
+ // and callstack of sample does not include "~~ internal library~~"
+ userCallstack.add(new CallStackItem(selfCallstackUnit, time));
+ }
+ } else if (eventType == MSG_FUNCTION_EXIT) {
+ if (size == 0) {
+ return;
+ }
+ CallStackUnit removeCallStackUnit = userCallstack.get(size - 1).getCallStackUnit();
+ if (selfCallstackUnit.getFunctionId() == removeCallStackUnit.getFunctionId()) {
+ userCallstack.remove(size - 1);
+ size = userCallstack.size();
+ if (size > 0) {
+ // restore start address of previous top callstackunit
+ CallStackItem prevCallstackItem = userCallstack.get(size - 1);
+ long prevSelfAddr = prevCallstackItem.getCallStackUnit().getFunctionStartAddr();
+ CallStackUnit callerCsa = addrMap.get(prevSelfAddr);
+ if (null == callerCsa) {
+ prevCallstackItem.getCallStackUnit().setAddr(prevSelfAddr);
+ } else {
+ userCallstack.set(size - 1,
+ new CallStackItem(callerCsa, prevCallstackItem.getStartTime()));
+ }
+ }
+ } else {
+ Logger.error("makeUserCallstack %d, %d, %s, %s", selfCallstackUnit.getFunctionId(),
+ removeCallStackUnit.getFunctionId(), Global.getFunctionName(selfCallstackUnit.getFunctionId()),
+ Global.getFunctionName(removeCallStackUnit.getFunctionId()));
+ // Logger.error("makeUserCallstack : EXIT self is not the same as top of user callstack");
+ }
+ }
+ }
+
+ @Override
+ public long getSeqOfUserCallstackForTime(int tid, long time) {
+ // do nothing, never been called
+ Logger.error("Should not be called in range callstack manager");
+ return 0;
+ }
+
+}
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListMap;
import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
import org.tizen.dynamicanalyzer.common.Global;
import org.tizen.dynamicanalyzer.swap.model.data.LogData;
import org.tizen.dynamicanalyzer.swap.model.data.ProbeCommonData;
import org.tizen.dynamicanalyzer.swap.model.data.ProfileData;
-import org.tizen.dynamicanalyzer.swap.platform.BinarySettingData;
-import org.tizen.dynamicanalyzer.swap.platform.BinarySettingManager;
import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackData;
import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackInserter;
import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackItem;
import org.tizen.dynamicanalyzer.ui.timeline.calltrace.FunctionExitDBTable;
import org.tizen.dynamicanalyzer.util.Logger;
-public class SWAPCallStackManager extends BaseCallstackManager {
+public class RuntimeCallstackManager extends BaseCallstackManager {
+ protected CallStackInserter callstackInserter = null;
+
+ protected Map<Integer, NavigableMap<Long, Long>> seqTimeByTidMap = new ConcurrentHashMap<Integer, NavigableMap<Long, Long>>();
// callstackdata made in range analysis should not be saved to DB
- public SWAPCallStackManager(boolean isRange) {
- if (!isRange) {
- callstackInserter = CallStackInserter.getInstance();
- } else {
- callstackInserter = null;
+ public RuntimeCallstackManager() {
+ callstackInserter = CallStackInserter.getInstance();
+ }
+
+ public void offerCallStackUnit(CallStackUnit csu) {
+ if (callstackInserter != null) {
+ CallStackInserter.startInserterThread();
+ callstackInserter.offerCallstackUnit(csu);
+ }
+ return;
+ }
+
+ public void offerCallStackData(CallStackData csd) {
+ if (callstackInserter != null) {
+ CallStackInserter.startInserterThread();
+ callstackInserter.offerCallstackData(csd);
}
+ return;
}
+ public NavigableMap<Long, Long> getSeqTimeByTidMap(int tid) {
+ NavigableMap<Long, Long> seqByTimeMap = seqTimeByTidMap.get(tid);
+ if (null == seqByTimeMap) {
+ seqByTimeMap = new ConcurrentSkipListMap<Long, Long>();
+ seqTimeByTidMap.put(tid, seqByTimeMap);
+ }
+ return seqByTimeMap;
+ }
+
+ public List<Integer> getTidsOfSeqTimeMap() {
+ ArrayList<Integer> tids = new ArrayList<Integer>();
+ tids.addAll(seqTimeByTidMap.keySet());
+
+ return tids;
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+ seqTimeByTidMap.clear();
+ }
+
+ @Override
public void makeUserCallstack(LogData input, ProfileDataMaker profiler) {
ProfileData log = (ProfileData) input;
int pid = log.getPid();
String apiName = Global.getFunctionName(log.getApiId());
if (apiName.equals("main")) { //$NON-NLS-1$
- ProcessInformation process = Global.getProject().getProcessInformation(
- log.getPid());
+ ProcessInformation process = Global.getProject()
+ .getProcessInformation(log.getPid());
process.setDropLog(true);
}
}
}
- public void makeUserCallstackforRange(LogData input, ProfileDataMaker profiler) {
- ProfileData pData = (ProfileData) input;
- int pid = pData.getPid();
- long time = pData.getTime();
-
- Map<Long, CallStackUnit> addrMap = getCallStackApiAddrByPidMap(pid);
-
- int tid = pData.getTid();
- long selfAddr = pData.getPcAddr();
- long callerAddr = pData.getCallerPcAddr();
-
- CallStackUnit selfCallstackUnit = addrMap.get(selfAddr);
- // TODO: use callstackunit made during trace time
- if (null == selfCallstackUnit) {
- String strSelfFuncName = Global.getFunctionName(pData.getApiId());
- BinaryInfo binInfo = Global.getProject().getDeviceStatusInfo()
- .getBinaryInfo(pData.getBinaryId());
- String strSelfSymbol = binInfo.getTargetBinaryPath()
- + AnalyzerConstants.CALLSTACK_API_TOKEN_STRING + strSelfFuncName;
- selfCallstackUnit = new CallStackUnit(selfAddr, strSelfSymbol, pData.getApiId(), pData);
- addrMap.put(selfAddr, selfCallstackUnit);
- }
-
- // make ProfilingData
- profiler.makeFupDataForCallTrace(selfCallstackUnit, pData);
-
- List<CallStackItem> userCallstack = getUserCallstack(tid);
- int size = userCallstack.size();
-
- CallStackUnit callerCallstackUnit = addrMap.get(callerAddr);
- if (null == callerCallstackUnit) {
- String strCallerSymbol = getCallStackSymbol(callerAddr, pid, time);
- callerCallstackUnit = new CallStackUnit(callerAddr, strCallerSymbol, pData);
- addrMap.put(callerAddr, callerCallstackUnit);
- }
-
- int eventType = pData.getMsgID();
- if (eventType == MSG_FUNCTION_ENTRY) {
- if (size == 0) {
- userCallstack.add(new CallStackItem(selfCallstackUnit, time));
- } else {
- if (isAddrInBinaryRange(pid, time, callerAddr)) {
- // change previous top callstackunit's address to caller address of this callstackunit
- CallStackUnit callerCsa = addrMap.get(callerAddr);
- if (null == callerCsa) {
- callerCsa = userCallstack.get(size - 1).getCallStackUnit();
- callerCsa.setFunctionStartAddr(callerCsa.getAddr());
- callerCsa.setAddr(callerAddr);
- } else {
- CallStackItem topCallstackItem = userCallstack.get(size - 1);
- callerCsa.setFunctionStartAddr(topCallstackItem
- .getCallStackUnit().getAddr());
- userCallstack.set(size - 1, new CallStackItem(callerCsa,
- topCallstackItem.getStartTime()));
- }
- } // do nothing when call is from library
- // in range analysis, user callstack is only used to make callstack of sample
- // and callstack of sample does not include "~~ internal library~~"
- userCallstack.add(new CallStackItem(selfCallstackUnit, time));
- }
- } else if (eventType == MSG_FUNCTION_EXIT) {
- if (size == 0) {
- return;
- }
- CallStackUnit removeCallStackUnit = userCallstack.get(size - 1)
- .getCallStackUnit();
- if (selfCallstackUnit.getFunctionId() == removeCallStackUnit.getFunctionId()) {
- userCallstack.remove(size - 1);
- size = userCallstack.size();
- if (size > 0) {
- // restore start address of previous top callstackunit
- CallStackItem prevCallstackItem = userCallstack.get(size - 1);
- long prevSelfAddr = prevCallstackItem.getCallStackUnit()
- .getFunctionStartAddr();
- CallStackUnit callerCsa = addrMap.get(prevSelfAddr);
- if (null == callerCsa) {
- prevCallstackItem.getCallStackUnit().setAddr(prevSelfAddr);
- } else {
- userCallstack.set(size - 1, new CallStackItem(callerCsa,
- prevCallstackItem.getStartTime()));
- }
- }
- } else {
- Logger.error("makeUserCallstack : EXIT self is not the same as top of user callstack");
- }
- }
- }
-
public void makeCallstackWithoutBacktrace(LogData inputData) {
ProbeCommonData log = (ProbeCommonData) inputData;
long userCallstackSeq = getSeqOfUserCallstackForTime(tid, time);
List<Long> addrs = new ArrayList<Long>();
int size = 0;
-
+
if (-1 != userCallstackSeq) { // seq for usercallstack is found
List<Long> addrsFromUserCallStack = getCallstackAddrListFromSeq(userCallstackSeq);
if (null != addrsFromUserCallStack) { // callstack data for seq is found
}
// to make callstack for sample, probe
+ @Override
public long getSeqOfUserCallstackForTime(int tid, long time) {
long seq = -1;
String query;
ResultSet rs;
NavigableMap<Long, Long> seqByTimeMap = getSeqTimeByTidMap(tid);
Long callstackTime = seqByTimeMap.floorKey(time);
-
+
if (null != callstackTime) { // found from memory
seq = seqByTimeMap.get(callstackTime);
} else { // select from database
if (rs.next()) {
entrySeq = rs.getLong(1);
}
- SqlConnectionManager.releaseResultSet(rs);
+ SqlConnectionManager.releaseResultSet(rs);
}
-
+
query = String.format(FunctionExitDBTable.USERCALLSTACK_QUERY, time);
rs = SqlConnectionManager.executeQueryRS(query);
if (rs == null) {
}
SqlConnectionManager.releaseResultSet(rs);
}
-
+
if (entrySeq < exitSeq) { // greater seq which time is less than sample/probe time
seq = exitSeq;
} else {
seq = entrySeq;
- }
+ }
} catch (SQLException e) {
Logger.exception(e);
}
}
-
+
return seq;
}
-
+
public List<Long> getCallstackAddrListFromSeq(long seq) {
List<Long> addrs = null;
CallStackData csd = getCallStackDataBySeqMap().get(seq);
-
+
if (null == csd) { // callstackdata is not in memory, find from DB
List<List<Object>> callStackAddrs = CallStackInserter.getInstance()
.getCallStackDataTable().getCallStackAddrsFromDB(seq);
-
+
if (null == callStackAddrs || 0 == callStackAddrs.size()
|| null == callStackAddrs.get(0)) { // not found
Logger.debug("CallStackData is not found for seq : " + seq);
return null;
}
-
+
@SuppressWarnings("unchecked")
List<Long> addressList = (List<Long>) callStackAddrs.get(0).get(0);
addrs.addAll(addressList);
} else { // callstackdata is in memory
addrs = csd.getAddrs();
- }
+ }
return addrs;
}
-//TODO: 1. execute select query once 2. change return type - <seq, List<Long>>
-//TODO: 3. additional discussion with leak analysis implementer if needed
+
+ // TODO: 1. execute select query once 2. change return type - <seq, List<Long>>
+ // TODO: 3. additional discussion with leak analysis implementer if needed
public List<List<Long>> getArrayOfAddrListFromSeq(List<Long> seqs) {
List<List<Long>> addrsList = null;
if (null == seqs) {
return null;
}
-
+
addrsList = new ArrayList<List<Long>>();
int size = seqs.size();
for (int i = 0; i < size; i++) {
addrsList.add(addrs);
}
}
-
- return addrsList;
- }
-
- public void clear() {
- callstackApiAddrByPidMap.clear();
- callstackDataBySeqMap.clear();
- userFunctionBin = null;
- userCallstackByTidMap.clear();
- dupUserCallByTidMap.clear();
- seqTimeByTidMap.clear();
- }
-
- public boolean isAddrInBinaryRange(int pid, long time, long addr) {
- ProcessMemoryMap pmap = Global.getProject().getProcessInformation(pid)
- .getProcessMemoryMap(time);
- if (null == pmap) {
- return false;
- }
- // return true when addr is within memory range of main executable
- // or library which is set in the binary setting
- if (addr >= pmap.getMainbinary().getLowestAddress()
- && addr <= pmap.getMainbinary().getHighestAddress()) {
- return true;
- }
- List<BinarySettingData> binDataList = BinarySettingManager.getInstance()
- .getBinarySettingList();
- List<String> binPaths = new ArrayList<String>();
- for (BinarySettingData binData : binDataList) {
- binPaths.add(binData.getBinaryPath());
- }
- // TODO: performance improvement
- int size = binPaths.size();
- for (int i = 0; i < size; i++) {
- String binPath = binPaths.get(i);
- BinaryInfo bininfo = Global.getProject().getDeviceStatusInfo()
- .getBinaryInfo(binPath);
- LibraryObject libObj = pmap.getLibraryByBinaryID(bininfo.getID());
- if (null == libObj) {
- continue;
- }
- if (addr >= libObj.getLowestAddress() && addr <= libObj.getHighestAddress()) {
- return true;
- }
- }
- return false;
+ return addrsList;
}
public boolean isPieBuild(int pid, long time) {
case MSG_PROBE_SCREENSHOT:
processScreenshotData((ScreenShotData) log);
packLog(log, logPack);
- AnalyzerManager.getCallstackManager().makeCallstackWithoutBacktrace(log);
+ AnalyzerManager.getRuntimeCallstackManager().makeCallstackWithoutBacktrace(log);
break;
default:
packLog(log, logPack);
- AnalyzerManager.getCallstackManager().makeCallstackWithoutBacktrace(log);
+ AnalyzerManager.getRuntimeCallstackManager().makeCallstackWithoutBacktrace(log);
break;
}
}
}
}
- AnalyzerManager.getCallstackManager().makeUserCallstack(pData,
+ AnalyzerManager.getRuntimeCallstackManager().makeUserCallstack(pData,
FunctionUsageProfiler.getInstance().getProfileDataMakerByPid(pData.getPid()));
}
removeCallstackData(lastInsertSeq);
}
// clear SeqTimeMap if number of entries over > 1M
- List<Integer> tids = AnalyzerManager.getCallstackManager().getTidsOfSeqTimeMap();
+ List<Integer> tids = AnalyzerManager.getRuntimeCallstackManager().getTidsOfSeqTimeMap();
int size = tids.size();
for (int i = 0; i < size; i++) {
- NavigableMap<Long, Long> seqByTimeMap = AnalyzerManager.getCallstackManager()
+ NavigableMap<Long, Long> seqByTimeMap = AnalyzerManager.getRuntimeCallstackManager()
.getSeqTimeByTidMap(tids.get(i));
if (seqByTimeMap.size() > DALimit.MAX_CALLSTACK_SEQTIMEMAP_SIZE) {
seqByTimeMap.clear();
}
private void removeCallstackData(long seq) {
- NavigableMap<Long, CallStackData> callstackDataMap = AnalyzerManager.getCallstackManager()
+ NavigableMap<Long, CallStackData> callstackDataMap = AnalyzerManager.getRuntimeCallstackManager()
.getCallStackDataBySeqMap();
SortedMap<Long, CallStackData> headMap = callstackDataMap.headMap(seq);
Iterator<Map.Entry<Long, CallStackData>> itr = headMap.entrySet().iterator();
public class CallStackUnit {
private long address;
private long functionStartAddress;
- private String originSymbol;
private String path;
private String functionName;
private String offset;
// TODO: get path and function name as parameter, not symbol
public CallStackUnit(long addr, String symbol, LogData log) {
- address = addr;
- functionStartAddress = addr;
- this.originSymbol = symbol;
+ this.address = addr;
+ this.functionStartAddress = addr;
this.time = log.getTime();
- this.functionId = AnalyzerConstants.INVALID_ID;
-
- functionName = CommonConstants.EMPTY;
- offset = CommonConstants.EMPTY;
- etc = CommonConstants.EMPTY;
this.pid = log.getPid();
- makeCallstackData();
+ this.functionId = AnalyzerConstants.INVALID_ID;
+ this.functionName = CommonConstants.EMPTY;
+ this.offset = CommonConstants.EMPTY;
+ this.etc = CommonConstants.EMPTY;
+ makeCallstackData(symbol);
}
public CallStackUnit(long addr, String symbol, int functionId, LogData log) {
- address = addr;
- functionStartAddress = addr;
- this.originSymbol = symbol;
+ this.address = addr;
+ this.functionStartAddress = addr;
this.time = log.getTime();
- this.functionId = functionId;
-
- functionName = CommonConstants.EMPTY;
- offset = CommonConstants.EMPTY;
- etc = CommonConstants.EMPTY;
this.pid = log.getPid();
- makeCallstackData();
+ this.functionId = functionId;
+ this.functionName = CommonConstants.EMPTY;
+ this.offset = CommonConstants.EMPTY;
+ this.etc = CommonConstants.EMPTY;
+ makeCallstackData(symbol);
}
/** using open trace **/
public CallStackUnit(long addr, int pid, int functionId, int binaryId) {
- address = addr;
- functionStartAddress = addr;
- originSymbol = CommonConstants.EMPTY;
+ this.address = addr;
+ this.functionStartAddress = addr;
this.time = -1;
+ this.pid = pid;
this.functionId = functionId;
-
this.functionName = Global.getFunctionName(functionId);
+
BinaryInfo bInfo = Global.getProject().getDeviceStatusInfo().getBinaryInfo(binaryId);
this.path = bInfo.getTargetBinaryPath();
- offset = CommonConstants.EMPTY;
- etc = CommonConstants.EMPTY;
- this.pid = pid;
+ this.offset = CommonConstants.EMPTY;
+ this.etc = CommonConstants.EMPTY;
}
- private void makeCallstackData() {
+ private void makeCallstackData(String symbol) {
// callstack symbol format : path(functionName
// ex. /usr/lib/libpthread.so(pthread_create
- String[] splitPath = originSymbol.split("\\(", 2); //$NON-NLS-1$
+ String[] splitPath = symbol.split("\\(", 2); //$NON-NLS-1$
path = splitPath[0];
- if (!path.startsWith("/") && !path.contains(FunctionUsageProfiler.APPLICATION) //$NON-NLS-1$
+ if (!path.startsWith("/") && !path.contains(FunctionUsageProfiler.APPLICATION)
&& !path.contains(FunctionUsageProfiler.DEPENDENT_LIB)) {
path = InformationViewLabels.CALLSTACK_TABLE_UNKNOWN_LIBRARY;
}
return functionStartAddress;
}
- public String getOriginSymbol() {
- return originSymbol;
- }
-
public String getSymbol() {
return path + CommonConstants.OPEN_BRACKET + functionName;
}
}
Map<Long, CallStackUnit> addrMap = AnalyzerManager
- .getCallstackManager().getCallStackApiAddrByPidMap(pid);
+ .getRuntimeCallstackManager().getCallStackApiAddrByPidMap(pid);
if (null == addrMap) {
return;
}
List<Long> addrs = null;
- addrs = AnalyzerManager.getCallstackManager().getCallstackAddrListFromSeq(seqNum);
+ addrs = AnalyzerManager.getRuntimeCallstackManager().getCallstackAddrListFromSeq(seqNum);
if (null == addrs) {
return;
}
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.PriorityQueue;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.tizen.dynamicanalyzer.common.AnalyzerManager;
-import org.tizen.dynamicanalyzer.communicator.DACommunicator;
import org.tizen.dynamicanalyzer.database.SqlConnectionManager;
import org.tizen.dynamicanalyzer.swap.callstack.BaseCallstackManager;
-import org.tizen.dynamicanalyzer.swap.callstack.SWAPCallStackManager;
+import org.tizen.dynamicanalyzer.swap.callstack.RangeCallstackManager;
import org.tizen.dynamicanalyzer.swap.channel.data.DataChannelConstants;
import org.tizen.dynamicanalyzer.swap.model.data.ProfileData;
import org.tizen.dynamicanalyzer.ui.summary.SummaryDataManager;
import org.tizen.dynamicanalyzer.ui.summary.profiling.FunctionSampleDBTable;
import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfileDataMaker;
+import org.tizen.dynamicanalyzer.ui.summary.profiling.RangeProfileDataMaker;
import org.tizen.dynamicanalyzer.ui.timeline.TimelinePage;
import org.tizen.dynamicanalyzer.ui.timeline.calltrace.FunctionEntryDBTable;
import org.tizen.dynamicanalyzer.ui.timeline.calltrace.FunctionExitDBTable;
public class RangeDataManager implements Runnable {
private static RangeDataManager instance = null;
private Thread rangeThread = null;
- // private FileDataMaker fileDataMaker = null;
- private HashMap<Integer, ProfileDataMaker> profileDataMakerMap = null;
- private HashMap<Integer, ProfileDataMaker> swapProfileDataMakerMap = null;
- private BaseCallstackManager swapCallstackManager = null;
+ private Map<Integer, ProfileDataMaker> profileDataMakerMap = null;
+ private BaseCallstackManager rangeCallstackManager = null;
private long markerStartTime = 0;
private long markerEndTime = 0;
}
private RangeDataManager() {
- swapCallstackManager = new SWAPCallStackManager(true);
-
- // fileDataMaker = new FileDataMaker(failedChecker, leakDetector,
- // warningChecker);
+ rangeCallstackManager = new RangeCallstackManager();
}
public void clearRange() {
- swapCallstackManager.clear();
+ rangeCallstackManager.clear();
if (profileDataMakerMap != null)
profileDataMakerMap.clear();
- if (swapProfileDataMakerMap != null)
- swapProfileDataMakerMap.clear();
SummaryDataManager.getInstance().getLeakDataMaker().clearLeakDataForRange();
}
return pids;
}
- public synchronized HashMap<Integer, ProfileDataMaker> getProfileDataMakerMap() {
- if (DACommunicator.isSWAPVersion()) {
- if (null == swapProfileDataMakerMap) {
- swapProfileDataMakerMap = new HashMap<Integer, ProfileDataMaker>();
- }
- return swapProfileDataMakerMap;
- } else {
- if (null == profileDataMakerMap) {
- profileDataMakerMap = new HashMap<Integer, ProfileDataMaker>();
- }
- return profileDataMakerMap;
+ public synchronized Map<Integer, ProfileDataMaker> getProfileDataMakerMap() {
+ if (null == profileDataMakerMap) {
+ profileDataMakerMap = new HashMap<Integer, ProfileDataMaker>();
}
+ return profileDataMakerMap;
}
public ProfileDataMaker getProfileDataMakerByPid(int pid) {
ProfileDataMaker profileDataMaker = getProfileDataMakerMap().get(pid);
if (null == profileDataMaker) {
// if (DACommunicator.isSWAPVersion()) {
- profileDataMaker = new ProfileDataMaker(swapCallstackManager);
+ profileDataMaker = new RangeProfileDataMaker(rangeCallstackManager);
// }
profileDataMaker.setPid(pid);
getProfileDataMakerMap().put(pid, profileDataMaker);
DataChannelConstants.MSG_FUNCTION_ENTRY, rsEntry);
pQueue.offer(pEntry);
}
- swapCallstackManager.makeUserCallstackforRange(top, profileDataMaker);
+ rangeCallstackManager.makeUserCallstack(top, profileDataMaker);
break;
case DataChannelConstants.MSG_FUNCTION_EXIT:
if (rsExit.next()) {
DataChannelConstants.MSG_FUNCTION_EXIT, rsExit);
pQueue.offer(pExit);
}
- swapCallstackManager.makeUserCallstackforRange(top, profileDataMaker);
+ rangeCallstackManager.makeUserCallstack(top, profileDataMaker);
break;
case DataChannelConstants.MSG_DATA_SAMPLE:
if (rsSample.next()) {
ProfileData pSample = makeSampleProfileData(rsSample);
pQueue.offer(pSample);
}
- profileDataMaker.makeFunctionUsageProfileDataforRange(top);
+ profileDataMaker.makeFunctionUsageProfileData(top);
break;
default: // never goes here
Logger.error("Wrong data from selecting function profiling data inside range");
public ProfileDataMaker getProfileDataMakerByPid(int pid) {
ProfileDataMaker profileDataMaker = getProfileDataMakerMap().get(pid);
if (null == profileDataMaker) {
- profileDataMaker = new ProfileDataMaker(AnalyzerManager.getCallstackManager());
+ profileDataMaker = new RuntimeProfileDataMaker();
profileDataMaker.setPid(pid);
getProfileDataMakerMap().put(pid, profileDataMaker);
}
if (profileDataMakerMap != null) {
profileDataMakerMap.clear();
}
+ ProfilingData.clear(); // reset internal sequence number
}
public void saveProfilingData() {
getInstance().getProfileDataMakerByPid(sample.get(i).getPid())
.makeFunctionUsageProfileData(sampleLog);
// set LastSampleSeq
- NavigableMap<Long, Long> seqByTimeMap = AnalyzerManager.getCallstackManager()
+ NavigableMap<Long, Long> seqByTimeMap = AnalyzerManager.getRuntimeCallstackManager()
.getSeqTimeByTidMap(sampleLog.getTid());
// find the time of callstackdata which was made
// right before the current sample time
import static org.tizen.dynamicanalyzer.swap.channel.data.DataChannelConstants.MSG_FUNCTION_EXIT;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
-import org.tizen.dynamicanalyzer.common.path.PathConstants;
-import org.tizen.dynamicanalyzer.communicator.DACommunicator;
+import org.tizen.dynamicanalyzer.common.Global;
+import org.tizen.dynamicanalyzer.project.AppInfo;
+import org.tizen.dynamicanalyzer.project.BinaryInfo;
import org.tizen.dynamicanalyzer.swap.callstack.BaseCallstackManager;
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.info.callstack.CallStackItem;
import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackUnit;
import org.tizen.dynamicanalyzer.util.Logger;
import org.tizen.dynamicanalyzer.utils.Formatter;
-public class ProfileDataMaker {
+public abstract class ProfileDataMaker {
static class CallstackTree {
ProfilingData me;
CallstackTree parent;
}
}
- private HashMap<Integer, CallstackTree> callstackTreeByTidMap = new HashMap<Integer, CallstackTree>();
- private int totalSampleCount = 0;
- private BaseCallstackManager callstackManager = null;
+ private Map<Integer, CallstackTree> callstackTreeByTidMap = new HashMap<Integer, CallstackTree>();
+ protected int totalSampleCount = 0;
+ protected BaseCallstackManager callstackManager = null;
private int pid = 0;
-
+
/**
- * key: ID - value : function usage profiling data hash map all function
- * usage profiling data are in this hash map
+ * key: ID - value : function usage profiling data hash map all function usage profiling data
+ * are in this hash map
**/
- private ConcurrentHashMap<Integer, ProfilingData> profilingDataMap = null;
- private ConcurrentHashMap<String, String> symbolIDHash = null;
+ private Map<Integer, ProfilingData> profilingDataMap = null;
+ private Map<String, String> symbolIDHash = null;
/**
* key : ID - value : child ID list // all child lists are in this hash
*/
- private ConcurrentHashMap<String, ProfilingChildData> childListMap = null;
+ private Map<String, ProfilingChildData> childListMap = null;
private ProfilingData appBin = null;
private ProfilingData dependentLib = null;
callstackTreeByTidMap.clear();
}
- public BaseCallstackManager getCallstackManager() {
- return callstackManager;
- }
-
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
-
+
public String getAppBinName() {
return appBinName;
}
public CallstackTree getCurrentCallstackTree(int tid) {
CallstackTree current = callstackTreeByTidMap.get(tid);
- return current;
+ return current;
}
-
+
public void putCurrentCallstackTree(int tid, CallstackTree current) {
callstackTreeByTidMap.put(tid, current);
- return;
- }
-
+ return;
+ }
+
public String getCpuRate(ProfilingData data, boolean exclusive) {
int count = 0;
double rate = 0.;
if (exclusive) {
count = data.getExCount();
- if(totalSampleCount == 0) {
+ if (totalSampleCount == 0) {
rate = 0;
- } else {
+ } else {
rate = count / (double) totalSampleCount * 100;
}
} else {
count = data.getInCount();
- if(totalSampleCount == 0) {
+ if (totalSampleCount == 0) {
rate = 0;
- } else {
+ } else {
rate = count / (double) totalSampleCount * 100;
}
}
return Long.toString(count * FunctionUsageProfiler.SAMPLE_TIME);
}
- private void checkUserCall(CallStackUnit csa, ProfilingData parent,
- ProfilingData pp, LogData log) {
- if (callstackManager.checkUserCall(csa.getPath())) {
+ protected void checkUserCall(CallStackUnit csa, ProfilingData parent, ProfilingData pp,
+ LogData log) {
+ AppInfo appInfo = Global.getProject().getApplicationInfo();
+ BinaryInfo binfo = Global.getProject().getDeviceStatusInfo()
+ .getBinaryInfo(appInfo.getExecBinaryPath());
+ if (binfo.getTargetBinaryPath().equals(csa.getPath())) {
if (null == appBin) {
- CallStackUnit appBinCsa = new CallStackUnit(-1,
- FunctionUsageProfiler.APPLICATION, log);
+ CallStackUnit appBinCsa = new CallStackUnit(-1, FunctionUsageProfiler.APPLICATION,
+ log);
appBin = makeNewProfilingData(appBinCsa, true);
appBin.setKey(FunctionUsageProfiler.APPLICATION_KEY);
appBinName = csa.getPath();
}
}
}
-
- public void makeFunctionUsageProfileData(ProfileData sampleLog) {
- totalSampleCount++;
- List<Long> addrs = null;
- long selfAddr = sampleLog.getPcAddr();
- int pid = sampleLog.getPid();
-
- if(DACommunicator.isSWAPVersion()) {
- long userCallstackSeq;
- int tid = sampleLog.getTid();
- long sampleTime = sampleLog.getTime();
-
- CallStackData callstackData;
- Map<Long, CallStackUnit> addrMap = callstackManager
- .getCallStackApiAddrByPidMap(pid);
-
- CallStackUnit callstackUnit = addrMap.get(selfAddr);
- if (null == callstackUnit) {
- CallStackUnit newCallstackUnit = new CallStackUnit(selfAddr,
- callstackManager.getCallStackSymbol(selfAddr, pid, sampleTime), sampleLog);
- callstackManager.offerCallStackUnit(newCallstackUnit);
- addrMap.put(selfAddr, newCallstackUnit);
- }
-
- userCallstackSeq = callstackManager.getSeqOfUserCallstackForTime(tid, sampleTime);
- if (-1 != userCallstackSeq) {
- callstackData = callstackManager.getCallStackDataBySeqMap().get(userCallstackSeq);
- if (null == callstackData) {
- Logger.debug("CallStackData is not found for seq : " + userCallstackSeq);
- addrs = new ArrayList<Long>();
- addrs.add(selfAddr);
- } else {
- addrs = new ArrayList<Long>(callstackData.getAddrs());
- for(int i = 0; i < addrs.size(); i++) {
- if(addrs.get(i) == 0) {
- addrs.remove(i);
- }
- }
- addrs.add(0, selfAddr);
- }
- } else {
-// Logger.debug("makeFunctionUsageProfileData : cannot find seq by time");
- addrs = new ArrayList<Long>();
- addrs.add(selfAddr);
- }
-
- } else {
- String callstack = sampleLog.getCallstack();
- if (null == callstack) {
- return;
- }
- String[] splitCallstack = callstack
- .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]));
- }
-
- addrs = makeCallstackHashAndList(sampleCallstack, sampleLog);
- }
-
- Map<Long, CallStackUnit> addrMap = callstackManager
- .getCallStackApiAddrByPidMap(pid);
- CallStackUnit inputData = addrMap.get(selfAddr);
- if (null == inputData) {
- return;
- }
-
- // drop samples of probe library
- if (inputData.getPath().startsWith(PathConstants.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, sampleLog);
- 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
- int size = 0;
- if (null != addrs) {
- size = addrs.size();
- }
- for (int i = 0; i < size; i++) {
- CallStackUnit callstackCsa = addrMap.get(addrs.get(i));
-
- 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, sampleLog);
- }
- inParent.addInCount(totalSampleCount);
-
- if (null != inParent.getParent()) {
- String pInParentName = inParent.getParent();
- pp = getProfilingDataByKey(pInParentName);
- if (null != pp) {
- 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, sampleLog);
- }
- 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);
- if (null != pp) {
- pp.addInCount(totalSampleCount);
- }
- }
- } else {
- String pName = fupData.getParent();
- ProfilingData inParent = getProfilingDataByKey(pName);
- if (inParent == null) {
- Logger.error("ProfilingData: function item without library item");
- continue;
- }
- inParent.addInCount(totalSampleCount);
-
- if (null != inParent.getParent()) {
- String pInParentName = inParent.getParent();
- ProfilingData ppData = getProfilingDataByKey(pInParentName);
- if (null != ppData) {
- ppData.addInCount(totalSampleCount);
- }
- }
- }
- fupData.addInCount(totalSampleCount);
- }
- }
- }
- // TODO: divide this method into sub-methods, redesign data process
- public void makeFunctionUsageProfileDataforRange(ProfileData sampleLog) {
- totalSampleCount++;
- List<Long> addrs = new ArrayList<Long>();
- long selfAddr = sampleLog.getPcAddr();
- int pid = sampleLog.getPid();
- int tid = sampleLog.getTid();
- long sampleTime = sampleLog.getTime();
-
- Map<Long, CallStackUnit> addrMap = callstackManager
- .getCallStackApiAddrByPidMap(pid);
-
- CallStackUnit selfCallstackUnit = addrMap.get(selfAddr);
- if (null == selfCallstackUnit) {
- selfCallstackUnit = new CallStackUnit(selfAddr,
- callstackManager.getCallStackSymbol(selfAddr, pid, sampleTime), sampleLog);
- addrMap.put(selfAddr, selfCallstackUnit);
- }
-
- List<CallStackItem> userCallstack = callstackManager.getUserCallstack(tid);
- int callstackSize = userCallstack.size();
-
- for (int i = 0; i < callstackSize; i++) {
- long addr = userCallstack.get(i).getCallStackUnit().getAddr();
- addrs.add(addr);
- }
- addrs.add(selfAddr);
-
- // drop samples of probe library
- if (selfCallstackUnit.getPath().startsWith(PathConstants.DA_REMOTE_PROBE_PATH)) {
- return;
- }
- String inputPath = selfCallstackUnit.getPath();
- String inputFuncName = selfCallstackUnit.getFunctionName();
+ abstract public void makeFunctionUsageProfileData(ProfileData sampleLog);
- ProfilingData parent = getProfilingDataByKey(inputPath);
- // exclusive cpu time
- if (null == parent) {
- parent = makeNewProfilingData(selfCallstackUnit, true);
- checkUserCall(selfCallstackUnit, parent, null, sampleLog);
- if (inputFuncName.equals(FunctionUsageProfiler.UNKNOWN)) {
- parent.addExCount();
- } else {
- ProfilingData child = makeNewProfilingData(selfCallstackUnit, false);
- parent.addChild(child);
- child.addExCount();
- child.setParent(parent.getName());
- }
- } else {
- if (inputFuncName.isEmpty()) {
- parent.addExCount();
- } else {
- ProfilingData child = getProfilingDataByKey(selfCallstackUnit
- .getSymbol());
- if (null == child) {
- child = makeNewProfilingData(selfCallstackUnit, false);
- parent.addChild(child);
- child.setParent(parent.getName());
- }
- child.addExCount();
- }
- }
-
- // inclusive cpu time
- int size = 0;
- if (null != addrs) {
- size = addrs.size();
- }
- for (int i = 0; i < size; i++) {
- CallStackUnit callstackCsa = addrMap.get(addrs.get(i));
-
- 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, sampleLog);
- }
- inParent.addInCount(totalSampleCount);
-
- if (null != inParent.getParent()) {
- String pInParentName = inParent.getParent();
- pp = getProfilingDataByKey(pInParentName);
- if (null != pp) {
- 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, sampleLog);
- }
- 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);
- if (null != pp) {
- 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);
- if (null != ppData) {
- ppData.addInCount(totalSampleCount);
- }
- }
- }
- fupData.addInCount(totalSampleCount);
- }
- }
- }
-
- private List<Long> makeCallstackHashAndList(List<String> callstackLog,
- LogData log) {
- int pid = log.getPid();
- Map<Long, CallStackUnit> addrMap = callstackManager
- .getCallStackApiAddrByPidMap(pid);
- 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) {
- Logger.exception(e);
- return null;
- }
- addrs.add(addr);
-
- CallStackUnit callstackUnit = addrMap.get(addr);
- if (null == callstackUnit) {
- String funcName = callstackLog.get(i + 1);
- CallStackUnit newCallstackUnit = new CallStackUnit(addr,
- funcName, log);
- callstackManager.offerCallStackUnit(newCallstackUnit);
- addrMap.put(addr, newCallstackUnit);
- }
- }
- return addrs;
- }
-
- private ProfilingData makeNewProfilingData(CallStackUnit inputData,
- boolean isParent) {
- ProfilingData newProfilingData = new ProfilingData(inputData, isParent,
- this);
- getProfilingDataMap().put(newProfilingData.getProfilingDataID(),
- newProfilingData);
+ protected ProfilingData makeNewProfilingData(CallStackUnit inputData, boolean isParent) {
+ ProfilingData newProfilingData = new ProfilingData(inputData, isParent, this);
+ getProfilingDataMap().put(newProfilingData.getProfilingDataID(), newProfilingData);
if (isParent) {
getSymbolIDHash().put(inputData.getPath(),
Integer.toString(newProfilingData.getProfilingDataID()));
return newProfilingData;
}
- public void makeFupDataForCallTrace(CallStackUnit inputCallstackApiData,
- ProfileData log) {
+ public void makeFupDataForCallTrace(CallStackUnit inputCallstackApiData, ProfileData log) {
long exeTime = 0;
int type = log.getMsgID();
int tid = log.getTid();
List<CallStackItem> userCallstack = callstackManager.getUserCallstack(tid);
int size = userCallstack.size();
-
- if (type == MSG_FUNCTION_EXIT) {
- if(size == 0 ||
- userCallstack.get(size - 1).getCallStackUnit()
- .getFunctionId() != inputCallstackApiData.getFunctionId()) {
- Logger.debug("exit without entry or EXIT self is not the same as top of user callstack :"
- + inputCallstackApiData.getFunctionName()); //$NON-NLS-1$
+
+ if (type == MSG_FUNCTION_EXIT) {
+ if (size == 0
+ || userCallstack.get(size - 1).getCallStackUnit().getFunctionId() != inputCallstackApiData
+ .getFunctionId()) {
+ Logger.debug("exit without entry or EXIT self is not the same as top of user callstack :"
+ + inputCallstackApiData.getFunctionName()); //$NON-NLS-1$
return;
}
startTime = userCallstack.get(size - 1).getStartTime();
- if(startTime != -1) {
+ if (startTime != -1) {
exeTime += time - startTime;
- }
- }
+ }
+ }
- ProfilingData parent = getProfilingDataByKey(inputCallstackApiData
- .getPath());
+ ProfilingData parent = getProfilingDataByKey(inputCallstackApiData.getPath());
if (null == parent) {
parent = makeNewProfilingData(inputCallstackApiData, true);
checkUserCall(inputCallstackApiData, parent, null, log);
- ProfilingData child = makeNewProfilingData(inputCallstackApiData,
- false);
+ ProfilingData child = makeNewProfilingData(inputCallstackApiData, false);
parent.addChild(child);
child.addElapsedTime(exeTime);
child.setParent(parent.getName());
child.addCallCount();
}
} else { // null != parent
- ProfilingData child = getProfilingDataByKey(inputCallstackApiData
- .getSymbol());
+ ProfilingData child = getProfilingDataByKey(inputCallstackApiData.getSymbol());
if (null == child) {
child = makeNewProfilingData(inputCallstackApiData, false);
parent.addChild(child);
}
// calculate internal time
- CallstackTree current = getCurrentCallstackTree(tid);
+ CallstackTree current = getCurrentCallstackTree(tid);
if (type == MSG_FUNCTION_EXIT) {
if (null == current) {
// bug
} else {
CallstackTree parentCt = current.getParent();
if (null != parentCt) {
- parentCt.addChildExeTime(current.getThis()
- .getLastElapsedTime());
+ parentCt.addChildExeTime(current.getThis().getLastElapsedTime());
}
child.addExclusiveElapsedTime(current.getExclusiveExeTime());
- putCurrentCallstackTree(tid, current.getParent());
+ putCurrentCallstackTree(tid, current.getParent());
}
} else {
if (null == current) {
--- /dev/null
+/*
+ * Dynamic Analyzer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * WooJin Jung <woojin2.jung@samsung.com>
+ * Jooyoul Lee <jy.exe.lee@samsung.com>
+ * Juyoung Kim <j0.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+package org.tizen.dynamicanalyzer.ui.summary.profiling;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.tizen.dynamicanalyzer.common.path.PathConstants;
+import org.tizen.dynamicanalyzer.swap.callstack.BaseCallstackManager;
+import org.tizen.dynamicanalyzer.swap.model.data.ProfileData;
+import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackItem;
+import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackUnit;
+
+public class RangeProfileDataMaker extends ProfileDataMaker {
+
+ public RangeProfileDataMaker(BaseCallstackManager callstackManager) {
+ super(callstackManager);
+ }
+
+ @Override
+ public void makeFunctionUsageProfileData(ProfileData sampleLog) {
+ totalSampleCount++;
+ List<Long> addrs = new ArrayList<Long>();
+ long selfAddr = sampleLog.getPcAddr();
+ int pid = sampleLog.getPid();
+ int tid = sampleLog.getTid();
+ long sampleTime = sampleLog.getTime();
+
+ Map<Long, CallStackUnit> addrMap = callstackManager.getCallStackApiAddrByPidMap(pid);
+
+ CallStackUnit selfCallstackUnit = addrMap.get(selfAddr);
+ if (null == selfCallstackUnit) {
+ selfCallstackUnit = new CallStackUnit(selfAddr, callstackManager.getCallStackSymbol(
+ selfAddr, pid, sampleTime), sampleLog);
+ addrMap.put(selfAddr, selfCallstackUnit);
+ }
+
+ List<CallStackItem> userCallstack = callstackManager.getUserCallstack(tid);
+ int callstackSize = userCallstack.size();
+
+ for (int i = 0; i < callstackSize; i++) {
+ long addr = userCallstack.get(i).getCallStackUnit().getAddr();
+ addrs.add(addr);
+ }
+ addrs.add(selfAddr);
+
+ // drop samples of probe library
+ if (selfCallstackUnit.getPath().startsWith(PathConstants.DA_REMOTE_PROBE_PATH)) {
+ return;
+ }
+
+ String inputPath = selfCallstackUnit.getPath();
+ String inputFuncName = selfCallstackUnit.getFunctionName();
+
+ ProfilingData parent = getProfilingDataByKey(inputPath);
+ // exclusive cpu time
+ if (null == parent) {
+ parent = makeNewProfilingData(selfCallstackUnit, true);
+ checkUserCall(selfCallstackUnit, parent, null, sampleLog);
+ if (inputFuncName.equals(FunctionUsageProfiler.UNKNOWN)) {
+ parent.addExCount();
+ } else {
+ ProfilingData child = makeNewProfilingData(selfCallstackUnit, false);
+ parent.addChild(child);
+ child.addExCount();
+ child.setParent(parent.getName());
+ }
+ } else {
+ if (inputFuncName.isEmpty()) {
+ parent.addExCount();
+ } else {
+ ProfilingData child = getProfilingDataByKey(selfCallstackUnit.getSymbol());
+ if (null == child) {
+ child = makeNewProfilingData(selfCallstackUnit, false);
+ parent.addChild(child);
+ child.setParent(parent.getName());
+ }
+ child.addExCount();
+ }
+ }
+
+ // inclusive cpu time
+ int size = 0;
+ if (null != addrs) {
+ size = addrs.size();
+ }
+ for (int i = 0; i < size; i++) {
+ CallStackUnit callstackCsa = addrMap.get(addrs.get(i));
+
+ 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, sampleLog);
+ }
+ inParent.addInCount(totalSampleCount);
+
+ if (null != inParent.getParent()) {
+ String pInParentName = inParent.getParent();
+ pp = getProfilingDataByKey(pInParentName);
+ if (null != pp) {
+ 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, sampleLog);
+ }
+ 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);
+ if (null != pp) {
+ 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);
+ if (null != ppData) {
+ ppData.addInCount(totalSampleCount);
+ }
+ }
+ }
+ fupData.addInCount(totalSampleCount);
+ }
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Dynamic Analyzer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * WooJin Jung <woojin2.jung@samsung.com>
+ * Jooyoul Lee <jy.exe.lee@samsung.com>
+ * Juyoung Kim <j0.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+package org.tizen.dynamicanalyzer.ui.summary.profiling;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
+import org.tizen.dynamicanalyzer.common.AnalyzerManager;
+import org.tizen.dynamicanalyzer.common.path.PathConstants;
+import org.tizen.dynamicanalyzer.communicator.DACommunicator;
+import org.tizen.dynamicanalyzer.swap.callstack.RuntimeCallstackManager;
+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.info.callstack.CallStackUnit;
+import org.tizen.dynamicanalyzer.util.Logger;
+
+public class RuntimeProfileDataMaker extends ProfileDataMaker {
+
+ public RuntimeProfileDataMaker() {
+ super(AnalyzerManager.getRuntimeCallstackManager());
+ }
+
+ public void makeFunctionUsageProfileData(ProfileData sampleLog) {
+ totalSampleCount++;
+ List<Long> addrs = null;
+ long selfAddr = sampleLog.getPcAddr();
+ int pid = sampleLog.getPid();
+
+ if (DACommunicator.isSWAPVersion()) {
+ long userCallstackSeq;
+ int tid = sampleLog.getTid();
+ long sampleTime = sampleLog.getTime();
+
+ CallStackData callstackData;
+ Map<Long, CallStackUnit> addrMap = callstackManager.getCallStackApiAddrByPidMap(pid);
+
+ CallStackUnit callstackUnit = addrMap.get(selfAddr);
+ if (null == callstackUnit) {
+ CallStackUnit newCallstackUnit = new CallStackUnit(selfAddr,
+ callstackManager.getCallStackSymbol(selfAddr, pid, sampleTime), sampleLog);
+ ((RuntimeCallstackManager) callstackManager).offerCallStackUnit(newCallstackUnit);
+ addrMap.put(selfAddr, newCallstackUnit);
+ }
+
+ userCallstackSeq = callstackManager.getSeqOfUserCallstackForTime(tid, sampleTime);
+ if (-1 != userCallstackSeq) {
+ callstackData = callstackManager.getCallStackDataBySeqMap().get(userCallstackSeq);
+ if (null == callstackData) {
+ Logger.debug("CallStackData is not found for seq : " + userCallstackSeq);
+ addrs = new ArrayList<Long>();
+ addrs.add(selfAddr);
+ } else {
+ addrs = new ArrayList<Long>(callstackData.getAddrs());
+ for (int i = 0; i < addrs.size(); i++) {
+ if (addrs.get(i) == 0) {
+ addrs.remove(i);
+ }
+ }
+ addrs.add(0, selfAddr);
+ }
+ } else {
+ // Logger.debug("makeFunctionUsageProfileData : cannot find seq by time");
+ addrs = new ArrayList<Long>();
+ addrs.add(selfAddr);
+ }
+
+ } else {
+ String callstack = sampleLog.getCallstack();
+ if (null == callstack) {
+ return;
+ }
+ String[] splitCallstack = callstack.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]));
+ }
+
+ addrs = makeCallstackHashAndList(sampleCallstack, sampleLog);
+ }
+
+ Map<Long, CallStackUnit> addrMap = callstackManager.getCallStackApiAddrByPidMap(pid);
+ CallStackUnit inputData = addrMap.get(selfAddr);
+ if (null == inputData) {
+ return;
+ }
+
+ // drop samples of probe library
+ if (inputData.getPath().startsWith(PathConstants.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, sampleLog);
+ 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
+ int size = 0;
+ if (null != addrs) {
+ size = addrs.size();
+ }
+ for (int i = 0; i < size; i++) {
+ CallStackUnit callstackCsa = addrMap.get(addrs.get(i));
+
+ 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, sampleLog);
+ }
+ inParent.addInCount(totalSampleCount);
+
+ if (null != inParent.getParent()) {
+ String pInParentName = inParent.getParent();
+ pp = getProfilingDataByKey(pInParentName);
+ if (null != pp) {
+ 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, sampleLog);
+ }
+ 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);
+ if (null != pp) {
+ pp.addInCount(totalSampleCount);
+ }
+ }
+ } else {
+ String pName = fupData.getParent();
+ ProfilingData inParent = getProfilingDataByKey(pName);
+ if (inParent == null) {
+ Logger.error("ProfilingData: function item without library item");
+ continue;
+ }
+ inParent.addInCount(totalSampleCount);
+
+ if (null != inParent.getParent()) {
+ String pInParentName = inParent.getParent();
+ ProfilingData ppData = getProfilingDataByKey(pInParentName);
+ if (null != ppData) {
+ ppData.addInCount(totalSampleCount);
+ }
+ }
+ }
+ fupData.addInCount(totalSampleCount);
+ }
+ }
+ }
+
+ private List<Long> makeCallstackHashAndList(List<String> callstackLog, LogData log) {
+ int pid = log.getPid();
+ Map<Long, CallStackUnit> addrMap = callstackManager.getCallStackApiAddrByPidMap(pid);
+ 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) {
+ Logger.exception(e);
+ return null;
+ }
+ addrs.add(addr);
+
+ CallStackUnit callstackUnit = addrMap.get(addr);
+ if (null == callstackUnit) {
+ String funcName = callstackLog.get(i + 1);
+ CallStackUnit newCallstackUnit = new CallStackUnit(addr, funcName, log);
+ ((RuntimeCallstackManager) callstackManager).offerCallStackUnit(newCallstackUnit);
+ addrMap.put(addr, newCallstackUnit);
+ }
+ }
+ return addrs;
+ }
+}