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
) {
100 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, LttngKernelAnalysis
.ID
);
104 Comparator
<ITimeGraphEntry
> comparator
= new Comparator
<ITimeGraphEntry
>() {
106 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
107 return ((ResourcesEntry
) o1
).compareTo(o2
);
111 Map
<Integer
, ResourcesEntry
> entryMap
= new HashMap
<>();
112 TimeGraphEntry traceEntry
= null;
114 long startTime
= ssq
.getStartTime();
115 long start
= startTime
;
116 setStartTime(Math
.min(getStartTime(), startTime
));
117 boolean complete
= false;
119 if (monitor
.isCanceled()) {
122 complete
= ssq
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
123 if (ssq
.isCancelled()) {
126 long end
= ssq
.getCurrentEndTime();
127 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
130 long endTime
= end
+ 1;
131 setEndTime(Math
.max(getEndTime(), endTime
));
133 if (traceEntry
== null) {
134 traceEntry
= new ResourcesEntry(trace
, trace
.getName(), startTime
, endTime
, 0);
135 traceEntry
.sortChildren(comparator
);
136 List
<TimeGraphEntry
> entryList
= Collections
.singletonList(traceEntry
);
137 addToEntryList(parentTrace
, entryList
);
139 traceEntry
.updateEndTime(endTime
);
142 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
143 for (Integer cpuQuark
: cpuQuarks
) {
144 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
145 ResourcesEntry entry
= entryMap
.get(cpuQuark
);
147 entry
= new ResourcesEntry(cpuQuark
, trace
, startTime
, endTime
, Type
.CPU
, cpu
);
148 entryMap
.put(cpuQuark
, entry
);
149 traceEntry
.addChild(entry
);
151 entry
.updateEndTime(endTime
);
154 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
155 for (Integer irqQuark
: irqQuarks
) {
156 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
157 ResourcesEntry entry
= entryMap
.get(irqQuark
);
159 entry
= new ResourcesEntry(irqQuark
, trace
, startTime
, endTime
, Type
.IRQ
, irq
);
160 entryMap
.put(irqQuark
, entry
);
161 traceEntry
.addChild(entry
);
163 entry
.updateEndTime(endTime
);
166 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
167 for (Integer softIrqQuark
: softIrqQuarks
) {
168 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
169 ResourcesEntry entry
= entryMap
.get(softIrqQuark
);
171 entry
= new ResourcesEntry(softIrqQuark
, trace
, startTime
, endTime
, Type
.SOFT_IRQ
, softIrq
);
172 entryMap
.put(softIrqQuark
, entry
);
173 traceEntry
.addChild(entry
);
175 entry
.updateEndTime(endTime
);
179 if (parentTrace
.equals(getTrace())) {
182 long resolution
= Math
.max(1, (endTime
- ssq
.getStartTime()) / getDisplayWidth());
183 for (ITimeGraphEntry child
: traceEntry
.getChildren()) {
184 if (monitor
.isCanceled()) {
187 if (child
instanceof TimeGraphEntry
) {
188 TimeGraphEntry entry
= (TimeGraphEntry
) child
;
189 List
<ITimeEvent
> eventList
= getEventList(entry
, start
, endTime
, resolution
, monitor
);
190 if (eventList
!= null) {
191 for (ITimeEvent event
: eventList
) {
192 entry
.addEvent(event
);
204 protected @Nullable List
<ITimeEvent
> getEventList(TimeGraphEntry entry
,
205 long startTime
, long endTime
, long resolution
,
206 IProgressMonitor monitor
) {
207 ResourcesEntry resourcesEntry
= (ResourcesEntry
) entry
;
208 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(resourcesEntry
.getTrace(), LttngKernelAnalysis
.ID
);
212 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
213 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
214 if (realEnd
<= realStart
) {
217 List
<ITimeEvent
> eventList
= null;
218 int quark
= resourcesEntry
.getQuark();
221 if (resourcesEntry
.getType().equals(Type
.CPU
)) {
224 statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
225 } catch (AttributeNotFoundException e
) {
227 * The sub-attribute "status" is not available. May happen
228 * if the trace does not have sched_switch events enabled.
232 List
<ITmfStateInterval
> statusIntervals
= StateSystemUtils
.queryHistoryRange(ssq
, statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
233 eventList
= new ArrayList
<>(statusIntervals
.size());
234 long lastEndTime
= -1;
235 for (ITmfStateInterval statusInterval
: statusIntervals
) {
236 if (monitor
.isCanceled()) {
239 int status
= statusInterval
.getStateValue().unboxInt();
240 long time
= statusInterval
.getStartTime();
241 long duration
= statusInterval
.getEndTime() - time
+ 1;
242 if (!statusInterval
.getStateValue().isNull()) {
243 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
244 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
246 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
247 } else if (lastEndTime
== -1 || time
+ duration
>= endTime
) {
248 // add null event if it intersects the start or end time
249 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
251 lastEndTime
= time
+ duration
;
253 } else if (resourcesEntry
.getType().equals(Type
.IRQ
)) {
254 List
<ITmfStateInterval
> irqIntervals
= StateSystemUtils
.queryHistoryRange(ssq
, quark
, realStart
, realEnd
- 1, resolution
, monitor
);
255 eventList
= new ArrayList
<>(irqIntervals
.size());
256 long lastEndTime
= -1;
257 boolean lastIsNull
= true;
258 for (ITmfStateInterval irqInterval
: irqIntervals
) {
259 if (monitor
.isCanceled()) {
262 long time
= irqInterval
.getStartTime();
263 long duration
= irqInterval
.getEndTime() - time
+ 1;
264 if (!irqInterval
.getStateValue().isNull()) {
265 int cpu
= irqInterval
.getStateValue().unboxInt();
266 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
269 if (lastEndTime
== -1) {
270 // add null event if it intersects the start time
271 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
273 if (lastEndTime
!= time
&& lastIsNull
) {
274 /* 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) */
275 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
277 if (time
+ duration
>= endTime
) {
278 // add null event if it intersects the end time
279 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
284 lastEndTime
= time
+ duration
;
286 } else if (resourcesEntry
.getType().equals(Type
.SOFT_IRQ
)) {
287 List
<ITmfStateInterval
> softIrqIntervals
= StateSystemUtils
.queryHistoryRange(ssq
, quark
, realStart
, realEnd
- 1, resolution
, monitor
);
288 eventList
= new ArrayList
<>(softIrqIntervals
.size());
289 long lastEndTime
= -1;
290 boolean lastIsNull
= true;
291 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
292 if (monitor
.isCanceled()) {
295 long time
= softIrqInterval
.getStartTime();
296 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
297 if (!softIrqInterval
.getStateValue().isNull()) {
298 int cpu
= softIrqInterval
.getStateValue().unboxInt();
299 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
301 if (lastEndTime
== -1) {
302 // add null event if it intersects the start time
303 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
305 if (lastEndTime
!= time
&& lastIsNull
) {
306 /* 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) */
307 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
309 if (time
+ duration
>= endTime
) {
310 // add null event if it intersects the end time
311 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
316 lastEndTime
= time
+ duration
;
320 } catch (AttributeNotFoundException
| TimeRangeException
| StateValueTypeException e
) {
322 } catch (StateSystemDisposedException e
) {