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
.linuxtools
.internal
.lttng2
.kernel
.core
.Attributes
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.Messages
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
.ResourcesEntry
.Type
;
26 import org
.eclipse
.linuxtools
.lttng2
.kernel
.ui
.analysis
.LttngKernelAnalysisModule
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateSystemDisposedException
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.timegraph
.AbstractTimeGraphView
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
41 * Main implementation for the LTTng 2.0 kernel Resource view
43 * @author Patrick Tasse
45 public class ResourcesView
extends AbstractTimeGraphView
{
48 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
50 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
51 Messages
.ResourcesView_stateTypeName
54 // Timeout between updates in the build thread in ms
55 private static final long BUILD_UPDATE_TIMEOUT
= 500;
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
64 public ResourcesView() {
65 super(ID
, new ResourcesPresentationProvider());
66 setFilterColumns(FILTER_COLUMN_NAMES
);
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
74 protected String
getNextText() {
75 return Messages
.ResourcesView_nextResourceActionNameText
;
79 protected String
getNextTooltip() {
80 return Messages
.ResourcesView_nextResourceActionToolTipText
;
84 protected String
getPrevText() {
85 return Messages
.ResourcesView_previousResourceActionNameText
;
89 protected String
getPrevTooltip() {
90 return Messages
.ResourcesView_previousResourceActionToolTipText
;
94 protected void buildEventList(ITmfTrace trace
, ITmfTrace parentTrace
, IProgressMonitor monitor
) {
95 LttngKernelAnalysisModule module
= trace
.getAnalysisModules(LttngKernelAnalysisModule
.class).get(LttngKernelAnalysisModule
.ID
);
100 module
.waitForInitialization();
101 ITmfStateSystem ssq
= module
.getStateSystem();
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 (TimeGraphEntry entry
: traceEntry
.getChildren()) {
178 if (monitor
.isCanceled()) {
181 List
<ITimeEvent
> eventList
= getEventList(entry
, start
, endTime
, resolution
, monitor
);
182 if (eventList
!= null) {
183 for (ITimeEvent event
: eventList
) {
184 entry
.addEvent(event
);
195 protected List
<ITimeEvent
> getEventList(TimeGraphEntry entry
,
196 long startTime
, long endTime
, long resolution
,
197 IProgressMonitor monitor
) {
198 ResourcesEntry resourcesEntry
= (ResourcesEntry
) entry
;
199 LttngKernelAnalysisModule module
= resourcesEntry
.getTrace().getAnalysisModules(LttngKernelAnalysisModule
.class).get(LttngKernelAnalysisModule
.ID
);
200 if (module
== null) {
203 ITmfStateSystem ssq
= module
.getStateSystem();
207 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
208 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
209 if (realEnd
<= realStart
) {
212 List
<ITimeEvent
> eventList
= null;
213 int quark
= resourcesEntry
.getQuark();
216 if (resourcesEntry
.getType().equals(Type
.CPU
)) {
217 int statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
218 List
<ITmfStateInterval
> statusIntervals
= ssq
.queryHistoryRange(statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
219 eventList
= new ArrayList
<>(statusIntervals
.size());
220 long lastEndTime
= -1;
221 for (ITmfStateInterval statusInterval
: statusIntervals
) {
222 if (monitor
.isCanceled()) {
225 int status
= statusInterval
.getStateValue().unboxInt();
226 long time
= statusInterval
.getStartTime();
227 long duration
= statusInterval
.getEndTime() - time
+ 1;
228 if (!statusInterval
.getStateValue().isNull()) {
229 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
230 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
232 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
233 } else if (lastEndTime
== -1 || time
+ duration
>= endTime
) {
234 // add null event if it intersects the start or end time
235 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
237 lastEndTime
= time
+ duration
;
239 } else if (resourcesEntry
.getType().equals(Type
.IRQ
)) {
240 List
<ITmfStateInterval
> irqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
241 eventList
= new ArrayList
<>(irqIntervals
.size());
242 long lastEndTime
= -1;
243 boolean lastIsNull
= true;
244 for (ITmfStateInterval irqInterval
: irqIntervals
) {
245 if (monitor
.isCanceled()) {
248 long time
= irqInterval
.getStartTime();
249 long duration
= irqInterval
.getEndTime() - time
+ 1;
250 if (!irqInterval
.getStateValue().isNull()) {
251 int cpu
= irqInterval
.getStateValue().unboxInt();
252 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
255 if (lastEndTime
== -1) {
256 // add null event if it intersects the start time
257 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
259 if (lastEndTime
!= time
&& lastIsNull
) {
260 /* 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) */
261 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
263 if (time
+ duration
>= endTime
) {
264 // add null event if it intersects the end time
265 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
270 lastEndTime
= time
+ duration
;
272 } else if (resourcesEntry
.getType().equals(Type
.SOFT_IRQ
)) {
273 List
<ITmfStateInterval
> softIrqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
274 eventList
= new ArrayList
<>(softIrqIntervals
.size());
275 long lastEndTime
= -1;
276 boolean lastIsNull
= true;
277 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
278 if (monitor
.isCanceled()) {
281 long time
= softIrqInterval
.getStartTime();
282 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
283 if (!softIrqInterval
.getStateValue().isNull()) {
284 int cpu
= softIrqInterval
.getStateValue().unboxInt();
285 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
287 if (lastEndTime
== -1) {
288 // add null event if it intersects the start time
289 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
291 if (lastEndTime
!= time
&& lastIsNull
) {
292 /* 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) */
293 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
295 if (time
+ duration
>= endTime
) {
296 // add null event if it intersects the end time
297 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
302 lastEndTime
= time
+ duration
;
306 } catch (AttributeNotFoundException
| TimeRangeException
| StateValueTypeException e
) {
308 } catch (StateSystemDisposedException e
) {