tmf: Split ITmfStateSystem.waitUntilBuilt() in separate methods
[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 == null) {
102 return;
103 }
104 ssq.waitUntilBuilt();
105 if (ssq.isCancelled()) {
106 return;
107 }
108 long startTime = ssq.getStartTime();
109 long endTime = ssq.getCurrentEndTime() + 1;
110 ResourcesEntry groupEntry = new ResourcesEntry(lttngKernelTrace, aTrace.getName(), startTime, endTime, 0);
111 entryList.add(groupEntry);
112 setStartTime(Math.min(getStartTime(), startTime));
113 setEndTime(Math.max(getEndTime(), endTime));
114 List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$
115 ResourcesEntry[] cpuEntries = new ResourcesEntry[cpuQuarks.size()];
116 for (int i = 0; i < cpuQuarks.size(); i++) {
117 int cpuQuark = cpuQuarks.get(i);
118 int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark));
119 ResourcesEntry entry = new ResourcesEntry(cpuQuark, lttngKernelTrace, getStartTime(), getEndTime(), Type.CPU, cpu);
120 groupEntry.addChild(entry);
121 cpuEntries[i] = entry;
122 }
123 List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
124 ResourcesEntry[] irqEntries = new ResourcesEntry[irqQuarks.size()];
125 for (int i = 0; i < irqQuarks.size(); i++) {
126 int irqQuark = irqQuarks.get(i);
127 int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
128 ResourcesEntry entry = new ResourcesEntry(irqQuark, lttngKernelTrace, getStartTime(), getEndTime(), Type.IRQ, irq);
129 groupEntry.addChild(entry);
130 irqEntries[i] = entry;
131 }
132 List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
133 ResourcesEntry[] softIrqEntries = new ResourcesEntry[softIrqQuarks.size()];
134 for (int i = 0; i < softIrqQuarks.size(); i++) {
135 int softIrqQuark = softIrqQuarks.get(i);
136 int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
137 ResourcesEntry entry = new ResourcesEntry(softIrqQuark, lttngKernelTrace, getStartTime(), getEndTime(), Type.SOFT_IRQ, softIrq);
138 groupEntry.addChild(entry);
139 softIrqEntries[i] = entry;
140 }
141 }
142 }
143 putEntryList(trace, new ArrayList<TimeGraphEntry>(entryList));
144
145 if (trace.equals(getTrace())) {
146 refresh();
147 }
148 for (ResourcesEntry traceEntry : entryList) {
149 if (monitor.isCanceled()) {
150 return;
151 }
152 LttngKernelTrace lttngKernelTrace = traceEntry.getTrace();
153 ITmfStateSystem ssq = lttngKernelTrace.getStateSystems().get(LttngKernelTrace.STATE_ID);
154 long startTime = ssq.getStartTime();
155 long endTime = ssq.getCurrentEndTime() + 1;
156 long resolution = (endTime - startTime) / getDisplayWidth();
157 for (TimeGraphEntry entry : traceEntry.getChildren()) {
158 List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, monitor);
159 entry.setEventList(eventList);
160 redraw();
161 }
162 }
163 }
164
165 @Override
166 protected List<ITimeEvent> getEventList(TimeGraphEntry entry,
167 long startTime, long endTime, long resolution,
168 IProgressMonitor monitor) {
169 ResourcesEntry resourcesEntry = (ResourcesEntry) entry;
170 ITmfStateSystem ssq = resourcesEntry.getTrace().getStateSystems().get(LttngKernelTrace.STATE_ID);
171 final long realStart = Math.max(startTime, ssq.getStartTime());
172 final long realEnd = Math.min(endTime, ssq.getCurrentEndTime() + 1);
173 if (realEnd <= realStart) {
174 return null;
175 }
176 List<ITimeEvent> eventList = null;
177 int quark = resourcesEntry.getQuark();
178
179 try {
180 if (resourcesEntry.getType().equals(Type.CPU)) {
181 int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);
182 List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, realStart, realEnd - 1, resolution, monitor);
183 eventList = new ArrayList<>(statusIntervals.size());
184 long lastEndTime = -1;
185 for (ITmfStateInterval statusInterval : statusIntervals) {
186 if (monitor.isCanceled()) {
187 return null;
188 }
189 int status = statusInterval.getStateValue().unboxInt();
190 long time = statusInterval.getStartTime();
191 long duration = statusInterval.getEndTime() - time + 1;
192 if (!statusInterval.getStateValue().isNull()) {
193 if (lastEndTime != time && lastEndTime != -1) {
194 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
195 }
196 eventList.add(new TimeEvent(entry, time, duration, status));
197 } else if (lastEndTime == -1 || time + duration >= endTime) {
198 // add null event if it intersects the start or end time
199 eventList.add(new NullTimeEvent(entry, time, duration));
200 }
201 lastEndTime = time + duration;
202 }
203 } else if (resourcesEntry.getType().equals(Type.IRQ)) {
204 List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
205 eventList = new ArrayList<>(irqIntervals.size());
206 long lastEndTime = -1;
207 boolean lastIsNull = true;
208 for (ITmfStateInterval irqInterval : irqIntervals) {
209 if (monitor.isCanceled()) {
210 return null;
211 }
212 long time = irqInterval.getStartTime();
213 long duration = irqInterval.getEndTime() - time + 1;
214 if (!irqInterval.getStateValue().isNull()) {
215 int cpu = irqInterval.getStateValue().unboxInt();
216 eventList.add(new TimeEvent(entry, time, duration, cpu));
217 lastIsNull = false;
218 } else {
219 if (lastEndTime == -1) {
220 // add null event if it intersects the start time
221 eventList.add(new NullTimeEvent(entry, time, duration));
222 } else {
223 if (lastEndTime != time && lastIsNull) {
224 /* 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) */
225 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1));
226 }
227 if (time + duration >= endTime) {
228 // add null event if it intersects the end time
229 eventList.add(new NullTimeEvent(entry, time, duration));
230 }
231 }
232 lastIsNull = true;
233 }
234 lastEndTime = time + duration;
235 }
236 } else if (resourcesEntry.getType().equals(Type.SOFT_IRQ)) {
237 List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor);
238 eventList = new ArrayList<>(softIrqIntervals.size());
239 long lastEndTime = -1;
240 boolean lastIsNull = true;
241 for (ITmfStateInterval softIrqInterval : softIrqIntervals) {
242 if (monitor.isCanceled()) {
243 return null;
244 }
245 long time = softIrqInterval.getStartTime();
246 long duration = softIrqInterval.getEndTime() - time + 1;
247 if (!softIrqInterval.getStateValue().isNull()) {
248 int cpu = softIrqInterval.getStateValue().unboxInt();
249 eventList.add(new TimeEvent(entry, time, duration, cpu));
250 } else {
251 if (lastEndTime == -1) {
252 // add null event if it intersects the start time
253 eventList.add(new NullTimeEvent(entry, time, duration));
254 } else {
255 if (lastEndTime != time && lastIsNull) {
256 /* 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) */
257 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1));
258 }
259 if (time + duration >= endTime) {
260 // add null event if it intersects the end time
261 eventList.add(new NullTimeEvent(entry, time, duration));
262 }
263 }
264 lastIsNull = true;
265 }
266 lastEndTime = time + duration;
267 }
268 }
269
270 } catch (AttributeNotFoundException e) {
271 e.printStackTrace();
272 } catch (TimeRangeException e) {
273 e.printStackTrace();
274 } catch (StateValueTypeException e) {
275 e.printStackTrace();
276 } catch (StateSystemDisposedException e) {
277 /* Ignored */
278 }
279 return eventList;
280 }
281
282 }
This page took 0.03916 seconds and 5 git commands to generate.