Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2012, 2015 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 | ||
e363eae1 | 14 | package org.eclipse.tracecompass.analysis.os.linux.ui.views.resources; |
6151d86c PT |
15 | |
16 | import java.util.ArrayList; | |
1cf25311 | 17 | import java.util.Collections; |
9ba941e9 | 18 | import java.util.Comparator; |
1cf25311 | 19 | import java.util.HashMap; |
6151d86c | 20 | import java.util.List; |
1cf25311 | 21 | import java.util.Map; |
6151d86c PT |
22 | |
23 | import org.eclipse.core.runtime.IProgressMonitor; | |
8213a0c0 | 24 | import org.eclipse.jdt.annotation.NonNull; |
d2120fb6 | 25 | import org.eclipse.jdt.annotation.Nullable; |
e363eae1 | 26 | import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.Attributes; |
6d16f5a9 | 27 | import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule; |
e363eae1 AM |
28 | import org.eclipse.tracecompass.analysis.os.linux.ui.views.resources.ResourcesEntry.Type; |
29 | import org.eclipse.tracecompass.internal.analysis.os.linux.ui.Messages; | |
e894a508 AM |
30 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
31 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; | |
e894a508 | 32 | import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; |
2bdf0193 AM |
33 | import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule; |
34 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
8213a0c0 | 35 | import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractStateSystemTimeGraphView; |
2bdf0193 AM |
36 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent; |
37 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
38 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent; | |
39 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent; | |
40 | import org.eclipse.tracecompass.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 | */ | |
8213a0c0 | 47 | public class ResourcesView extends AbstractStateSystemTimeGraphView { |
6151d86c PT |
48 | |
49 | /** View ID. */ | |
e363eae1 | 50 | public static final String ID = "org.eclipse.tracecompass.analysis.os.linux.views.resources"; //$NON-NLS-1$ |
6151d86c | 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); | |
bb447fcb PT |
69 | setFilterLabelProvider(new ResourcesFilterLabelProvider()); |
70 | } | |
71 | ||
72 | private static class ResourcesFilterLabelProvider extends TreeLabelProvider { | |
73 | @Override | |
74 | public String getColumnText(Object element, int columnIndex) { | |
75 | ResourcesEntry entry = (ResourcesEntry) element; | |
76 | if (columnIndex == 0) { | |
77 | return entry.getName(); | |
78 | } | |
79 | return ""; //$NON-NLS-1$ | |
80 | } | |
81 | ||
6151d86c PT |
82 | } |
83 | ||
1cf25311 PT |
84 | // ------------------------------------------------------------------------ |
85 | // Internal | |
86 | // ------------------------------------------------------------------------ | |
87 | ||
6151d86c | 88 | @Override |
4999a196 GB |
89 | protected String getNextText() { |
90 | return Messages.ResourcesView_nextResourceActionNameText; | |
6151d86c PT |
91 | } |
92 | ||
6151d86c | 93 | @Override |
4999a196 GB |
94 | protected String getNextTooltip() { |
95 | return Messages.ResourcesView_nextResourceActionToolTipText; | |
fec1ac0b BH |
96 | } |
97 | ||
4999a196 GB |
98 | @Override |
99 | protected String getPrevText() { | |
100 | return Messages.ResourcesView_previousResourceActionNameText; | |
6151d86c PT |
101 | } |
102 | ||
4999a196 GB |
103 | @Override |
104 | protected String getPrevTooltip() { | |
105 | return Messages.ResourcesView_previousResourceActionToolTipText; | |
6151d86c PT |
106 | } |
107 | ||
4999a196 | 108 | @Override |
8213a0c0 PT |
109 | protected void buildEventList(ITmfTrace trace, ITmfTrace parentTrace, final IProgressMonitor monitor) { |
110 | final ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID); | |
1cf25311 PT |
111 | if (ssq == null) { |
112 | return; | |
113 | } | |
9ba941e9 PT |
114 | Comparator<ITimeGraphEntry> comparator = new Comparator<ITimeGraphEntry>() { |
115 | @Override | |
116 | public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) { | |
117 | return ((ResourcesEntry) o1).compareTo(o2); | |
118 | } | |
119 | }; | |
fec1ac0b | 120 | |
1cf25311 PT |
121 | Map<Integer, ResourcesEntry> entryMap = new HashMap<>(); |
122 | TimeGraphEntry traceEntry = null; | |
123 | ||
124 | long startTime = ssq.getStartTime(); | |
125 | long start = startTime; | |
126 | setStartTime(Math.min(getStartTime(), startTime)); | |
127 | boolean complete = false; | |
128 | while (!complete) { | |
faa38350 PT |
129 | if (monitor.isCanceled()) { |
130 | return; | |
131 | } | |
1cf25311 PT |
132 | complete = ssq.waitUntilBuilt(BUILD_UPDATE_TIMEOUT); |
133 | if (ssq.isCancelled()) { | |
134 | return; | |
135 | } | |
136 | long end = ssq.getCurrentEndTime(); | |
137 | if (start == end && !complete) { // when complete execute one last time regardless of end time | |
138 | continue; | |
139 | } | |
140 | long endTime = end + 1; | |
141 | setEndTime(Math.max(getEndTime(), endTime)); | |
142 | ||
143 | if (traceEntry == null) { | |
144 | traceEntry = new ResourcesEntry(trace, trace.getName(), startTime, endTime, 0); | |
9ba941e9 | 145 | traceEntry.sortChildren(comparator); |
1cf25311 | 146 | List<TimeGraphEntry> entryList = Collections.singletonList(traceEntry); |
8213a0c0 | 147 | addToEntryList(parentTrace, ssq, entryList); |
1cf25311 PT |
148 | } else { |
149 | traceEntry.updateEndTime(endTime); | |
150 | } | |
151 | ||
152 | List<Integer> cpuQuarks = ssq.getQuarks(Attributes.CPUS, "*"); //$NON-NLS-1$ | |
153 | for (Integer cpuQuark : cpuQuarks) { | |
154 | int cpu = Integer.parseInt(ssq.getAttributeName(cpuQuark)); | |
155 | ResourcesEntry entry = entryMap.get(cpuQuark); | |
156 | if (entry == null) { | |
157 | entry = new ResourcesEntry(cpuQuark, trace, startTime, endTime, Type.CPU, cpu); | |
158 | entryMap.put(cpuQuark, entry); | |
159 | traceEntry.addChild(entry); | |
160 | } else { | |
161 | entry.updateEndTime(endTime); | |
6151d86c | 162 | } |
1cf25311 PT |
163 | } |
164 | List<Integer> irqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$ | |
165 | for (Integer irqQuark : irqQuarks) { | |
166 | int irq = Integer.parseInt(ssq.getAttributeName(irqQuark)); | |
167 | ResourcesEntry entry = entryMap.get(irqQuark); | |
168 | if (entry == null) { | |
169 | entry = new ResourcesEntry(irqQuark, trace, startTime, endTime, Type.IRQ, irq); | |
170 | entryMap.put(irqQuark, entry); | |
171 | traceEntry.addChild(entry); | |
172 | } else { | |
173 | entry.updateEndTime(endTime); | |
6151d86c | 174 | } |
1cf25311 PT |
175 | } |
176 | List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$ | |
177 | for (Integer softIrqQuark : softIrqQuarks) { | |
178 | int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark)); | |
179 | ResourcesEntry entry = entryMap.get(softIrqQuark); | |
180 | if (entry == null) { | |
181 | entry = new ResourcesEntry(softIrqQuark, trace, startTime, endTime, Type.SOFT_IRQ, softIrq); | |
182 | entryMap.put(softIrqQuark, entry); | |
183 | traceEntry.addChild(entry); | |
184 | } else { | |
185 | entry.updateEndTime(endTime); | |
6151d86c PT |
186 | } |
187 | } | |
4999a196 | 188 | |
1cf25311 PT |
189 | if (parentTrace.equals(getTrace())) { |
190 | refresh(); | |
faa38350 | 191 | } |
8213a0c0 PT |
192 | final List<? extends ITimeGraphEntry> traceEntryChildren = traceEntry.getChildren(); |
193 | final long resolution = Math.max(1, (endTime - ssq.getStartTime()) / getDisplayWidth()); | |
194 | final long qStart = start; | |
195 | final long qEnd = end; | |
196 | queryFullStates(ssq, qStart, qEnd, resolution, monitor, new IQueryHandler() { | |
197 | @Override | |
198 | public void handle(List<List<ITmfStateInterval>> fullStates, List<ITmfStateInterval> prevFullState) { | |
199 | for (ITimeGraphEntry child : traceEntryChildren) { | |
200 | if (monitor.isCanceled()) { | |
201 | return; | |
202 | } | |
203 | if (child instanceof TimeGraphEntry) { | |
204 | TimeGraphEntry entry = (TimeGraphEntry) child; | |
205 | List<ITimeEvent> eventList = getEventList(entry, ssq, fullStates, prevFullState, monitor); | |
206 | if (eventList != null) { | |
207 | for (ITimeEvent event : eventList) { | |
208 | entry.addEvent(event); | |
209 | } | |
210 | } | |
a3188982 | 211 | } |
1cf25311 PT |
212 | } |
213 | } | |
8213a0c0 | 214 | }); |
1cf25311 PT |
215 | |
216 | start = end; | |
6151d86c PT |
217 | } |
218 | } | |
219 | ||
4999a196 | 220 | @Override |
8213a0c0 PT |
221 | protected @Nullable List<ITimeEvent> getEventList(@NonNull TimeGraphEntry entry, ITmfStateSystem ssq, |
222 | @NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull IProgressMonitor monitor) { | |
1d46dc38 | 223 | ResourcesEntry resourcesEntry = (ResourcesEntry) entry; |
6151d86c | 224 | List<ITimeEvent> eventList = null; |
4999a196 GB |
225 | int quark = resourcesEntry.getQuark(); |
226 | ||
8213a0c0 PT |
227 | if (resourcesEntry.getType().equals(Type.CPU)) { |
228 | int statusQuark; | |
229 | try { | |
230 | statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS); | |
231 | } catch (AttributeNotFoundException e) { | |
232 | /* | |
233 | * The sub-attribute "status" is not available. May happen | |
234 | * if the trace does not have sched_switch events enabled. | |
235 | */ | |
236 | return null; | |
237 | } | |
238 | eventList = new ArrayList<>(fullStates.size()); | |
239 | ITmfStateInterval lastInterval = prevFullState == null || statusQuark >= prevFullState.size() ? null : prevFullState.get(statusQuark); | |
240 | long lastStartTime = lastInterval == null ? -1 : lastInterval.getStartTime(); | |
241 | long lastEndTime = lastInterval == null ? -1 : lastInterval.getEndTime() + 1; | |
242 | for (List<ITmfStateInterval> fullState : fullStates) { | |
243 | if (monitor.isCanceled()) { | |
8f9ad413 AM |
244 | return null; |
245 | } | |
8213a0c0 | 246 | if (statusQuark >= fullState.size()) { |
0bacba1a | 247 | /* No information on this CPU (yet?), skip it for now */ |
8213a0c0 | 248 | continue; |
6151d86c | 249 | } |
8213a0c0 PT |
250 | ITmfStateInterval statusInterval = fullState.get(statusQuark); |
251 | int status = statusInterval.getStateValue().unboxInt(); | |
252 | long time = statusInterval.getStartTime(); | |
253 | long duration = statusInterval.getEndTime() - time + 1; | |
254 | if (time == lastStartTime) { | |
255 | continue; | |
6151d86c | 256 | } |
8213a0c0 PT |
257 | if (!statusInterval.getStateValue().isNull()) { |
258 | if (lastEndTime != time && lastEndTime != -1) { | |
259 | eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime)); | |
6151d86c | 260 | } |
8213a0c0 PT |
261 | eventList.add(new TimeEvent(entry, time, duration, status)); |
262 | } else { | |
263 | eventList.add(new NullTimeEvent(entry, time, duration)); | |
264 | } | |
265 | lastStartTime = time; | |
266 | lastEndTime = time + duration; | |
267 | } | |
268 | } else if (resourcesEntry.getType().equals(Type.IRQ) || resourcesEntry.getType().equals(Type.SOFT_IRQ)) { | |
269 | eventList = new ArrayList<>(fullStates.size()); | |
0bacba1a | 270 | ITmfStateInterval lastInterval = prevFullState == null || quark >= prevFullState.size() ? null : prevFullState.get(quark); |
8213a0c0 PT |
271 | long lastStartTime = lastInterval == null ? -1 : lastInterval.getStartTime(); |
272 | long lastEndTime = lastInterval == null ? -1 : lastInterval.getEndTime() + 1; | |
273 | boolean lastIsNull = lastInterval == null ? false : lastInterval.getStateValue().isNull(); | |
274 | for (List<ITmfStateInterval> fullState : fullStates) { | |
275 | if (monitor.isCanceled()) { | |
276 | return null; | |
277 | } | |
0bacba1a PT |
278 | if (quark >= fullState.size()) { |
279 | /* No information on this IRQ (yet?), skip it for now */ | |
280 | continue; | |
281 | } | |
8213a0c0 PT |
282 | ITmfStateInterval irqInterval = fullState.get(quark); |
283 | long time = irqInterval.getStartTime(); | |
284 | long duration = irqInterval.getEndTime() - time + 1; | |
285 | if (time == lastStartTime) { | |
286 | continue; | |
287 | } | |
288 | if (!irqInterval.getStateValue().isNull()) { | |
289 | int cpu = irqInterval.getStateValue().unboxInt(); | |
290 | eventList.add(new TimeEvent(entry, time, duration, cpu)); | |
291 | lastIsNull = false; | |
292 | } else { | |
293 | if (lastEndTime != time && lastIsNull) { | |
294 | /* 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) */ | |
295 | eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime, -1)); | |
6151d86c | 296 | } |
8213a0c0 PT |
297 | eventList.add(new NullTimeEvent(entry, time, duration)); |
298 | lastIsNull = true; | |
6151d86c | 299 | } |
8213a0c0 PT |
300 | lastStartTime = time; |
301 | lastEndTime = time + duration; | |
6151d86c | 302 | } |
6151d86c | 303 | } |
8213a0c0 | 304 | |
6151d86c PT |
305 | return eventList; |
306 | } | |
307 | ||
6151d86c | 308 | } |