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