os.linux: Move buildThreadAttributeName() methods to Attributes interface
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 8 Apr 2016 21:41:23 +0000 (17:41 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Tue, 12 Apr 2016 21:06:41 +0000 (17:06 -0400)
The method buildThreadAttributeName() and its counterpart
parseThreadAttributeName() are related to attributes tree
walking, and not to the event handlers themselves. Move them
to the Attributes interface.

Change-Id: Ide7b7154cfff0e12f74eda7a64f3545114b93e80
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/70298

analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/event/aspect/ThreadPriorityAspect.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/Attributes.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/KernelEventHandlerUtils.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/PiSetprioHandler.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/ProcessForkHandler.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/ProcessFreeHandler.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedSwitchHandler.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedWakeupHandler.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/StateDumpHandler.java
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/controlflow/ControlFlowView.java

index 58092f4ab13e4590db5ea0a1c6a15f1cc074a064..9702577776e39fd7ee0479508823136d369dafa2 100644 (file)
@@ -18,7 +18,6 @@ import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModu
 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelTidAspect;
 import org.eclipse.tracecompass.common.core.NonNullUtils;
 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.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
@@ -82,7 +81,7 @@ public final class ThreadPriorityAspect implements ITmfEventAspect {
                 /* Find the CPU this event is run on */
                 cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(trace, TmfCpuAspect.class, event);
             }
-            int execPrioQuark = ss.getQuarkAbsolute(Attributes.THREADS, KernelEventHandlerUtils.buildThreadAttributeName(tid, cpu), Attributes.PRIO);
+            int execPrioQuark = ss.getQuarkAbsolute(Attributes.THREADS, Attributes.buildThreadAttributeName(tid, cpu), Attributes.PRIO);
             ITmfStateInterval interval = ss.querySingleState(ts, execPrioQuark);
             ITmfStateValue prioValue = interval.getStateValue();
             /* We know the prio must be an Integer */
index b5e50b0eb405b5bc84b6b23d18a55d1b435b5456..89e370d738777756ef0410afc1c6914bcef3455c 100644 (file)
@@ -9,6 +9,9 @@
 
 package org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel;
 
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.tmf.core.util.Pair;
+
 /**
  * This file defines all the attribute names used in the handler. Both the
  * construction and query steps should use them.
@@ -19,9 +22,8 @@ package org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel;
  * be done on the viewer side.
  *
  * @author Alexandre Montplaisir
- * @since 2.0
  */
-@SuppressWarnings({"nls", "javadoc"})
+@SuppressWarnings({ "nls", "javadoc" })
 public interface Attributes {
 
     /* First-level attributes */
@@ -36,10 +38,9 @@ public interface Attributes {
 
     /* Sub-attributes of the Thread nodes */
     String PPID = "PPID";
-    //static final String STATUS = "Status"
+    // static final String STATUS = "Status"
     String EXEC_NAME = "Exec_name";
 
-    /** @since 1.0 */
     String PRIO = "Prio";
     String SYSTEM_CALL = "System_call";
 
@@ -47,4 +48,61 @@ public interface Attributes {
     String UNKNOWN = "Unknown";
     String THREAD_0_PREFIX = "0_";
     String THREAD_0_SEPARATOR = "_";
+
+    /**
+     * Build the thread attribute name.
+     *
+     * For all threads except "0" this is the string representation of the
+     * threadId. For thread "0" which is the idle thread and can be running
+     * concurrently on multiple CPUs, append "_cpuId".
+     *
+     * @param threadId
+     *            the thread id
+     * @param cpuId
+     *            the cpu id
+     * @return the thread attribute name null if the threadId is zero and the
+     *         cpuId is null
+     */
+    public static @Nullable String buildThreadAttributeName(int threadId, @Nullable Integer cpuId) {
+        if (threadId == 0) {
+            if (cpuId == null) {
+                return null;
+            }
+            return Attributes.THREAD_0_PREFIX + String.valueOf(cpuId);
+        }
+
+        return String.valueOf(threadId);
+    }
+
+    /**
+     * Parse the thread id and CPU id from the thread attribute name string
+     *
+     * For thread "0" the attribute name is in the form "threadId_cpuId",
+     * extract both values from the string.
+     *
+     * For all other threads, the attribute name is the string representation of
+     * the threadId and there is no cpuId.
+     *
+     * @param threadAttributeName
+     *            the thread attribute name
+     * @return the thread id and cpu id
+     */
+    public static Pair<Integer, Integer> parseThreadAttributeName(String threadAttributeName) {
+        Integer threadId = -1;
+        Integer cpuId = -1;
+
+        try {
+            if (threadAttributeName.startsWith(Attributes.THREAD_0_PREFIX)) {
+                threadId = 0;
+                String[] tokens = threadAttributeName.split(Attributes.THREAD_0_SEPARATOR);
+                cpuId = Integer.parseInt(tokens[1]);
+            } else {
+                threadId = Integer.parseInt(threadAttributeName);
+            }
+        } catch (NumberFormatException e1) {
+            // pass
+        }
+
+        return new Pair<>(threadId, cpuId);
+    }
 }
index 089342388058b2c7f2a273168e31006ce2b34cff..b1cc556ccc17399cb081aebc494d03f9af07f371 100644 (file)
@@ -23,7 +23,6 @@ import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
-import org.eclipse.tracecompass.tmf.core.util.Pair;
 
 /**
  * Kernel Event Handler Utils is a collection of static methods to be used in
@@ -100,7 +99,7 @@ public final class KernelEventHandlerUtils {
         int quark = ss.getQuarkRelativeAndAdd(getCurrentCPUNode(cpuNumber, ss), Attributes.CURRENT_THREAD);
         ITmfStateValue value = ss.queryOngoingState(quark);
         int thread = value.isNull() ? -1 : value.unboxInt();
-        return ss.getQuarkRelativeAndAdd(getNodeThreads(ss), buildThreadAttributeName(thread, cpuNumber));
+        return ss.getQuarkRelativeAndAdd(getNodeThreads(ss), Attributes.buildThreadAttributeName(thread, cpuNumber));
     }
 
     /**
@@ -279,63 +278,4 @@ public final class KernelEventHandlerUtils {
                 StateValues.CPU_STATUS_RUN_USERMODE_VALUE :
                 StateValues.CPU_STATUS_RUN_SYSCALL_VALUE);
     }
-
-    /**
-     * Build the thread attribute name.
-     *
-     * For all threads except "0" this is the string representation of the threadId.
-     * For thread "0" which is the idle thread and can be running concurrently on multiple
-     * CPUs, append "_cpuId".
-     *
-     * @param threadId
-     *              the thread id
-     * @param cpuId
-     *              the cpu id
-     *
-     * @return the thread attribute name
-     *         null if the threadId is zero and the cpuId is null
-     */
-    public static @Nullable String buildThreadAttributeName(int threadId, @Nullable Integer cpuId) {
-
-        if (threadId == 0) {
-            if (cpuId == null) {
-                return null;
-            }
-            return Attributes.THREAD_0_PREFIX + String.valueOf(cpuId);
-        }
-
-        return String.valueOf(threadId);
-    }
-
-    /**
-     * Parse the thread id and CPU id from the thread attribute name string
-     *
-     * For thread "0" the attribute name is in the form "threadId_cpuId", extract both
-     * values from the string.
-     *
-     * For all other threads, the attribute name is the string representation of the
-     * threadId and there is no cpuId.
-     *
-     * @param threadAttributeName
-     *              the thread attribute name
-     * @return the thread id and cpu id
-     */
-    public static Pair<Integer, Integer> parseThreadAttributeName(String threadAttributeName) {
-        Integer threadId = -1;
-        Integer cpuId = -1;
-
-        try {
-            if (threadAttributeName.startsWith(Attributes.THREAD_0_PREFIX)) {
-                threadId = 0;
-                String[] tokens = threadAttributeName.split(Attributes.THREAD_0_SEPARATOR);
-                cpuId = Integer.parseInt(tokens[1]);
-            } else {
-                threadId = Integer.parseInt(threadAttributeName);
-            }
-        } catch (NumberFormatException e1) {
-            //pass
-        }
-
-        return new Pair<>(threadId, cpuId);
-    }
 }
index 6d21c3200c1e4133d7a034def060f6180a5dcaba..722bc5c1185517bee7315870ce639c9c70298634 100644 (file)
@@ -41,7 +41,7 @@ public class PiSetprioHandler extends KernelEventHandler {
         Integer tid = ((Long) content.getField(getLayout().fieldTid()).getValue()).intValue();
         Integer prio = ((Long) content.getField(getLayout().fieldNewPrio()).getValue()).intValue();
 
-        String threadAttributeName = KernelEventHandlerUtils.buildThreadAttributeName(tid, cpu);
+        String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu);
         if (threadAttributeName == null) {
             return;
         }
index f3ffaaac95c2f9f4037db29fc6901bb73524a3f0..4696c25bf01c8bbeace0dbf3da2ec2b8f29127d5 100644 (file)
@@ -46,12 +46,12 @@ public class ProcessForkHandler extends KernelEventHandler {
         Integer parentTid = ((Long) content.getField(getLayout().fieldParentTid()).getValue()).intValue();
         Integer childTid = ((Long) content.getField(getLayout().fieldChildTid()).getValue()).intValue();
 
-        String parentThreadAttributeName = KernelEventHandlerUtils.buildThreadAttributeName(parentTid, cpu);
+        String parentThreadAttributeName = Attributes.buildThreadAttributeName(parentTid, cpu);
         if (parentThreadAttributeName == null) {
             return;
         }
 
-        String childThreadAttributeName = KernelEventHandlerUtils.buildThreadAttributeName(childTid, cpu);
+        String childThreadAttributeName = Attributes.buildThreadAttributeName(childTid, cpu);
         if (childThreadAttributeName == null) {
             return;
         }
index 7c3b4d4be911523da70c0061a8a9faca69122e9d..a02a10bd56b6a6d599677a9a1e87260831d660e5 100644 (file)
@@ -13,6 +13,7 @@
 package org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers;
 
 import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
+import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
@@ -38,7 +39,7 @@ public class ProcessFreeHandler extends KernelEventHandler {
         Integer cpu = KernelEventHandlerUtils.getCpu(event);
         Integer tid = ((Long) event.getContent().getField(getLayout().fieldTid()).getValue()).intValue();
 
-        String threadAttributeName = KernelEventHandlerUtils.buildThreadAttributeName(tid, cpu);
+        String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu);
         if (threadAttributeName == null) {
             return;
         }
index 94238ce5074452abccea8ce617743e1ed07bb2c3..1387f494ab59d80c2895a316e3b4ad371fb43d51 100644 (file)
@@ -55,8 +55,8 @@ public class SchedSwitchHandler extends KernelEventHandler {
         Integer nextPrio = ((Long) content.getField(getLayout().fieldNextPrio()).getValue()).intValue();
 
         /* Will never return null since "cpu" is null checked */
-        String formerThreadAttributeName = KernelEventHandlerUtils.buildThreadAttributeName(prevTid, cpu);
-        String currenThreadAttributeName = KernelEventHandlerUtils.buildThreadAttributeName(nextTid, cpu);
+        String formerThreadAttributeName = Attributes.buildThreadAttributeName(prevTid, cpu);
+        String currenThreadAttributeName = Attributes.buildThreadAttributeName(nextTid, cpu);
 
         int nodeThreads = KernelEventHandlerUtils.getNodeThreads(ss);
         int formerThreadNode = ss.getQuarkRelativeAndAdd(nodeThreads, formerThreadAttributeName);
index 625dbcdc49aa8dd7422028bb59e51dc842b04e69..d0fb0940d6b8965c6446e58f3309a1161c4f6184 100644 (file)
@@ -40,7 +40,7 @@ public class SchedWakeupHandler extends KernelEventHandler {
         final int tid = ((Long) event.getContent().getField(getLayout().fieldTid()).getValue()).intValue();
         final int prio = ((Long) event.getContent().getField(getLayout().fieldPrio()).getValue()).intValue();
 
-        String threadAttributeName = KernelEventHandlerUtils.buildThreadAttributeName(tid, cpu);
+        String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu);
         if (threadAttributeName == null) {
             return;
         }
index ea75bcd322137c5bd9a594057cd457af76479233..020b145c589a920ae8cf59552ab876b3303d1b29 100644 (file)
@@ -54,7 +54,7 @@ public class StateDumpHandler extends KernelEventHandler {
          * with anything relevant for now.
          */
 
-        String threadAttributeName = KernelEventHandlerUtils.buildThreadAttributeName(tid, cpu);
+        String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu);
         if (threadAttributeName == null) {
             return;
         }
index 1835f8f48c9adefafb6e978033d95d293e672da1..c31fd207797655cd8364f9c2507c8ca7e822d883 100644 (file)
@@ -32,7 +32,6 @@ import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.widgets.Composite;
 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;
@@ -284,7 +283,7 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
                     for (int threadQuark : threadQuarks) {
                         String threadAttributeName = ssq.getAttributeName(threadQuark);
 
-                        Pair<Integer, Integer> entryKey = KernelEventHandlerUtils.parseThreadAttributeName(threadAttributeName);
+                        Pair<Integer, Integer> entryKey = Attributes.parseThreadAttributeName(threadAttributeName);
                         int threadId = entryKey.getFirst();
 
                         if (threadId < 0) { // ignore the 'unknown' (-1) thread
This page took 0.030604 seconds and 5 git commands to generate.