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