analysis.kernel: bug 491276 Add a getPriority method to KernelThreadInformationProvider
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 21 Apr 2016 19:41:32 +0000 (15:41 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Tue, 10 May 2016 00:39:15 +0000 (20:39 -0400)
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 <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/71180
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.os.linux.core/META-INF/MANIFEST.MF
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/kernel/KernelThreadInformationProvider.java
lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/LttngWorker.java

index d5cd15b209ee8d16254e41d58b32ff74d03be43e..1145e5408d5b0601ffdbfc0db6efc512f675adf1 100644 (file)
@@ -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"
index 2ea594db4dbcf8976a6dae65c36de7d3ba30fbaf..0beb0e5c85f825771bed3983f00a4e3b141c7399 100644 (file)
@@ -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<Integer> 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 <code>-1</code> 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
index 2eb51b2ebc34cc5dc447ab340ecac064bcc8d74c..1b3a107cec6430d8172900cd0aa691a2dac10fba 100644 (file)
@@ -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<String, String> 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<String, String> 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;
     }
 
     /**
This page took 0.028716 seconds and 5 git commands to generate.