lttng: Move to Java 7 and fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / resources / ResourcesView.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson, École Polytechnique de Montréal
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 * Geneviève Bastien - Move code to provide base classes for time graph views
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
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.core.trace.TmfTraceManager;
32 import org.eclipse.linuxtools.tmf.ui.views.timegraph.AbstractTimeGraphView;
33 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
34 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.NullTimeEvent;
35 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent;
36 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
37
38 /**
39 * Main implementation for the LTTng 2.0 kernel Resource view
40 *
41 * @author Patrick Tasse
42 */
43 public class ResourcesView extends AbstractTimeGraphView {
44
45 /** View ID. */
46 public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
47
48 private static final String[] FILTER_COLUMN_NAMES = new String[] {
49 Messages.ResourcesView_stateTypeName
50 };
51
52 // ------------------------------------------------------------------------
53 // Constructors
54 // ------------------------------------------------------------------------
55
56 /**
57 * Default constructor
58 */
59 public ResourcesView() {
60 super(ID, new ResourcesPresentationProvider());
61 setFilterColumns(FILTER_COLUMN_NAMES);
62 }
63
64 @Override
65 protected String getNextText() {
66 return Messages.ResourcesView_nextResourceActionNameText;
67 }
68
69 @Override
70 protected String getNextTooltip() {
71 return Messages.ResourcesView_nextResourceActionToolTipText;
72 }
73
74 @Override
75 protected String getPrevText() {
76 return Messages.ResourcesView_previousResourceActionNameText;
77 }
78
79 @Override
80 protected String getPrevTooltip() {
81 return Messages.ResourcesView_previousResourceActionToolTipText;
82 }
83
84 // ------------------------------------------------------------------------
85 // Internal
86 // ------------------------------------------------------------------------
87
88 @Override
89 protected void buildEventList(ITmfTrace trace, IProgressMonitor monitor) {
90 setStartTime(Long.MAX_VALUE);
91 setEndTime(Long.MIN_VALUE);
92
93 ArrayList<ResourcesEntry> entryList = new ArrayList<>();
94 for (ITmfTrace aTrace : TmfTraceManager.getTraceSet(trace)) {
95 if (monitor.isCanceled()) {
96 return;
97 }
98 if (aTrace instanceof LttngKernelTrace) {
99 LttngKernelTrace lttngKernelTrace = (LttngKernelTrace) aTrace;
100 ITmfStateSystem ssq = lttngKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID);
101 if (!ssq.waitUntilBuilt()) {
102 return;
103 }
104 long startTime = ssq.getStartTime();
105 long endTime = ssq.getCurrentEndTime() + 1;
106 ResourcesEntry groupEntry = new ResourcesEntry(lttngKernelTrace, aTrace.getName(), startTime, endTime, 0);
107 entryList.add(groupEntry);
108 setStartTime(Math.min(getStartTime(), startTime));
109 setEndTime(Math.max(getEndTime(), endTime));
110 List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$
111 ResourcesEntry[] cpuEntries = new ResourcesEntry[cpuQuarks.size()];
112 for (int i = 0; i < cpuQuarks.size(); i++) {
113 int cpuQuark = cpuQuarks.get(i);
114 int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));
115 ResourcesEntry entry = new ResourcesEntry(cpuQuark, lttngKernelTrace, getStartTime(), getEndTime(), Type.CPU, cpu);
116 groupEntry.addChild(entry);
117 cpuEntries[i] = entry;
118 }
119 List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
120 ResourcesEntry[] irqEntries = new ResourcesEntry[irqQuarks.size()];
121 for (int i = 0; i < irqQuarks.size(); i++) {
122 int irqQuark = irqQuarks.get(i);
123 int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
124 ResourcesEntry entry = new ResourcesEntry(irqQuark, lttngKernelTrace, getStartTime(), getEndTime(), Type.IRQ, irq);
125 groupEntry.addChild(entry);
126 irqEntries[i] = entry;
127 }
128 List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
129 ResourcesEntry[] softIrqEntries = new ResourcesEntry[softIrqQuarks.size()];
130 for (int i = 0; i < softIrqQuarks.size(); i++) {
131 int softIrqQuark = softIrqQuarks.get(i);
132 int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
133 ResourcesEntry entry = new ResourcesEntry(softIrqQuark, lttngKernelTrace, getStartTime(), getEndTime(), Type.SOFT_IRQ, softIrq);
134 groupEntry.addChild(entry);
135 softIrqEntries[i] = entry;
136 }
137 }
138 }
139 putEntryList(trace, new ArrayList<TimeGraphEntry>(entryList));
140
141 if (trace.equals(getTrace())) {
142 refresh();
143 }
144 for (ResourcesEntry traceEntry : entryList) {
145 if (monitor.isCanceled()) {
146 return;
147 }
148 LttngKernelTrace lttngKernelTrace = traceEntry.getTrace();
149 ITmfStateSystem ssq = lttngKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID);
150 long startTime = ssq.getStartTime();
151 long endTime = ssq.getCurrentEndTime() + 1;
152 long resolution = (endTime - startTime) / getDisplayWidth();
153 for (TimeGraphEntry entry : traceEntry.getChildren()) {
154 List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, monitor);
155 entry.setEventList(eventList);
156 redraw();
157 }
158 }
159 }
160
161 @Override
162 protected List<ITimeEvent> getEventList(TimeGraphEntry entry,
163 long startTime, long endTime, long resolution,
164 IProgressMonitor monitor) {
165 ResourcesEntry resourcesEntry = (ResourcesEntry) entry;
166 ITmfStateSystem ssq = resourcesEntry.getTrace().getStateSystems().get(LttngKernelTrace.STATE_ID);
167 final long realStart = Math.max(startTime, ssq.getStartTime());
168 final long realEnd = Math.min(endTime, ssq.getCurrentEndTime() + 1);
169 if (realEnd <= realStart) {
170 return null;
171 }
172 List<ITimeEvent> eventList = null;
173 int quark = resourcesEntry.getQuark();
174
175 try {
176 if (resourcesEntry.getType().equals(Type.CPU)) {
177 int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);
178 List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, realStart, realEnd - 1, resolution, monitor);
179 eventList = new ArrayList<>(statusIntervals.size());
180 long lastEndTime = -1;
181 for (ITmfStateInterval statusInterval : statusIntervals) {
182 if (monitor.isCanceled()) {
183 return null;
184 }
185 int status = statusInterval.getStateValue().unboxInt();
186 long time = statusInterval.getStartTime();
187 long duration = statusInterval.getEndTime() - time + 1;
188 if (!statusInterval.getStateValue().isNull()) {
189 if (lastEndTime != time && lastEndTime != -1) {
190 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
191 }
192 eventList.add(new TimeEvent(entry, time, duration, status));
193 } else if (lastEndTime == -1 || time + duration >= endTime) {
194 // add null event if it intersects the start or end time
195 eventList.add(new NullTimeEvent(entry, time, duration));
196 }
197 lastEndTime = time + duration;
198 }
199 } else if (resourcesEntry.getType().equals(Type.IRQ)) {
200 List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
201 eventList = new ArrayList<>(irqIntervals.size());
202 long lastEndTime = -1;
203 boolean lastIsNull = true;
204 for (ITmfStateInterval irqInterval : irqIntervals) {
205 if (monitor.isCanceled()) {
206 return null;
207 }
208 long time = irqInterval.getStartTime();
209 long duration = irqInterval.getEndTime() - time + 1;
210 if (!irqInterval.getStateValue().isNull()) {
211 int cpu = irqInterval.getStateValue().unboxInt();
212 eventList.add(new TimeEvent(entry, time, duration, cpu));
213 lastIsNull = false;
214 } else {
215 if (lastEndTime == -1) {
216 // add null event if it intersects the start time
217 eventList.add(new NullTimeEvent(entry, time, duration));
218 } else {
219 if (lastEndTime != time && lastIsNull) {
220 /* 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) */
221 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1));
222 }
223 if (time + duration >= endTime) {
224 // add null event if it intersects the end time
225 eventList.add(new NullTimeEvent(entry, time, duration));
226 }
227 }
228 lastIsNull = true;
229 }
230 lastEndTime = time + duration;
231 }
232 } else if (resourcesEntry.getType().equals(Type.SOFT_IRQ)) {
233 List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
234 eventList = new ArrayList<>(softIrqIntervals.size());
235 long lastEndTime = -1;
236 boolean lastIsNull = true;
237 for (ITmfStateInterval softIrqInterval : softIrqIntervals) {
238 if (monitor.isCanceled()) {
239 return null;
240 }
241 long time = softIrqInterval.getStartTime();
242 long duration = softIrqInterval.getEndTime() - time + 1;
243 if (!softIrqInterval.getStateValue().isNull()) {
244 int cpu = softIrqInterval.getStateValue().unboxInt();
245 eventList.add(new TimeEvent(entry, time, duration, cpu));
246 } else {
247 if (lastEndTime == -1) {
248 // add null event if it intersects the start time
249 eventList.add(new NullTimeEvent(entry, time, duration));
250 } else {
251 if (lastEndTime != time && lastIsNull) {
252 /* 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) */
253 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1));
254 }
255 if (time + duration >= endTime) {
256 // add null event if it intersects the end time
257 eventList.add(new NullTimeEvent(entry, time, duration));
258 }
259 }
260 lastIsNull = true;
261 }
262 lastEndTime = time + duration;
263 }
264 }
265
266 } catch (AttributeNotFoundException e) {
267 e.printStackTrace();
268 } catch (TimeRangeException e) {
269 e.printStackTrace();
270 } catch (StateValueTypeException e) {
271 e.printStackTrace();
272 } catch (StateSystemDisposedException e) {
273 /* Ignored */
274 }
275 return eventList;
276 }
277
278 }
This page took 0.037779 seconds and 5 git commands to generate.