linux: make KernelStateProvider handle aggregate prev_states of sched_switch
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 25 Jan 2016 21:02:31 +0000 (16:02 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 26 Feb 2016 19:50:34 +0000 (14:50 -0500)
Use an if statement instead of a switch to check individual bits in the
prev_state bitmask.

fixes bug 486515

An example would be any state of EXIT_TRACE where it is two bits,
EXIT_ZOMBIE and EXIT_DEAD that are active. In the previous implementation
the state would be UNKNOWN, but now it would correctly show DEAD (null).

Change-Id: Ia9372e4d196e3a87a1e902753803a87ecafb3b33
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/65139
Reviewed-by: Hudson CI
Reviewed-by: Francis Giraldeau <francis.giraldeau@gmail.com>
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedSwitchHandler.java

index a0d83776d98e3c61004a2e4af0ae19083ee0f5df..1fb7b0ccd618d98ba4e5e4372909527992a093b8 100644 (file)
@@ -86,33 +86,41 @@ public class SchedSwitchHandler extends KernelEventHandler {
     private static void setOldProcessStatus(ITmfStateSystemBuilder ss, Long prevState, Integer formerThreadNode, long timestamp) throws AttributeNotFoundException {
         ITmfStateValue value;
         /*
-         * Empirical observations and look into the linux code have
-         * shown that the TASK_STATE_MAX flag is used internally and
-         * |'ed with other states, most often the running state, so it
-         * is ignored from the prevState value.
+         * Empirical observations and look into the linux code have shown that
+         * the TASK_STATE_MAX flag is used internally and |'ed with other
+         * states, most often the running state, so it is ignored from the
+         * prevState value.
          */
         int state = (int) (prevState & ~(LinuxValues.TASK_STATE_MAX));
 
-        switch (state) {
-        case LinuxValues.TASK_STATE_RUNNING:
+        if (isRunning(state)) {
             value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE;
-            break;
-        case LinuxValues.TASK_INTERRUPTIBLE:
-        case LinuxValues.TASK_UNINTERRUPTIBLE:
+        } else if (isWaiting(state)) {
             value = StateValues.PROCESS_STATUS_WAIT_BLOCKED_VALUE;
-            break;
-        case LinuxValues.TASK_DEAD:
+        } else if (isDead(state)) {
             value = TmfStateValue.nullValue();
-            break;
-        default:
+        } else {
             value = StateValues.PROCESS_STATUS_WAIT_UNKNOWN_VALUE;
-            break;
         }
         int quark = ss.getQuarkRelativeAndAdd(formerThreadNode, Attributes.STATUS);
         ss.modifyAttribute(timestamp, value, quark);
 
     }
 
+    private static boolean isDead(int state) {
+        return (state & LinuxValues.TASK_DEAD) != 0;
+    }
+
+    private static boolean isWaiting(int state) {
+        return (state & (LinuxValues.TASK_INTERRUPTIBLE | LinuxValues.TASK_UNINTERRUPTIBLE)) != 0;
+    }
+
+    private static boolean isRunning(int state) {
+        // special case, this means ALL STATES ARE 0
+        // this is effectively an anti-state
+        return state == 0;
+    }
+
     private static void setCpuStatus(ITmfStateSystemBuilder ss, Integer nextTid, Integer newCurrentThreadNode, long timestamp, int currentCPUNode) throws AttributeNotFoundException {
         int quark;
         ITmfStateValue value;
This page took 0.027599 seconds and 5 git commands to generate.