Commit | Line | Data |
---|---|---|
1a23419e | 1 | /******************************************************************************* |
f8f46a52 | 2 | * Copyright (c) 2014, 2016 École Polytechnique de Montréal |
1a23419e FW |
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 | * Florian Wininger - Initial API and implementation | |
11 | * Geneviève Bastien - Review of the initial implementation | |
12 | *******************************************************************************/ | |
13 | ||
6eca054d | 14 | package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph; |
1a23419e | 15 | |
1d83ed07 AM |
16 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
17 | ||
1a23419e FW |
18 | import java.util.ArrayList; |
19 | import java.util.Collections; | |
20 | import java.util.Comparator; | |
21 | import java.util.HashMap; | |
836d7c77 | 22 | import java.util.HashSet; |
1a23419e FW |
23 | import java.util.LinkedList; |
24 | import java.util.List; | |
25 | import java.util.Map; | |
26 | import java.util.Set; | |
27 | import java.util.TreeSet; | |
28 | ||
29 | import org.eclipse.core.runtime.IProgressMonitor; | |
e1c415b3 | 30 | import org.eclipse.core.runtime.IStatus; |
1a23419e | 31 | import org.eclipse.jdt.annotation.NonNull; |
f9e76b64 | 32 | import org.eclipse.jdt.annotation.Nullable; |
1a23419e FW |
33 | import org.eclipse.jface.util.IPropertyChangeListener; |
34 | import org.eclipse.jface.util.PropertyChangeEvent; | |
e23402bb | 35 | import org.eclipse.swt.widgets.Composite; |
1a23419e | 36 | import org.eclipse.swt.widgets.Display; |
e23402bb | 37 | import org.eclipse.tracecompass.common.core.NonNullUtils; |
6eca054d GB |
38 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory; |
39 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute; | |
40 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory; | |
41 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer; | |
42 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils; | |
43 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; | |
2bdf0193 AM |
44 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator; |
45 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings; | |
46 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.XmlViewInfo; | |
6eca054d | 47 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph.XmlEntry.EntryDisplayType; |
e894a508 | 48 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
1dd75589 | 49 | import org.eclipse.tracecompass.statesystem.core.StateSystemUtils; |
e894a508 AM |
50 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; |
51 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; | |
52 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException; | |
53 | import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException; | |
54 | import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; | |
6d8889e1 | 55 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; |
2bdf0193 | 56 | import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems; |
2bdf0193 | 57 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
b8585c7c | 58 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; |
2bdf0193 AM |
59 | import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView; |
60 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider2; | |
61 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent; | |
62 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent; | |
63 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
64 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent; | |
65 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent; | |
66 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry; | |
1a23419e FW |
67 | import org.w3c.dom.Element; |
68 | ||
836d7c77 MK |
69 | import com.google.common.collect.Iterables; |
70 | ||
1a23419e FW |
71 | /** |
72 | * This view displays state system data in a time graph view. It uses an XML | |
73 | * {@link TmfXmlUiStrings#TIME_GRAPH_VIEW} element from an XML file. This | |
74 | * element defines which entries from the state system will be shown and also | |
75 | * gives additional information on the presentation of the view (states, colors, | |
76 | * etc) | |
77 | * | |
78 | * @author Florian Wininger | |
79 | */ | |
80 | public class XmlTimeGraphView extends AbstractTimeGraphView { | |
81 | ||
82 | /** View ID. */ | |
35423ee0 | 83 | public static final @NonNull String ID = "org.eclipse.linuxtools.tmf.analysis.xml.ui.views.timegraph"; //$NON-NLS-1$ |
1a23419e FW |
84 | |
85 | private static final String[] DEFAULT_COLUMN_NAMES = new String[] { | |
86 | Messages.XmlTimeGraphView_ColumnName, | |
87 | Messages.XmlTimeGraphView_ColumnId, | |
88 | Messages.XmlTimeGraphView_ColumnParentId, | |
89 | }; | |
90 | ||
91 | private static final String[] DEFAULT_FILTER_COLUMN_NAMES = new String[] { | |
92 | Messages.XmlTimeGraphView_ColumnName, | |
93 | Messages.XmlTimeGraphView_ColumnId | |
94 | }; | |
95 | ||
96 | /** The relative weight of the sash */ | |
97 | private static final int[] fWeight = { 1, 2 }; | |
98 | ||
99 | private static final String EMPTY_STRING = ""; //$NON-NLS-1$ | |
8ecd89fa | 100 | private static final @NonNull String SPLIT_STRING = "/"; //$NON-NLS-1$ |
1a23419e | 101 | |
35423ee0 | 102 | private final @NonNull XmlViewInfo fViewInfo = new XmlViewInfo(ID); |
1a23419e | 103 | private final ITmfXmlModelFactory fFactory; |
6d8889e1 | 104 | private final Map<String, Integer> fStringValueMap = new HashMap<>(); |
1a23419e FW |
105 | |
106 | // ------------------------------------------------------------------------ | |
107 | // Constructors | |
108 | // ------------------------------------------------------------------------ | |
109 | ||
110 | /** | |
111 | * Default constructor | |
112 | */ | |
113 | public XmlTimeGraphView() { | |
114 | super(ID, new XmlPresentationProvider()); | |
115 | setWeight(fWeight); | |
116 | setTreeColumns(DEFAULT_COLUMN_NAMES); | |
117 | setTreeLabelProvider(new XmlTreeLabelProvider()); | |
118 | setFilterColumns(DEFAULT_FILTER_COLUMN_NAMES); | |
119 | setFilterLabelProvider(new XmlTreeLabelProvider()); | |
120 | setEntryComparator(new XmlEntryComparator()); | |
121 | this.addPartPropertyListener(new IPropertyChangeListener() { | |
122 | @Override | |
123 | public void propertyChange(PropertyChangeEvent event) { | |
124 | if (event.getProperty().equals(TmfXmlUiStrings.XML_OUTPUT_DATA)) { | |
35423ee0 GB |
125 | Object newValue = event.getNewValue(); |
126 | if (newValue instanceof String) { | |
127 | String data = (String) newValue; | |
128 | fViewInfo.setViewData(data); | |
129 | loadNewXmlView(); | |
130 | } | |
1a23419e FW |
131 | } |
132 | } | |
133 | }); | |
1a23419e FW |
134 | fFactory = TmfXmlReadOnlyModelFactory.getInstance(); |
135 | } | |
136 | ||
e23402bb GB |
137 | @Override |
138 | public void createPartControl(Composite parent) { | |
139 | super.createPartControl(parent); | |
140 | fViewInfo.setName(NonNullUtils.checkNotNull(getViewSite().getSecondaryId())); | |
141 | } | |
142 | ||
1a23419e FW |
143 | private void loadNewXmlView() { |
144 | rebuild(); | |
145 | } | |
146 | ||
147 | private void setViewTitle(final String title) { | |
148 | Display.getDefault().asyncExec(new Runnable() { | |
149 | @Override | |
150 | public void run() { | |
151 | setPartName(title); | |
152 | } | |
153 | }); | |
154 | ||
155 | } | |
156 | ||
157 | @Override | |
158 | protected String getNextText() { | |
159 | return Messages.XmlTimeGraphView_NextText; | |
160 | } | |
161 | ||
162 | @Override | |
163 | protected String getNextTooltip() { | |
164 | return Messages.XmlTimeGraphView_NextTooltip; | |
165 | } | |
166 | ||
167 | @Override | |
168 | protected String getPrevText() { | |
169 | return Messages.XmlTimeGraphView_PreviousText; | |
170 | } | |
171 | ||
172 | @Override | |
173 | protected String getPrevTooltip() { | |
174 | return Messages.XmlTimeGraphView_PreviousInterval; | |
175 | } | |
176 | ||
177 | /** | |
178 | * Default label provider, it shows name, id and parent columns | |
179 | * | |
180 | * TODO: There should be a way to define columns in the XML | |
836d7c77 | 181 | */ |
1a23419e FW |
182 | private static class XmlTreeLabelProvider extends TreeLabelProvider { |
183 | ||
184 | @Override | |
185 | public String getColumnText(Object element, int columnIndex) { | |
186 | XmlEntry entry = (XmlEntry) element; | |
187 | ||
188 | if (DEFAULT_COLUMN_NAMES[columnIndex].equals(Messages.XmlTimeGraphView_ColumnName)) { | |
189 | return entry.getName(); | |
190 | } else if (DEFAULT_COLUMN_NAMES[columnIndex].equals(Messages.XmlTimeGraphView_ColumnId)) { | |
191 | return entry.getId(); | |
192 | } else if (DEFAULT_COLUMN_NAMES[columnIndex].equals(Messages.XmlTimeGraphView_ColumnParentId)) { | |
193 | return entry.getParentId(); | |
194 | } | |
195 | return EMPTY_STRING; | |
196 | } | |
197 | ||
198 | } | |
199 | ||
200 | private static class XmlEntryComparator implements Comparator<ITimeGraphEntry> { | |
201 | ||
202 | @Override | |
203 | public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) { | |
204 | ||
205 | int result = 0; | |
206 | ||
207 | if ((o1 instanceof XmlEntry) && (o2 instanceof XmlEntry)) { | |
208 | XmlEntry entry1 = (XmlEntry) o1; | |
209 | XmlEntry entry2 = (XmlEntry) o2; | |
210 | result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime()); | |
211 | if (result == 0) { | |
212 | result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName()); | |
213 | } | |
214 | if (result == 0) { | |
215 | result = entry1.getName().compareTo(entry2.getName()); | |
216 | } | |
217 | } | |
218 | ||
219 | if (result == 0) { | |
220 | result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0; | |
221 | } | |
222 | ||
223 | return result; | |
224 | } | |
225 | } | |
226 | ||
227 | // ------------------------------------------------------------------------ | |
228 | // Internal | |
229 | // ------------------------------------------------------------------------ | |
230 | ||
231 | @Override | |
f8f46a52 | 232 | protected void buildEntryList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) { |
1a23419e | 233 | |
e23402bb GB |
234 | if (!fViewInfo.waitForInitialization()) { |
235 | return; | |
236 | } | |
1a23419e FW |
237 | /* |
238 | * Get the view element from the XML file. If the element can't be | |
239 | * found, return. | |
240 | */ | |
35423ee0 | 241 | Element viewElement = fViewInfo.getViewElement(TmfXmlUiStrings.TIME_GRAPH_VIEW); |
1a23419e FW |
242 | if (viewElement == null) { |
243 | return; | |
244 | } | |
245 | ITimeGraphPresentationProvider2 pres = this.getPresentationProvider(); | |
246 | if (pres instanceof XmlPresentationProvider) { | |
247 | /* | |
248 | * TODO: Each entry of a line could have their own states/color. | |
249 | * That will require an update to the presentation provider | |
250 | */ | |
251 | ((XmlPresentationProvider) pres).loadNewStates(viewElement); | |
252 | } | |
253 | ||
35423ee0 GB |
254 | String title = fViewInfo.getViewTitle(viewElement); |
255 | if (title == null) { | |
256 | title = Messages.XmlTimeGraphView_DefaultTitle; | |
1a23419e | 257 | } |
35423ee0 | 258 | setViewTitle(title); |
6d8889e1 GB |
259 | |
260 | // Empty the additional state values | |
261 | fStringValueMap.clear(); | |
262 | ||
35423ee0 GB |
263 | Set<String> analysisIds = fViewInfo.getViewAnalysisIds(viewElement); |
264 | ||
1a23419e FW |
265 | List<Element> entries = XmlUtils.getChildElements(viewElement, TmfXmlUiStrings.ENTRY_ELEMENT); |
266 | Set<XmlEntry> entryList = new TreeSet<>(getEntryComparator()); | |
836d7c77 MK |
267 | if (monitor.isCanceled()) { |
268 | return; | |
269 | } | |
1a23419e | 270 | |
aa353506 | 271 | Set<@NonNull ITmfAnalysisModuleWithStateSystems> stateSystemModules = new HashSet<>(); |
836d7c77 MK |
272 | if (analysisIds.isEmpty()) { |
273 | /* | |
274 | * No analysis specified, take all state system analysis modules | |
275 | */ | |
276 | Iterables.addAll(stateSystemModules, TmfTraceUtils.getAnalysisModulesOfClass(trace, ITmfAnalysisModuleWithStateSystems.class)); | |
277 | } else { | |
278 | for (String moduleId : analysisIds) { | |
279 | moduleId = checkNotNull(moduleId); | |
280 | ITmfAnalysisModuleWithStateSystems module = TmfTraceUtils.getAnalysisModuleOfClass(trace, ITmfAnalysisModuleWithStateSystems.class, moduleId); | |
281 | if (module != null) { | |
1a23419e FW |
282 | stateSystemModules.add(module); |
283 | } | |
1a23419e | 284 | } |
836d7c77 | 285 | } |
1a23419e | 286 | |
836d7c77 MK |
287 | for (ITmfAnalysisModuleWithStateSystems module : stateSystemModules) { |
288 | IStatus status = module.schedule(); | |
289 | if (!status.isOK()) { | |
290 | return; | |
291 | } | |
c81ffdf2 JCK |
292 | if (!module.waitForInitialization()) { |
293 | return; | |
836d7c77 MK |
294 | } |
295 | for (ITmfStateSystem ssq : module.getStateSystems()) { | |
296 | ssq.waitUntilBuilt(); | |
297 | ||
298 | long startTime = ssq.getStartTime(); | |
299 | long endTime = ssq.getCurrentEndTime(); | |
300 | XmlEntry groupEntry = new XmlEntry(-1, trace, trace.getName(), ssq); | |
301 | entryList.add(groupEntry); | |
302 | setStartTime(Math.min(getStartTime(), startTime)); | |
303 | setEndTime(Math.max(getEndTime(), endTime)); | |
304 | ||
305 | /* Add children entry of this entry for each line */ | |
306 | for (Element entry : entries) { | |
307 | buildEntry(entry, groupEntry, -1); | |
1a23419e FW |
308 | } |
309 | } | |
310 | } | |
836d7c77 | 311 | |
dbae6118 | 312 | addToEntryList(parentTrace, new ArrayList<TimeGraphEntry>(entryList)); |
1a23419e | 313 | |
836d7c77 | 314 | if (parentTrace.equals(getTrace())) { |
1a23419e FW |
315 | refresh(); |
316 | } | |
317 | for (XmlEntry traceEntry : entryList) { | |
318 | if (monitor.isCanceled()) { | |
319 | return; | |
320 | } | |
321 | long startTime = traceEntry.getStateSystem().getStartTime(); | |
322 | long endTime = traceEntry.getStateSystem().getCurrentEndTime() + 1; | |
323 | buildStatusEvent(traceEntry, monitor, startTime, endTime); | |
324 | } | |
325 | } | |
326 | ||
327 | private void buildEntry(Element entryElement, XmlEntry parentEntry, int baseQuark) { | |
328 | /* Get the attribute string to display */ | |
329 | String path = entryElement.getAttribute(TmfXmlUiStrings.PATH); | |
330 | if (path.isEmpty()) { | |
331 | path = TmfXmlStrings.WILDCARD; | |
332 | } | |
333 | ||
334 | /* | |
335 | * Make sure the XML element has either a display attribute or entries, | |
336 | * otherwise issue a warning | |
337 | */ | |
338 | ||
339 | List<Element> displayElements = XmlUtils.getChildElements(entryElement, TmfXmlUiStrings.DISPLAY_ELEMENT); | |
340 | List<Element> entryElements = XmlUtils.getChildElements(entryElement, TmfXmlUiStrings.ENTRY_ELEMENT); | |
341 | ||
342 | if (displayElements.isEmpty() && entryElements.isEmpty()) { | |
343 | Activator.logWarning(String.format("XML view: entry for %s should have either a display element or entry elements", path)); //$NON-NLS-1$ | |
344 | return; | |
345 | } | |
346 | ||
347 | ITmfStateSystem ss = parentEntry.getStateSystem(); | |
348 | ||
349 | /* Get the list of quarks to process with this path */ | |
350 | String[] paths = path.split(SPLIT_STRING); | |
351 | int i = 0; | |
352 | List<Integer> quarks = Collections.singletonList(baseQuark); | |
353 | ||
ed48dc75 PT |
354 | while (i < paths.length) { |
355 | List<Integer> subQuarks = new LinkedList<>(); | |
356 | /* Replace * by .* to have a regex string */ | |
357 | String name = paths[i].replaceAll("\\*", ".*"); //$NON-NLS-1$ //$NON-NLS-2$ | |
358 | for (int relativeQuark : quarks) { | |
359 | for (int quark : ss.getSubAttributes(relativeQuark, false, name)) { | |
360 | subQuarks.add(quark); | |
1a23419e | 361 | } |
1a23419e | 362 | } |
ed48dc75 PT |
363 | quarks = subQuarks; |
364 | i++; | |
365 | } | |
1a23419e | 366 | |
ed48dc75 PT |
367 | /* Process each quark */ |
368 | XmlEntry currentEntry = parentEntry; | |
369 | Element displayElement = null; | |
370 | Map<String, XmlEntry> entryMap = new HashMap<>(); | |
371 | if (!displayElements.isEmpty()) { | |
372 | displayElement = displayElements.get(0); | |
373 | } | |
374 | for (int quark : quarks) { | |
375 | currentEntry = parentEntry; | |
376 | /* Process the current entry, if specified */ | |
377 | if (displayElement != null) { | |
378 | currentEntry = processEntry(entryElement, displayElement, parentEntry, quark, ss); | |
379 | entryMap.put(currentEntry.getId(), currentEntry); | |
1a23419e | 380 | } |
ed48dc75 PT |
381 | /* Process the children entry of this entry */ |
382 | for (Element subEntryEl : entryElements) { | |
383 | buildEntry(subEntryEl, currentEntry, quark); | |
1a23419e | 384 | } |
ed48dc75 PT |
385 | } |
386 | if (!entryMap.isEmpty()) { | |
387 | buildTree(entryMap, parentEntry); | |
1a23419e FW |
388 | } |
389 | } | |
390 | ||
391 | private XmlEntry processEntry(@NonNull Element entryElement, @NonNull Element displayEl, | |
12685851 | 392 | @NonNull XmlEntry parentEntry, int quark, ITmfStateSystem ss) { |
1a23419e FW |
393 | /* |
394 | * Get the start time and end time of this entry from the display | |
395 | * attribute | |
396 | */ | |
397 | ITmfXmlStateAttribute display = fFactory.createStateAttribute(displayEl, parentEntry); | |
0b563c20 | 398 | int displayQuark = display.getAttributeQuark(quark, null); |
1a23419e FW |
399 | if (displayQuark == IXmlStateSystemContainer.ERROR_QUARK) { |
400 | return new XmlEntry(quark, parentEntry.getTrace(), | |
401 | String.format("Unknown display quark for %s", ss.getAttributeName(quark)), ss); //$NON-NLS-1$ | |
402 | } | |
403 | ||
404 | long entryStart = ss.getStartTime(); | |
405 | long entryEnd = ss.getCurrentEndTime(); | |
fadf52eb | 406 | |
1a23419e | 407 | try { |
1a23419e | 408 | |
fadf52eb | 409 | ITmfStateInterval oneInterval = ss.querySingleState(entryStart, displayQuark); |
1a23419e | 410 | |
fadf52eb FR |
411 | /* The entry start is the first non-null interval */ |
412 | while (oneInterval.getStateValue().isNull()) { | |
413 | long ts = oneInterval.getEndTime() + 1; | |
414 | if (ts > ss.getCurrentEndTime()) { | |
415 | break; | |
1a23419e | 416 | } |
fadf52eb | 417 | oneInterval = ss.querySingleState(ts, displayQuark); |
1a23419e | 418 | } |
fadf52eb FR |
419 | entryStart = oneInterval.getStartTime(); |
420 | ||
421 | /* The entry end is the last non-null interval */ | |
422 | oneInterval = ss.querySingleState(entryEnd, displayQuark); | |
423 | while (oneInterval.getStateValue().isNull()) { | |
424 | long ts = oneInterval.getStartTime() - 1; | |
425 | if (ts < ss.getStartTime()) { | |
426 | break; | |
427 | } | |
428 | oneInterval = ss.querySingleState(ts, displayQuark); | |
429 | } | |
430 | entryEnd = oneInterval.getEndTime(); | |
431 | ||
ed48dc75 | 432 | } catch (StateSystemDisposedException e) { |
1a23419e FW |
433 | } |
434 | ||
435 | return new XmlEntry(quark, displayQuark, parentEntry.getTrace(), ss.getAttributeName(quark), | |
436 | entryStart, entryEnd, EntryDisplayType.DISPLAY, ss, entryElement); | |
437 | } | |
438 | ||
dfa0ef96 | 439 | private void buildStatusEvent(XmlEntry traceEntry, @NonNull IProgressMonitor monitor, long start, long end) { |
1a23419e FW |
440 | long resolution = (end - start) / getDisplayWidth(); |
441 | long startTime = Math.max(start, traceEntry.getStartTime()); | |
442 | long endTime = Math.min(end + 1, traceEntry.getEndTime()); | |
443 | List<ITimeEvent> eventList = getEventList(traceEntry, startTime, endTime, resolution, monitor); | |
444 | if (monitor.isCanceled()) { | |
445 | return; | |
446 | } | |
447 | traceEntry.setEventList(eventList); | |
448 | redraw(); | |
449 | ||
a3188982 | 450 | for (ITimeGraphEntry entry : traceEntry.getChildren()) { |
1a23419e FW |
451 | if (monitor.isCanceled()) { |
452 | return; | |
453 | } | |
454 | XmlEntry xmlEntry = (XmlEntry) entry; | |
455 | buildStatusEvent(xmlEntry, monitor, start, end); | |
456 | } | |
457 | } | |
458 | ||
459 | /** Build a tree using getParentId() and getId() */ | |
460 | private static void buildTree(Map<String, XmlEntry> entryMap, XmlEntry rootEntry) { | |
461 | for (XmlEntry entry : entryMap.values()) { | |
462 | boolean root = true; | |
463 | if (!entry.getParentId().isEmpty()) { | |
464 | XmlEntry parent = entryMap.get(entry.getParentId()); | |
0a35a36f GB |
465 | /* |
466 | * Associate the parent entry only if their time overlap. A | |
467 | * child entry may start before its parent, for example at the | |
468 | * beginning of the trace if a parent has not yet appeared in | |
469 | * the state system. We just want to make sure that the entry | |
470 | * didn't start after the parent ended or ended before the | |
471 | * parent started. | |
472 | */ | |
1a23419e | 473 | if (parent != null && |
0a35a36f | 474 | !(entry.getStartTime() > parent.getEndTime() || |
836d7c77 | 475 | entry.getEndTime() < parent.getStartTime())) { |
1a23419e FW |
476 | parent.addChild(entry); |
477 | root = false; | |
478 | } | |
479 | } | |
480 | if (root) { | |
481 | rootEntry.addChild(entry); | |
482 | } | |
483 | } | |
484 | } | |
485 | ||
486 | @Override | |
487 | protected List<ITimeEvent> getEventList(TimeGraphEntry entry, long startTime, long endTime, long resolution, IProgressMonitor monitor) { | |
488 | if (!(entry instanceof XmlEntry)) { | |
489 | return Collections.EMPTY_LIST; | |
490 | } | |
491 | XmlEntry xmlEntry = (XmlEntry) entry; | |
492 | ITmfStateSystem ssq = xmlEntry.getStateSystem(); | |
493 | final long realStart = Math.max(startTime, entry.getStartTime()); | |
494 | final long realEnd = Math.min(endTime, entry.getEndTime()); | |
495 | if (realEnd <= realStart) { | |
496 | return null; | |
497 | } | |
498 | List<ITimeEvent> eventList = null; | |
499 | int quark = xmlEntry.getDisplayQuark(); | |
500 | ||
501 | try { | |
502 | if (xmlEntry.getType() == EntryDisplayType.DISPLAY) { | |
503 | ||
1dd75589 | 504 | List<ITmfStateInterval> statusIntervals = StateSystemUtils.queryHistoryRange(ssq, quark, realStart, realEnd - 1, resolution, monitor); |
1a23419e FW |
505 | eventList = new ArrayList<>(statusIntervals.size()); |
506 | long lastEndTime = -1; | |
507 | for (ITmfStateInterval statusInterval : statusIntervals) { | |
508 | if (monitor.isCanceled()) { | |
509 | return null; | |
510 | } | |
6d8889e1 | 511 | int status = getStatusFromInterval(statusInterval); |
1a23419e FW |
512 | long time = statusInterval.getStartTime(); |
513 | long duration = statusInterval.getEndTime() - time + 1; | |
514 | if (!statusInterval.getStateValue().isNull()) { | |
515 | if (lastEndTime != time && lastEndTime != -1) { | |
516 | eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime)); | |
517 | } | |
518 | eventList.add(new TimeEvent(entry, time, duration, status)); | |
519 | } else if (lastEndTime == -1 || time + duration >= endTime) { | |
520 | // add null event if it intersects the start or end time | |
521 | eventList.add(new NullTimeEvent(entry, time, duration)); | |
522 | } | |
523 | lastEndTime = time + duration; | |
524 | } | |
525 | } | |
526 | } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException | StateSystemDisposedException e) { | |
527 | /* Ignored */ | |
528 | } | |
529 | return eventList; | |
530 | } | |
531 | ||
6d8889e1 GB |
532 | private int getStatusFromInterval(ITmfStateInterval statusInterval) { |
533 | ITmfStateValue stateValue = statusInterval.getStateValue(); | |
534 | int status = -1; | |
535 | switch (stateValue.getType()) { | |
536 | case INTEGER: | |
537 | case NULL: | |
538 | status = stateValue.unboxInt(); | |
539 | break; | |
540 | case LONG: | |
541 | status = (int) stateValue.unboxLong(); | |
542 | break; | |
543 | case STRING: | |
544 | String statusStr = stateValue.unboxStr(); | |
545 | Integer statusInt = fStringValueMap.get(statusStr); | |
546 | if (statusInt != null) { | |
547 | status = statusInt; | |
548 | break; | |
549 | } | |
550 | ITimeGraphPresentationProvider2 pres = this.getPresentationProvider(); | |
551 | if (pres instanceof XmlPresentationProvider) { | |
552 | // Add this new state to the presentation provider | |
553 | status = ((XmlPresentationProvider) pres).addState(statusStr); | |
554 | fStringValueMap.put(statusStr, status); | |
555 | } | |
556 | break; | |
557 | case DOUBLE: | |
558 | status = (int) stateValue.unboxDouble(); | |
559 | break; | |
560 | case CUSTOM: | |
561 | default: | |
562 | break; | |
563 | } | |
564 | ||
565 | return status; | |
566 | } | |
567 | ||
1a23419e FW |
568 | @Override |
569 | protected List<ILinkEvent> getLinkList(long startTime, long endTime, long resolution, IProgressMonitor monitor) { | |
570 | /* TODO: not implemented yet, need XML to go along */ | |
571 | return Collections.EMPTY_LIST; | |
572 | } | |
573 | ||
9f054bf6 | 574 | @Override |
f9e76b64 | 575 | protected @NonNull Iterable<ITmfTrace> getTracesToBuild(@Nullable ITmfTrace trace) { |
9f054bf6 GB |
576 | /* |
577 | * Return the current trace only. Experiments will return their | |
578 | * children's analyses | |
579 | */ | |
f9e76b64 | 580 | return (trace != null) ? Collections.singleton(trace) : Collections.EMPTY_LIST; |
9f054bf6 GB |
581 | } |
582 | ||
1a23419e | 583 | } |