timing: Bug 500592: fix symbols for with debug info of Lttng 2.8
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.core / src / org / eclipse / tracecompass / internal / analysis / timing / core / callgraph / CallGraphAnalysis.java
index 8b87520a1ad5a0f3d48033a261c7bf8b1f8a0e26..e679508037e666aa05b9400d7ed5e7ab0a095158 100644 (file)
@@ -23,7 +23,7 @@ import org.eclipse.tracecompass.analysis.timing.core.segmentstore.IAnalysisProgr
 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;
@@ -32,6 +32,7 @@ import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedE
 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;
@@ -69,7 +70,7 @@ public abstract class CallGraphAnalysis extends TmfAbstractAnalysisModule implem
     /**
      * Segment store
      */
-    private final ISegmentStore<@NonNull ISegment> fStore = new ArrayListStore<>();
+    private final ISegmentStore<@NonNull ISegment> fStore = new LazyArrayListStore<>();
 
     /**
      * Listeners
@@ -89,7 +90,7 @@ public abstract class CallGraphAnalysis extends TmfAbstractAnalysisModule implem
      * 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
@@ -179,8 +180,9 @@ public abstract class CallGraphAnalysis extends TmfAbstractAnalysisModule implem
         }
         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;
                 }
             }
@@ -195,44 +197,62 @@ public abstract class CallGraphAnalysis extends TmfAbstractAnalysisModule implem
      *
      * @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);
@@ -240,12 +260,11 @@ public abstract class CallGraphAnalysis extends TmfAbstractAnalysisModule implem
 
                 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;
     }
 
@@ -262,13 +281,15 @@ public abstract class CallGraphAnalysis extends TmfAbstractAnalysisModule implem
      *            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();
@@ -294,10 +315,10 @@ public abstract class CallGraphAnalysis extends TmfAbstractAnalysisModule implem
                 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);
             }
@@ -363,8 +384,30 @@ public abstract class CallGraphAnalysis extends TmfAbstractAnalysisModule implem
      *
      * @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
This page took 0.035258 seconds and 5 git commands to generate.