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