1 package org
.lttng
.scope
.lttng
.kernel
.core
.views
.timegraph
.threads
;
3 import static java
.util
.Objects
.requireNonNull
;
6 import java
.util
.function
.Predicate
;
8 import org
.eclipse
.jdt
.annotation
.Nullable
;
9 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.KernelTidAspect
;
10 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.core
.kernel
.Attributes
;
11 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
12 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
13 import org
.lttng
.scope
.tmf2
.views
.core
.timegraph
.model
.provider
.statesystem
.StateSystemTimeGraphTreeElement
;
14 import org
.lttng
.scope
.tmf2
.views
.core
.timegraph
.model
.render
.tree
.TimeGraphTreeElement
;
16 import com
.google
.common
.primitives
.Ints
;
18 public class ThreadsTreeElement
extends StateSystemTimeGraphTreeElement
{
20 private static final String UNKNOWN_THREAD_NAME
= "???"; //$NON-NLS-1$
22 private final int fTid
;
23 /** CPU is only defined when fTid == 0 */
24 private final @Nullable Integer fCpu
;
25 private final String fThreadName
;
27 public ThreadsTreeElement(String tidStr
, @Nullable String threadName
,
28 List
<TimeGraphTreeElement
> children
, int sourceQuark
) {
29 super(getElementName(tidStr
, threadName
),
33 if (tidStr
.startsWith(Attributes
.THREAD_0_PREFIX
)) {
35 String cpuStr
= tidStr
.substring(Attributes
.THREAD_0_PREFIX
.length());
36 Integer cpu
= Ints
.tryParse(cpuStr
);
37 fCpu
= (cpu
== null ?
0 : cpu
);
39 fTid
= Integer
.parseInt(tidStr
);
43 fThreadName
= (threadName
== null ? UNKNOWN_THREAD_NAME
: threadName
);
46 private static String
getElementName(String tidStr
, @Nullable String threadName
) {
47 String tidPart
= tidStr
;
48 if (tidPart
.startsWith(Attributes
.THREAD_0_PREFIX
)) {
49 /* Display "0/0" instead of "0_0" */
50 tidPart
= tidPart
.replace('_', '/');
53 String threadNamePart
= (threadName
== null ? UNKNOWN_THREAD_NAME
: threadName
);
54 return (tidPart
+ " - " + threadNamePart
); //$NON-NLS-1$
61 public String
getThreadName() {
66 public @Nullable Predicate
<ITmfEvent
> getEventMatching() {
68 * This tree element represents a thread ID. Return true for events
69 * whose TID aspect is the same as the TID of this element.
72 Integer eventTid
= KernelTidAspect
.INSTANCE
.resolve(event
);
73 if (eventTid
== null) {
77 return (eventTid
.intValue() == fTid
);
80 * There are many elements for TID 0. We also need to compare the
83 int elemCpu
= requireNonNull(fCpu
).intValue();
84 // TODO The notion of CPU should move to the framework
86 if (event
instanceof CtfTmfEvent
) {
87 eventCpu
= ((CtfTmfEvent
) event
).getCPU();
91 return (eventTid
.intValue() == fTid
92 && eventCpu
== elemCpu
);