Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[linuxtools-dev] TMF state of processes from LTTng kernel traces

I noticed that the control flow view does not distinguish between processes waiting for CPU (runnable) and processes blocked (e.g. waiting for IO). The information is available from the sched_switch event (prevState) and it is thus easy to add this state information. 

Please find at the end of the message a trivial patch which adds a state (WAIT_BLOCKED) and gets the needed information from the sched_switch event. You need to erase the precomputed state of a trace to see the effect of this change; this could be automated, checking the precomputed state "version" or "TMF build date" versus that of the Eclipse TMF tool. I selected a dark red color for that state but have no strong opinion on the right color. Perhaps you can see what other tools use. 

It may be interesting to further distinguish the state of processes depending on what they are waiting on (CPU, Disk, Network, Pipe, Child...). The state can be determined either by looking at events leading to the wait, or at the end of the wait when we get the wakeup event. 

diff --git a/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/StateValues.java b/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/StateValues.java
index c63d346..851abee 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/StateValues.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/StateValues.java
@@ -36,6 +36,7 @@ public class StateValues {
     public static final int PROCESS_STATUS_RUN_USERMODE = 2;
     public static final int PROCESS_STATUS_RUN_SYSCALL = 3;
     public static final int PROCESS_STATUS_INTERRUPTED = 4;
+    public static final int PROCESS_STATUS_WAIT_BLOCKED = 5;
 
     /* SoftIRQ-specific stuff. -1: null/disabled, >= 0: running on that CPU */
     public static final int SOFT_IRQ_RAISED = -2;
diff --git a/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelStateInput.java b/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelStateInput.java
index 2d48bbb..ddb8ac7 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelStateInput.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/CtfKernelStateInput.java
@@ -224,7 +224,7 @@ public class CtfKernelStateInput extends AbstractStateChangeInput {
              */
             {
                 Integer prevTid = ((Long) content.getField(LttngStrings.PREV_TID).getValue()).intValue();
-                //Long prevState = (Long) content.getField(LttngStrings.PREV_STATE).getValue();
+                Long prevState = (Long) content.getField(LttngStrings.PREV_STATE).getValue();
                 String nextProcessName = (String) content.getField(LttngStrings.NEXT_COMM).getValue();
                 Integer nextTid = ((Long) content.getField(LttngStrings.NEXT_TID).getValue()).intValue();
 
@@ -233,7 +233,12 @@ public class CtfKernelStateInput extends AbstractStateChangeInput {
 
                 /* Set the status of the process that got scheduled out. */
                 quark = ss.getQuarkRelativeAndAdd(formerThreadNode, Attributes.STATUS);
-                value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT);
+                if(prevState != 0) {
+                    value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT_BLOCKED);
+                }
+                else {
+                    value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT);
+                }
                 ss.modifyAttribute(ts, value, quark);
 
                 /* Set the status of the new scheduled process */
@@ -374,9 +379,11 @@ public class CtfKernelStateInput extends AbstractStateChangeInput {
                 /* Set the process' status */
                 quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.STATUS);
                 if (ss.queryOngoingState(quark).isNull()) {
-                    /*"5" here means "LTTNG_WAIT" in the LTTng kernel tracer */
-                    if (status == 5) {
+                    /*"2" here means "WAIT_FOR_CPU" and "5" "WAIT_BLOCKED" in the LTTng kernel */
+                    if (status == 2) {
                         value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT);
+                    } else if (status == 5) {
+                            value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_WAIT_BLOCKED);
                     } else {
                         value = TmfStateValue.newValueInt(StateValues.PROCESS_STATUS_UNKNOWN);
                     }
diff --git a/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java b/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java
index 0023e78..a830ec0 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowPresentationProvider.java
@@ -46,7 +46,8 @@ public class ControlFlowPresentationProvider extends TimeGraphPresentationProvid
         WAIT        (new RGB(200, 200, 0)),
         USERMODE    (new RGB(0, 200, 0)),
         SYSCALL     (new RGB(0, 0, 200)),
-        INTERRUPTED (new RGB(200, 100, 100));
+        INTERRUPTED (new RGB(200, 100, 100)),
+        WAIT_BLOCKED (new RGB(100, 0, 0));
 
         public final RGB rgb;
 
@@ -82,6 +83,8 @@ public class ControlFlowPresentationProvider extends TimeGraphPresentationProvid
                 return State.SYSCALL.ordinal();
             } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {
                 return State.INTERRUPTED.ordinal();
+            } else if (status == StateValues.PROCESS_STATUS_WAIT_BLOCKED) {
+                return State.WAIT_BLOCKED.ordinal();
             }
         }
         return State.UNKNOWN.ordinal();
@@ -99,6 +102,8 @@ public class ControlFlowPresentationProvider extends TimeGraphPresentationProvid
                 return State.SYSCALL.toString();
             } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {
                 return State.INTERRUPTED.toString();
+            } else if (status == StateValues.PROCESS_STATUS_WAIT_BLOCKED) {
+                return State.WAIT_BLOCKED.toString();
             }
         }
         return State.UNKNOWN.toString();


Back to the top