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
.HashMap
;
19 import java
.util
.List
;
22 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
23 import org
.eclipse
.jdt
.annotation
.Nullable
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.Attributes
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.Messages
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
.ResourcesEntry
.Type
;
27 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.analysis
.LttngKernelAnalysisModule
;
28 import org
.eclipse
.linuxtools
.statesystem
.core
.ITmfStateSystem
;
29 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
30 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
31 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.StateValueTypeException
;
32 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.TimeRangeException
;
33 import org
.eclipse
.linuxtools
.statesystem
.core
.interval
.ITmfStateInterval
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.timegraph
.AbstractTimeGraphView
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
44 * Main implementation for the LTTng 2.0 kernel Resource view
46 * @author Patrick Tasse
48 public class ResourcesView
extends AbstractTimeGraphView
{
51 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
53 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
54 Messages
.ResourcesView_stateTypeName
57 // Timeout between updates in the build thread in ms
58 private static final long BUILD_UPDATE_TIMEOUT
= 500;
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
67 public ResourcesView() {
68 super(ID
, new ResourcesPresentationProvider());
69 setFilterColumns(FILTER_COLUMN_NAMES
);
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 protected String
getNextText() {
78 return Messages
.ResourcesView_nextResourceActionNameText
;
82 protected String
getNextTooltip() {
83 return Messages
.ResourcesView_nextResourceActionToolTipText
;
87 protected String
getPrevText() {
88 return Messages
.ResourcesView_previousResourceActionNameText
;
92 protected String
getPrevTooltip() {
93 return Messages
.ResourcesView_previousResourceActionToolTipText
;
97 protected void buildEventList(ITmfTrace trace
, ITmfTrace parentTrace
, IProgressMonitor monitor
) {
101 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, LttngKernelAnalysisModule
.ID
);
106 Map
<Integer
, ResourcesEntry
> entryMap
= new HashMap
<>();
107 TimeGraphEntry traceEntry
= null;
109 long startTime
= ssq
.getStartTime();
110 long start
= startTime
;
111 setStartTime(Math
.min(getStartTime(), startTime
));
112 boolean complete
= false;
114 if (monitor
.isCanceled()) {
117 complete
= ssq
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
118 if (ssq
.isCancelled()) {
121 long end
= ssq
.getCurrentEndTime();
122 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
125 long endTime
= end
+ 1;
126 setEndTime(Math
.max(getEndTime(), endTime
));
128 if (traceEntry
== null) {
129 traceEntry
= new ResourcesEntry(trace
, trace
.getName(), startTime
, endTime
, 0);
130 List
<TimeGraphEntry
> entryList
= Collections
.singletonList(traceEntry
);
131 addToEntryList(parentTrace
, entryList
);
133 traceEntry
.updateEndTime(endTime
);
136 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
137 for (Integer cpuQuark
: cpuQuarks
) {
138 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
139 ResourcesEntry entry
= entryMap
.get(cpuQuark
);
141 entry
= new ResourcesEntry(cpuQuark
, trace
, startTime
, endTime
, Type
.CPU
, cpu
);
142 entryMap
.put(cpuQuark
, entry
);
143 traceEntry
.addChild(entry
);
145 entry
.updateEndTime(endTime
);
148 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
149 for (Integer irqQuark
: irqQuarks
) {
150 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
151 ResourcesEntry entry
= entryMap
.get(irqQuark
);
153 entry
= new ResourcesEntry(irqQuark
, trace
, startTime
, endTime
, Type
.IRQ
, irq
);
154 entryMap
.put(irqQuark
, entry
);
155 traceEntry
.addChild(entry
);
157 entry
.updateEndTime(endTime
);
160 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
161 for (Integer softIrqQuark
: softIrqQuarks
) {
162 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
163 ResourcesEntry entry
= entryMap
.get(softIrqQuark
);
165 entry
= new ResourcesEntry(softIrqQuark
, trace
, startTime
, endTime
, Type
.SOFT_IRQ
, softIrq
);
166 entryMap
.put(softIrqQuark
, entry
);
167 traceEntry
.addChild(entry
);
169 entry
.updateEndTime(endTime
);
173 if (parentTrace
.equals(getTrace())) {
176 long resolution
= Math
.max(1, (endTime
- ssq
.getStartTime()) / getDisplayWidth());
177 for (ITimeGraphEntry child
: traceEntry
.getChildren()) {
178 if (monitor
.isCanceled()) {
181 if (child
instanceof TimeGraphEntry
) {
182 TimeGraphEntry entry
= (TimeGraphEntry
) child
;
183 List
<ITimeEvent
> eventList
= getEventList(entry
, start
, endTime
, resolution
, monitor
);
184 if (eventList
!= null) {
185 for (ITimeEvent event
: eventList
) {
186 entry
.addEvent(event
);
198 protected @Nullable List
<ITimeEvent
> getEventList(TimeGraphEntry entry
,
199 long startTime
, long endTime
, long resolution
,
200 IProgressMonitor monitor
) {
201 ResourcesEntry resourcesEntry
= (ResourcesEntry
) entry
;
202 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(resourcesEntry
.getTrace(), LttngKernelAnalysisModule
.ID
);
206 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
207 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
208 if (realEnd
<= realStart
) {
211 List
<ITimeEvent
> eventList
= null;
212 int quark
= resourcesEntry
.getQuark();
215 if (resourcesEntry
.getType().equals(Type
.CPU
)) {
216 int statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
217 List
<ITmfStateInterval
> statusIntervals
= ssq
.queryHistoryRange(statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
218 eventList
= new ArrayList
<>(statusIntervals
.size());
219 long lastEndTime
= -1;
220 for (ITmfStateInterval statusInterval
: statusIntervals
) {
221 if (monitor
.isCanceled()) {
224 int status
= statusInterval
.getStateValue().unboxInt();
225 long time
= statusInterval
.getStartTime();
226 long duration
= statusInterval
.getEndTime() - time
+ 1;
227 if (!statusInterval
.getStateValue().isNull()) {
228 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
229 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
231 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
232 } else if (lastEndTime
== -1 || time
+ duration
>= endTime
) {
233 // add null event if it intersects the start or end time
234 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
236 lastEndTime
= time
+ duration
;
238 } else if (resourcesEntry
.getType().equals(Type
.IRQ
)) {
239 List
<ITmfStateInterval
> irqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
240 eventList
= new ArrayList
<>(irqIntervals
.size());
241 long lastEndTime
= -1;
242 boolean lastIsNull
= true;
243 for (ITmfStateInterval irqInterval
: irqIntervals
) {
244 if (monitor
.isCanceled()) {
247 long time
= irqInterval
.getStartTime();
248 long duration
= irqInterval
.getEndTime() - time
+ 1;
249 if (!irqInterval
.getStateValue().isNull()) {
250 int cpu
= irqInterval
.getStateValue().unboxInt();
251 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
254 if (lastEndTime
== -1) {
255 // add null event if it intersects the start time
256 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
258 if (lastEndTime
!= time
&& lastIsNull
) {
259 /* 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) */
260 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
262 if (time
+ duration
>= endTime
) {
263 // add null event if it intersects the end time
264 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
269 lastEndTime
= time
+ duration
;
271 } else if (resourcesEntry
.getType().equals(Type
.SOFT_IRQ
)) {
272 List
<ITmfStateInterval
> softIrqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
273 eventList
= new ArrayList
<>(softIrqIntervals
.size());
274 long lastEndTime
= -1;
275 boolean lastIsNull
= true;
276 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
277 if (monitor
.isCanceled()) {
280 long time
= softIrqInterval
.getStartTime();
281 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
282 if (!softIrqInterval
.getStateValue().isNull()) {
283 int cpu
= softIrqInterval
.getStateValue().unboxInt();
284 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
286 if (lastEndTime
== -1) {
287 // add null event if it intersects the start time
288 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
290 if (lastEndTime
!= time
&& lastIsNull
) {
291 /* 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) */
292 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
294 if (time
+ duration
>= endTime
) {
295 // add null event if it intersects the end time
296 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
301 lastEndTime
= time
+ duration
;
305 } catch (AttributeNotFoundException
| TimeRangeException
| StateValueTypeException e
) {
307 } catch (StateSystemDisposedException e
) {