From: Alexandre Montplaisir Date: Fri, 8 Apr 2016 21:41:23 +0000 (-0400) Subject: os.linux: Move buildThreadAttributeName() methods to Attributes interface X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=642b494702cb392351be34bc9e5208f0b2c36636;p=deliverable%2Ftracecompass.git os.linux: Move buildThreadAttributeName() methods to Attributes interface 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 Reviewed-on: https://git.eclipse.org/r/70298 --- diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/event/aspect/ThreadPriorityAspect.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/event/aspect/ThreadPriorityAspect.java index 58092f4ab1..9702577776 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/event/aspect/ThreadPriorityAspect.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/event/aspect/ThreadPriorityAspect.java @@ -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 */ diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/Attributes.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/Attributes.java index b5e50b0eb4..89e370d738 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/Attributes.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/Attributes.java @@ -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 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); + } } diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/KernelEventHandlerUtils.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/KernelEventHandlerUtils.java index 0893423880..b1cc556ccc 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/KernelEventHandlerUtils.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/KernelEventHandlerUtils.java @@ -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 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); - } } diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/PiSetprioHandler.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/PiSetprioHandler.java index 6d21c3200c..722bc5c118 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/PiSetprioHandler.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/PiSetprioHandler.java @@ -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; } diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/ProcessForkHandler.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/ProcessForkHandler.java index f3ffaaac95..4696c25bf0 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/ProcessForkHandler.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/ProcessForkHandler.java @@ -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; } diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/ProcessFreeHandler.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/ProcessFreeHandler.java index 7c3b4d4be9..a02a10bd56 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/ProcessFreeHandler.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/ProcessFreeHandler.java @@ -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; } diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedSwitchHandler.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedSwitchHandler.java index 94238ce507..1387f494ab 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedSwitchHandler.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedSwitchHandler.java @@ -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); diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedWakeupHandler.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedWakeupHandler.java index 625dbcdc49..d0fb0940d6 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedWakeupHandler.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernel/handlers/SchedWakeupHandler.java @@ -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; } 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 ea75bcd322..020b145c58 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 @@ -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; } diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/controlflow/ControlFlowView.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/controlflow/ControlFlowView.java index 1835f8f48c..c31fd20779 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/controlflow/ControlFlowView.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/controlflow/ControlFlowView.java @@ -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 entryKey = KernelEventHandlerUtils.parseThreadAttributeName(threadAttributeName); + Pair entryKey = Attributes.parseThreadAttributeName(threadAttributeName); int threadId = entryKey.getFirst(); if (threadId < 0) { // ignore the 'unknown' (-1) thread