1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 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
.analysis
.os
.linux
.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
.NonNull
;
25 import org
.eclipse
.jdt
.annotation
.Nullable
;
26 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.Attributes
;
27 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernelanalysis
.KernelAnalysisModule
;
28 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.ui
.views
.resources
.ResourcesEntry
.Type
;
29 import org
.eclipse
.tracecompass
.internal
.analysis
.os
.linux
.ui
.Messages
;
30 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
31 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
32 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
35 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
.AbstractStateSystemTimeGraphView
;
36 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
37 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
38 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
39 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
43 * Main implementation for the LTTng 2.0 kernel Resource view
45 * @author Patrick Tasse
47 public class ResourcesView
extends AbstractStateSystemTimeGraphView
{
50 public static final String ID
= "org.eclipse.tracecompass.analysis.os.linux.views.resources"; //$NON-NLS-1$
52 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
53 Messages
.ResourcesView_stateTypeName
56 // Timeout between updates in the build thread in ms
57 private static final long BUILD_UPDATE_TIMEOUT
= 500;
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
66 public ResourcesView() {
67 super(ID
, new ResourcesPresentationProvider());
68 setFilterColumns(FILTER_COLUMN_NAMES
);
69 setFilterLabelProvider(new ResourcesFilterLabelProvider());
72 private static class ResourcesFilterLabelProvider
extends TreeLabelProvider
{
74 public String
getColumnText(Object element
, int columnIndex
) {
75 ResourcesEntry entry
= (ResourcesEntry
) element
;
76 if (columnIndex
== 0) {
77 return entry
.getName();
79 return ""; //$NON-NLS-1$
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
89 protected String
getNextText() {
90 return Messages
.ResourcesView_nextResourceActionNameText
;
94 protected String
getNextTooltip() {
95 return Messages
.ResourcesView_nextResourceActionToolTipText
;
99 protected String
getPrevText() {
100 return Messages
.ResourcesView_previousResourceActionNameText
;
104 protected String
getPrevTooltip() {
105 return Messages
.ResourcesView_previousResourceActionToolTipText
;
109 protected void buildEventList(ITmfTrace trace
, ITmfTrace parentTrace
, final IProgressMonitor monitor
) {
110 final ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, KernelAnalysisModule
.ID
);
114 Comparator
<ITimeGraphEntry
> comparator
= new Comparator
<ITimeGraphEntry
>() {
116 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
117 return ((ResourcesEntry
) o1
).compareTo(o2
);
121 Map
<Integer
, ResourcesEntry
> entryMap
= new HashMap
<>();
122 TimeGraphEntry traceEntry
= null;
124 long startTime
= ssq
.getStartTime();
125 long start
= startTime
;
126 setStartTime(Math
.min(getStartTime(), startTime
));
127 boolean complete
= false;
129 if (monitor
.isCanceled()) {
132 complete
= ssq
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
133 if (ssq
.isCancelled()) {
136 long end
= ssq
.getCurrentEndTime();
137 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
140 long endTime
= end
+ 1;
141 setEndTime(Math
.max(getEndTime(), endTime
));
143 if (traceEntry
== null) {
144 traceEntry
= new ResourcesEntry(trace
, trace
.getName(), startTime
, endTime
, 0);
145 traceEntry
.sortChildren(comparator
);
146 List
<TimeGraphEntry
> entryList
= Collections
.singletonList(traceEntry
);
147 addToEntryList(parentTrace
, ssq
, entryList
);
149 traceEntry
.updateEndTime(endTime
);
152 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
153 for (Integer cpuQuark
: cpuQuarks
) {
154 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
155 ResourcesEntry entry
= entryMap
.get(cpuQuark
);
157 entry
= new ResourcesEntry(cpuQuark
, trace
, startTime
, endTime
, Type
.CPU
, cpu
);
158 entryMap
.put(cpuQuark
, entry
);
159 traceEntry
.addChild(entry
);
161 entry
.updateEndTime(endTime
);
164 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
165 for (Integer irqQuark
: irqQuarks
) {
166 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
167 ResourcesEntry entry
= entryMap
.get(irqQuark
);
169 entry
= new ResourcesEntry(irqQuark
, trace
, startTime
, endTime
, Type
.IRQ
, irq
);
170 entryMap
.put(irqQuark
, entry
);
171 traceEntry
.addChild(entry
);
173 entry
.updateEndTime(endTime
);
176 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
177 for (Integer softIrqQuark
: softIrqQuarks
) {
178 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
179 ResourcesEntry entry
= entryMap
.get(softIrqQuark
);
181 entry
= new ResourcesEntry(softIrqQuark
, trace
, startTime
, endTime
, Type
.SOFT_IRQ
, softIrq
);
182 entryMap
.put(softIrqQuark
, entry
);
183 traceEntry
.addChild(entry
);
185 entry
.updateEndTime(endTime
);
189 if (parentTrace
.equals(getTrace())) {
192 final List
<?
extends ITimeGraphEntry
> traceEntryChildren
= traceEntry
.getChildren();
193 final long resolution
= Math
.max(1, (endTime
- ssq
.getStartTime()) / getDisplayWidth());
194 final long qStart
= start
;
195 final long qEnd
= end
;
196 queryFullStates(ssq
, qStart
, qEnd
, resolution
, monitor
, new IQueryHandler() {
198 public void handle(List
<List
<ITmfStateInterval
>> fullStates
, List
<ITmfStateInterval
> prevFullState
) {
199 for (ITimeGraphEntry child
: traceEntryChildren
) {
200 if (monitor
.isCanceled()) {
203 if (child
instanceof TimeGraphEntry
) {
204 TimeGraphEntry entry
= (TimeGraphEntry
) child
;
205 List
<ITimeEvent
> eventList
= getEventList(entry
, ssq
, fullStates
, prevFullState
, monitor
);
206 if (eventList
!= null) {
207 for (ITimeEvent event
: eventList
) {
208 entry
.addEvent(event
);
221 protected @Nullable List
<ITimeEvent
> getEventList(@NonNull TimeGraphEntry entry
, ITmfStateSystem ssq
,
222 @NonNull List
<List
<ITmfStateInterval
>> fullStates
, @Nullable List
<ITmfStateInterval
> prevFullState
, @NonNull IProgressMonitor monitor
) {
223 ResourcesEntry resourcesEntry
= (ResourcesEntry
) entry
;
224 List
<ITimeEvent
> eventList
= null;
225 int quark
= resourcesEntry
.getQuark();
227 if (resourcesEntry
.getType().equals(Type
.CPU
)) {
230 statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
231 } catch (AttributeNotFoundException e
) {
233 * The sub-attribute "status" is not available. May happen
234 * if the trace does not have sched_switch events enabled.
238 eventList
= new ArrayList
<>(fullStates
.size());
239 ITmfStateInterval lastInterval
= prevFullState
== null || statusQuark
>= prevFullState
.size() ?
null : prevFullState
.get(statusQuark
);
240 long lastStartTime
= lastInterval
== null ?
-1 : lastInterval
.getStartTime();
241 long lastEndTime
= lastInterval
== null ?
-1 : lastInterval
.getEndTime() + 1;
242 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
243 if (monitor
.isCanceled()) {
246 if (statusQuark
>= fullState
.size()) {
247 /* No information on this CPU (yet?), skip it for now */
250 ITmfStateInterval statusInterval
= fullState
.get(statusQuark
);
251 int status
= statusInterval
.getStateValue().unboxInt();
252 long time
= statusInterval
.getStartTime();
253 long duration
= statusInterval
.getEndTime() - time
+ 1;
254 if (time
== lastStartTime
) {
257 if (!statusInterval
.getStateValue().isNull()) {
258 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
259 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
261 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
263 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
265 lastStartTime
= time
;
266 lastEndTime
= time
+ duration
;
268 } else if (resourcesEntry
.getType().equals(Type
.IRQ
) || resourcesEntry
.getType().equals(Type
.SOFT_IRQ
)) {
269 eventList
= new ArrayList
<>(fullStates
.size());
270 ITmfStateInterval lastInterval
= prevFullState
== null || quark
>= prevFullState
.size() ?
null : prevFullState
.get(quark
);
271 long lastStartTime
= lastInterval
== null ?
-1 : lastInterval
.getStartTime();
272 long lastEndTime
= lastInterval
== null ?
-1 : lastInterval
.getEndTime() + 1;
273 boolean lastIsNull
= lastInterval
== null ?
false : lastInterval
.getStateValue().isNull();
274 for (List
<ITmfStateInterval
> fullState
: fullStates
) {
275 if (monitor
.isCanceled()) {
278 if (quark
>= fullState
.size()) {
279 /* No information on this IRQ (yet?), skip it for now */
282 ITmfStateInterval irqInterval
= fullState
.get(quark
);
283 long time
= irqInterval
.getStartTime();
284 long duration
= irqInterval
.getEndTime() - time
+ 1;
285 if (time
== lastStartTime
) {
288 if (!irqInterval
.getStateValue().isNull()) {
289 int cpu
= irqInterval
.getStateValue().unboxInt();
290 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
293 if (lastEndTime
!= time
&& lastIsNull
) {
294 /* 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) */
295 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
297 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
300 lastStartTime
= time
;
301 lastEndTime
= time
+ duration
;