analysis: Show thread priority in critical path view
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / internal / lttng2 / kernel / core / analysis / graph / model / LttngWorker.java
CommitLineData
af7f72ce
FG
1/*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
3 *
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 *******************************************************************************/
9
10package org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.model;
11
e14c1f71
GB
12import java.util.Collections;
13import java.util.HashMap;
14import java.util.Map;
15
16import org.eclipse.jdt.annotation.NonNull;
af7f72ce
FG
17import org.eclipse.jdt.annotation.Nullable;
18import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker;
e14c1f71
GB
19import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.Attributes;
20import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule;
af7f72ce 21import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread;
e14c1f71
GB
22import org.eclipse.tracecompass.common.core.NonNullUtils;
23import org.eclipse.tracecompass.internal.lttng2.kernel.core.Activator;
af7f72ce 24import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.building.LttngKernelExecGraphProvider.ProcessStatus;
e14c1f71
GB
25import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
26import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
27import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
28import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
29import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
30import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
31import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
af7f72ce
FG
32
33/**
34 * This class represents the worker unit from the execution graph
35 *
36 * TODO: See if this class could be integrated inside HostThread instead.
37 *
38 * @author Geneviève Bastien
39 */
40public class LttngWorker implements IGraphWorker {
41
42 private final HostThread fHostTid;
43 private final long fStart;
44
45 private String fThreadName;
46 private ProcessStatus fStatus = ProcessStatus.UNKNOWN;
47 private ProcessStatus fOldStatus = ProcessStatus.UNKNOWN;
48
49 /**
50 * Constructor
51 *
52 * @param ht
53 * The host thread represented by this worker
54 * @param name
55 * The name of this thread
56 * @param ts
57 * The timestamp
58 */
59 public LttngWorker(HostThread ht, String name, long ts) {
60 fHostTid = ht;
61 fThreadName = name;
62 fStart = ts;
63 }
64
65 @Override
66 public String getHostId() {
67 return fHostTid.getHost();
68 }
69
e14c1f71
GB
70 @SuppressWarnings("null")
71 @Override
72 public @NonNull Map<@NonNull String, @NonNull String> getWorkerInformation(long t) {
73
74 try {
75 int tid = fHostTid.getTid();
76 if (tid == -1) {
77 return Collections.EMPTY_MAP;
78 }
79 @Nullable KernelAnalysisModule kam = TmfTraceManager.getInstance().getActiveTraceSet().stream()
80 .filter(trace -> trace.getHostId().equals(getHostId()))
81 .map(trace -> TmfTraceUtils.getAnalysisModuleOfClass(trace, KernelAnalysisModule.class, KernelAnalysisModule.ID))
82 .filter(mod -> mod != null)
83 .findFirst().get();
84 if (kam == null) {
85 return Collections.EMPTY_MAP;
86 }
87 ITmfStateSystem ss = kam.getStateSystem();
88 if (ss == null) {
89 return Collections.EMPTY_MAP;
90 }
91 int quark;
92 Map<String, String> info = new HashMap<>();
93 quark = ss.getQuarkAbsolute(Attributes.THREADS, Integer.toString(tid), Attributes.PRIO);
94 ITmfStateInterval interval = ss.querySingleState(t, quark);
95 ITmfStateValue stateValue = interval.getStateValue();
96 if (stateValue.getType().equals(ITmfStateValue.Type.INTEGER)) {
97 info.put(NonNullUtils.nullToEmptyString(Messages.LttngWorker_threadPriority), Integer.toString(stateValue.unboxInt()));
98 }
99 return info;
100 } catch (AttributeNotFoundException | StateSystemDisposedException e) {
101 Activator.getDefault().logError(e.getMessage(), e);
102 }
103 return Collections.EMPTY_MAP;
104 }
105
af7f72ce
FG
106 /**
107 * Set the name of this worker
108 *
e14c1f71
GB
109 * @param name
110 * The name of this worker
af7f72ce
FG
111 */
112 public void setName(String name) {
113 fThreadName = name;
114 }
115
116 /**
117 * Get the name of this worker
118 *
119 * @return The name of the worker
120 */
121 public String getName() {
122 return fThreadName;
123 }
124
125 /**
e14c1f71
GB
126 * Set the status, saving the old value that can still be accessed using
127 * {@link LttngWorker#getOldStatus()}
af7f72ce 128 *
e14c1f71
GB
129 * @param status
130 * The new status of this
af7f72ce
FG
131 */
132 public void setStatus(ProcessStatus status) {
133 fOldStatus = fStatus;
134 fStatus = status;
135 }
136
137 /**
138 * Get the status of this thread
139 *
140 * @return The thread status
141 */
142 public ProcessStatus getStatus() {
143 return fStatus;
144 }
145
146 /**
147 * Return the previous status this worker was in
148 *
149 * @return The previous status of this worker
150 */
151 public ProcessStatus getOldStatus() {
152 return fOldStatus;
153 }
154
155 /**
156 * Get the host thread associated with this worker
157 *
158 * @return The {@link HostThread} associated with this worker
159 */
160 public HostThread getHostThread() {
161 return fHostTid;
162 }
163
164 /**
165 * Get the start time of this worker
166 *
167 * @return The start time in nanoseconds
168 */
169 public long getStart() {
170 return fStart;
171 }
172
173 @Override
174 public boolean equals(@Nullable Object obj) {
175 if (obj instanceof LttngWorker) {
176 return getHostThread().equals(((LttngWorker) obj).getHostThread());
177 }
178 return false;
179 }
180
181 @Override
182 public int hashCode() {
183 return fHostTid.hashCode();
184 }
185
186 @Override
187 public String toString() {
188 return '[' + fThreadName + ',' + fHostTid.getTid() + ']';
189 }
190
191}
This page took 0.038288 seconds and 5 git commands to generate.