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