From e14c1f714a84692e206d6818a4c3ca735e572e63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Mon, 8 Feb 2016 22:21:33 -0500 Subject: [PATCH] analysis: Show thread priority in critical path view MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/66063 Reviewed-by: Hudson CI --- .../analysis/graph/model/LttngWorker.java | 61 ++++++++++++++++++- .../core/analysis/graph/model/Messages.java | 34 +++++++++++ .../analysis/graph/model/messages.properties | 11 ++++ 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/Messages.java create mode 100644 lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/messages.properties 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 433c746f0f..e109c4d46a 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 @@ -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 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 index 0000000000..8b55e9874d --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/Messages.java @@ -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 index 0000000000..8fea69d47e --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/graph/model/messages.properties @@ -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 -- 2.34.1