From: Geneviève Bastien Date: Thu, 21 Apr 2016 19:41:32 +0000 (-0400) Subject: analysis.kernel: bug 491276 Add a getPriority method to KernelThreadInformationProvider X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=1add07ef9bf1a919993397267da8e29056086b4f;p=deliverable%2Ftracecompass.git analysis.kernel: bug 491276 Add a getPriority method to KernelThreadInformationProvider This removes the need to x-friend internal.analysis.os.linux.core.kernel with lttng2.kernel.core Change-Id: I75d18c42e9da5bef884cd76209b63ad5db6a7e8c Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/71180 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/META-INF/MANIFEST.MF b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/META-INF/MANIFEST.MF index d5cd15b209..1145e5408d 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/META-INF/MANIFEST.MF +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/META-INF/MANIFEST.MF @@ -36,7 +36,6 @@ Export-Package: org.eclipse.tracecompass.analysis.os.linux.core.contextswitch, org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel; x-friends:="org.eclipse.tracecompass.analysis.os.linux.core.tests, org.eclipse.tracecompass.analysis.os.linux.ui, - org.eclipse.tracecompass.lttng2.kernel.core.tests, - org.eclipse.tracecompass.lttng2.kernel.core", + org.eclipse.tracecompass.lttng2.kernel.core.tests", org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers;x-friends:="org.eclipse.tracecompass.analysis.os.linux.core.tests", org.eclipse.tracecompass.internal.analysis.os.linux.core.latency.statistics;x-friends:="org.eclipse.tracecompass.analysis.os.linux.ui,org.eclipse.tracecompass.analysis.os.linux.core.tests" diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/kernel/KernelThreadInformationProvider.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/kernel/KernelThreadInformationProvider.java index 2ea594db4d..0beb0e5c85 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/kernel/KernelThreadInformationProvider.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/kernel/KernelThreadInformationProvider.java @@ -50,7 +50,7 @@ public final class KernelThreadInformationProvider { * resolve to something that is not an event * * @param module - * The lttng kernel analysis instance to run this method on + * The kernel analysis instance to run this method on * @param cpuId * The CPU number the process is running on * @param ts @@ -79,7 +79,7 @@ public final class KernelThreadInformationProvider { * Get the TIDs of the threads from an analysis * * @param module - * The lttng kernel analysis instance to run this method on + * The kernel analysis instance to run this method on * @return The set of TIDs corresponding to the threads */ public static Collection getThreadIds(KernelAnalysisModule module) { @@ -105,7 +105,7 @@ public final class KernelThreadInformationProvider { * Get the parent process ID of a thread * * @param module - * The lttng kernel analysis instance to run this method on + * The kernel analysis instance to run this method on * @param threadId * The thread ID of the process for which to get the parent * @param ts @@ -137,7 +137,7 @@ public final class KernelThreadInformationProvider { * name the thread has taken, or {@code null} if no name is found * * @param module - * The lttng kernel analysis instance to run this method on + * The kernel analysis instance to run this method on * @param threadId * The thread ID of the process for which to get the name * @return The last executable name of this process, or {@code null} if not @@ -167,11 +167,38 @@ public final class KernelThreadInformationProvider { return null; } + /** + * Get the priority of this thread at time ts + * + * @param module + * The kernel analysis instance to run this method on + * @param threadId + * The ID of the thread to query + * @param ts + * The timestamp at which to query + * @return The priority of the thread or -1 if not available + */ + public static int getThreadPriority(KernelAnalysisModule module, int threadId, long ts) { + ITmfStateSystem ss = module.getStateSystem(); + if (ss == null) { + return -1; + } + int prioQuark = ss.optQuarkAbsolute(Attributes.THREADS, String.valueOf(threadId), Attributes.PRIO); + if (prioQuark == ITmfStateSystem.INVALID_ATTRIBUTE) { + return -1; + } + try { + return ss.querySingleState(ts, prioQuark).getStateValue().unboxInt(); + } catch (AttributeNotFoundException | StateSystemDisposedException e) { + return -1; + } + } + /** * Get the status intervals for a given thread with a resolution * * @param module - * The lttng kernel analysis instance to run this method on + * The kernel analysis instance to run this method on * @param threadId * The ID of the thread to get the intervals for * @param start diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/LttngWorker.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/LttngWorker.java index 2eb51b2ebc..1b3a107cec 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/LttngWorker.java +++ b/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/LttngWorker.java @@ -18,16 +18,10 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker; import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule; +import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelThreadInformationProvider; import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread; import org.eclipse.tracecompass.common.core.NonNullUtils; -import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes; -import org.eclipse.tracecompass.internal.lttng2.kernel.core.Activator; import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.building.LttngKernelExecGraphProvider.ProcessStatus; -import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; -import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; -import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; -import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; -import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; @@ -71,37 +65,28 @@ public class LttngWorker implements IGraphWorker { @SuppressWarnings("null") @Override public @NonNull Map<@NonNull String, @NonNull String> getWorkerInformation(long t) { + int tid = fHostTid.getTid(); + if (tid == -1) { + return Collections.EMPTY_MAP; + } + Optional<@Nullable KernelAnalysisModule> kam = TmfTraceManager.getInstance().getActiveTraceSet() + .stream() + .filter(trace -> trace.getHostId().equals(getHostId())) + .map(trace -> TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelAnalysisModule.class, KernelAnalysisModule.ID)) + .filter(mod -> mod != null) + .findFirst(); + if (!kam.isPresent()) { + return Collections.EMPTY_MAP; + } + KernelAnalysisModule module = kam.get(); + + Map info = new HashMap<>(); - try { - int tid = fHostTid.getTid(); - if (tid == -1) { - return Collections.EMPTY_MAP; - } - Optional<@Nullable KernelAnalysisModule> kam = TmfTraceManager.getInstance().getActiveTraceSet().stream() - .filter(trace -> trace.getHostId().equals(getHostId())) - .map(trace -> TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelAnalysisModule.class, KernelAnalysisModule.ID)) - .filter(mod -> mod != null) - .findFirst(); - if (!kam.isPresent()) { - return Collections.EMPTY_MAP; - } - ITmfStateSystem ss = kam.get().getStateSystem(); - if (ss == null) { - return Collections.EMPTY_MAP; - } - int quark; - Map info = new HashMap<>(); - quark = ss.getQuarkAbsolute(Attributes.THREADS, Integer.toString(tid), Attributes.PRIO); - ITmfStateInterval interval = ss.querySingleState(t, quark); - ITmfStateValue stateValue = interval.getStateValue(); - if (stateValue.getType().equals(ITmfStateValue.Type.INTEGER)) { - info.put(NonNullUtils.nullToEmptyString(Messages.LttngWorker_threadPriority), Integer.toString(stateValue.unboxInt())); - } - return info; - } catch (AttributeNotFoundException | StateSystemDisposedException e) { - Activator.getDefault().logError(e.getMessage(), e); + int priority = KernelThreadInformationProvider.getThreadPriority(module, tid, t); + if (priority != -1) { + info.put(NonNullUtils.nullToEmptyString(Messages.LttngWorker_threadPriority), Integer.toString(priority)); } - return Collections.EMPTY_MAP; + return info; } /**