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
.trace
.ITmfTrace
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.timegraph
.AbstractTimeGraphView
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
42 * Main implementation for the LTTng 2.0 kernel Resource view
44 * @author Patrick Tasse
46 public class ResourcesView
extends AbstractTimeGraphView
{
49 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
51 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
52 Messages
.ResourcesView_stateTypeName
55 // Timeout between updates in the build thread in ms
56 private static final long BUILD_UPDATE_TIMEOUT
= 500;
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
65 public ResourcesView() {
66 super(ID
, new ResourcesPresentationProvider());
67 setFilterColumns(FILTER_COLUMN_NAMES
);
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
75 protected String
getNextText() {
76 return Messages
.ResourcesView_nextResourceActionNameText
;
80 protected String
getNextTooltip() {
81 return Messages
.ResourcesView_nextResourceActionToolTipText
;
85 protected String
getPrevText() {
86 return Messages
.ResourcesView_previousResourceActionNameText
;
90 protected String
getPrevTooltip() {
91 return Messages
.ResourcesView_previousResourceActionToolTipText
;
95 protected void buildEventList(ITmfTrace trace
, ITmfTrace parentTrace
, IProgressMonitor monitor
) {
96 LttngKernelAnalysisModule module
= trace
.getAnalysisModuleOfClass(LttngKernelAnalysisModule
.class, LttngKernelAnalysisModule
.ID
);
101 module
.waitForInitialization();
102 ITmfStateSystem ssq
= module
.getStateSystem();
107 Map
<Integer
, ResourcesEntry
> entryMap
= new HashMap
<>();
108 TimeGraphEntry traceEntry
= null;
110 long startTime
= ssq
.getStartTime();
111 long start
= startTime
;
112 setStartTime(Math
.min(getStartTime(), startTime
));
113 boolean complete
= false;
115 if (monitor
.isCanceled()) {
118 complete
= ssq
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
119 if (ssq
.isCancelled()) {
122 long end
= ssq
.getCurrentEndTime();
123 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
126 long endTime
= end
+ 1;
127 setEndTime(Math
.max(getEndTime(), endTime
));
129 if (traceEntry
== null) {
130 traceEntry
= new ResourcesEntry(trace
, trace
.getName(), startTime
, endTime
, 0);
131 List
<TimeGraphEntry
> entryList
= Collections
.singletonList(traceEntry
);
132 addToEntryList(parentTrace
, entryList
);
134 traceEntry
.updateEndTime(endTime
);
137 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
138 for (Integer cpuQuark
: cpuQuarks
) {
139 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
140 ResourcesEntry entry
= entryMap
.get(cpuQuark
);
142 entry
= new ResourcesEntry(cpuQuark
, trace
, startTime
, endTime
, Type
.CPU
, cpu
);
143 entryMap
.put(cpuQuark
, entry
);
144 traceEntry
.addChild(entry
);
146 entry
.updateEndTime(endTime
);
149 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
150 for (Integer irqQuark
: irqQuarks
) {
151 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
152 ResourcesEntry entry
= entryMap
.get(irqQuark
);
154 entry
= new ResourcesEntry(irqQuark
, trace
, startTime
, endTime
, Type
.IRQ
, irq
);
155 entryMap
.put(irqQuark
, entry
);
156 traceEntry
.addChild(entry
);
158 entry
.updateEndTime(endTime
);
161 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
162 for (Integer softIrqQuark
: softIrqQuarks
) {
163 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
164 ResourcesEntry entry
= entryMap
.get(softIrqQuark
);
166 entry
= new ResourcesEntry(softIrqQuark
, trace
, startTime
, endTime
, Type
.SOFT_IRQ
, softIrq
);
167 entryMap
.put(softIrqQuark
, entry
);
168 traceEntry
.addChild(entry
);
170 entry
.updateEndTime(endTime
);
174 if (parentTrace
.equals(getTrace())) {
177 long resolution
= Math
.max(1, (endTime
- ssq
.getStartTime()) / getDisplayWidth());
178 for (TimeGraphEntry entry
: traceEntry
.getChildren()) {
179 if (monitor
.isCanceled()) {
182 List
<ITimeEvent
> eventList
= getEventList(entry
, start
, endTime
, resolution
, monitor
);
183 if (eventList
!= null) {
184 for (ITimeEvent event
: eventList
) {
185 entry
.addEvent(event
);
196 protected @Nullable List
<ITimeEvent
> getEventList(TimeGraphEntry entry
,
197 long startTime
, long endTime
, long resolution
,
198 IProgressMonitor monitor
) {
199 ResourcesEntry resourcesEntry
= (ResourcesEntry
) entry
;
200 LttngKernelAnalysisModule module
= resourcesEntry
.getTrace().getAnalysisModuleOfClass(LttngKernelAnalysisModule
.class, LttngKernelAnalysisModule
.ID
);
201 if (module
== null) {
204 ITmfStateSystem ssq
= module
.getStateSystem();
208 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
209 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
210 if (realEnd
<= realStart
) {
213 List
<ITimeEvent
> eventList
= null;
214 int quark
= resourcesEntry
.getQuark();
217 if (resourcesEntry
.getType().equals(Type
.CPU
)) {
218 int statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
219 List
<ITmfStateInterval
> statusIntervals
= ssq
.queryHistoryRange(statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
220 eventList
= new ArrayList
<>(statusIntervals
.size());
221 long lastEndTime
= -1;
222 for (ITmfStateInterval statusInterval
: statusIntervals
) {
223 if (monitor
.isCanceled()) {
226 int status
= statusInterval
.getStateValue().unboxInt();
227 long time
= statusInterval
.getStartTime();
228 long duration
= statusInterval
.getEndTime() - time
+ 1;
229 if (!statusInterval
.getStateValue().isNull()) {
230 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
231 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
233 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
234 } else if (lastEndTime
== -1 || time
+ duration
>= endTime
) {
235 // add null event if it intersects the start or end time
236 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
238 lastEndTime
= time
+ duration
;
240 } else if (resourcesEntry
.getType().equals(Type
.IRQ
)) {
241 List
<ITmfStateInterval
> irqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
242 eventList
= new ArrayList
<>(irqIntervals
.size());
243 long lastEndTime
= -1;
244 boolean lastIsNull
= true;
245 for (ITmfStateInterval irqInterval
: irqIntervals
) {
246 if (monitor
.isCanceled()) {
249 long time
= irqInterval
.getStartTime();
250 long duration
= irqInterval
.getEndTime() - time
+ 1;
251 if (!irqInterval
.getStateValue().isNull()) {
252 int cpu
= irqInterval
.getStateValue().unboxInt();
253 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
256 if (lastEndTime
== -1) {
257 // add null event if it intersects the start time
258 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
260 if (lastEndTime
!= time
&& lastIsNull
) {
261 /* 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) */
262 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
264 if (time
+ duration
>= endTime
) {
265 // add null event if it intersects the end time
266 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
271 lastEndTime
= time
+ duration
;
273 } else if (resourcesEntry
.getType().equals(Type
.SOFT_IRQ
)) {
274 List
<ITmfStateInterval
> softIrqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
275 eventList
= new ArrayList
<>(softIrqIntervals
.size());
276 long lastEndTime
= -1;
277 boolean lastIsNull
= true;
278 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
279 if (monitor
.isCanceled()) {
282 long time
= softIrqInterval
.getStartTime();
283 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
284 if (!softIrqInterval
.getStateValue().isNull()) {
285 int cpu
= softIrqInterval
.getStateValue().unboxInt();
286 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
288 if (lastEndTime
== -1) {
289 // add null event if it intersects the start time
290 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
292 if (lastEndTime
!= time
&& lastIsNull
) {
293 /* 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) */
294 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
296 if (time
+ duration
>= endTime
) {
297 // add null event if it intersects the end time
298 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
303 lastEndTime
= time
+ duration
;
307 } catch (AttributeNotFoundException
| TimeRangeException
| StateValueTypeException e
) {
309 } catch (StateSystemDisposedException e
) {