From: Alexandre Montplaisir Date: Fri, 25 Nov 2016 03:51:17 +0000 (-0500) Subject: os.linux: Handle cpu field in statedump events X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=b054b99a937ef8c06c016fcf94e5dabe849a3e7f;hp=16ad5604d4c4e36e149d149e1bf999ca53781d3b;p=deliverable%2Ftracecompass.git os.linux: Handle cpu field in statedump events 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 --- diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/StateDumpHandler.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/StateDumpHandler.java index 333c2f69af..6499da0f6f 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/StateDumpHandler.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/StateDumpHandler.java @@ -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;