1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.analysis
.graph
.model
;
12 import java
.util
.Collections
;
13 import java
.util
.HashMap
;
15 import java
.util
.Optional
;
17 import org
.eclipse
.jdt
.annotation
.NonNull
;
18 import org
.eclipse
.jdt
.annotation
.Nullable
;
19 import org
.eclipse
.tracecompass
.analysis
.graph
.core
.base
.IGraphWorker
;
20 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.Attributes
;
21 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.KernelAnalysisModule
;
22 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.model
.HostThread
;
23 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
24 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.Activator
;
25 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.analysis
.graph
.building
.LttngKernelExecGraphProvider
.ProcessStatus
;
26 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
27 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
28 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
29 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
30 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
35 * This class represents the worker unit from the execution graph
37 * TODO: See if this class could be integrated inside HostThread instead.
39 * @author Geneviève Bastien
41 public class LttngWorker
implements IGraphWorker
{
43 private final HostThread fHostTid
;
44 private final long fStart
;
46 private String fThreadName
;
47 private ProcessStatus fStatus
= ProcessStatus
.UNKNOWN
;
48 private ProcessStatus fOldStatus
= ProcessStatus
.UNKNOWN
;
54 * The host thread represented by this worker
56 * The name of this thread
60 public LttngWorker(HostThread ht
, String name
, long ts
) {
67 public String
getHostId() {
68 return fHostTid
.getHost();
71 @SuppressWarnings("null")
73 public @NonNull Map
<@NonNull String
, @NonNull String
> getWorkerInformation(long t
) {
76 int tid
= fHostTid
.getTid();
78 return Collections
.EMPTY_MAP
;
80 Optional
<@Nullable KernelAnalysisModule
> kam
= TmfTraceManager
.getInstance().getActiveTraceSet().stream()
81 .filter(trace
-> trace
.getHostId().equals(getHostId()))
82 .map(trace
-> TmfTraceUtils
.getAnalysisModuleOfClass(trace
, KernelAnalysisModule
.class, KernelAnalysisModule
.ID
))
83 .filter(mod
-> mod
!= null)
85 if (!kam
.isPresent()) {
86 return Collections
.EMPTY_MAP
;
88 ITmfStateSystem ss
= kam
.get().getStateSystem();
90 return Collections
.EMPTY_MAP
;
93 Map
<String
, String
> info
= new HashMap
<>();
94 quark
= ss
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(tid
), Attributes
.PRIO
);
95 ITmfStateInterval interval
= ss
.querySingleState(t
, quark
);
96 ITmfStateValue stateValue
= interval
.getStateValue();
97 if (stateValue
.getType().equals(ITmfStateValue
.Type
.INTEGER
)) {
98 info
.put(NonNullUtils
.nullToEmptyString(Messages
.LttngWorker_threadPriority
), Integer
.toString(stateValue
.unboxInt()));
101 } catch (AttributeNotFoundException
| StateSystemDisposedException e
) {
102 Activator
.getDefault().logError(e
.getMessage(), e
);
104 return Collections
.EMPTY_MAP
;
108 * Set the name of this worker
111 * The name of this worker
113 public void setName(String name
) {
118 * Get the name of this worker
120 * @return The name of the worker
122 public String
getName() {
127 * Set the status, saving the old value that can still be accessed using
128 * {@link LttngWorker#getOldStatus()}
131 * The new status of this
133 public void setStatus(ProcessStatus status
) {
134 fOldStatus
= fStatus
;
139 * Get the status of this thread
141 * @return The thread status
143 public ProcessStatus
getStatus() {
148 * Return the previous status this worker was in
150 * @return The previous status of this worker
152 public ProcessStatus
getOldStatus() {
157 * Get the host thread associated with this worker
159 * @return The {@link HostThread} associated with this worker
161 public HostThread
getHostThread() {
166 * Get the start time of this worker
168 * @return The start time in nanoseconds
170 public long getStart() {
175 public boolean equals(@Nullable Object obj
) {
176 if (obj
instanceof LttngWorker
) {
177 return getHostThread().equals(((LttngWorker
) obj
).getHostThread());
183 public int hashCode() {
184 return fHostTid
.hashCode();
188 public String
toString() {
189 return '[' + fThreadName
+ ',' + fHostTid
.getTid() + ']';