analysis: Show thread priority in critical path view
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Tue, 9 Feb 2016 03:21:33 +0000 (22:21 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 10 Feb 2016 02:20:34 +0000 (21:20 -0500)
This effectively allows the critical path to become a priority
inversion explorer too.

Note: Priority inversions should not happen in modern OSes. But
users can badly set their thread priority. This patch highlights
that error.

Change-Id: I4db2f5b69329a0b868758a35f15ee6cfc13fa43c
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/66063
Reviewed-by: Hudson CI
lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/LttngWorker.java
lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/Messages.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/messages.properties [new file with mode: 0644]

index 433c746f0f19ed800c663e43a539893c5d24ef3f..e109c4d46ad0f3d307e2738bf49e3ae3265bb669 100644 (file)
@@ -9,10 +9,26 @@
 
 package org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.model;
 
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+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.kernelanalysis.Attributes;
+import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule;
 import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+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;
 
 /**
  * This class represents the worker unit from the execution graph
@@ -51,10 +67,47 @@ public class LttngWorker implements IGraphWorker {
         return fHostTid.getHost();
     }
 
+    @SuppressWarnings("null")
+    @Override
+    public @NonNull Map<@NonNull String, @NonNull String> getWorkerInformation(long t) {
+
+        try {
+            int tid = fHostTid.getTid();
+            if (tid == -1) {
+                return Collections.EMPTY_MAP;
+            }
+            @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().get();
+            if (kam == null) {
+                return Collections.EMPTY_MAP;
+            }
+            ITmfStateSystem ss = kam.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);
+        }
+        return Collections.EMPTY_MAP;
+    }
+
     /**
      * Set the name of this worker
      *
-     * @param name The name of this worker
+     * @param name
+     *            The name of this worker
      */
     public void setName(String name) {
         fThreadName = name;
@@ -70,9 +123,11 @@ public class LttngWorker implements IGraphWorker {
     }
 
     /**
-     * Set the status, saving the old value that can still be accessed using {@link LttngWorker#getOldStatus()}
+     * Set the status, saving the old value that can still be accessed using
+     * {@link LttngWorker#getOldStatus()}
      *
-     * @param status The new status of this
+     * @param status
+     *            The new status of this
      */
     public void setStatus(ProcessStatus status) {
         fOldStatus = fStatus;
diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/Messages.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/Messages.java
new file mode 100644 (file)
index 0000000..8b55e98
--- /dev/null
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.model;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Externalized strings for this package
+ *
+ * @author Geneviève Bastien
+ */
+public class Messages extends NLS {
+    private static final String BUNDLE_NAME = "org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.model.messages"; //$NON-NLS-1$
+    /**
+     * Thread priority text
+     */
+    public static @Nullable String LttngWorker_threadPriority;
+
+    static {
+        // initialize resource bundle
+        NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+    }
+
+    private Messages() {
+    }
+}
diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/messages.properties b/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/messages.properties
new file mode 100644 (file)
index 0000000..8fea69d
--- /dev/null
@@ -0,0 +1,11 @@
+###############################################################################
+# Copyright (c) 2016 Ecole Polytechnique de Montreal
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+###############################################################################
+
+
+LttngWorker_threadPriority=Priority
This page took 0.034193 seconds and 5 git commands to generate.