Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
1cf25311 | 2 | * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal |
6151d86c PT |
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 | |
4999a196 | 11 | * Geneviève Bastien - Move code to provide base classes for time graph views |
6151d86c PT |
12 | *******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources; | |
15 | ||
16 | import java.util.ArrayList; | |
1cf25311 PT |
17 | import java.util.Collections; |
18 | import java.util.HashMap; | |
6151d86c | 19 | import java.util.List; |
1cf25311 | 20 | import java.util.Map; |
6151d86c PT |
21 | |
22 | import org.eclipse.core.runtime.IProgressMonitor; | |
d2120fb6 | 23 | import org.eclipse.jdt.annotation.Nullable; |
6151d86c PT |
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; | |
e3366401 | 27 | import org.eclipse.linuxtools.lttng2.kernel.core.analysis.LttngKernelAnalysisModule; |
bcec0116 AM |
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; | |
72221aa4 | 34 | import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule; |
6151d86c | 35 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
4999a196 | 36 | import org.eclipse.linuxtools.tmf.ui.views.timegraph.AbstractTimeGraphView; |
6151d86c | 37 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; |
1d46dc38 | 38 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.NullTimeEvent; |
6151d86c | 39 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeEvent; |
4999a196 | 40 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.TimeGraphEntry; |
6151d86c PT |
41 | |
42 | /** | |
43 | * Main implementation for the LTTng 2.0 kernel Resource view | |
44 | * | |
45 | * @author Patrick Tasse | |
46 | */ | |
4999a196 | 47 | public class ResourcesView extends AbstractTimeGraphView { |
6151d86c PT |
48 | |
49 | /** View ID. */ | |
50 | public static final String ID = "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$ | |
51 | ||
4999a196 | 52 | private static final String[] FILTER_COLUMN_NAMES = new String[] { |
747adf5c | 53 | Messages.ResourcesView_stateTypeName |
4999a196 | 54 | }; |
6151d86c | 55 | |
1cf25311 PT |
56 | // Timeout between updates in the build thread in ms |
57 | private static final long BUILD_UPDATE_TIMEOUT = 500; | |
58 | ||
6151d86c PT |
59 | // ------------------------------------------------------------------------ |
60 | // Constructors | |
61 | // ------------------------------------------------------------------------ | |
62 | ||
63 | /** | |
64 | * Default constructor | |
65 | */ | |
66 | public ResourcesView() { | |
747adf5c PT |
67 | super(ID, new ResourcesPresentationProvider()); |
68 | setFilterColumns(FILTER_COLUMN_NAMES); | |
6151d86c PT |
69 | } |
70 | ||
1cf25311 PT |
71 | // ------------------------------------------------------------------------ |
72 | // Internal | |
73 | // ------------------------------------------------------------------------ | |
74 | ||
6151d86c | 75 | @Override |
4999a196 GB |
76 | protected String getNextText() { |
77 | return Messages.ResourcesView_nextResourceActionNameText; | |
6151d86c PT |
78 | } |
79 | ||
6151d86c | 80 | @Override |
4999a196 GB |
81 | protected String getNextTooltip() { |
82 | return Messages.ResourcesView_nextResourceActionToolTipText; | |
fec1ac0b BH |
83 | } |
84 | ||
4999a196 GB |
85 | @Override |
86 | protected String getPrevText() { | |
87 | return Messages.ResourcesView_previousResourceActionNameText; | |
6151d86c PT |
88 | } |
89 | ||
4999a196 GB |
90 | @Override |
91 | protected String getPrevTooltip() { | |
92 | return Messages.ResourcesView_previousResourceActionToolTipText; | |
6151d86c PT |
93 | } |
94 | ||
4999a196 | 95 | @Override |
1cf25311 | 96 | protected void buildEventList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) { |
72221aa4 | 97 | if (trace == null) { |
1cf25311 PT |
98 | return; |
99 | } | |
72221aa4 | 100 | ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, LttngKernelAnalysisModule.ID); |
1cf25311 PT |
101 | if (ssq == null) { |
102 | return; | |
103 | } | |
fec1ac0b | 104 | |
1cf25311 PT |
105 | Map<Integer, ResourcesEntry> entryMap = new HashMap<>(); |
106 | TimeGraphEntry traceEntry = null; | |
107 | ||
108 | long startTime = ssq.getStartTime(); | |
109 | long start = startTime; | |
110 | setStartTime(Math.min(getStartTime(), startTime)); | |
111 | boolean complete = false; | |
112 | while (!complete) { | |
faa38350 PT |
113 | if (monitor.isCanceled()) { |
114 | return; | |
115 | } | |
1cf25311 PT |
116 | complete = ssq.waitUntilBuilt(BUILD_UPDATE_TIMEOUT); |
117 | if (ssq.isCancelled()) { | |
118 | return; | |
119 | } | |
120 | long end = ssq.getCurrentEndTime(); | |
121 | if (start == end && !complete) { // when complete execute one last time regardless of end time | |
122 | continue; | |
123 | } | |
124 | long endTime = end + 1; | |
125 | setEndTime(Math.max(getEndTime(), endTime)); | |
126 | ||
127 | if (traceEntry == null) { | |
128 | traceEntry = new ResourcesEntry(trace, trace.getName(), startTime, endTime, 0); | |
129 | List<TimeGraphEntry> entryList = Collections.singletonList(traceEntry); | |
130 | addToEntryList(parentTrace, entryList); | |
131 | } else { | |
132 | traceEntry.updateEndTime(endTime); | |
133 | } | |
134 | ||
135 | List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$ | |
136 | for (Integer cpuQuark : cpuQuarks) { | |
137 | int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark)); | |
138 | ResourcesEntry entry = entryMap.get(cpuQuark); | |
139 | if (entry == null) { | |
140 | entry = new ResourcesEntry(cpuQuark, trace, startTime, endTime, Type.CPU, cpu); | |
141 | entryMap.put(cpuQuark, entry); | |
142 | traceEntry.addChild(entry); | |
143 | } else { | |
144 | entry.updateEndTime(endTime); | |
6151d86c | 145 | } |
1cf25311 PT |
146 | } |
147 | List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$ | |
148 | for (Integer irqQuark : irqQuarks) { | |
149 | int irq = Integer.parseInt(ssq.getAttributeName(irqQuark)); | |
150 | ResourcesEntry entry = entryMap.get(irqQuark); | |
151 | if (entry == null) { | |
152 | entry = new ResourcesEntry(irqQuark, trace, startTime, endTime, Type.IRQ, irq); | |
153 | entryMap.put(irqQuark, entry); | |
154 | traceEntry.addChild(entry); | |
155 | } else { | |
156 | entry.updateEndTime(endTime); | |
6151d86c | 157 | } |
1cf25311 PT |
158 | } |
159 | List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$ | |
160 | for (Integer softIrqQuark : softIrqQuarks) { | |
161 | int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark)); | |
162 | ResourcesEntry entry = entryMap.get(softIrqQuark); | |
163 | if (entry == null) { | |
164 | entry = new ResourcesEntry(softIrqQuark, trace, startTime, endTime, Type.SOFT_IRQ, softIrq); | |
165 | entryMap.put(softIrqQuark, entry); | |
166 | traceEntry.addChild(entry); | |
167 | } else { | |
168 | entry.updateEndTime(endTime); | |
6151d86c PT |
169 | } |
170 | } | |
4999a196 | 171 | |
1cf25311 PT |
172 | if (parentTrace.equals(getTrace())) { |
173 | refresh(); | |
faa38350 | 174 | } |
1cf25311 | 175 | long resolution = Math.max(1, (endTime - ssq.getStartTime()) / getDisplayWidth()); |
4999a196 | 176 | for (TimeGraphEntry entry : traceEntry.getChildren()) { |
1cf25311 PT |
177 | if (monitor.isCanceled()) { |
178 | return; | |
179 | } | |
180 | List<ITimeEvent> eventList = getEventList(entry, start, endTime, resolution, monitor); | |
181 | if (eventList != null) { | |
182 | for (ITimeEvent event : eventList) { | |
183 | entry.addEvent(event); | |
184 | } | |
185 | } | |
6151d86c PT |
186 | redraw(); |
187 | } | |
1cf25311 PT |
188 | |
189 | start = end; | |
6151d86c PT |
190 | } |
191 | } | |
192 | ||
4999a196 | 193 | @Override |
d2120fb6 | 194 | protected @Nullable List<ITimeEvent> getEventList(TimeGraphEntry entry, |
4999a196 | 195 | long startTime, long endTime, long resolution, |
6151d86c | 196 | IProgressMonitor monitor) { |
1d46dc38 | 197 | ResourcesEntry resourcesEntry = (ResourcesEntry) entry; |
72221aa4 | 198 | ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(resourcesEntry.getTrace(), LttngKernelAnalysisModule.ID); |
4bc53929 GB |
199 | if (ssq == null) { |
200 | return null; | |
201 | } | |
41b5c37f AM |
202 | final long realStart = Math.max(startTime, ssq.getStartTime()); |
203 | final long realEnd = Math.min(endTime, ssq.getCurrentEndTime() + 1); | |
204 | if (realEnd <= realStart) { | |
6151d86c PT |
205 | return null; |
206 | } | |
207 | List<ITimeEvent> eventList = null; | |
4999a196 GB |
208 | int quark = resourcesEntry.getQuark(); |
209 | ||
6151d86c | 210 | try { |
4999a196 | 211 | if (resourcesEntry.getType().equals(Type.CPU)) { |
6151d86c | 212 | int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS); |
41b5c37f | 213 | List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, realStart, realEnd - 1, resolution, monitor); |
e0838ca1 | 214 | eventList = new ArrayList<>(statusIntervals.size()); |
6151d86c PT |
215 | long lastEndTime = -1; |
216 | for (ITmfStateInterval statusInterval : statusIntervals) { | |
217 | if (monitor.isCanceled()) { | |
218 | return null; | |
219 | } | |
220 | int status = statusInterval.getStateValue().unboxInt(); | |
221 | long time = statusInterval.getStartTime(); | |
222 | long duration = statusInterval.getEndTime() - time + 1; | |
223 | if (!statusInterval.getStateValue().isNull()) { | |
224 | if (lastEndTime != time && lastEndTime != -1) { | |
225 | eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime)); | |
226 | } | |
4999a196 | 227 | eventList.add(new TimeEvent(entry, time, duration, status)); |
1d46dc38 PT |
228 | } else if (lastEndTime == -1 || time + duration >= endTime) { |
229 | // add null event if it intersects the start or end time | |
230 | eventList.add(new NullTimeEvent(entry, time, duration)); | |
6151d86c | 231 | } |
1d46dc38 | 232 | lastEndTime = time + duration; |
6151d86c | 233 | } |
4999a196 | 234 | } else if (resourcesEntry.getType().equals(Type.IRQ)) { |
41b5c37f | 235 | List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor); |
e0838ca1 | 236 | eventList = new ArrayList<>(irqIntervals.size()); |
6151d86c PT |
237 | long lastEndTime = -1; |
238 | boolean lastIsNull = true; | |
239 | for (ITmfStateInterval irqInterval : irqIntervals) { | |
240 | if (monitor.isCanceled()) { | |
241 | return null; | |
242 | } | |
243 | long time = irqInterval.getStartTime(); | |
244 | long duration = irqInterval.getEndTime() - time + 1; | |
245 | if (!irqInterval.getStateValue().isNull()) { | |
246 | int cpu = irqInterval.getStateValue().unboxInt(); | |
4999a196 | 247 | eventList.add(new TimeEvent(entry, time, duration, cpu)); |
6151d86c PT |
248 | lastIsNull = false; |
249 | } else { | |
1d46dc38 PT |
250 | if (lastEndTime == -1) { |
251 | // add null event if it intersects the start time | |
252 | eventList.add(new NullTimeEvent(entry, time, duration)); | |
4999a196 | 253 | } else { |
1d46dc38 PT |
254 | if (lastEndTime != time && lastIsNull) { |
255 | /* 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) */ | |
256 | eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1)); | |
257 | } | |
258 | if (time + duration >= endTime) { | |
259 | // add null event if it intersects the end time | |
260 | eventList.add(new NullTimeEvent(entry, time, duration)); | |
261 | } | |
6151d86c PT |
262 | } |
263 | lastIsNull = true; | |
264 | } | |
265 | lastEndTime = time + duration; | |
266 | } | |
4999a196 | 267 | } else if (resourcesEntry.getType().equals(Type.SOFT_IRQ)) { |
41b5c37f | 268 | List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, realStart, realEnd - 1, resolution, monitor); |
e0838ca1 | 269 | eventList = new ArrayList<>(softIrqIntervals.size()); |
6151d86c PT |
270 | long lastEndTime = -1; |
271 | boolean lastIsNull = true; | |
272 | for (ITmfStateInterval softIrqInterval : softIrqIntervals) { | |
273 | if (monitor.isCanceled()) { | |
274 | return null; | |
275 | } | |
276 | long time = softIrqInterval.getStartTime(); | |
277 | long duration = softIrqInterval.getEndTime() - time + 1; | |
278 | if (!softIrqInterval.getStateValue().isNull()) { | |
279 | int cpu = softIrqInterval.getStateValue().unboxInt(); | |
4999a196 | 280 | eventList.add(new TimeEvent(entry, time, duration, cpu)); |
6151d86c | 281 | } else { |
1d46dc38 PT |
282 | if (lastEndTime == -1) { |
283 | // add null event if it intersects the start time | |
284 | eventList.add(new NullTimeEvent(entry, time, duration)); | |
4999a196 | 285 | } else { |
1d46dc38 PT |
286 | if (lastEndTime != time && lastIsNull) { |
287 | /* 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) */ | |
288 | eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1)); | |
289 | } | |
290 | if (time + duration >= endTime) { | |
291 | // add null event if it intersects the end time | |
292 | eventList.add(new NullTimeEvent(entry, time, duration)); | |
293 | } | |
6151d86c PT |
294 | } |
295 | lastIsNull = true; | |
296 | } | |
297 | lastEndTime = time + duration; | |
298 | } | |
299 | } | |
4999a196 | 300 | |
1cf25311 | 301 | } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) { |
6151d86c | 302 | e.printStackTrace(); |
96345c5a AM |
303 | } catch (StateSystemDisposedException e) { |
304 | /* Ignored */ | |
6151d86c PT |
305 | } |
306 | return eventList; | |
307 | } | |
308 | ||
6151d86c | 309 | } |