Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Khouzam2019-07-02 13:00:38 -0400
committerMatthew Khouzam2019-07-04 20:33:00 -0400
commitf96689fd4c6400c2502fa43d45a93597c18fb3e1 (patch)
tree9058e5f217050e900bba82924ab2c9876a78329c
parent702a98e185b0dc578559e93be2a4152606266e43 (diff)
downloadorg.eclipse.tracecompass-f96689fd4c6400c2502fa43d45a93597c18fb3e1.tar.gz
org.eclipse.tracecompass-f96689fd4c6400c2502fa43d45a93597c18fb3e1.tar.xz
org.eclipse.tracecompass-f96689fd4c6400c2502fa43d45a93597c18fb3e1.zip
linux.core: Introduce getExecutableName(module, TID, time)
Fix issue with tid re-use [Fixed] Thread names being incorrect when TIDs are re-used. Change-Id: I8c48f675699d212a108e8229380e8ee37f8b28c6 Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Reviewed-on: https://git.eclipse.org/r/145326 Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net> Tested-by: CI Bot
-rw-r--r--analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/kernel/KernelThreadInformationProviderTest.java8
-rw-r--r--analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/kernel/KernelThreadInformationProvider.java52
-rw-r--r--analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/cpuusage/CpuUsageDataProvider.java6
-rw-r--r--analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernelmemoryusage/KernelMemoryUsageDataProvider.java6
4 files changed, 58 insertions, 14 deletions
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/kernel/KernelThreadInformationProviderTest.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/kernel/KernelThreadInformationProviderTest.java
index 091e1f734e..4fde357cdc 100644
--- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/kernel/KernelThreadInformationProviderTest.java
+++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/src/org/eclipse/tracecompass/analysis/os/linux/core/tests/kernel/KernelThreadInformationProviderTest.java
@@ -325,18 +325,18 @@ public class KernelThreadInformationProviderTest {
KernelAnalysisModule module = checkNotNull(fModule);
/* Check with invalid threads */
- String execName = KernelThreadInformationProvider.getExecutableName(module, 101);
+ String execName = KernelThreadInformationProvider.getExecutableName(module, 101, 70);
assertNull(execName);
- execName = KernelThreadInformationProvider.getExecutableName(module, -2);
+ execName = KernelThreadInformationProvider.getExecutableName(module, -2, 70);
assertNull(execName);
/* Check valid value */
- execName = KernelThreadInformationProvider.getExecutableName(module, 20);
+ execName = KernelThreadInformationProvider.getExecutableName(module, 20, 70);
assertEquals("proc20", execName);
/* Check valid value with process name change in history */
- execName = KernelThreadInformationProvider.getExecutableName(module, 21);
+ execName = KernelThreadInformationProvider.getExecutableName(module, 21, 70);
assertEquals("tid21", execName);
}
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 19b455ed69..a2619e872d 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
@@ -351,8 +351,52 @@ public final class KernelThreadInformationProvider {
* 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
* found
+ *
+ * TODO: use
+ * {@link #getExecutableName(KernelAnalysisModule, Integer, long)}
+ * to handle TID reuse
*/
public static @Nullable String getExecutableName(KernelAnalysisModule module, Integer threadId) {
+ ITmfStateSystem stateSystem = module.getStateSystem();
+ if(stateSystem == null) {
+ return null;
+ }
+ return getExecutableName(module, threadId, stateSystem.getCurrentEndTime());
+ }
+
+ /**
+ * Get the executable name of the thread ID at a specified time. If the
+ * thread ID was used multiple time or the name changed in between, it will
+ * return the last name the thread has taken before the given timestamp, or
+ * {@code null} if no name is found before the time.
+ *
+ * In other words, if:
+ * <ul>
+ * <li>trace start < <em>ts</em> < start of the first process: the TID was
+ * never seen to be used in this trace, and
+ * {@link #getExecutableName(KernelAnalysisModule, Integer, long)} returns
+ * null</li>
+ * <li><em>ts</em> > trace end: the name of the last thread to run is returned.
+ * (could be null if the tid was never used)</li>
+ * <li>thread start > <em>ts</em> > thread end: the thread name will be the
+ * thread name of the process at that time. This may be a parent as the
+ * thread inherrits the parent's name until it is changed.</li>
+ * <li>thread end > <em>ts</em> > next thread start: the last valid
+ * executable name is returned</li>
+ * </ul>
+ *
+ * @param module
+ * The kernel analysis instance to run this method on
+ * @param threadId
+ * The thread ID of the process for which to get the name
+ * @param ts
+ * timestamp to query at. It will look up the thread name of the
+ * current or closest previous lifetime
+ * @return The last executable name of this process for a given time, or
+ * {@code null} if not found.
+ * @since 4.0
+ */
+ public static @Nullable String getExecutableName(KernelAnalysisModule module, Integer threadId, long ts) {
ITmfStateSystem ss = module.getStateSystem();
if (ss == null) {
return null;
@@ -361,11 +405,11 @@ public final class KernelThreadInformationProvider {
if (execNameNode == ITmfStateSystem.INVALID_ATTRIBUTE) {
return null;
}
- QuarkIterator reversedIterator = new QuarkIterator(ss, execNameNode, ss.getCurrentEndTime());
+ QuarkIterator reversedIterator = new QuarkIterator(ss, execNameNode, ts);
while (reversedIterator.hasPrevious()) {
- ITmfStateValue nameInterval = reversedIterator.previous().getStateValue();
- if (nameInterval.getType() == Type.STRING) {
- return nameInterval.unboxStr();
+ Object value = reversedIterator.previous().getValue();
+ if (value instanceof String) {
+ return (String) value;
}
}
return null;
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/cpuusage/CpuUsageDataProvider.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/cpuusage/CpuUsageDataProvider.java
index 869d657d99..7ebd37622d 100644
--- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/cpuusage/CpuUsageDataProvider.java
+++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/cpuusage/CpuUsageDataProvider.java
@@ -232,7 +232,7 @@ public class CpuUsageDataProvider extends AbstractTreeCommonXDataProvider<Kernel
if (strings.length > 1) {
int tid = Integer.parseInt(strings[1]);
if (tid != 0) {
- entryList.add(new CpuUsageEntryModel(getId(tid), totalId, Collections.singletonList(getProcessName(tid, strings[1])), tid, entry.getValue()));
+ entryList.add(new CpuUsageEntryModel(getId(tid), totalId, Collections.singletonList(getProcessName(tid, strings[1], end)), tid, entry.getValue()));
}
}
}
@@ -243,14 +243,14 @@ public class CpuUsageDataProvider extends AbstractTreeCommonXDataProvider<Kernel
* Get the process name from its TID by using the LTTng kernel analysis
* module
*/
- private String getProcessName(int tid, String defaultTidName) {
+ private String getProcessName(int tid, String defaultTidName, long endTime) {
// try and get from cache
String execName = fProcessNameMap.get(tid);
if (execName != null) {
return execName;
}
- execName = KernelThreadInformationProvider.getExecutableName(fKernelAnalysisModule, tid);
+ execName = KernelThreadInformationProvider.getExecutableName(fKernelAnalysisModule, tid, endTime);
ITmfStateSystem ss = fKernelAnalysisModule.getStateSystem();
if (ss != null && ss.waitUntilBuilt(0) && execName != null) {
// cache only if non null and state system analysis completed
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernelmemoryusage/KernelMemoryUsageDataProvider.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernelmemoryusage/KernelMemoryUsageDataProvider.java
index 581ec63eb9..bda11f6d85 100644
--- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernelmemoryusage/KernelMemoryUsageDataProvider.java
+++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/internal/analysis/os/linux/core/kernelmemoryusage/KernelMemoryUsageDataProvider.java
@@ -268,7 +268,7 @@ public class KernelMemoryUsageDataProvider extends AbstractTreeCommonXDataProvid
for (Integer threadQuark : threadQuarkList) {
if (active == null || active.get(threadQuark).getEndTime() < end) {
String tidString = ss.getAttributeName(threadQuark);
- String procname = fProcessNameMap.computeIfAbsent(tidString, this::getProcessName);
+ String procname = fProcessNameMap.computeIfAbsent(tidString, string -> getProcessName(string, end));
// Ensure that we reuse the same id for a given quark.
long id = getId(threadQuark);
@@ -289,11 +289,11 @@ public class KernelMemoryUsageDataProvider extends AbstractTreeCommonXDataProvid
/*
* Get the process name from its TID by using the LTTng kernel analysis module
*/
- private String getProcessName(String tid) {
+ private String getProcessName(String tid, long ts) {
if (tid.equals(KernelMemoryStateProvider.OTHER_TID)) {
return tid;
}
- String execName = KernelThreadInformationProvider.getExecutableName(fKernelModule, Integer.parseInt(tid));
+ String execName = KernelThreadInformationProvider.getExecutableName(fKernelModule, Integer.parseInt(tid), ts);
return execName != null ? execName : tid;
}

Back to the top