os.linux: Handle cpu field in statedump events
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 25 Nov 2016 03:51:17 +0000 (22:51 -0500)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 25 Nov 2016 21:57:52 +0000 (16:57 -0500)
LTTng 2.10 will introduce a new "cpu" field in
statedump_process_state events, which will indicate
on which CPU's run queue the thread is currently
scheduled.

Change-Id: I521aea89d5802c5bad4881ab4172c8a7211285b4
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/StateDumpHandler.java

index 333c2f69af363cf9a3ea94025943127958ece063..6499da0f6f38d01dedb9b6de6a64f5f176469766 100644 (file)
@@ -14,6 +14,7 @@ package org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers
 
 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
 
+import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.LinuxValues;
 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues;
 import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
@@ -43,18 +44,20 @@ public class StateDumpHandler extends KernelEventHandler {
     @Override
     public void handleEvent(ITmfStateSystemBuilder ss, ITmfEvent event) throws AttributeNotFoundException {
         ITmfEventField content = event.getContent();
-        Integer cpu = KernelEventHandlerUtils.getCpu(event);
+        Integer eventCpu = KernelEventHandlerUtils.getCpu(event);
         int tid = ((Long) content.getField("tid").getValue()).intValue(); //$NON-NLS-1$
         int pid = ((Long) content.getField("pid").getValue()).intValue(); //$NON-NLS-1$
         int ppid = ((Long) content.getField("ppid").getValue()).intValue(); //$NON-NLS-1$
         int status = ((Long) content.getField("status").getValue()).intValue(); //$NON-NLS-1$
         String name = checkNotNull((String) content.getField("name").getValue()); //$NON-NLS-1$
+        /* Only present in LTTng 2.10+ */
+        @Nullable Long cpuField = content.getFieldValue(Long.class, "cpu"); //$NON-NLS-1$
         /*
          * "mode" could be interesting too, but it doesn't seem to be populated
          * with anything relevant for now.
          */
 
-        String threadAttributeName = Attributes.buildThreadAttributeName(tid, cpu);
+        String threadAttributeName = Attributes.buildThreadAttributeName(tid, eventCpu);
         if (threadAttributeName == null) {
             return;
         }
@@ -68,15 +71,16 @@ public class StateDumpHandler extends KernelEventHandler {
         setPpid(ss, tid, pid, ppid, curThreadNode, timestamp);
 
         /* Set the process' status */
-        setStatus(ss, status, curThreadNode, timestamp);
+        setStatus(ss, status, curThreadNode, cpuField, timestamp);
     }
 
-    private static void setStatus(ITmfStateSystemBuilder ss, int status, int curThreadNode, long timestamp) {
+    private static void setStatus(ITmfStateSystemBuilder ss, int status, int curThreadNode, @Nullable Long cpu, long timestamp) {
         ITmfStateValue value;
         if (ss.queryOngoingState(curThreadNode).isNull()) {
             switch (status) {
             case LinuxValues.STATEDUMP_PROCESS_STATUS_WAIT_CPU:
                 value = StateValues.PROCESS_STATUS_WAIT_FOR_CPU_VALUE;
+                setRunQueue(ss, curThreadNode, cpu, timestamp);
                 break;
             case LinuxValues.STATEDUMP_PROCESS_STATUS_WAIT:
                 /*
@@ -94,6 +98,14 @@ public class StateDumpHandler extends KernelEventHandler {
         }
     }
 
+    private static void setRunQueue(ITmfStateSystemBuilder ss, int curThreadNode, @Nullable Long cpu, long timestamp) {
+        if (cpu != null) {
+            int quark = ss.getQuarkRelativeAndAdd(curThreadNode, Attributes.CURRENT_CPU_RQ);
+            ITmfStateValue value = TmfStateValue.newValueInt(cpu.intValue());
+            ss.modifyAttribute(timestamp, value, quark);
+        }
+    }
+
     private static void setPpid(ITmfStateSystemBuilder ss, int tid, int pid, int ppid, int curThreadNode, long timestamp) {
         ITmfStateValue value;
         int quark;
This page took 0.025473 seconds and 5 git commands to generate.