os.linux: Move Attributes class to internal package
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui / src / org / eclipse / tracecompass / analysis / os / linux / ui / views / controlflow / ControlFlowView.java
index 99dc269f6f5caed7af99f1f4d8e835831d10cad6..1835f8f48c9adefafb6e978033d95d293e672da1 100644 (file)
@@ -24,13 +24,18 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.Attributes;
-import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule;
+import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
+import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes;
+import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers.KernelEventHandlerUtils;
 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.Activator;
 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.Messages;
+import org.eclipse.tracecompass.internal.analysis.os.linux.ui.actions.FollowThreadAction;
 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow.ControlFlowColumnComparators;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
@@ -42,6 +47,7 @@ import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.util.Pair;
 import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractStateSystemTimeGraphView;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
@@ -94,13 +100,15 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
 
     private static final Comparator<ITimeGraphEntry>[] COLUMN_COMPARATORS;
 
+    private static final int INITIAL_SORT_COLUMN_INDEX = 3;
+
     static {
         ImmutableList.Builder<Comparator<ITimeGraphEntry>> builder = ImmutableList.builder();
         builder.add(ControlFlowColumnComparators.PROCESS_NAME_COLUMN_COMPARATOR)
-               .add(ControlFlowColumnComparators.TID_COLUMN_COMPARATOR)
-               .add(ControlFlowColumnComparators.PTID_COLUMN_COMPARATOR)
-               .add(ControlFlowColumnComparators.BIRTH_TIME_COLUMN_COMPARATOR)
-               .add(ControlFlowColumnComparators.TRACE_COLUMN_COMPARATOR);
+            .add(ControlFlowColumnComparators.TID_COLUMN_COMPARATOR)
+            .add(ControlFlowColumnComparators.PTID_COLUMN_COMPARATOR)
+            .add(ControlFlowColumnComparators.BIRTH_TIME_COLUMN_COMPARATOR)
+            .add(ControlFlowColumnComparators.TRACE_COLUMN_COMPARATOR);
         List<Comparator<ITimeGraphEntry>> l = builder.build();
         COLUMN_COMPARATORS = l.toArray(new Comparator[l.size()]);
     }
@@ -114,7 +122,7 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
      */
     public ControlFlowView() {
         super(ID, new ControlFlowPresentationProvider());
-        setTreeColumns(COLUMN_NAMES, COLUMN_COMPARATORS, 3);
+        setTreeColumns(COLUMN_NAMES, COLUMN_COMPARATORS, INITIAL_SORT_COLUMN_INDEX);
         setTreeLabelProvider(new ControlFlowTreeLabelProvider());
         setFilterColumns(FILTER_COLUMN_NAMES);
         setFilterLabelProvider(new ControlFlowFilterLabelProvider());
@@ -132,6 +140,21 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
                 new ControlFlowCheckActiveProvider(Messages.ControlFlowView_uncheckInactiveLabel, Messages.ControlFlowView_uncheckInactiveToolTip));
     }
 
+    /**
+     * @since 2.0
+     */
+    @Override
+    protected void fillTimeGraphEntryContextMenu(@NonNull IMenuManager menuManager) {
+        ISelection selection = getSite().getSelectionProvider().getSelection();
+        if (selection instanceof StructuredSelection) {
+            StructuredSelection sSel = (StructuredSelection) selection;
+            if (sSel.getFirstElement() instanceof ControlFlowEntry) {
+                ControlFlowEntry entry = (ControlFlowEntry) sSel.getFirstElement();
+                menuManager.add(new FollowThreadAction(ControlFlowView.this, entry.getName(), entry.getThreadId(), entry.getTrace()));
+            }
+        }
+    }
+
     @Override
     protected void fillLocalToolBar(IToolBarManager manager) {
         super.fillLocalToolBar(manager);
@@ -231,7 +254,8 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
         }
 
         final List<ControlFlowEntry> entryList = new ArrayList<>();
-        final Map<Integer, ControlFlowEntry> entryMap = new HashMap<>();
+        /** Map of view entries, key is a pair [threadId, cpuId] */
+        final Map<Pair<Integer, Integer>, ControlFlowEntry> entryMap = new HashMap<>();
 
         long start = ssq.getStartTime();
         setStartTime(Math.min(getStartTime(), start));
@@ -258,14 +282,12 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
                 @Override
                 public void handle(List<List<ITmfStateInterval>> fullStates, List<ITmfStateInterval> prevFullState) {
                     for (int threadQuark : threadQuarks) {
-                        String threadName = ssq.getAttributeName(threadQuark);
-                        int threadId = -1;
-                        try {
-                            threadId = Integer.parseInt(threadName);
-                        } catch (NumberFormatException e1) {
-                            continue;
-                        }
-                        if (threadId <= 0) { // ignore the 'unknown' (-1) and swapper (0) threads
+                        String threadAttributeName = ssq.getAttributeName(threadQuark);
+
+                        Pair<Integer, Integer> entryKey = KernelEventHandlerUtils.parseThreadAttributeName(threadAttributeName);
+                        int threadId = entryKey.getFirst();
+
+                        if (threadId < 0) { // ignore the 'unknown' (-1) thread
                             continue;
                         }
 
@@ -318,11 +340,11 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
                                     execNameInterval.getStateValue().getType() == ITmfStateValue.Type.STRING) {
                                 String execName = execNameInterval.getStateValue().unboxStr();
                                 int ppid = ppidInterval.getStateValue().unboxInt();
-                                ControlFlowEntry entry = entryMap.get(threadId);
+                                ControlFlowEntry entry = entryMap.get(entryKey);
                                 if (entry == null) {
                                     entry = new ControlFlowEntry(threadQuark, trace, execName, threadId, ppid, startTime, endTime);
                                     entryList.add(entry);
-                                    entryMap.put(threadId, entry);
+                                    entryMap.put(entryKey, entry);
                                 } else {
                                     /*
                                      * Update the name of the entry to the
@@ -335,7 +357,7 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
                                 }
                             }
                             if (isNull) {
-                                entryMap.remove(threadId);
+                                entryMap.remove(entryKey);
                             }
                             lastExecNameStartTime = startTime;
                             lastExecNameEndTime = endTime;
This page took 0.027618 seconds and 5 git commands to generate.