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
.linuxtools
.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
.linuxtools
.internal
.lttng2
.kernel
.core
.Attributes
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.Messages
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
.ResourcesEntry
.Type
;
28 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.analysis
.LttngKernelAnalysisModule
;
29 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
30 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
31 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
32 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
33 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
34 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
37 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
.AbstractTimeGraphView
;
38 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
39 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
41 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
42 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
45 * Main implementation for the LTTng 2.0 kernel Resource view
47 * @author Patrick Tasse
49 public class ResourcesView
extends AbstractTimeGraphView
{
52 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
54 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
55 Messages
.ResourcesView_stateTypeName
58 // Timeout between updates in the build thread in ms
59 private static final long BUILD_UPDATE_TIMEOUT
= 500;
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
68 public ResourcesView() {
69 super(ID
, new ResourcesPresentationProvider());
70 setFilterColumns(FILTER_COLUMN_NAMES
);
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 protected String
getNextText() {
79 return Messages
.ResourcesView_nextResourceActionNameText
;
83 protected String
getNextTooltip() {
84 return Messages
.ResourcesView_nextResourceActionToolTipText
;
88 protected String
getPrevText() {
89 return Messages
.ResourcesView_previousResourceActionNameText
;
93 protected String
getPrevTooltip() {
94 return Messages
.ResourcesView_previousResourceActionToolTipText
;
98 protected void buildEventList(ITmfTrace trace
, ITmfTrace parentTrace
, IProgressMonitor monitor
) {
102 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, LttngKernelAnalysisModule
.ID
);
106 Comparator
<ITimeGraphEntry
> comparator
= new Comparator
<ITimeGraphEntry
>() {
108 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
109 return ((ResourcesEntry
) o1
).compareTo(o2
);
113 Map
<Integer
, ResourcesEntry
> entryMap
= new HashMap
<>();
114 TimeGraphEntry traceEntry
= null;
116 long startTime
= ssq
.getStartTime();
117 long start
= startTime
;
118 setStartTime(Math
.min(getStartTime(), startTime
));
119 boolean complete
= false;
121 if (monitor
.isCanceled()) {
124 complete
= ssq
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
125 if (ssq
.isCancelled()) {
128 long end
= ssq
.getCurrentEndTime();
129 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
132 long endTime
= end
+ 1;
133 setEndTime(Math
.max(getEndTime(), endTime
));
135 if (traceEntry
== null) {
136 traceEntry
= new ResourcesEntry(trace
, trace
.getName(), startTime
, endTime
, 0);
137 traceEntry
.sortChildren(comparator
);
138 List
<TimeGraphEntry
> entryList
= Collections
.singletonList(traceEntry
);
139 addToEntryList(parentTrace
, entryList
);
141 traceEntry
.updateEndTime(endTime
);
144 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
145 for (Integer cpuQuark
: cpuQuarks
) {
146 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
147 ResourcesEntry entry
= entryMap
.get(cpuQuark
);
149 entry
= new ResourcesEntry(cpuQuark
, trace
, startTime
, endTime
, Type
.CPU
, cpu
);
150 entryMap
.put(cpuQuark
, entry
);
151 traceEntry
.addChild(entry
);
153 entry
.updateEndTime(endTime
);
156 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
157 for (Integer irqQuark
: irqQuarks
) {
158 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
159 ResourcesEntry entry
= entryMap
.get(irqQuark
);
161 entry
= new ResourcesEntry(irqQuark
, trace
, startTime
, endTime
, Type
.IRQ
, irq
);
162 entryMap
.put(irqQuark
, entry
);
163 traceEntry
.addChild(entry
);
165 entry
.updateEndTime(endTime
);
168 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
169 for (Integer softIrqQuark
: softIrqQuarks
) {
170 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
171 ResourcesEntry entry
= entryMap
.get(softIrqQuark
);
173 entry
= new ResourcesEntry(softIrqQuark
, trace
, startTime
, endTime
, Type
.SOFT_IRQ
, softIrq
);
174 entryMap
.put(softIrqQuark
, entry
);
175 traceEntry
.addChild(entry
);
177 entry
.updateEndTime(endTime
);
181 if (parentTrace
.equals(getTrace())) {
184 long resolution
= Math
.max(1, (endTime
- ssq
.getStartTime()) / getDisplayWidth());
185 for (ITimeGraphEntry child
: traceEntry
.getChildren()) {
186 if (monitor
.isCanceled()) {
189 if (child
instanceof TimeGraphEntry
) {
190 TimeGraphEntry entry
= (TimeGraphEntry
) child
;
191 List
<ITimeEvent
> eventList
= getEventList(entry
, start
, endTime
, resolution
, monitor
);
192 if (eventList
!= null) {
193 for (ITimeEvent event
: eventList
) {
194 entry
.addEvent(event
);
206 protected @Nullable List
<ITimeEvent
> getEventList(TimeGraphEntry entry
,
207 long startTime
, long endTime
, long resolution
,
208 IProgressMonitor monitor
) {
209 ResourcesEntry resourcesEntry
= (ResourcesEntry
) entry
;
210 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(resourcesEntry
.getTrace(), LttngKernelAnalysisModule
.ID
);
214 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
215 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
216 if (realEnd
<= realStart
) {
219 List
<ITimeEvent
> eventList
= null;
220 int quark
= resourcesEntry
.getQuark();
223 if (resourcesEntry
.getType().equals(Type
.CPU
)) {
224 int statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
225 List
<ITmfStateInterval
> statusIntervals
= ssq
.queryHistoryRange(statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
226 eventList
= new ArrayList
<>(statusIntervals
.size());
227 long lastEndTime
= -1;
228 for (ITmfStateInterval statusInterval
: statusIntervals
) {
229 if (monitor
.isCanceled()) {
232 int status
= statusInterval
.getStateValue().unboxInt();
233 long time
= statusInterval
.getStartTime();
234 long duration
= statusInterval
.getEndTime() - time
+ 1;
235 if (!statusInterval
.getStateValue().isNull()) {
236 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
237 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
239 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
240 } else if (lastEndTime
== -1 || time
+ duration
>= endTime
) {
241 // add null event if it intersects the start or end time
242 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
244 lastEndTime
= time
+ duration
;
246 } else if (resourcesEntry
.getType().equals(Type
.IRQ
)) {
247 List
<ITmfStateInterval
> irqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
248 eventList
= new ArrayList
<>(irqIntervals
.size());
249 long lastEndTime
= -1;
250 boolean lastIsNull
= true;
251 for (ITmfStateInterval irqInterval
: irqIntervals
) {
252 if (monitor
.isCanceled()) {
255 long time
= irqInterval
.getStartTime();
256 long duration
= irqInterval
.getEndTime() - time
+ 1;
257 if (!irqInterval
.getStateValue().isNull()) {
258 int cpu
= irqInterval
.getStateValue().unboxInt();
259 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
262 if (lastEndTime
== -1) {
263 // add null event if it intersects the start time
264 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
266 if (lastEndTime
!= time
&& lastIsNull
) {
267 /* 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) */
268 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
270 if (time
+ duration
>= endTime
) {
271 // add null event if it intersects the end time
272 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
277 lastEndTime
= time
+ duration
;
279 } else if (resourcesEntry
.getType().equals(Type
.SOFT_IRQ
)) {
280 List
<ITmfStateInterval
> softIrqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
281 eventList
= new ArrayList
<>(softIrqIntervals
.size());
282 long lastEndTime
= -1;
283 boolean lastIsNull
= true;
284 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
285 if (monitor
.isCanceled()) {
288 long time
= softIrqInterval
.getStartTime();
289 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
290 if (!softIrqInterval
.getStateValue().isNull()) {
291 int cpu
= softIrqInterval
.getStateValue().unboxInt();
292 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
294 if (lastEndTime
== -1) {
295 // add null event if it intersects the start time
296 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
298 if (lastEndTime
!= time
&& lastIsNull
) {
299 /* 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) */
300 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
302 if (time
+ duration
>= endTime
) {
303 // add null event if it intersects the end time
304 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
309 lastEndTime
= time
+ duration
;
313 } catch (AttributeNotFoundException
| TimeRangeException
| StateValueTypeException e
) {
315 } catch (StateSystemDisposedException e
) {