1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Arrays
;
17 import java
.util
.Comparator
;
18 import java
.util
.HashMap
;
19 import java
.util
.Iterator
;
20 import java
.util
.List
;
22 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
23 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
24 import org
.eclipse
.jface
.action
.Action
;
25 import org
.eclipse
.jface
.action
.IToolBarManager
;
26 import org
.eclipse
.jface
.action
.Separator
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.Attributes
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.Messages
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
.ResourcesEntry
.Type
;
30 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.trace
.LttngKernelTrace
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTimestamp
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateSystemDisposedException
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
47 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
48 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
49 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
57 import org
.eclipse
.swt
.SWT
;
58 import org
.eclipse
.swt
.widgets
.Composite
;
59 import org
.eclipse
.swt
.widgets
.Display
;
60 import org
.eclipse
.ui
.IActionBars
;
63 * Main implementation for the LTTng 2.0 kernel Resource view
65 * @author Patrick Tasse
67 public class ResourcesView
extends TmfView
{
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
74 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
79 private enum State
{ IDLE
, BUSY
, PENDING
}
81 // ------------------------------------------------------------------------
83 // ------------------------------------------------------------------------
85 // The time graph viewer
86 TimeGraphViewer fTimeGraphViewer
;
89 private ITmfTrace fTrace
;
91 // The time graph entry list
92 private ArrayList
<TraceEntry
> fEntryList
;
94 // The trace to entry list hash map
95 final private HashMap
<ITmfTrace
, ArrayList
<TraceEntry
>> fEntryListMap
= new HashMap
<ITmfTrace
, ArrayList
<TraceEntry
>>();
97 // The trace to build thread hash map
98 final private HashMap
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<ITmfTrace
, BuildThread
>();
101 private long fStartTime
;
104 private long fEndTime
;
107 private final int fDisplayWidth
;
109 // The next resource action
110 private Action fNextResourceAction
;
112 // The previous resource action
113 private Action fPreviousResourceAction
;
116 private ZoomThread fZoomThread
;
118 // The redraw state used to prevent unnecessary queuing of display runnables
119 private State fRedrawState
= State
.IDLE
;
121 // The redraw synchronization object
122 final private Object fSyncObj
= new Object();
124 // ------------------------------------------------------------------------
126 // ------------------------------------------------------------------------
128 private class TraceEntry
implements ITimeGraphEntry
{
130 private final LttngKernelTrace fKernelTrace
;
132 private final long fTraceStartTime
;
134 private final long fTraceEndTime
;
135 // The children of the entry
136 private final ArrayList
<ResourcesEntry
> fChildren
;
138 private final String fName
;
140 public TraceEntry(LttngKernelTrace trace
, String name
, long startTime
, long endTime
) {
141 fKernelTrace
= trace
;
142 fChildren
= new ArrayList
<ResourcesEntry
>();
144 fTraceStartTime
= startTime
;
145 fTraceEndTime
= endTime
;
149 public ITimeGraphEntry
getParent() {
154 public boolean hasChildren() {
155 return fChildren
!= null && fChildren
.size() > 0;
159 public List
<ResourcesEntry
> getChildren() {
164 public String
getName() {
169 public long getStartTime() {
170 return fTraceStartTime
;
174 public long getEndTime() {
175 return fTraceEndTime
;
179 public boolean hasTimeEvents() {
184 public Iterator
<ITimeEvent
> getTimeEventsIterator() {
189 public <T
extends ITimeEvent
> Iterator
<T
> getTimeEventsIterator(long startTime
, long stopTime
, long visibleDuration
) {
193 public LttngKernelTrace
getTrace() {
197 public void addChild(ResourcesEntry entry
) {
199 for (index
= 0; index
< fChildren
.size(); index
++) {
200 ResourcesEntry other
= fChildren
.get(index
);
201 if (entry
.getType().compareTo(other
.getType()) < 0) {
203 } else if (entry
.getType().equals(other
.getType())) {
204 if (entry
.getId() < other
.getId()) {
209 entry
.setParent(this);
210 fChildren
.add(index
, entry
);
214 private static class TraceEntryComparator
implements Comparator
<ITimeGraphEntry
> {
216 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
217 int result
= o1
.getStartTime() < o2
.getStartTime() ?
-1 : o1
.getStartTime() > o2
.getStartTime() ?
1 : 0;
219 result
= o1
.getName().compareTo(o2
.getName());
225 private class BuildThread
extends Thread
{
226 private final ITmfTrace fBuildTrace
;
227 private final IProgressMonitor fMonitor
;
229 public BuildThread(ITmfTrace trace
) {
230 super("ResourcesView build"); //$NON-NLS-1$
232 fMonitor
= new NullProgressMonitor();
237 buildEventList(fBuildTrace
, fMonitor
);
238 synchronized (fBuildThreadMap
) {
239 fBuildThreadMap
.remove(this);
243 public void cancel() {
244 fMonitor
.setCanceled(true);
248 private class ZoomThread
extends Thread
{
249 private final ArrayList
<TraceEntry
> fZoomEntryList
;
250 private final long fZoomStartTime
;
251 private final long fZoomEndTime
;
252 private final IProgressMonitor fMonitor
;
254 public ZoomThread(ArrayList
<TraceEntry
> entryList
, long startTime
, long endTime
) {
255 super("ResourcesView zoom"); //$NON-NLS-1$
256 fZoomEntryList
= entryList
;
257 fZoomStartTime
= startTime
;
258 fZoomEndTime
= endTime
;
259 fMonitor
= new NullProgressMonitor();
264 if (fZoomEntryList
== null) {
267 long resolution
= Math
.max(1, (fZoomEndTime
- fZoomStartTime
) / fDisplayWidth
);
268 for (TraceEntry traceEntry
: fZoomEntryList
) {
269 if (!traceEntry
.fKernelTrace
.getStateSystems().get(LttngKernelTrace
.STATE_ID
).waitUntilBuilt()) {
272 for (ITimeGraphEntry child
: traceEntry
.getChildren()) {
273 if (fMonitor
.isCanceled()) {
276 ResourcesEntry entry
= (ResourcesEntry
) child
;
277 if (fZoomStartTime
<= fStartTime
&& fZoomEndTime
>= fEndTime
) {
278 entry
.setZoomedEventList(null);
280 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, fZoomStartTime
, fZoomEndTime
, resolution
, true, fMonitor
);
281 if (zoomedEventList
!= null) {
282 entry
.setZoomedEventList(zoomedEventList
);
290 public void cancel() {
291 fMonitor
.setCanceled(true);
295 // ------------------------------------------------------------------------
297 // ------------------------------------------------------------------------
300 * Default constructor
302 public ResourcesView() {
304 fDisplayWidth
= Display
.getDefault().getBounds().width
;
307 // ------------------------------------------------------------------------
309 // ------------------------------------------------------------------------
312 public void createPartControl(Composite parent
) {
313 fTimeGraphViewer
= new TimeGraphViewer(parent
, SWT
.NONE
);
315 fTimeGraphViewer
.setTimeGraphProvider(new ResourcesPresentationProvider(fTimeGraphViewer
));
317 fTimeGraphViewer
.setTimeFormat(TimeFormat
.CALENDAR
);
319 fTimeGraphViewer
.addRangeListener(new ITimeGraphRangeListener() {
321 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
322 long startTime
= event
.getStartTime();
323 long endTime
= event
.getEndTime();
324 TmfTimeRange range
= new TmfTimeRange(new CtfTmfTimestamp(startTime
), new CtfTmfTimestamp(endTime
));
325 TmfTimestamp time
= new CtfTmfTimestamp(fTimeGraphViewer
.getSelectedTime());
326 broadcast(new TmfRangeSynchSignal(ResourcesView
.this, range
, time
));
327 startZoomThread(startTime
, endTime
);
331 fTimeGraphViewer
.addTimeListener(new ITimeGraphTimeListener() {
333 public void timeSelected(TimeGraphTimeEvent event
) {
334 long time
= event
.getTime();
335 broadcast(new TmfTimeSynchSignal(ResourcesView
.this, new CtfTmfTimestamp(time
)));
339 // View Action Handling
341 contributeToActionBars();
343 ITmfTrace trace
= getActiveTrace();
345 traceSelected(new TmfTraceSelectedSignal(this, trace
));
350 public void setFocus() {
351 fTimeGraphViewer
.setFocus();
354 // ------------------------------------------------------------------------
356 // ------------------------------------------------------------------------
359 * Handler for the trace selected signal
362 * The incoming signal
365 public void traceSelected(final TmfTraceSelectedSignal signal
) {
366 if (signal
.getTrace() == fTrace
) {
369 fTrace
= signal
.getTrace();
371 synchronized (fEntryListMap
) {
372 fEntryList
= fEntryListMap
.get(fTrace
);
373 if (fEntryList
== null) {
374 synchronized (fBuildThreadMap
) {
375 BuildThread buildThread
= new BuildThread(fTrace
);
376 fBuildThreadMap
.put(fTrace
, buildThread
);
380 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
381 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
388 * Trace is disposed: clear the data structures and the view
390 * @param signal the signal received
393 public void traceClosed(final TmfTraceClosedSignal signal
) {
394 synchronized (fBuildThreadMap
) {
395 BuildThread buildThread
= fBuildThreadMap
.remove(signal
.getTrace());
396 if (buildThread
!= null) {
397 buildThread
.cancel();
400 synchronized (fEntryListMap
) {
401 fEntryListMap
.remove(signal
.getTrace());
403 if (signal
.getTrace() == fTrace
) {
407 if (fZoomThread
!= null) {
408 fZoomThread
.cancel();
415 * Handler for the TimeSynch signal
418 * The incoming signal
421 public void synchToTime(final TmfTimeSynchSignal signal
) {
422 if (signal
.getSource() == this || fTrace
== null) {
425 final long time
= signal
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
426 Display
.getDefault().asyncExec(new Runnable() {
429 if (fTimeGraphViewer
.getControl().isDisposed()) {
432 fTimeGraphViewer
.setSelectedTime(time
, true);
433 startZoomThread(fTimeGraphViewer
.getTime0(), fTimeGraphViewer
.getTime1());
439 * Handler for the RangeSynch signal
442 * The incoming signal
445 public void synchToRange(final TmfRangeSynchSignal signal
) {
446 if (signal
.getSource() == this || fTrace
== null) {
449 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
452 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
453 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
454 final long time
= signal
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
455 Display
.getDefault().asyncExec(new Runnable() {
458 if (fTimeGraphViewer
.getControl().isDisposed()) {
461 fTimeGraphViewer
.setStartFinishTime(startTime
, endTime
);
462 fTimeGraphViewer
.setSelectedTime(time
, false);
463 startZoomThread(startTime
, endTime
);
468 // ------------------------------------------------------------------------
470 // ------------------------------------------------------------------------
472 private void buildEventList(final ITmfTrace trace
, IProgressMonitor monitor
) {
473 fStartTime
= Long
.MAX_VALUE
;
474 fEndTime
= Long
.MIN_VALUE
;
475 ArrayList
<TraceEntry
> entryList
= new ArrayList
<TraceEntry
>();
476 for (ITmfTrace aTrace
: trace
.getTraces()) {
477 if (monitor
.isCanceled()) {
480 if (aTrace
instanceof LttngKernelTrace
) {
481 LttngKernelTrace ctfKernelTrace
= (LttngKernelTrace
) aTrace
;
482 ITmfStateSystem ssq
= ctfKernelTrace
.getStateSystems().get(LttngKernelTrace
.STATE_ID
);
483 if (!ssq
.waitUntilBuilt()) {
486 long startTime
= ssq
.getStartTime();
487 long endTime
= ssq
.getCurrentEndTime() + 1;
488 TraceEntry groupEntry
= new TraceEntry(ctfKernelTrace
, aTrace
.getName(), startTime
, endTime
);
489 entryList
.add(groupEntry
);
490 fStartTime
= Math
.min(fStartTime
, startTime
);
491 fEndTime
= Math
.max(fEndTime
, endTime
);
492 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
493 ResourcesEntry
[] cpuEntries
= new ResourcesEntry
[cpuQuarks
.size()];
494 for (int i
= 0; i
< cpuQuarks
.size(); i
++) {
495 int cpuQuark
= cpuQuarks
.get(i
);
496 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
497 ResourcesEntry entry
= new ResourcesEntry(cpuQuark
, ctfKernelTrace
, Type
.CPU
, cpu
);
498 groupEntry
.addChild(entry
);
499 cpuEntries
[i
] = entry
;
501 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
502 ResourcesEntry
[] irqEntries
= new ResourcesEntry
[irqQuarks
.size()];
503 for (int i
= 0; i
< irqQuarks
.size(); i
++) {
504 int irqQuark
= irqQuarks
.get(i
);
505 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
506 ResourcesEntry entry
= new ResourcesEntry(irqQuark
, ctfKernelTrace
, Type
.IRQ
, irq
);
507 groupEntry
.addChild(entry
);
508 irqEntries
[i
] = entry
;
510 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
511 ResourcesEntry
[] softIrqEntries
= new ResourcesEntry
[softIrqQuarks
.size()];
512 for (int i
= 0; i
< softIrqQuarks
.size(); i
++) {
513 int softIrqQuark
= softIrqQuarks
.get(i
);
514 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
515 ResourcesEntry entry
= new ResourcesEntry(softIrqQuark
, ctfKernelTrace
, Type
.SOFT_IRQ
, softIrq
);
516 groupEntry
.addChild(entry
);
517 softIrqEntries
[i
] = entry
;
521 synchronized (fEntryListMap
) {
522 fEntryListMap
.put(trace
, (ArrayList
<TraceEntry
>) entryList
.clone());
524 if (trace
== fTrace
) {
527 for (TraceEntry traceEntry
: entryList
) {
528 if (monitor
.isCanceled()) {
531 LttngKernelTrace ctfKernelTrace
= traceEntry
.getTrace();
532 ITmfStateSystem ssq
= ctfKernelTrace
.getStateSystems().get(LttngKernelTrace
.STATE_ID
);
533 long startTime
= ssq
.getStartTime();
534 long endTime
= ssq
.getCurrentEndTime() + 1;
535 long resolution
= (endTime
- startTime
) / fDisplayWidth
;
536 for (ResourcesEntry entry
: traceEntry
.getChildren()) {
537 List
<ITimeEvent
> eventList
= getEventList(entry
, startTime
, endTime
, resolution
, false, monitor
);
538 entry
.setEventList(eventList
);
544 private static List
<ITimeEvent
> getEventList(ResourcesEntry entry
,
545 long startTime
, long endTime
, long resolution
, boolean includeNull
,
546 IProgressMonitor monitor
) {
547 ITmfStateSystem ssq
= entry
.getTrace().getStateSystems().get(LttngKernelTrace
.STATE_ID
);
548 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
549 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
550 if (realEnd
<= realStart
) {
553 List
<ITimeEvent
> eventList
= null;
554 int quark
= entry
.getQuark();
556 if (entry
.getType().equals(Type
.CPU
)) {
557 int statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
558 List
<ITmfStateInterval
> statusIntervals
= ssq
.queryHistoryRange(statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
559 eventList
= new ArrayList
<ITimeEvent
>(statusIntervals
.size());
560 long lastEndTime
= -1;
561 for (ITmfStateInterval statusInterval
: statusIntervals
) {
562 if (monitor
.isCanceled()) {
565 int status
= statusInterval
.getStateValue().unboxInt();
566 long time
= statusInterval
.getStartTime();
567 long duration
= statusInterval
.getEndTime() - time
+ 1;
568 if (!statusInterval
.getStateValue().isNull()) {
569 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
570 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
572 eventList
.add(new ResourcesEvent(entry
, time
, duration
, status
));
573 lastEndTime
= time
+ duration
;
576 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
580 } else if (entry
.getType().equals(Type
.IRQ
)) {
581 List
<ITmfStateInterval
> irqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
582 eventList
= new ArrayList
<ITimeEvent
>(irqIntervals
.size());
583 long lastEndTime
= -1;
584 boolean lastIsNull
= true;
585 for (ITmfStateInterval irqInterval
: irqIntervals
) {
586 if (monitor
.isCanceled()) {
589 long time
= irqInterval
.getStartTime();
590 long duration
= irqInterval
.getEndTime() - time
+ 1;
591 if (!irqInterval
.getStateValue().isNull()) {
592 int cpu
= irqInterval
.getStateValue().unboxInt();
593 eventList
.add(new ResourcesEvent(entry
, time
, duration
, cpu
));
596 if (lastEndTime
!= time
&& lastEndTime
!= -1 && lastIsNull
) {
597 eventList
.add(new ResourcesEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
600 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
604 lastEndTime
= time
+ duration
;
606 } else if (entry
.getType().equals(Type
.SOFT_IRQ
)) {
607 List
<ITmfStateInterval
> softIrqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
608 eventList
= new ArrayList
<ITimeEvent
>(softIrqIntervals
.size());
609 long lastEndTime
= -1;
610 boolean lastIsNull
= true;
611 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
612 if (monitor
.isCanceled()) {
615 long time
= softIrqInterval
.getStartTime();
616 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
617 if (!softIrqInterval
.getStateValue().isNull()) {
618 int cpu
= softIrqInterval
.getStateValue().unboxInt();
619 eventList
.add(new ResourcesEvent(entry
, time
, duration
, cpu
));
621 if (lastEndTime
!= time
&& lastEndTime
!= -1 && lastIsNull
) {
622 eventList
.add(new ResourcesEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
625 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
629 lastEndTime
= time
+ duration
;
632 } catch (AttributeNotFoundException e
) {
634 } catch (TimeRangeException e
) {
636 } catch (StateValueTypeException e
) {
638 } catch (StateSystemDisposedException e
) {
644 private void refresh() {
645 Display
.getDefault().asyncExec(new Runnable() {
648 if (fTimeGraphViewer
.getControl().isDisposed()) {
651 ITimeGraphEntry
[] entries
= null;
652 synchronized (fEntryListMap
) {
653 fEntryList
= fEntryListMap
.get(fTrace
);
654 if (fEntryList
== null) {
655 fEntryList
= new ArrayList
<TraceEntry
>();
657 entries
= fEntryList
.toArray(new ITimeGraphEntry
[0]);
659 if (entries
!= null) {
660 Arrays
.sort(entries
, new TraceEntryComparator());
661 fTimeGraphViewer
.setInput(entries
);
662 fTimeGraphViewer
.setTimeBounds(fStartTime
, fEndTime
);
664 long timestamp
= fTrace
== null ?
0 : fTrace
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
665 long startTime
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
666 long endTime
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
667 startTime
= Math
.max(startTime
, fStartTime
);
668 endTime
= Math
.min(endTime
, fEndTime
);
669 fTimeGraphViewer
.setSelectedTime(timestamp
, false);
670 fTimeGraphViewer
.setStartFinishTime(startTime
, endTime
);
672 startZoomThread(startTime
, endTime
);
678 private void redraw() {
679 synchronized (fSyncObj
) {
680 if (fRedrawState
== State
.IDLE
) {
681 fRedrawState
= State
.BUSY
;
683 fRedrawState
= State
.PENDING
;
687 Display
.getDefault().asyncExec(new Runnable() {
690 if (fTimeGraphViewer
.getControl().isDisposed()) {
693 fTimeGraphViewer
.getControl().redraw();
694 fTimeGraphViewer
.getControl().update();
695 synchronized (fSyncObj
) {
696 if (fRedrawState
== State
.PENDING
) {
697 fRedrawState
= State
.IDLE
;
700 fRedrawState
= State
.IDLE
;
707 private void startZoomThread(long startTime
, long endTime
) {
708 if (fZoomThread
!= null) {
709 fZoomThread
.cancel();
711 fZoomThread
= new ZoomThread(fEntryList
, startTime
, endTime
);
715 private void makeActions() {
716 fPreviousResourceAction
= fTimeGraphViewer
.getPreviousItemAction();
717 fPreviousResourceAction
.setText(Messages
.ResourcesView_previousResourceActionNameText
);
718 fPreviousResourceAction
.setToolTipText(Messages
.ResourcesView_previousResourceActionToolTipText
);
719 fNextResourceAction
= fTimeGraphViewer
.getNextItemAction();
720 fNextResourceAction
.setText(Messages
.ResourcesView_nextResourceActionNameText
);
721 fNextResourceAction
.setToolTipText(Messages
.ResourcesView_previousResourceActionToolTipText
);
724 private void contributeToActionBars() {
725 IActionBars bars
= getViewSite().getActionBars();
726 fillLocalToolBar(bars
.getToolBarManager());
729 private void fillLocalToolBar(IToolBarManager manager
) {
730 manager
.add(fTimeGraphViewer
.getShowLegendAction());
731 manager
.add(new Separator());
732 manager
.add(fTimeGraphViewer
.getResetScaleAction());
733 manager
.add(fTimeGraphViewer
.getPreviousEventAction());
734 manager
.add(fTimeGraphViewer
.getNextEventAction());
735 manager
.add(fPreviousResourceAction
);
736 manager
.add(fNextResourceAction
);
737 manager
.add(fTimeGraphViewer
.getZoomInAction());
738 manager
.add(fTimeGraphViewer
.getZoomOutAction());
739 manager
.add(new Separator());