Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2010, 2013 Ericsson |
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 | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.timechart; | |
14 | ||
15 | import java.util.ArrayList; | |
16 | import java.util.HashMap; | |
17 | import java.util.Iterator; | |
18 | import java.util.Map; | |
19 | ||
20 | import org.eclipse.core.resources.IFile; | |
21 | import org.eclipse.core.resources.IMarker; | |
22 | import org.eclipse.core.resources.IMarkerDelta; | |
23 | import org.eclipse.core.resources.IResourceChangeEvent; | |
24 | import org.eclipse.core.resources.IResourceChangeListener; | |
25 | import org.eclipse.core.resources.IResourceDelta; | |
26 | import org.eclipse.core.resources.ResourcesPlugin; | |
27 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
faa38350 PT |
28 | import org.eclipse.linuxtools.tmf.core.signal.TmfEventFilterAppliedSignal; |
29 | import org.eclipse.linuxtools.tmf.core.signal.TmfEventSearchAppliedSignal; | |
30 | import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal; | |
6151d86c PT |
31 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; |
32 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; | |
faa38350 PT |
33 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal; |
34 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; | |
6151d86c PT |
35 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal; |
36 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; | |
3bd46eef AM |
37 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
38 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
39 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
6151d86c PT |
40 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
41 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
42 | import org.eclipse.linuxtools.tmf.ui.editors.ITmfTraceEditor; | |
6151d86c PT |
43 | import org.eclipse.linuxtools.tmf.ui.views.TmfView; |
44 | import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting; | |
45 | import org.eclipse.linuxtools.tmf.ui.views.colors.ColorSettingsManager; | |
46 | import org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener; | |
47 | import org.eclipse.linuxtools.tmf.ui.views.timechart.TimeChartEvent.RankRange; | |
48 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider; | |
49 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphRangeListener; | |
50 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphSelectionListener; | |
51 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeGraphTimeListener; | |
52 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphRangeUpdateEvent; | |
53 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphSelectionEvent; | |
54 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphTimeEvent; | |
55 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphViewer; | |
56 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; | |
57 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry; | |
026664b7 | 58 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat; |
6151d86c PT |
59 | import org.eclipse.swt.SWT; |
60 | import org.eclipse.swt.widgets.Composite; | |
61 | import org.eclipse.swt.widgets.Display; | |
62 | import org.eclipse.ui.IEditorPart; | |
63 | import org.eclipse.ui.IEditorReference; | |
64 | ||
65 | /** | |
66 | * Generic Time Chart view, which is similar to a Gantt chart for trace analysis | |
67 | * | |
68 | * @version 1.0 | |
69 | * @author Patrick Tasse | |
70 | */ | |
faa38350 | 71 | public class TimeChartView extends TmfView implements ITimeGraphRangeListener, ITimeGraphSelectionListener, ITimeGraphTimeListener, IColorSettingsListener, IResourceChangeListener { |
6151d86c PT |
72 | |
73 | /** TimeChartView's ID */ | |
74 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.timechart"; //$NON-NLS-1$ | |
75 | ||
76 | private static final int TIMESTAMP_SCALE = -9; | |
77 | ||
78 | private final int fDisplayWidth; | |
79 | private TimeGraphViewer fViewer; | |
80 | private final ArrayList<TimeChartAnalysisEntry> fTimeAnalysisEntries = new ArrayList<TimeChartAnalysisEntry>(); | |
81 | private final Map<ITmfTrace, TimeChartDecorationProvider> fDecorationProviders = new HashMap<ITmfTrace, TimeChartDecorationProvider>(); | |
82 | private ArrayList<DecorateThread> fDecorateThreads; | |
83 | private long fStartTime = 0; | |
84 | private long fStopTime = Long.MAX_VALUE; | |
85 | private boolean fRefreshBusy = false; | |
86 | private boolean fRefreshPending = false; | |
87 | private boolean fRedrawBusy = false; | |
88 | private boolean fRedrawPending = false; | |
89 | private final Object fSyncObj = new Object(); | |
90 | private ITimeGraphPresentationProvider fPresentationProvider; | |
91 | ||
92 | /** | |
93 | * Default constructor | |
94 | */ | |
95 | public TimeChartView() { | |
96 | super("Time Chart"); //$NON-NLS-1$ | |
97 | fDisplayWidth = Display.getDefault().getBounds().width; | |
98 | } | |
99 | ||
100 | @Override | |
101 | public void createPartControl(Composite parent) { | |
ad128fd8 | 102 | fViewer = new TimeGraphViewer(parent, SWT.NONE); |
6151d86c PT |
103 | fPresentationProvider = new TimeChartAnalysisProvider(); |
104 | fViewer.setTimeGraphProvider(fPresentationProvider); | |
026664b7 | 105 | fViewer.setTimeFormat(TimeFormat.CALENDAR); |
6151d86c PT |
106 | fViewer.addTimeListener(this); |
107 | fViewer.addRangeListener(this); | |
108 | fViewer.addSelectionListener(this); | |
109 | fViewer.setMinimumItemWidth(1); | |
110 | ||
111 | IEditorReference[] editorReferences = getSite().getPage().getEditorReferences(); | |
112 | for (IEditorReference editorReference : editorReferences) { | |
113 | IEditorPart editor = editorReference.getEditor(false); | |
114 | if (editor instanceof ITmfTraceEditor) { | |
115 | ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace(); | |
116 | if (trace != null) { | |
117 | IFile bookmarksFile = ((ITmfTraceEditor) editor).getBookmarksFile(); | |
118 | TimeChartAnalysisEntry timeAnalysisEntry = new TimeChartAnalysisEntry(trace, fDisplayWidth * 2); | |
119 | fTimeAnalysisEntries.add(timeAnalysisEntry); | |
120 | fDecorationProviders.put(trace, new TimeChartDecorationProvider(bookmarksFile)); | |
121 | Thread thread = new ProcessTraceThread(timeAnalysisEntry); | |
122 | thread.start(); | |
123 | } | |
124 | } | |
125 | } | |
126 | fViewer.setInput(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0])); | |
127 | ||
128 | fDecorateThreads = new ArrayList<DecorateThread>(); | |
129 | ColorSettingsManager.addColorSettingsListener(this); | |
130 | ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); | |
131 | } | |
132 | ||
133 | @Override | |
134 | public void dispose() { | |
135 | ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); | |
136 | for (DecorateThread thread : fDecorateThreads) { | |
137 | thread.cancel(); | |
138 | } | |
139 | ColorSettingsManager.removeColorSettingsListener(this); | |
140 | super.dispose(); | |
141 | } | |
142 | ||
143 | @Override | |
144 | public void setFocus() { | |
145 | fViewer.setFocus(); | |
146 | } | |
147 | ||
148 | private class ProcessTraceThread extends Thread { | |
149 | ||
150 | private final TimeChartAnalysisEntry fTimeAnalysisEntry; | |
151 | ||
152 | public ProcessTraceThread(TimeChartAnalysisEntry timeAnalysisEntry) { | |
153 | super("ProcessTraceJob:" + timeAnalysisEntry.getName()); //$NON-NLS-1$ | |
154 | fTimeAnalysisEntry = timeAnalysisEntry; | |
155 | } | |
156 | ||
157 | @Override | |
158 | public void run() { | |
159 | updateTraceEntry(fTimeAnalysisEntry, Long.MAX_VALUE, 0, Long.MAX_VALUE); | |
160 | } | |
161 | } | |
162 | ||
163 | private void updateTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry, long stopRank, long startTime, long stopTime) { | |
164 | ITmfTrace trace = timeAnalysisEntry.getTrace(); | |
165 | TimeChartDecorationProvider decorationProvider = fDecorationProviders.get(trace); | |
166 | if (decorationProvider == null) { | |
167 | return; // the trace has been closed | |
168 | } | |
169 | ITmfContext context = null; | |
170 | // TmfTimestamp lastTimestamp = null; | |
171 | boolean done = false; | |
172 | while (!done) { | |
173 | synchronized (timeAnalysisEntry) { | |
174 | if (timeAnalysisEntry.getLastRank() >= trace.getNbEvents()) { | |
175 | done = true; | |
176 | break; | |
177 | } | |
178 | if (context == null || context.getRank() != timeAnalysisEntry.getLastRank()) { | |
179 | if (context != null) { | |
180 | context.dispose(); | |
181 | } | |
182 | if (timeAnalysisEntry.getLastRank() != -1) { | |
183 | context = trace.seekEvent(timeAnalysisEntry.getLastRank()); | |
184 | } else { | |
185 | // context = trace.seekLocation(null); | |
186 | context = trace.seekEvent(0); | |
187 | } | |
188 | } | |
189 | while (true) { | |
190 | long rank = context.getRank(); | |
191 | ITmfEvent event = trace.getNext(context); | |
192 | if (event == null) { | |
193 | done = true; | |
194 | break; | |
195 | } | |
196 | // if (!event.getTimestamp().equals(lastTimestamp)) { | |
197 | TimeChartEvent timeEvent = new TimeChartEvent(timeAnalysisEntry, event, rank, decorationProvider); | |
198 | if (timeEvent.getTime() >= startTime && timeEvent.getTime() <= stopTime) { | |
199 | timeAnalysisEntry.addTraceEvent(timeEvent); | |
200 | } | |
201 | // lastTimestamp = event.getTimestamp(); | |
202 | // } *** commented out so that color setting priority gets | |
203 | // set even if the event has same time | |
204 | if (context.getRank() == trace.getNbEvents() || context.getRank() == stopRank) { | |
205 | done = true; | |
206 | break; | |
207 | } | |
208 | if (context.getRank() % trace.getCacheSize() == 1) { | |
209 | // break for UI refresh | |
210 | break; | |
211 | } | |
212 | } | |
213 | // timeAnalysisEntry.setLastRank(Math.min(trace.getNbEvents(), | |
214 | // stopRank)); | |
215 | timeAnalysisEntry.setLastRank(context.getRank()); | |
216 | } | |
217 | redrawViewer(true); | |
218 | } | |
219 | if (context != null) { | |
220 | context.dispose(); | |
221 | } | |
222 | } | |
223 | ||
224 | private void refreshViewer() { | |
225 | synchronized (fSyncObj) { | |
226 | if (fRefreshBusy) { | |
227 | fRefreshPending = true; | |
228 | return; | |
229 | } | |
230 | fRefreshBusy = true; | |
231 | } | |
232 | // Perform the refresh on the UI thread | |
233 | Display.getDefault().asyncExec(new Runnable() { | |
234 | @Override | |
235 | public void run() { | |
236 | if (fViewer.getControl().isDisposed()) { | |
237 | return; | |
238 | } | |
239 | fViewer.setInput(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0])); | |
240 | fViewer.resetStartFinishTime(); | |
241 | synchronized (fSyncObj) { | |
242 | fRefreshBusy = false; | |
243 | if (fRefreshPending) { | |
244 | fRefreshPending = false; | |
245 | refreshViewer(); | |
246 | } | |
247 | } | |
248 | } | |
249 | }); | |
250 | } | |
251 | ||
252 | private void redrawViewer(boolean resetTimeIntervals) { | |
253 | synchronized (fSyncObj) { | |
254 | if (fRedrawBusy) { | |
255 | fRedrawPending = true; | |
256 | return; | |
257 | } | |
258 | fRedrawBusy = true; | |
259 | } | |
260 | final boolean reset = resetTimeIntervals; | |
261 | // Perform the refresh on the UI thread | |
262 | Display.getDefault().asyncExec(new Runnable() { | |
263 | @Override | |
264 | public void run() { | |
265 | if (fViewer.getControl().isDisposed()) { | |
266 | return; | |
267 | } | |
268 | if (reset) { | |
269 | fViewer.setTimeRange(fTimeAnalysisEntries.toArray(new TimeChartAnalysisEntry[0])); | |
270 | fViewer.setTimeBounds(); | |
271 | } | |
272 | fViewer.getControl().redraw(); | |
273 | fViewer.getControl().update(); | |
274 | synchronized (fSyncObj) { | |
275 | fRedrawBusy = false; | |
276 | if (fRedrawPending) { | |
277 | fRedrawPending = false; | |
278 | redrawViewer(reset); | |
279 | } | |
280 | } | |
281 | } | |
282 | }); | |
283 | } | |
284 | ||
285 | private void itemize(long startTime, long stopTime) { | |
286 | for (int i = 0; i < fTimeAnalysisEntries.size(); i++) { | |
287 | Thread thread = new ItemizeThread(fTimeAnalysisEntries.get(i), startTime, stopTime); | |
288 | thread.start(); | |
289 | } | |
290 | } | |
291 | ||
292 | private class ItemizeThread extends Thread { | |
293 | ||
294 | private final TimeChartAnalysisEntry fTimeAnalysisEntry; | |
3dca7aa5 AM |
295 | private final long startTime; |
296 | private final long stopTime; | |
6151d86c PT |
297 | private final long fMaxDuration; |
298 | ||
299 | private ItemizeThread(TimeChartAnalysisEntry timeAnalysisEntry, long startTime, long stopTime) { | |
300 | super("Itemize Thread:" + timeAnalysisEntry.getName()); //$NON-NLS-1$ | |
301 | fTimeAnalysisEntry = timeAnalysisEntry; | |
3dca7aa5 AM |
302 | this.startTime = startTime; |
303 | this.stopTime = stopTime; | |
304 | fMaxDuration = 3 * (stopTime - startTime) / fDisplayWidth; | |
6151d86c PT |
305 | } |
306 | ||
307 | @Override | |
308 | public void run() { | |
309 | itemizeTraceEntry(fTimeAnalysisEntry); | |
310 | } | |
311 | ||
312 | public void itemizeTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry) { | |
313 | Iterator<ITimeEvent> iterator = timeAnalysisEntry.getTimeEventsIterator(); | |
314 | TimeChartEvent event = null; | |
315 | boolean hasNext = true; | |
316 | while (hasNext) { | |
317 | synchronized (timeAnalysisEntry) { | |
3dca7aa5 | 318 | while ((hasNext = iterator.hasNext()) == true) { |
6151d86c | 319 | event = (TimeChartEvent) iterator.next(); |
3dca7aa5 | 320 | if (event.getTime() + event.getDuration() > startTime && event.getTime() < stopTime && event.getDuration() > fMaxDuration |
6151d86c PT |
321 | && event.getNbEvents() > 1) { |
322 | break; | |
323 | } | |
324 | } | |
325 | } | |
3dca7aa5 | 326 | if (hasNext && event != null) { |
6151d86c PT |
327 | if (event.getItemizedEntry() == null) { |
328 | itemizeEvent(event); | |
329 | } else { | |
330 | itemizeTraceEntry(event.getItemizedEntry()); | |
331 | } | |
332 | } | |
333 | } | |
334 | } | |
335 | ||
336 | public void itemizeEvent(TimeChartEvent event) { | |
337 | synchronized (event) { | |
338 | if (event.isItemizing()) { | |
339 | return; | |
340 | } | |
341 | event.setItemizing(true); | |
342 | } | |
343 | TimeChartAnalysisEntry timeAnalysisEntry = new TimeChartAnalysisEntry(fTimeAnalysisEntry.getTrace(), (int) Math.min( | |
344 | event.getNbEvents() + 1, fDisplayWidth * 2)); | |
345 | synchronized (event.getRankRangeList()) { | |
346 | for (RankRange range : event.getRankRangeList()) { | |
347 | timeAnalysisEntry.setLastRank(range.getFirstRank()); | |
348 | updateTraceEntry(timeAnalysisEntry, range.getLastRank() + 1, event.getTime(), event.getTime() + event.getDuration()); | |
349 | } | |
350 | } | |
351 | event.setItemizedEntry(timeAnalysisEntry); | |
352 | redrawViewer(false); | |
353 | itemizeTraceEntry(timeAnalysisEntry); | |
354 | synchronized (event) { | |
355 | event.setItemizing(false); | |
356 | } | |
357 | } | |
358 | } | |
359 | ||
360 | private void redecorate() { | |
361 | synchronized (fDecorateThreads) { | |
362 | for (DecorateThread thread : fDecorateThreads) { | |
363 | thread.cancel(); | |
364 | } | |
365 | fDecorateThreads.clear(); | |
366 | for (int i = 0; i < fTimeAnalysisEntries.size(); i++) { | |
367 | DecorateThread thread = new DecorateThread(fTimeAnalysisEntries.get(i)); | |
368 | thread.start(); | |
369 | fDecorateThreads.add(thread); | |
370 | } | |
371 | } | |
372 | } | |
373 | ||
374 | private class DecorateThread extends Thread { | |
375 | private volatile boolean interrupted = false; | |
376 | private final TimeChartAnalysisEntry fTimeAnalysisEntry; | |
377 | private final TimeChartDecorationProvider fDecorationProvider; | |
378 | private ITmfContext fContext; | |
379 | private int fCount = 0; | |
380 | ||
381 | private DecorateThread(TimeChartAnalysisEntry timeAnalysisEntry) { | |
382 | super("Decorate Thread:" + timeAnalysisEntry.getName()); //$NON-NLS-1$ | |
383 | fTimeAnalysisEntry = timeAnalysisEntry; | |
384 | fDecorationProvider = fDecorationProviders.get(timeAnalysisEntry.getTrace()); | |
385 | } | |
386 | ||
387 | @Override | |
388 | public void run() { | |
389 | resetTraceEntry(fTimeAnalysisEntry); | |
390 | redrawViewer(false); | |
391 | decorateTraceEntry(fTimeAnalysisEntry, null); | |
392 | redrawViewer(false); | |
393 | synchronized (fDecorateThreads) { | |
394 | fDecorateThreads.remove(this); | |
395 | } | |
396 | if (fContext != null) { | |
faa38350 | 397 | fContext.dispose(); |
6151d86c PT |
398 | } |
399 | } | |
400 | ||
401 | public void resetTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry) { | |
402 | Iterator<ITimeEvent> iterator = timeAnalysisEntry.getTimeEventsIterator(); | |
403 | TimeChartEvent event = null; | |
404 | boolean hasNext = true; | |
405 | while (!interrupted && hasNext) { | |
406 | synchronized (timeAnalysisEntry) { | |
3dca7aa5 | 407 | while ((hasNext = iterator.hasNext()) == true) { |
6151d86c PT |
408 | event = (TimeChartEvent) iterator.next(); |
409 | break; | |
410 | } | |
411 | } | |
3dca7aa5 | 412 | if (hasNext && event != null) { |
6151d86c PT |
413 | // TODO possible concurrency problem here with ItemizeJob |
414 | event.setColorSettingPriority(ColorSettingsManager.PRIORITY_NONE); | |
415 | if (event.getItemizedEntry() != null) { | |
416 | resetTraceEntry(event.getItemizedEntry()); | |
417 | } | |
418 | } | |
419 | } | |
420 | } | |
421 | ||
422 | public void decorateTraceEntry(TimeChartAnalysisEntry timeAnalysisEntry, TimeChartEvent parentEvent) { | |
423 | // Set max duration high to ensure iterator does not consider | |
424 | // itemized events | |
425 | Iterator<ITimeEvent> iterator = timeAnalysisEntry.getTimeEventsIterator(0, Long.MAX_VALUE, Long.MAX_VALUE); | |
426 | TimeChartEvent event = null; | |
427 | int entryPriority = ColorSettingsManager.PRIORITY_NONE; | |
428 | boolean entryIsBookmarked = false; | |
429 | boolean entryIsVisible = false; | |
430 | boolean entryIsSearchMatch = false; | |
431 | boolean hasNext = true; | |
432 | while (!interrupted && hasNext) { | |
433 | synchronized (timeAnalysisEntry) { | |
3dca7aa5 | 434 | while ((hasNext = iterator.hasNext()) == true) { |
6151d86c PT |
435 | event = (TimeChartEvent) iterator.next(); |
436 | break; | |
437 | } | |
438 | } | |
3dca7aa5 | 439 | if (hasNext && event != null) { |
6151d86c PT |
440 | // TODO possible concurrency problem here with ItemizeJob |
441 | if (event.getItemizedEntry() == null) { | |
442 | decorateEvent(event); | |
443 | } else { | |
444 | decorateTraceEntry(event.getItemizedEntry(), event); | |
445 | } | |
446 | entryPriority = Math.min(entryPriority, event.getColorSettingPriority()); | |
447 | entryIsBookmarked |= event.isBookmarked(); | |
448 | entryIsVisible |= event.isVisible(); | |
449 | entryIsSearchMatch |= event.isSearchMatch(); | |
450 | if (++fCount % timeAnalysisEntry.getTrace().getCacheSize() == 0) { | |
451 | redrawViewer(false); | |
452 | } | |
453 | } | |
454 | } | |
455 | if (parentEvent != null) { | |
456 | parentEvent.setColorSettingPriority(entryPriority); | |
457 | parentEvent.setIsBookmarked(entryIsBookmarked); | |
458 | parentEvent.setIsVisible(entryIsVisible); | |
459 | parentEvent.setIsSearchMatch(entryIsSearchMatch); | |
460 | } | |
461 | } | |
462 | ||
463 | public void decorateEvent(TimeChartEvent timeChartEvent) { | |
464 | // TODO possible concurrency problem here with ItemizeJob | |
465 | TimeChartAnalysisEntry timeAnalysisEntry = (TimeChartAnalysisEntry) timeChartEvent.getEntry(); | |
466 | ITmfTrace trace = timeAnalysisEntry.getTrace(); | |
467 | int priority = ColorSettingsManager.PRIORITY_NONE; | |
468 | boolean isBookmarked = false; | |
469 | boolean isVisible = false; | |
470 | boolean isSearchMatch = false; | |
471 | synchronized (timeChartEvent.getRankRangeList()) { | |
472 | for (RankRange range : timeChartEvent.getRankRangeList()) { | |
473 | if (interrupted) { | |
474 | return; | |
475 | } | |
476 | if (fContext == null || fContext.getRank() != range.getFirstRank()) { | |
477 | if (fContext != null) { | |
faa38350 | 478 | fContext.dispose(); |
6151d86c PT |
479 | } |
480 | fContext = trace.seekEvent(range.getFirstRank()); | |
481 | fContext.setRank(range.getFirstRank()); | |
482 | } | |
483 | while (true) { | |
484 | if (interrupted) { | |
485 | return; | |
486 | } | |
487 | long rank = fContext.getRank(); | |
488 | ITmfEvent event = trace.getNext(fContext); | |
489 | if (event == null) { | |
490 | break; | |
491 | } | |
faa38350 | 492 | long eventTime = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
6151d86c PT |
493 | if (eventTime >= timeChartEvent.getTime() && eventTime <= timeChartEvent.getTime() + timeChartEvent.getDuration()) { |
494 | priority = Math.min(priority, ColorSettingsManager.getColorSettingPriority(event)); | |
495 | } | |
496 | isBookmarked |= fDecorationProvider.isBookmark(rank); | |
497 | isVisible |= fDecorationProvider.isVisible(event); | |
498 | isSearchMatch |= fDecorationProvider.isSearchMatch(event); | |
499 | if (fContext.getRank() > range.getLastRank()) { | |
500 | break; | |
501 | } | |
502 | } | |
503 | } | |
504 | } | |
505 | timeChartEvent.setColorSettingPriority(priority); | |
506 | timeChartEvent.setIsBookmarked(isBookmarked); | |
507 | timeChartEvent.setIsVisible(isVisible); | |
508 | timeChartEvent.setIsSearchMatch(isSearchMatch); | |
509 | } | |
510 | ||
511 | public void cancel() { | |
512 | interrupted = true; | |
513 | } | |
514 | } | |
515 | ||
516 | // ------------------------------------------------------------------------ | |
517 | // Listeners | |
518 | // ------------------------------------------------------------------------ | |
519 | ||
520 | @Override | |
521 | public void timeRangeUpdated(TimeGraphRangeUpdateEvent event) { | |
522 | fStartTime = event.getStartTime(); | |
523 | fStopTime = event.getEndTime(); | |
524 | itemize(fStartTime, fStopTime); | |
faa38350 PT |
525 | final ITmfTimestamp startTimestamp = new TmfTimestamp(event.getStartTime(), ITmfTimestamp.NANOSECOND_SCALE); |
526 | final ITmfTimestamp endTimestamp = new TmfTimestamp(event.getEndTime(), ITmfTimestamp.NANOSECOND_SCALE); | |
527 | TmfTimeRange range = new TmfTimeRange(startTimestamp, endTimestamp); | |
528 | TmfTimestamp timestamp = new TmfTimestamp(fViewer.getSelectedTime(), ITmfTimestamp.NANOSECOND_SCALE); | |
529 | broadcast(new TmfRangeSynchSignal(this, range, timestamp)); | |
6151d86c PT |
530 | } |
531 | ||
532 | @Override | |
533 | public void selectionChanged(TimeGraphSelectionEvent event) { | |
534 | ITimeGraphEntry timeAnalysisEntry = null; | |
535 | if (event.getSelection() instanceof TimeChartAnalysisEntry) { | |
536 | timeAnalysisEntry = event.getSelection(); | |
537 | } else if (event.getSelection() instanceof TimeChartEvent) { | |
538 | timeAnalysisEntry = ((TimeChartEvent) event.getSelection()).getEntry(); | |
539 | } | |
540 | if (timeAnalysisEntry instanceof TimeChartAnalysisEntry) { | |
541 | broadcast(new TmfTraceSelectedSignal(this, ((TimeChartAnalysisEntry) timeAnalysisEntry).getTrace())); | |
542 | } | |
543 | } | |
544 | ||
545 | @Override | |
546 | public void timeSelected(TimeGraphTimeEvent event) { | |
547 | broadcast(new TmfTimeSynchSignal(this, new TmfTimestamp(event.getTime(), TIMESTAMP_SCALE))); | |
548 | } | |
549 | ||
550 | @Override | |
551 | public void colorSettingsChanged(ColorSetting[] colorSettings) { | |
552 | // Set presentation provider again to trigger re-creation of new color settings which are stored | |
553 | // in the TimeGraphControl class | |
554 | fViewer.setTimeGraphProvider(fPresentationProvider); | |
555 | redecorate(); | |
556 | } | |
557 | ||
558 | @Override | |
559 | public void resourceChanged(IResourceChangeEvent event) { | |
560 | for (IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) { | |
561 | for (TimeChartDecorationProvider provider : fDecorationProviders.values()) { | |
562 | if (delta.getResource().equals(provider.getBookmarksFile())) { | |
563 | if (delta.getKind() == IResourceDelta.CHANGED && delta.getMarker().getAttribute(IMarker.LOCATION, -1) != -1) { | |
564 | provider.refreshBookmarks(); | |
565 | } else if (delta.getKind() == IResourceDelta.REMOVED) { | |
566 | provider.refreshBookmarks(); | |
567 | } | |
568 | } | |
569 | } | |
570 | } | |
571 | redecorate(); | |
572 | } | |
573 | ||
6151d86c PT |
574 | // ------------------------------------------------------------------------ |
575 | // Signal handlers | |
576 | // ------------------------------------------------------------------------ | |
577 | ||
578 | /** | |
579 | * Handler for the Trace Opened signal | |
580 | * | |
581 | * @param signal | |
582 | * The incoming signal | |
faa38350 | 583 | * @since 2.0 |
6151d86c PT |
584 | */ |
585 | @TmfSignalHandler | |
586 | public void traceOpened(TmfTraceOpenedSignal signal) { | |
6151d86c PT |
587 | final ITmfTrace trace = signal.getTrace(); |
588 | final IFile bookmarksFile = signal.getBookmarksFile(); | |
6151d86c PT |
589 | TimeChartAnalysisEntry timeAnalysisEntry = null; |
590 | for (int i = 0; i < fTimeAnalysisEntries.size(); i++) { | |
591 | if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) { | |
592 | timeAnalysisEntry = fTimeAnalysisEntries.get(i); | |
593 | break; | |
594 | } | |
595 | } | |
596 | if (timeAnalysisEntry == null) { | |
597 | timeAnalysisEntry = new TimeChartAnalysisEntry(trace, fDisplayWidth * 2); | |
598 | fTimeAnalysisEntries.add(timeAnalysisEntry); | |
599 | fDecorationProviders.put(trace, new TimeChartDecorationProvider(bookmarksFile)); | |
600 | Thread thread = new ProcessTraceThread(timeAnalysisEntry); | |
601 | thread.start(); | |
602 | } | |
603 | refreshViewer(); | |
6151d86c PT |
604 | } |
605 | ||
606 | /** | |
607 | * Handler for the Trace Closed signal | |
608 | * | |
609 | * @param signal | |
610 | * The incoming signal | |
faa38350 | 611 | * @since 2.0 |
6151d86c PT |
612 | */ |
613 | @TmfSignalHandler | |
614 | public void traceClosed(TmfTraceClosedSignal signal) { | |
6151d86c PT |
615 | final ITmfTrace trace = signal.getTrace(); |
616 | for (int i = 0; i < fTimeAnalysisEntries.size(); i++) { | |
617 | if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) { | |
618 | fTimeAnalysisEntries.remove(i); | |
619 | fDecorationProviders.remove(trace); | |
faa38350 PT |
620 | synchronized (fDecorateThreads) { |
621 | for (DecorateThread thread : fDecorateThreads) { | |
622 | if (thread.fTimeAnalysisEntry.getTrace() == trace) { | |
623 | thread.cancel(); | |
624 | fDecorateThreads.remove(thread); | |
625 | break; | |
626 | } | |
627 | } | |
628 | } | |
6151d86c PT |
629 | refreshViewer(); |
630 | break; | |
631 | } | |
632 | } | |
633 | } | |
634 | ||
635 | /** | |
636 | * Handler for the Trace Selected signal | |
637 | * | |
638 | * @param signal | |
639 | * The incoming signal | |
640 | */ | |
641 | @TmfSignalHandler | |
642 | public void traceSelected(TmfTraceSelectedSignal signal) { | |
77fdc5df | 643 | if (signal.getSource() != this) { |
6151d86c PT |
644 | ITmfTrace trace = signal.getTrace(); |
645 | for (int i = 0; i < fTimeAnalysisEntries.size(); i++) { | |
646 | if (fTimeAnalysisEntries.get(i).getTrace().equals(trace)) { | |
647 | fViewer.setSelection(fTimeAnalysisEntries.get(i)); | |
648 | break; | |
649 | } | |
650 | } | |
d7ee91bb | 651 | fViewer.setSelectedTime(trace.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(), false); |
6151d86c PT |
652 | } |
653 | } | |
654 | ||
655 | /** | |
656 | * Handler for the Trace Updated signal | |
657 | * | |
658 | * @param signal | |
659 | * The incoming signal | |
660 | */ | |
661 | @TmfSignalHandler | |
662 | public void traceUpdated(TmfTraceUpdatedSignal signal) { | |
6151d86c PT |
663 | final ITmfTrace trace = signal.getTrace(); |
664 | for (int i = 0; i < fTimeAnalysisEntries.size(); i++) { | |
665 | TimeChartAnalysisEntry timeAnalysisEntry = fTimeAnalysisEntries.get(i); | |
666 | if (timeAnalysisEntry.getTrace().equals(trace)) { | |
667 | updateTraceEntry(timeAnalysisEntry, Long.MAX_VALUE, 0, Long.MAX_VALUE); | |
668 | break; | |
669 | } | |
670 | } | |
671 | } | |
672 | ||
673 | /** | |
674 | * Handler for the Time Synch signal | |
675 | * | |
676 | * @param signal | |
677 | * The incoming signal | |
678 | */ | |
679 | @TmfSignalHandler | |
680 | public void currentTimeUpdated(TmfTimeSynchSignal signal) { | |
681 | final long time = signal.getCurrentTime().normalize(0, TIMESTAMP_SCALE).getValue(); | |
682 | Display.getDefault().asyncExec(new Runnable() { | |
683 | @Override | |
684 | public void run() { | |
685 | fViewer.setSelectedTime(time, true); | |
686 | } | |
687 | }); | |
688 | } | |
689 | ||
faa38350 PT |
690 | /** |
691 | * Handler for the Time Range Synch signal | |
692 | * | |
693 | * @param signal | |
694 | * The incoming signal | |
695 | * @since 2.0 | |
696 | */ | |
697 | @TmfSignalHandler | |
698 | public void synchToRange(final TmfRangeSynchSignal signal) { | |
699 | if (signal.getSource() == this) { | |
700 | return; | |
701 | } | |
702 | final long startTime = signal.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
703 | final long endTime = signal.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
704 | final long time = signal.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
705 | Display.getDefault().asyncExec(new Runnable() { | |
706 | @Override | |
707 | public void run() { | |
708 | fStartTime = startTime; | |
709 | fStopTime = endTime; | |
710 | itemize(fStartTime, fStopTime); | |
711 | fViewer.setStartFinishTime(startTime, endTime); | |
712 | fViewer.setSelectedTime(time, false); | |
713 | } | |
714 | }); | |
715 | } | |
716 | ||
717 | /** | |
718 | * Handler for the Event Filter Applied signal | |
719 | * | |
720 | * @param signal | |
721 | * The incoming signal | |
722 | * @since 2.0 | |
723 | */ | |
724 | @TmfSignalHandler | |
725 | public void filterApplied(TmfEventFilterAppliedSignal signal) { | |
726 | TimeChartDecorationProvider decorationProvider = fDecorationProviders.get(signal.getTrace()); | |
727 | if (decorationProvider == null) { | |
728 | return; | |
729 | } | |
730 | decorationProvider.filterApplied(signal.getEventFilter()); | |
731 | redecorate(); | |
732 | } | |
733 | ||
734 | /** | |
735 | * Handler for the Event Search Applied signal | |
736 | * | |
737 | * @param signal | |
738 | * The incoming signal | |
739 | * @since 2.0 | |
740 | */ | |
741 | @TmfSignalHandler | |
742 | public void searchApplied(TmfEventSearchAppliedSignal signal) { | |
743 | TimeChartDecorationProvider decorationProvider = fDecorationProviders.get(signal.getTrace()); | |
744 | if (decorationProvider == null) { | |
745 | return; | |
746 | } | |
747 | decorationProvider.searchApplied(signal.getSearchFilter()); | |
748 | redecorate(); | |
749 | } | |
750 | ||
6151d86c | 751 | } |