import org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider;
import org.eclipse.tracecompass.common.core.StreamUtils;
import org.eclipse.tracecompass.internal.analysis.timing.core.Activator;
-import org.eclipse.tracecompass.internal.analysis.timing.core.store.ArrayListStore;
+import org.eclipse.tracecompass.internal.analysis.timing.core.store.LazyArrayListStore;
import org.eclipse.tracecompass.segmentstore.core.ISegment;
import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
import org.eclipse.tracecompass.tmf.core.callstack.CallStackAnalysis;
/**
* Segment store
*/
- private final ISegmentStore<@NonNull ISegment> fStore = new ArrayListStore<>();
+ private final ISegmentStore<@NonNull ISegment> fStore = new LazyArrayListStore<>();
/**
* Listeners
* The List of thread nodes. Each thread has a virtual node having the root
* function as children
*/
- private List<AggregatedCalledFunction> fThreadNodes = new ArrayList<>();
+ private List<ThreadNode> fThreadNodes = new ArrayList<>();
/**
* Default constructor
}
List<Integer> processQuarks = ss.getQuarks(processesPattern);
for (int processQuark : processQuarks) {
+ int processId = getProcessId(ss, processQuark, ss.getCurrentEndTime());
for (int threadQuark : ss.getQuarks(processQuark, threadsPattern)) {
- if (!iterateOverQuark(ss, threadQuark, callStackPath, monitor)) {
+ if (!iterateOverQuark(ss, processId, threadQuark, callStackPath, monitor)) {
return false;
}
}
*
* @param stateSystem
* The state system
- * @param quark
- * The quark
+ * @param processId
+ * The process ID of the traced application
+ * @param threadQuark
+ * The thread quark
* @param subAttributePath
* sub-Attributes path
* @param monitor
* The monitor
* @return Boolean
*/
- private boolean iterateOverQuark(ITmfStateSystem stateSystem, int quark, String[] subAttributePath, IProgressMonitor monitor) {
- String threadName = stateSystem.getAttributeName(quark);
- AggregatedCalledFunction init = null;
+ private boolean iterateOverQuark(ITmfStateSystem stateSystem, int processId, int threadQuark, String[] subAttributePath, IProgressMonitor monitor) {
+ String threadName = stateSystem.getAttributeName(threadQuark);
+ long threadId = -1;
+ ITmfStateInterval interval = null;
+ try {
+ interval = stateSystem.querySingleState(stateSystem.getStartTime(), threadQuark);
+ ITmfStateValue threadStateValue = interval.getStateValue();
+ if (threadStateValue.getType() == Type.LONG || threadStateValue.getType() == Type.INTEGER) {
+ threadId = threadStateValue.unboxLong();
+ } else {
+ try {
+ threadId = Long.parseLong(threadName);
+ } catch (NumberFormatException e) {
+ /* use default threadId */
+ }
+ }
+ } catch (StateSystemDisposedException error) {
+ Activator.getInstance().logError(Messages.QueringStateSystemError, error);
+ }
try {
long curTime = stateSystem.getStartTime();
long limit = stateSystem.getCurrentEndTime();
- AbstractCalledFunction initSegment = CalledFunctionFactory.create(0, 0, 0, threadName, null);
- init = new AggregatedCalledFunction(initSegment, 0);
+ AbstractCalledFunction initSegment = CalledFunctionFactory.create(0, 0, 0, threadName, processId, null);
+ ThreadNode init = new ThreadNode(initSegment, 0, threadId);
while (curTime < limit) {
if (monitor.isCanceled()) {
return false;
}
- int callStackQuark = stateSystem.getQuarkRelative(quark, subAttributePath);
+ int callStackQuark = stateSystem.getQuarkRelative(threadQuark, subAttributePath);
fCurrentQuarks = stateSystem.getSubAttributes(callStackQuark, false);
if (fCurrentQuarks.isEmpty()) {
return false;
}
final int depth = 0;
int quarkParent = fCurrentQuarks.get(depth);
- ITmfStateInterval interval = stateSystem.querySingleState(curTime, quarkParent);
+ interval = stateSystem.querySingleState(curTime, quarkParent);
ITmfStateValue stateValue = interval.getStateValue();
if (!stateValue.isNull()) {
long intervalStart = interval.getStartTime();
long intervalEnd = interval.getEndTime();
// Create the segment for the first call event.
- AbstractCalledFunction segment = CalledFunctionFactory.create(intervalStart, intervalEnd + 1, depth, stateValue, null);
+ AbstractCalledFunction segment = CalledFunctionFactory.create(intervalStart, intervalEnd + 1, depth, stateValue, processId, null);
fRootFunctions.add(segment);
AggregatedCalledFunction firstNode = new AggregatedCalledFunction(segment, fCurrentQuarks.size());
- if (!findChildren(segment, depth, stateSystem, fCurrentQuarks.size() + fCurrentQuarks.get(depth), firstNode, monitor)) {
+ if (!findChildren(segment, depth, stateSystem, fCurrentQuarks.size() + fCurrentQuarks.get(depth), firstNode, processId, monitor)) {
return false;
}
init.addChild(firstNode);
curTime = interval.getEndTime() + 1;
}
-
+ fThreadNodes.add(init);
} catch (AttributeNotFoundException | StateSystemDisposedException | TimeRangeException e) {
Activator.getInstance().logError(Messages.QueringStateSystemError, e);
return false;
}
- fThreadNodes.add(init);
return true;
}
* The quark of the segment parent ss The actual state system
* @param maxQuark
* The last quark in the state system
- * @param AggregatedCalledFunction
+ * @param aggregatedCalledFunction
* A node in the aggregation tree
+ * @param processId
+ * The process ID of the traced application
* @param monitor
* The progress monitor The progress monitor TODO: if stack size
* is an issue, convert to a stack instead of recursive function
*/
- private boolean findChildren(AbstractCalledFunction node, int depth, ITmfStateSystem ss, int maxQuark, AggregatedCalledFunction aggregatedCalledFunction, IProgressMonitor monitor) {
+ private boolean findChildren(AbstractCalledFunction node, int depth, ITmfStateSystem ss, int maxQuark, AggregatedCalledFunction aggregatedCalledFunction, int processId, IProgressMonitor monitor) {
fStore.add(node);
long curTime = node.getStart();
long limit = node.getEnd();
if (intervalStart < node.getStart() || intervalEnd > limit) {
return true;
}
- AbstractCalledFunction segment = CalledFunctionFactory.create(intervalStart, intervalEnd + 1, node.getDepth() + 1, stateValue, node);
+ AbstractCalledFunction segment = CalledFunctionFactory.create(intervalStart, intervalEnd + 1, node.getDepth() + 1, stateValue, processId, node);
AggregatedCalledFunction childNode = new AggregatedCalledFunction(segment, aggregatedCalledFunction);
// Search for the children with the next quark.
- findChildren(segment, depth + 1, ss, maxQuark, childNode, monitor);
+ findChildren(segment, depth + 1, ss, maxQuark, childNode, processId, monitor);
aggregatedCalledFunction.addChild(childNode);
node.addChild(segment);
}
*
* @return The thread nodes
*/
- public List<AggregatedCalledFunction> getThreadNodes() {
+ public List<ThreadNode> getThreadNodes() {
return ImmutableList.copyOf(fThreadNodes);
}
+ private static int getProcessId(ITmfStateSystem ss, int processQuark, long curTime) {
+ int processId = -1;
+ if (processQuark != ITmfStateSystem.ROOT_ATTRIBUTE) {
+ try {
+ ITmfStateInterval interval = ss.querySingleState(curTime, processQuark);
+ String processName = ss.getAttributeName(processQuark);
+ ITmfStateValue processStateValue = interval.getStateValue();
+ if (processStateValue.getType() == Type.INTEGER) {
+ processId = processStateValue.unboxInt();
+ } else {
+ try {
+ processId = Integer.parseInt(processName);
+ } catch (NumberFormatException e) {
+ /* use default processId */
+ }
+ }
+ } catch (StateSystemDisposedException e) {
+ // ignore
+ }
+ }
+ return processId;
+ }
}
\ No newline at end of file