1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson, É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
10 * Patrick Tasse - Initial API and implementation
11 * Geneviève Bastien - Move code to provide base classes for time graph views
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.ui
.views
.resources
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Collections
;
18 import java
.util
.Comparator
;
19 import java
.util
.HashMap
;
20 import java
.util
.List
;
23 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
24 import org
.eclipse
.jdt
.annotation
.Nullable
;
25 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.Attributes
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.ui
.Messages
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.ui
.views
.resources
.ResourcesEntry
.Type
;
28 import org
.eclipse
.tracecompass
.lttng2
.kernel
.core
.analysis
.kernel
.LttngKernelAnalysis
;
29 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
30 import org
.eclipse
.tracecompass
.statesystem
.core
.StateSystemUtils
;
31 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
32 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
33 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
34 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
35 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
38 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
.AbstractTimeGraphView
;
39 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
41 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
42 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
43 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
46 * Main implementation for the LTTng 2.0 kernel Resource view
48 * @author Patrick Tasse
50 public class ResourcesView
extends AbstractTimeGraphView
{
53 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
55 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
56 Messages
.ResourcesView_stateTypeName
59 // Timeout between updates in the build thread in ms
60 private static final long BUILD_UPDATE_TIMEOUT
= 500;
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
69 public ResourcesView() {
70 super(ID
, new ResourcesPresentationProvider());
71 setFilterColumns(FILTER_COLUMN_NAMES
);
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
79 protected String
getNextText() {
80 return Messages
.ResourcesView_nextResourceActionNameText
;
84 protected String
getNextTooltip() {
85 return Messages
.ResourcesView_nextResourceActionToolTipText
;
89 protected String
getPrevText() {
90 return Messages
.ResourcesView_previousResourceActionNameText
;
94 protected String
getPrevTooltip() {
95 return Messages
.ResourcesView_previousResourceActionToolTipText
;
99 protected void buildEventList(ITmfTrace trace
, ITmfTrace parentTrace
, IProgressMonitor monitor
) {
103 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, LttngKernelAnalysis
.ID
);
107 Comparator
<ITimeGraphEntry
> comparator
= new Comparator
<ITimeGraphEntry
>() {
109 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
110 return ((ResourcesEntry
) o1
).compareTo(o2
);
114 Map
<Integer
, ResourcesEntry
> entryMap
= new HashMap
<>();
115 TimeGraphEntry traceEntry
= null;
117 long startTime
= ssq
.getStartTime();
118 long start
= startTime
;
119 setStartTime(Math
.min(getStartTime(), startTime
));
120 boolean complete
= false;
122 if (monitor
.isCanceled()) {
125 complete
= ssq
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
126 if (ssq
.isCancelled()) {
129 long end
= ssq
.getCurrentEndTime();
130 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
133 long endTime
= end
+ 1;
134 setEndTime(Math
.max(getEndTime(), endTime
));
136 if (traceEntry
== null) {
137 traceEntry
= new ResourcesEntry(trace
, trace
.getName(), startTime
, endTime
, 0);
138 traceEntry
.sortChildren(comparator
);
139 List
<TimeGraphEntry
> entryList
= Collections
.singletonList(traceEntry
);
140 addToEntryList(parentTrace
, entryList
);
142 traceEntry
.updateEndTime(endTime
);
145 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
146 for (Integer cpuQuark
: cpuQuarks
) {
147 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
148 ResourcesEntry entry
= entryMap
.get(cpuQuark
);
150 entry
= new ResourcesEntry(cpuQuark
, trace
, startTime
, endTime
, Type
.CPU
, cpu
);
151 entryMap
.put(cpuQuark
, entry
);
152 traceEntry
.addChild(entry
);
154 entry
.updateEndTime(endTime
);
157 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
158 for (Integer irqQuark
: irqQuarks
) {
159 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
160 ResourcesEntry entry
= entryMap
.get(irqQuark
);
162 entry
= new ResourcesEntry(irqQuark
, trace
, startTime
, endTime
, Type
.IRQ
, irq
);
163 entryMap
.put(irqQuark
, entry
);
164 traceEntry
.addChild(entry
);
166 entry
.updateEndTime(endTime
);
169 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
170 for (Integer softIrqQuark
: softIrqQuarks
) {
171 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
172 ResourcesEntry entry
= entryMap
.get(softIrqQuark
);
174 entry
= new ResourcesEntry(softIrqQuark
, trace
, startTime
, endTime
, Type
.SOFT_IRQ
, softIrq
);
175 entryMap
.put(softIrqQuark
, entry
);
176 traceEntry
.addChild(entry
);
178 entry
.updateEndTime(endTime
);
182 if (parentTrace
.equals(getTrace())) {
185 long resolution
= Math
.max(1, (endTime
- ssq
.getStartTime()) / getDisplayWidth());
186 for (ITimeGraphEntry child
: traceEntry
.getChildren()) {
187 if (monitor
.isCanceled()) {
190 if (child
instanceof TimeGraphEntry
) {
191 TimeGraphEntry entry
= (TimeGraphEntry
) child
;
192 List
<ITimeEvent
> eventList
= getEventList(entry
, start
, endTime
, resolution
, monitor
);
193 if (eventList
!= null) {
194 for (ITimeEvent event
: eventList
) {
195 entry
.addEvent(event
);
207 protected @Nullable List
<ITimeEvent
> getEventList(TimeGraphEntry entry
,
208 long startTime
, long endTime
, long resolution
,
209 IProgressMonitor monitor
) {
210 ResourcesEntry resourcesEntry
= (ResourcesEntry
) entry
;
211 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(resourcesEntry
.getTrace(), LttngKernelAnalysis
.ID
);
215 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
216 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
217 if (realEnd
<= realStart
) {
220 List
<ITimeEvent
> eventList
= null;
221 int quark
= resourcesEntry
.getQuark();
224 if (resourcesEntry
.getType().equals(Type
.CPU
)) {
227 statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
228 } catch (AttributeNotFoundException e
) {
230 * The sub-attribute "status" is not available. May happen
231 * if the trace does not have sched_switch events enabled.
235 List
<ITmfStateInterval
> statusIntervals
= StateSystemUtils
.queryHistoryRange(ssq
, statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
236 eventList
= new ArrayList
<>(statusIntervals
.size());
237 long lastEndTime
= -1;
238 for (ITmfStateInterval statusInterval
: statusIntervals
) {
239 if (monitor
.isCanceled()) {
242 int status
= statusInterval
.getStateValue().unboxInt();
243 long time
= statusInterval
.getStartTime();
244 long duration
= statusInterval
.getEndTime() - time
+ 1;
245 if (!statusInterval
.getStateValue().isNull()) {
246 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
247 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
249 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
250 } else if (lastEndTime
== -1 || time
+ duration
>= endTime
) {
251 // add null event if it intersects the start or end time
252 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
254 lastEndTime
= time
+ duration
;
256 } else if (resourcesEntry
.getType().equals(Type
.IRQ
)) {
257 List
<ITmfStateInterval
> irqIntervals
= StateSystemUtils
.queryHistoryRange(ssq
, quark
, realStart
, realEnd
- 1, resolution
, monitor
);
258 eventList
= new ArrayList
<>(irqIntervals
.size());
259 long lastEndTime
= -1;
260 boolean lastIsNull
= true;
261 for (ITmfStateInterval irqInterval
: irqIntervals
) {
262 if (monitor
.isCanceled()) {
265 long time
= irqInterval
.getStartTime();
266 long duration
= irqInterval
.getEndTime() - time
+ 1;
267 if (!irqInterval
.getStateValue().isNull()) {
268 int cpu
= irqInterval
.getStateValue().unboxInt();
269 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
272 if (lastEndTime
== -1) {
273 // add null event if it intersects the start time
274 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
276 if (lastEndTime
!= time
&& lastIsNull
) {
277 /* This is a special case where we want to show IRQ_ACTIVE state but we don't know the CPU (it is between two null samples) */
278 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
280 if (time
+ duration
>= endTime
) {
281 // add null event if it intersects the end time
282 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
287 lastEndTime
= time
+ duration
;
289 } else if (resourcesEntry
.getType().equals(Type
.SOFT_IRQ
)) {
290 List
<ITmfStateInterval
> softIrqIntervals
= StateSystemUtils
.queryHistoryRange(ssq
, quark
, realStart
, realEnd
- 1, resolution
, monitor
);
291 eventList
= new ArrayList
<>(softIrqIntervals
.size());
292 long lastEndTime
= -1;
293 boolean lastIsNull
= true;
294 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
295 if (monitor
.isCanceled()) {
298 long time
= softIrqInterval
.getStartTime();
299 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
300 if (!softIrqInterval
.getStateValue().isNull()) {
301 int cpu
= softIrqInterval
.getStateValue().unboxInt();
302 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
304 if (lastEndTime
== -1) {
305 // add null event if it intersects the start time
306 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
308 if (lastEndTime
!= time
&& lastIsNull
) {
309 /* This is a special case where we want to show IRQ_ACTIVE state but we don't know the CPU (it is between two null samples) */
310 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
312 if (time
+ duration
>= endTime
) {
313 // add null event if it intersects the end time
314 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
319 lastEndTime
= time
+ duration
;
323 } catch (AttributeNotFoundException
| TimeRangeException
| StateValueTypeException e
) {
325 } catch (StateSystemDisposedException e
) {