Commit | Line | Data |
---|---|---|
dedc7dec | 1 | /******************************************************************************* |
4999a196 | 2 | * Copyright (c) 2012, 2013 Ericsson, École Polytechnique de Montréal |
dedc7dec PT |
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 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
4999a196 | 11 | * Geneviève Bastien - Move code to provide base classes for time graph view |
dedc7dec PT |
12 | *******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources; | |
15 | ||
16 | import java.util.LinkedHashMap; | |
17 | import java.util.List; | |
18 | import java.util.Map; | |
19 | ||
20 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; | |
21 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues; | |
4bc53929 | 22 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Activator; |
dedc7dec PT |
23 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages; |
24 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type; | |
4bc53929 | 25 | import org.eclipse.linuxtools.lttng2.kernel.ui.analysis.LttngKernelAnalysisModule; |
dedc7dec | 26 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; |
96345c5a | 27 | import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; |
dedc7dec PT |
28 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; |
29 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; | |
30 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; | |
f1f86dfb | 31 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
dedc7dec PT |
32 | import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; |
33 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem; | |
34 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; | |
35 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; | |
713a70ae | 36 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; |
1d46dc38 | 37 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.NullTimeEvent; |
4999a196 GB |
38 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent; |
39 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.ITmfTimeGraphDrawingHelper; | |
dedc7dec PT |
40 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils; |
41 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution; | |
42 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; | |
713a70ae PT |
43 | import org.eclipse.swt.SWT; |
44 | import org.eclipse.swt.graphics.GC; | |
dedc7dec | 45 | import org.eclipse.swt.graphics.RGB; |
713a70ae | 46 | import org.eclipse.swt.graphics.Rectangle; |
dedc7dec PT |
47 | |
48 | /** | |
49 | * Presentation provider for the Resource view, based on the generic TMF | |
50 | * presentation provider. | |
51 | * | |
52 | * @author Patrick Tasse | |
53 | */ | |
54 | public class ResourcesPresentationProvider extends TimeGraphPresentationProvider { | |
55 | ||
4999a196 | 56 | private long fLastThreadId = -1; |
713a70ae | 57 | |
dedc7dec | 58 | private enum State { |
4999a196 | 59 | IDLE (new RGB(200, 200, 200)), |
1d46dc38 PT |
60 | USERMODE (new RGB( 0, 200, 0)), |
61 | SYSCALL (new RGB( 0, 0, 200)), | |
4999a196 GB |
62 | IRQ (new RGB(200, 0, 100)), |
63 | SOFT_IRQ (new RGB(200, 150, 100)), | |
64 | IRQ_ACTIVE (new RGB(200, 0, 100)), | |
1d46dc38 | 65 | SOFT_IRQ_RAISED (new RGB(200, 200, 0)), |
4999a196 | 66 | SOFT_IRQ_ACTIVE (new RGB(200, 150, 100)); |
dedc7dec PT |
67 | |
68 | public final RGB rgb; | |
69 | ||
4999a196 | 70 | private State(RGB rgb) { |
dedc7dec PT |
71 | this.rgb = rgb; |
72 | } | |
73 | } | |
74 | ||
713a70ae PT |
75 | /** |
76 | * Default constructor | |
713a70ae | 77 | */ |
4999a196 | 78 | public ResourcesPresentationProvider() { |
713a70ae | 79 | super(); |
713a70ae PT |
80 | } |
81 | ||
4999a196 GB |
82 | private static State[] getStateValues() { |
83 | return State.values(); | |
dedc7dec PT |
84 | } |
85 | ||
1d46dc38 PT |
86 | private static State getEventState(TimeEvent event) { |
87 | if (event.hasValue()) { | |
4999a196 | 88 | ResourcesEntry entry = (ResourcesEntry) event.getEntry(); |
1d46dc38 | 89 | int value = event.getValue(); |
4999a196 GB |
90 | |
91 | if (entry.getType() == Type.CPU) { | |
92 | if (value == StateValues.CPU_STATUS_IDLE) { | |
93 | return State.IDLE; | |
94 | } else if (value == StateValues.CPU_STATUS_RUN_USERMODE) { | |
95 | return State.USERMODE; | |
96 | } else if (value == StateValues.CPU_STATUS_RUN_SYSCALL) { | |
97 | return State.SYSCALL; | |
98 | } else if (value == StateValues.CPU_STATUS_IRQ) { | |
99 | return State.IRQ; | |
100 | } else if (value == StateValues.CPU_STATUS_SOFTIRQ) { | |
101 | return State.SOFT_IRQ; | |
102 | } | |
1d46dc38 | 103 | } else if (entry.getType() == Type.IRQ) { |
4999a196 | 104 | return State.IRQ_ACTIVE; |
1d46dc38 | 105 | } else if (entry.getType() == Type.SOFT_IRQ) { |
4999a196 GB |
106 | if (value == StateValues.SOFT_IRQ_RAISED) { |
107 | return State.SOFT_IRQ_RAISED; | |
108 | } | |
109 | return State.SOFT_IRQ_ACTIVE; | |
110 | } | |
dedc7dec | 111 | } |
4999a196 | 112 | return null; |
dedc7dec PT |
113 | } |
114 | ||
115 | @Override | |
116 | public int getStateTableIndex(ITimeEvent event) { | |
1d46dc38 | 117 | State state = getEventState((TimeEvent) event); |
4999a196 GB |
118 | if (state != null) { |
119 | return state.ordinal(); | |
120 | } | |
1d46dc38 PT |
121 | if (event instanceof NullTimeEvent) { |
122 | return INVISIBLE; | |
dedc7dec | 123 | } |
af10fe06 | 124 | return TRANSPARENT; |
dedc7dec PT |
125 | } |
126 | ||
4999a196 GB |
127 | @Override |
128 | public StateItem[] getStateTable() { | |
129 | State[] states = getStateValues(); | |
130 | StateItem[] stateTable = new StateItem[states.length]; | |
131 | for (int i = 0; i < stateTable.length; i++) { | |
132 | State state = states[i]; | |
133 | stateTable[i] = new StateItem(state.rgb, state.toString()); | |
134 | } | |
135 | return stateTable; | |
136 | } | |
137 | ||
dedc7dec PT |
138 | @Override |
139 | public String getEventName(ITimeEvent event) { | |
1d46dc38 | 140 | State state = getEventState((TimeEvent) event); |
4999a196 GB |
141 | if (state != null) { |
142 | return state.toString(); | |
143 | } | |
1d46dc38 PT |
144 | if (event instanceof NullTimeEvent) { |
145 | return null; | |
dedc7dec | 146 | } |
af10fe06 | 147 | return Messages.ResourcesView_multipleStates; |
dedc7dec PT |
148 | } |
149 | ||
150 | @Override | |
151 | public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event, long hoverTime) { | |
152 | ||
e0838ca1 | 153 | Map<String, String> retMap = new LinkedHashMap<>(); |
4999a196 | 154 | if (event instanceof TimeEvent && ((TimeEvent) event).hasValue()) { |
dedc7dec | 155 | |
4999a196 GB |
156 | TimeEvent tcEvent = (TimeEvent) event; |
157 | ResourcesEntry entry = (ResourcesEntry) event.getEntry(); | |
dedc7dec | 158 | |
4999a196 | 159 | if (tcEvent.hasValue()) { |
4bc53929 GB |
160 | LttngKernelAnalysisModule module = entry.getTrace().getAnalysisModules(LttngKernelAnalysisModule.class).get(LttngKernelAnalysisModule.ID); |
161 | ITmfStateSystem ss = module.getStateSystem(); | |
162 | if (ss == null) { | |
163 | return retMap; | |
164 | } | |
4999a196 GB |
165 | // Check for IRQ or Soft_IRQ type |
166 | if (entry.getType().equals(Type.IRQ) || entry.getType().equals(Type.SOFT_IRQ)) { | |
dedc7dec | 167 | |
4999a196 GB |
168 | // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display |
169 | int cpu = tcEvent.getValue(); | |
170 | if (cpu >= 0) { | |
171 | retMap.put(Messages.ResourcesView_attributeCpuName, String.valueOf(cpu)); | |
172 | } | |
dedc7dec | 173 | } |
dedc7dec | 174 | |
4999a196 GB |
175 | // Check for type CPU |
176 | else if (entry.getType().equals(Type.CPU)) { | |
177 | int status = tcEvent.getValue(); | |
178 | ||
179 | if (status == StateValues.CPU_STATUS_IRQ) { | |
180 | // In IRQ state get the IRQ that caused the interruption | |
4999a196 GB |
181 | int cpu = entry.getId(); |
182 | ||
183 | try { | |
184 | List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime()); | |
185 | List<Integer> irqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$ | |
186 | ||
187 | for (int irqQuark : irqQuarks) { | |
188 | if (fullState.get(irqQuark).getStateValue().unboxInt() == cpu) { | |
189 | ITmfStateInterval value = ss.querySingleState(event.getTime(), irqQuark); | |
190 | if (!value.getStateValue().isNull()) { | |
191 | int irq = Integer.parseInt(ss.getAttributeName(irqQuark)); | |
192 | retMap.put(Messages.ResourcesView_attributeIrqName, String.valueOf(irq)); | |
193 | } | |
194 | break; | |
dedc7dec | 195 | } |
dedc7dec | 196 | } |
4bc53929 GB |
197 | } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) { |
198 | Activator.getDefault().logError("Error in ResourcesPresentationProvider", e); //$NON-NLS-1$ | |
4999a196 GB |
199 | } catch (StateSystemDisposedException e) { |
200 | /* Ignored */ | |
dedc7dec | 201 | } |
4999a196 GB |
202 | } else if (status == StateValues.CPU_STATUS_SOFTIRQ) { |
203 | // In SOFT_IRQ state get the SOFT_IRQ that caused the interruption | |
4999a196 GB |
204 | int cpu = entry.getId(); |
205 | ||
206 | try { | |
207 | List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime()); | |
208 | List<Integer> softIrqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$ | |
209 | ||
210 | for (int softIrqQuark : softIrqQuarks) { | |
211 | if (fullState.get(softIrqQuark).getStateValue().unboxInt() == cpu) { | |
212 | ITmfStateInterval value = ss.querySingleState(event.getTime(), softIrqQuark); | |
213 | if (!value.getStateValue().isNull()) { | |
214 | int softIrq = Integer.parseInt(ss.getAttributeName(softIrqQuark)); | |
215 | retMap.put(Messages.ResourcesView_attributeSoftIrqName, String.valueOf(softIrq)); | |
216 | } | |
217 | break; | |
dedc7dec | 218 | } |
dedc7dec | 219 | } |
4bc53929 GB |
220 | } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) { |
221 | Activator.getDefault().logError("Error in ResourcesPresentationProvider", e); //$NON-NLS-1$ | |
4999a196 GB |
222 | } catch (StateSystemDisposedException e) { |
223 | /* Ignored */ | |
dedc7dec | 224 | } |
4999a196 GB |
225 | } else if (status == StateValues.CPU_STATUS_RUN_USERMODE || status == StateValues.CPU_STATUS_RUN_SYSCALL) { |
226 | // In running state get the current tid | |
4999a196 GB |
227 | |
228 | try { | |
229 | retMap.put(Messages.ResourcesView_attributeHoverTime, Utils.formatTime(hoverTime, TimeFormat.CALENDAR, Resolution.NANOSEC)); | |
230 | int cpuQuark = entry.getQuark(); | |
4bc53929 GB |
231 | int currentThreadQuark = ss.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD); |
232 | ITmfStateInterval interval = ss.querySingleState(hoverTime, currentThreadQuark); | |
dedc7dec | 233 | if (!interval.getStateValue().isNull()) { |
4999a196 GB |
234 | ITmfStateValue value = interval.getStateValue(); |
235 | int currentThreadId = value.unboxInt(); | |
236 | retMap.put(Messages.ResourcesView_attributeTidName, Integer.toString(currentThreadId)); | |
4bc53929 GB |
237 | int execNameQuark = ss.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThreadId), Attributes.EXEC_NAME); |
238 | interval = ss.querySingleState(hoverTime, execNameQuark); | |
dedc7dec PT |
239 | if (!interval.getStateValue().isNull()) { |
240 | value = interval.getStateValue(); | |
4999a196 GB |
241 | retMap.put(Messages.ResourcesView_attributeProcessName, value.unboxStr()); |
242 | } | |
243 | if (status == StateValues.CPU_STATUS_RUN_SYSCALL) { | |
4bc53929 GB |
244 | int syscallQuark = ss.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThreadId), Attributes.SYSTEM_CALL); |
245 | interval = ss.querySingleState(hoverTime, syscallQuark); | |
4999a196 GB |
246 | if (!interval.getStateValue().isNull()) { |
247 | value = interval.getStateValue(); | |
248 | retMap.put(Messages.ResourcesView_attributeSyscallName, value.unboxStr()); | |
249 | } | |
dedc7dec PT |
250 | } |
251 | } | |
4bc53929 GB |
252 | } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) { |
253 | Activator.getDefault().logError("Error in ResourcesPresentationProvider", e); //$NON-NLS-1$ | |
4999a196 GB |
254 | } catch (StateSystemDisposedException e) { |
255 | /* Ignored */ | |
dedc7dec | 256 | } |
dedc7dec | 257 | } |
96345c5a | 258 | } |
dedc7dec PT |
259 | } |
260 | } | |
261 | ||
262 | return retMap; | |
263 | } | |
264 | ||
713a70ae PT |
265 | @Override |
266 | public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) { | |
4999a196 | 267 | ITmfTimeGraphDrawingHelper drawingHelper = getDrawingHelper(); |
713a70ae PT |
268 | if (bounds.width <= gc.getFontMetrics().getAverageCharWidth()) { |
269 | return; | |
270 | } | |
4999a196 GB |
271 | |
272 | if (!(event instanceof TimeEvent)) { | |
713a70ae PT |
273 | return; |
274 | } | |
4999a196 GB |
275 | TimeEvent tcEvent = (TimeEvent) event; |
276 | if (!tcEvent.hasValue()) { | |
713a70ae PT |
277 | return; |
278 | } | |
4999a196 GB |
279 | |
280 | ResourcesEntry entry = (ResourcesEntry) event.getEntry(); | |
281 | if (!entry.getType().equals(Type.CPU)) { | |
282 | return; | |
283 | } | |
284 | ||
285 | int status = tcEvent.getValue(); | |
713a70ae PT |
286 | if (status != StateValues.CPU_STATUS_RUN_USERMODE && status != StateValues.CPU_STATUS_RUN_SYSCALL) { |
287 | return; | |
288 | } | |
4999a196 | 289 | |
4bc53929 GB |
290 | LttngKernelAnalysisModule module = entry.getTrace().getAnalysisModules(LttngKernelAnalysisModule.class).get(LttngKernelAnalysisModule.ID); |
291 | ITmfStateSystem ss = module.getStateSystem(); | |
292 | if (ss == null) { | |
293 | return; | |
294 | } | |
713a70ae | 295 | long time = event.getTime(); |
a3fbd3f4 PT |
296 | try { |
297 | while (time < event.getTime() + event.getDuration()) { | |
713a70ae PT |
298 | int cpuQuark = entry.getQuark(); |
299 | int currentThreadQuark = ss.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD); | |
300 | ITmfStateInterval tidInterval = ss.querySingleState(time, currentThreadQuark); | |
301 | if (!tidInterval.getStateValue().isNull()) { | |
302 | ITmfStateValue value = tidInterval.getStateValue(); | |
303 | int currentThreadId = value.unboxInt(); | |
304 | if (status == StateValues.CPU_STATUS_RUN_USERMODE && currentThreadId != fLastThreadId) { | |
305 | int execNameQuark = ss.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThreadId), Attributes.EXEC_NAME); | |
306 | ITmfStateInterval interval = ss.querySingleState(time, execNameQuark); | |
307 | if (!interval.getStateValue().isNull()) { | |
308 | value = interval.getStateValue(); | |
309 | gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE)); | |
310 | long startTime = Math.max(tidInterval.getStartTime(), event.getTime()); | |
311 | long endTime = Math.min(tidInterval.getEndTime() + 1, event.getTime() + event.getDuration()); | |
4999a196 GB |
312 | if (drawingHelper.getXForTime(endTime) > bounds.x) { |
313 | int x = Math.max(drawingHelper.getXForTime(startTime), bounds.x); | |
314 | int width = Math.min(drawingHelper.getXForTime(endTime), bounds.x + bounds.width) - x; | |
713a70ae PT |
315 | int drawn = Utils.drawText(gc, value.unboxStr(), x + 1, bounds.y - 2, width - 1, true, true); |
316 | if (drawn > 0) { | |
317 | fLastThreadId = currentThreadId; | |
318 | } | |
319 | } | |
320 | } | |
321 | } else if (status == StateValues.CPU_STATUS_RUN_SYSCALL) { | |
322 | int syscallQuark = ss.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThreadId), Attributes.SYSTEM_CALL); | |
323 | ITmfStateInterval interval = ss.querySingleState(time, syscallQuark); | |
324 | if (!interval.getStateValue().isNull()) { | |
325 | value = interval.getStateValue(); | |
326 | gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE)); | |
327 | long startTime = Math.max(tidInterval.getStartTime(), event.getTime()); | |
328 | long endTime = Math.min(tidInterval.getEndTime() + 1, event.getTime() + event.getDuration()); | |
4999a196 GB |
329 | if (drawingHelper.getXForTime(endTime) > bounds.x) { |
330 | int x = Math.max(drawingHelper.getXForTime(startTime), bounds.x); | |
331 | int width = Math.min(drawingHelper.getXForTime(endTime), bounds.x + bounds.width) - x; | |
713a70ae PT |
332 | Utils.drawText(gc, value.unboxStr().substring(4), x + 1, bounds.y - 2, width - 1, true, true); |
333 | } | |
334 | } | |
335 | } | |
336 | } | |
337 | time = tidInterval.getEndTime() + 1; | |
338 | if (time < event.getTime() + event.getDuration()) { | |
4999a196 | 339 | int x = drawingHelper.getXForTime(time); |
713a70ae PT |
340 | if (x >= bounds.x) { |
341 | gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_GRAY)); | |
342 | gc.drawLine(x, bounds.y + 1, x, bounds.y + bounds.height - 2); | |
343 | } | |
344 | } | |
713a70ae | 345 | } |
4bc53929 GB |
346 | } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) { |
347 | Activator.getDefault().logError("Error in ResourcesPresentationProvider", e); //$NON-NLS-1$ | |
a3fbd3f4 PT |
348 | } catch (StateSystemDisposedException e) { |
349 | /* Ignored */ | |
713a70ae PT |
350 | } |
351 | } | |
352 | ||
353 | @Override | |
354 | public void postDrawEntry(ITimeGraphEntry entry, Rectangle bounds, GC gc) { | |
355 | fLastThreadId = -1; | |
356 | } | |
dedc7dec | 357 | } |