1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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
.List
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.Attributes
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.Messages
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
.ResourcesEntry
.Type
;
23 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.trace
.LttngKernelTrace
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateSystemDisposedException
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.timegraph
.AbstractTimeGraphView
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
37 * Main implementation for the LTTng 2.0 kernel Resource view
39 * @author Patrick Tasse
41 public class ResourcesView
extends AbstractTimeGraphView
{
44 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
47 * Default value for events with no other value. Since value in this case is
48 * often a CPU number, this constant should be <0
50 public static final int NO_VALUE_EVENT
= -999;
52 private static final String PROCESS_COLUMN
= Messages
.ControlFlowView_processColumn
;
54 private static final String
[] COLUMN_NAMES
= new String
[] {
58 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
62 private static final int[] WEIGHTS
= { 15, 85 };
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
71 public ResourcesView() {
72 super(ID
, COLUMN_NAMES
, FILTER_COLUMN_NAMES
, new ResourcesPresentationProvider());
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
;
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 protected void buildEventList(ITmfTrace trace
, IProgressMonitor monitor
) {
102 setStartTime(Long
.MAX_VALUE
);
103 setEndTime(Long
.MIN_VALUE
);
105 ArrayList
<ResourcesEntry
> entryList
= new ArrayList
<ResourcesEntry
>();
106 for (ITmfTrace aTrace
: fTraceManager
.getActiveTraceSet()) {
107 if (monitor
.isCanceled()) {
110 if (aTrace
instanceof LttngKernelTrace
) {
111 LttngKernelTrace lttngKernelTrace
= (LttngKernelTrace
) aTrace
;
112 ITmfStateSystem ssq
= lttngKernelTrace
.getStateSystems().get(LttngKernelTrace
.STATE_ID
);
113 if (!ssq
.waitUntilBuilt()) {
116 long startTime
= ssq
.getStartTime();
117 long endTime
= ssq
.getCurrentEndTime() + 1;
118 ResourcesEntry groupEntry
= new ResourcesEntry(lttngKernelTrace
, aTrace
.getName(), startTime
, endTime
, 0);
119 entryList
.add(groupEntry
);
120 setStartTime(Math
.min(getStartTime(), startTime
));
121 setEndTime(Math
.max(getEndTime(), endTime
));
122 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
123 ResourcesEntry
[] cpuEntries
= new ResourcesEntry
[cpuQuarks
.size()];
124 for (int i
= 0; i
< cpuQuarks
.size(); i
++) {
125 int cpuQuark
= cpuQuarks
.get(i
);
126 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
127 ResourcesEntry entry
= new ResourcesEntry(cpuQuark
, lttngKernelTrace
, getStartTime(), getEndTime(), Type
.CPU
, cpu
);
128 groupEntry
.addChild(entry
);
129 cpuEntries
[i
] = entry
;
131 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
132 ResourcesEntry
[] irqEntries
= new ResourcesEntry
[irqQuarks
.size()];
133 for (int i
= 0; i
< irqQuarks
.size(); i
++) {
134 int irqQuark
= irqQuarks
.get(i
);
135 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
136 ResourcesEntry entry
= new ResourcesEntry(irqQuark
, lttngKernelTrace
, getStartTime(), getEndTime(), Type
.IRQ
, irq
);
137 groupEntry
.addChild(entry
);
138 irqEntries
[i
] = entry
;
140 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
141 ResourcesEntry
[] softIrqEntries
= new ResourcesEntry
[softIrqQuarks
.size()];
142 for (int i
= 0; i
< softIrqQuarks
.size(); i
++) {
143 int softIrqQuark
= softIrqQuarks
.get(i
);
144 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
145 ResourcesEntry entry
= new ResourcesEntry(softIrqQuark
, lttngKernelTrace
, getStartTime(), getEndTime(), Type
.SOFT_IRQ
, softIrq
);
146 groupEntry
.addChild(entry
);
147 softIrqEntries
[i
] = entry
;
151 putEntryList(trace
, (ArrayList
<TimeGraphEntry
>) entryList
.clone());
153 if (trace
.equals(getTrace())) {
156 for (ResourcesEntry traceEntry
: entryList
) {
157 if (monitor
.isCanceled()) {
160 LttngKernelTrace lttngKernelTrace
= traceEntry
.getTrace();
161 ITmfStateSystem ssq
= lttngKernelTrace
.getStateSystems().get(LttngKernelTrace
.STATE_ID
);
162 long startTime
= ssq
.getStartTime();
163 long endTime
= ssq
.getCurrentEndTime() + 1;
164 long resolution
= (endTime
- startTime
) / getDisplayWidth();
165 for (TimeGraphEntry entry
: traceEntry
.getChildren()) {
166 List
<ITimeEvent
> eventList
= getEventList(entry
, startTime
, endTime
, resolution
, monitor
);
167 entry
.setEventList(eventList
);
174 protected List
<ITimeEvent
> getEventList(TimeGraphEntry entry
,
175 long startTime
, long endTime
, long resolution
,
176 IProgressMonitor monitor
) {
177 ITmfStateSystem ssq
= entry
.getTrace().getStateSystems().get(LttngKernelTrace
.STATE_ID
);
178 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
179 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
180 if (realEnd
<= realStart
) {
183 List
<ITimeEvent
> eventList
= null;
185 if (!(entry
instanceof ResourcesEntry
)) {
188 ResourcesEntry resourcesEntry
= (ResourcesEntry
) entry
;
189 int quark
= resourcesEntry
.getQuark();
192 if (resourcesEntry
.getType().equals(Type
.CPU
)) {
193 int statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
194 List
<ITmfStateInterval
> statusIntervals
= ssq
.queryHistoryRange(statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
195 eventList
= new ArrayList
<ITimeEvent
>(statusIntervals
.size());
196 long lastEndTime
= -1;
197 for (ITmfStateInterval statusInterval
: statusIntervals
) {
198 if (monitor
.isCanceled()) {
201 int status
= statusInterval
.getStateValue().unboxInt();
202 long time
= statusInterval
.getStartTime();
203 long duration
= statusInterval
.getEndTime() - time
+ 1;
204 if (!statusInterval
.getStateValue().isNull()) {
205 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
206 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
208 eventList
.add(new TimeEvent(entry
, time
, duration
, status
));
209 lastEndTime
= time
+ duration
;
211 if (true) {// includeNull) {
212 eventList
.add(new TimeEvent(entry
, time
, duration
, NO_VALUE_EVENT
));
216 } else if (resourcesEntry
.getType().equals(Type
.IRQ
)) {
217 List
<ITmfStateInterval
> irqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
218 eventList
= new ArrayList
<ITimeEvent
>(irqIntervals
.size());
219 long lastEndTime
= -1;
220 boolean lastIsNull
= true;
221 for (ITmfStateInterval irqInterval
: irqIntervals
) {
222 if (monitor
.isCanceled()) {
225 long time
= irqInterval
.getStartTime();
226 long duration
= irqInterval
.getEndTime() - time
+ 1;
227 if (!irqInterval
.getStateValue().isNull()) {
228 int cpu
= irqInterval
.getStateValue().unboxInt();
229 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
232 if (lastEndTime
!= time
&& lastEndTime
!= -1 && lastIsNull
) {
233 /* 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) */
234 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
236 eventList
.add(new TimeEvent(entry
, time
, duration
, NO_VALUE_EVENT
));
240 lastEndTime
= time
+ duration
;
242 } else if (resourcesEntry
.getType().equals(Type
.SOFT_IRQ
)) {
243 List
<ITmfStateInterval
> softIrqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
244 eventList
= new ArrayList
<ITimeEvent
>(softIrqIntervals
.size());
245 long lastEndTime
= -1;
246 boolean lastIsNull
= true;
247 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
248 if (monitor
.isCanceled()) {
251 long time
= softIrqInterval
.getStartTime();
252 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
253 if (!softIrqInterval
.getStateValue().isNull()) {
254 int cpu
= softIrqInterval
.getStateValue().unboxInt();
255 eventList
.add(new TimeEvent(entry
, time
, duration
, cpu
));
257 if (lastEndTime
!= time
&& lastEndTime
!= -1 && lastIsNull
) {
258 /* 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) */
259 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
261 eventList
.add(new TimeEvent(entry
, time
, duration
, NO_VALUE_EVENT
));
265 lastEndTime
= time
+ duration
;
269 } catch (AttributeNotFoundException e
) {
271 } catch (TimeRangeException e
) {
273 } catch (StateValueTypeException e
) {
275 } catch (StateSystemDisposedException e
) {