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
.CtfKernelTrace
;
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
.core
.trace
.TmfExperiment
;
48 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
49 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
51 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
52 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
53 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
58 import org
.eclipse
.swt
.SWT
;
59 import org
.eclipse
.swt
.widgets
.Composite
;
60 import org
.eclipse
.swt
.widgets
.Display
;
61 import org
.eclipse
.ui
.IActionBars
;
64 * Main implementation for the LTTng 2.0 kernel Resource view
66 * @author Patrick Tasse
68 public class ResourcesView
extends TmfView
{
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
75 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
80 private enum State
{ IDLE
, BUSY
, PENDING
}
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
86 // The time graph viewer
87 TimeGraphViewer fTimeGraphViewer
;
90 private ITmfTrace fTrace
;
92 // The time graph entry list
93 private ArrayList
<TraceEntry
> fEntryList
;
95 // The trace to entry list hash map
96 final private HashMap
<ITmfTrace
, ArrayList
<TraceEntry
>> fEntryListMap
= new HashMap
<ITmfTrace
, ArrayList
<TraceEntry
>>();
98 // The trace to build thread hash map
99 final private HashMap
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<ITmfTrace
, BuildThread
>();
102 private long fStartTime
;
105 private long fEndTime
;
108 private final int fDisplayWidth
;
110 // The next resource action
111 private Action fNextResourceAction
;
113 // The previous resource action
114 private Action fPreviousResourceAction
;
117 private ZoomThread fZoomThread
;
119 // The redraw state used to prevent unnecessary queuing of display runnables
120 private State fRedrawState
= State
.IDLE
;
122 // The redraw synchronization object
123 final private Object fSyncObj
= new Object();
125 // ------------------------------------------------------------------------
127 // ------------------------------------------------------------------------
129 private class TraceEntry
implements ITimeGraphEntry
{
131 private final CtfKernelTrace fKernelTrace
;
133 private final long fTraceStartTime
;
135 private final long fTraceEndTime
;
136 // The children of the entry
137 private final ArrayList
<ResourcesEntry
> fChildren
;
139 private final String fName
;
141 public TraceEntry(CtfKernelTrace trace
, String name
, long startTime
, long endTime
) {
142 fKernelTrace
= trace
;
143 fChildren
= new ArrayList
<ResourcesEntry
>();
145 fTraceStartTime
= startTime
;
146 fTraceEndTime
= endTime
;
150 public ITimeGraphEntry
getParent() {
155 public boolean hasChildren() {
156 return fChildren
!= null && fChildren
.size() > 0;
160 public List
<ResourcesEntry
> getChildren() {
165 public String
getName() {
170 public long getStartTime() {
171 return fTraceStartTime
;
175 public long getEndTime() {
176 return fTraceEndTime
;
180 public boolean hasTimeEvents() {
185 public Iterator
<ITimeEvent
> getTimeEventsIterator() {
190 public <T
extends ITimeEvent
> Iterator
<T
> getTimeEventsIterator(long startTime
, long stopTime
, long visibleDuration
) {
194 public CtfKernelTrace
getTrace() {
198 public void addChild(ResourcesEntry entry
) {
200 for (index
= 0; index
< fChildren
.size(); index
++) {
201 ResourcesEntry other
= fChildren
.get(index
);
202 if (entry
.getType().compareTo(other
.getType()) < 0) {
204 } else if (entry
.getType().equals(other
.getType())) {
205 if (entry
.getId() < other
.getId()) {
210 entry
.setParent(this);
211 fChildren
.add(index
, entry
);
215 private static class TraceEntryComparator
implements Comparator
<ITimeGraphEntry
> {
217 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
218 int result
= o1
.getStartTime() < o2
.getStartTime() ?
-1 : o1
.getStartTime() > o2
.getStartTime() ?
1 : 0;
220 result
= o1
.getName().compareTo(o2
.getName());
226 private class BuildThread
extends Thread
{
227 private final ITmfTrace fBuildTrace
;
228 private final IProgressMonitor fMonitor
;
230 public BuildThread(ITmfTrace trace
) {
231 super("ResourcesView build"); //$NON-NLS-1$
233 fMonitor
= new NullProgressMonitor();
238 buildEventList(fBuildTrace
, fMonitor
);
239 synchronized (fBuildThreadMap
) {
240 fBuildThreadMap
.remove(this);
244 public void cancel() {
245 fMonitor
.setCanceled(true);
249 private class ZoomThread
extends Thread
{
250 private final ArrayList
<TraceEntry
> fZoomEntryList
;
251 private final long fZoomStartTime
;
252 private final long fZoomEndTime
;
253 private final IProgressMonitor fMonitor
;
255 public ZoomThread(ArrayList
<TraceEntry
> entryList
, long startTime
, long endTime
) {
256 super("ResourcesView zoom"); //$NON-NLS-1$
257 fZoomEntryList
= entryList
;
258 fZoomStartTime
= startTime
;
259 fZoomEndTime
= endTime
;
260 fMonitor
= new NullProgressMonitor();
265 if (fZoomEntryList
== null) {
268 long resolution
= Math
.max(1, (fZoomEndTime
- fZoomStartTime
) / fDisplayWidth
);
269 for (TraceEntry traceEntry
: fZoomEntryList
) {
270 if (!traceEntry
.fKernelTrace
.getStateSystem(CtfKernelTrace
.STATE_ID
).waitUntilBuilt()) {
273 for (ITimeGraphEntry child
: traceEntry
.getChildren()) {
274 if (fMonitor
.isCanceled()) {
277 ResourcesEntry entry
= (ResourcesEntry
) child
;
278 if (fZoomStartTime
<= fStartTime
&& fZoomEndTime
>= fEndTime
) {
279 entry
.setZoomedEventList(null);
281 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, fZoomStartTime
, fZoomEndTime
, resolution
, true, fMonitor
);
282 if (zoomedEventList
!= null) {
283 entry
.setZoomedEventList(zoomedEventList
);
291 public void cancel() {
292 fMonitor
.setCanceled(true);
296 // ------------------------------------------------------------------------
298 // ------------------------------------------------------------------------
301 * Default constructor
303 public ResourcesView() {
305 fDisplayWidth
= Display
.getDefault().getBounds().width
;
308 // ------------------------------------------------------------------------
310 // ------------------------------------------------------------------------
313 * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)
316 public void createPartControl(Composite parent
) {
317 fTimeGraphViewer
= new TimeGraphViewer(parent
, SWT
.NONE
);
319 fTimeGraphViewer
.setTimeGraphProvider(new ResourcesPresentationProvider(fTimeGraphViewer
));
321 fTimeGraphViewer
.setTimeFormat(TimeFormat
.CALENDAR
);
323 fTimeGraphViewer
.addRangeListener(new ITimeGraphRangeListener() {
325 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
326 long startTime
= event
.getStartTime();
327 long endTime
= event
.getEndTime();
328 TmfTimeRange range
= new TmfTimeRange(new CtfTmfTimestamp(startTime
), new CtfTmfTimestamp(endTime
));
329 TmfTimestamp time
= new CtfTmfTimestamp(fTimeGraphViewer
.getSelectedTime());
330 broadcast(new TmfRangeSynchSignal(ResourcesView
.this, range
, time
));
331 startZoomThread(startTime
, endTime
);
335 fTimeGraphViewer
.addTimeListener(new ITimeGraphTimeListener() {
337 public void timeSelected(TimeGraphTimeEvent event
) {
338 long time
= event
.getTime();
339 broadcast(new TmfTimeSynchSignal(ResourcesView
.this, new CtfTmfTimestamp(time
)));
343 // View Action Handling
345 contributeToActionBars();
347 ITmfTrace trace
= getActiveTrace();
349 traceSelected(new TmfTraceSelectedSignal(this, trace
));
354 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
357 public void setFocus() {
358 fTimeGraphViewer
.setFocus();
361 // ------------------------------------------------------------------------
363 // ------------------------------------------------------------------------
366 * Handler for the trace selected signal
369 * The incoming signal
372 public void traceSelected(final TmfTraceSelectedSignal signal
) {
373 if (signal
.getTrace() == fTrace
) {
376 fTrace
= signal
.getTrace();
378 synchronized (fEntryListMap
) {
379 fEntryList
= fEntryListMap
.get(fTrace
);
380 if (fEntryList
== null) {
381 synchronized (fBuildThreadMap
) {
382 BuildThread buildThread
= new BuildThread(fTrace
);
383 fBuildThreadMap
.put(fTrace
, buildThread
);
387 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
388 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
395 * Trace is disposed: clear the data structures and the view
397 * @param signal the signal received
400 public void traceClosed(final TmfTraceClosedSignal signal
) {
401 synchronized (fBuildThreadMap
) {
402 BuildThread buildThread
= fBuildThreadMap
.remove(signal
.getTrace());
403 if (buildThread
!= null) {
404 buildThread
.cancel();
407 synchronized (fEntryListMap
) {
408 fEntryListMap
.remove(signal
.getTrace());
410 if (signal
.getTrace() == fTrace
) {
414 if (fZoomThread
!= null) {
415 fZoomThread
.cancel();
422 * Handler for the TimeSynch signal
425 * The incoming signal
428 public void synchToTime(final TmfTimeSynchSignal signal
) {
429 if (signal
.getSource() == this || fTrace
== null) {
432 final long time
= signal
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
433 Display
.getDefault().asyncExec(new Runnable() {
436 if (fTimeGraphViewer
.getControl().isDisposed()) {
439 fTimeGraphViewer
.setSelectedTime(time
, true);
440 startZoomThread(fTimeGraphViewer
.getTime0(), fTimeGraphViewer
.getTime1());
446 * Handler for the RangeSynch signal
449 * The incoming signal
452 public void synchToRange(final TmfRangeSynchSignal signal
) {
453 if (signal
.getSource() == this || fTrace
== null) {
456 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
459 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
460 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
461 final long time
= signal
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
462 Display
.getDefault().asyncExec(new Runnable() {
465 if (fTimeGraphViewer
.getControl().isDisposed()) {
468 fTimeGraphViewer
.setStartFinishTime(startTime
, endTime
);
469 fTimeGraphViewer
.setSelectedTime(time
, false);
470 startZoomThread(startTime
, endTime
);
475 // ------------------------------------------------------------------------
477 // ------------------------------------------------------------------------
479 private void buildEventList(final ITmfTrace trace
, IProgressMonitor monitor
) {
480 fStartTime
= Long
.MAX_VALUE
;
481 fEndTime
= Long
.MIN_VALUE
;
483 if (trace
instanceof TmfExperiment
) {
484 TmfExperiment experiment
= (TmfExperiment
) trace
;
485 traces
= experiment
.getTraces();
487 traces
= new ITmfTrace
[] { trace
};
489 ArrayList
<TraceEntry
> entryList
= new ArrayList
<TraceEntry
>();
490 for (ITmfTrace aTrace
: traces
) {
491 if (monitor
.isCanceled()) {
494 if (aTrace
instanceof CtfKernelTrace
) {
495 CtfKernelTrace ctfKernelTrace
= (CtfKernelTrace
) aTrace
;
496 ITmfStateSystem ssq
= ctfKernelTrace
.getStateSystem(CtfKernelTrace
.STATE_ID
);
497 if (!ssq
.waitUntilBuilt()) {
500 long startTime
= ssq
.getStartTime();
501 long endTime
= ssq
.getCurrentEndTime() + 1;
502 TraceEntry groupEntry
= new TraceEntry(ctfKernelTrace
, aTrace
.getName(), startTime
, endTime
);
503 entryList
.add(groupEntry
);
504 fStartTime
= Math
.min(fStartTime
, startTime
);
505 fEndTime
= Math
.max(fEndTime
, endTime
);
506 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
507 ResourcesEntry
[] cpuEntries
= new ResourcesEntry
[cpuQuarks
.size()];
508 for (int i
= 0; i
< cpuQuarks
.size(); i
++) {
509 int cpuQuark
= cpuQuarks
.get(i
);
510 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
511 ResourcesEntry entry
= new ResourcesEntry(cpuQuark
, ctfKernelTrace
, Type
.CPU
, cpu
);
512 groupEntry
.addChild(entry
);
513 cpuEntries
[i
] = entry
;
515 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
516 ResourcesEntry
[] irqEntries
= new ResourcesEntry
[irqQuarks
.size()];
517 for (int i
= 0; i
< irqQuarks
.size(); i
++) {
518 int irqQuark
= irqQuarks
.get(i
);
519 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
520 ResourcesEntry entry
= new ResourcesEntry(irqQuark
, ctfKernelTrace
, Type
.IRQ
, irq
);
521 groupEntry
.addChild(entry
);
522 irqEntries
[i
] = entry
;
524 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
525 ResourcesEntry
[] softIrqEntries
= new ResourcesEntry
[softIrqQuarks
.size()];
526 for (int i
= 0; i
< softIrqQuarks
.size(); i
++) {
527 int softIrqQuark
= softIrqQuarks
.get(i
);
528 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
529 ResourcesEntry entry
= new ResourcesEntry(softIrqQuark
, ctfKernelTrace
, Type
.SOFT_IRQ
, softIrq
);
530 groupEntry
.addChild(entry
);
531 softIrqEntries
[i
] = entry
;
535 synchronized (fEntryListMap
) {
536 fEntryListMap
.put(trace
, (ArrayList
<TraceEntry
>) entryList
.clone());
538 if (trace
== fTrace
) {
541 for (TraceEntry traceEntry
: entryList
) {
542 if (monitor
.isCanceled()) {
545 CtfKernelTrace ctfKernelTrace
= traceEntry
.getTrace();
546 ITmfStateSystem ssq
= ctfKernelTrace
.getStateSystem(CtfKernelTrace
.STATE_ID
);
547 long startTime
= ssq
.getStartTime();
548 long endTime
= ssq
.getCurrentEndTime() + 1;
549 long resolution
= (endTime
- startTime
) / fDisplayWidth
;
550 for (ResourcesEntry entry
: traceEntry
.getChildren()) {
551 List
<ITimeEvent
> eventList
= getEventList(entry
, startTime
, endTime
, resolution
, false, monitor
);
552 entry
.setEventList(eventList
);
558 private static List
<ITimeEvent
> getEventList(ResourcesEntry entry
,
559 long startTime
, long endTime
, long resolution
, boolean includeNull
,
560 IProgressMonitor monitor
) {
561 ITmfStateSystem ssq
= entry
.getTrace().getStateSystem(CtfKernelTrace
.STATE_ID
);
562 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
563 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
564 if (realEnd
<= realStart
) {
567 List
<ITimeEvent
> eventList
= null;
568 int quark
= entry
.getQuark();
570 if (entry
.getType().equals(Type
.CPU
)) {
571 int statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
572 List
<ITmfStateInterval
> statusIntervals
= ssq
.queryHistoryRange(statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
573 eventList
= new ArrayList
<ITimeEvent
>(statusIntervals
.size());
574 long lastEndTime
= -1;
575 for (ITmfStateInterval statusInterval
: statusIntervals
) {
576 if (monitor
.isCanceled()) {
579 int status
= statusInterval
.getStateValue().unboxInt();
580 long time
= statusInterval
.getStartTime();
581 long duration
= statusInterval
.getEndTime() - time
+ 1;
582 if (!statusInterval
.getStateValue().isNull()) {
583 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
584 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
586 eventList
.add(new ResourcesEvent(entry
, time
, duration
, status
));
587 lastEndTime
= time
+ duration
;
590 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
594 } else if (entry
.getType().equals(Type
.IRQ
)) {
595 List
<ITmfStateInterval
> irqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
596 eventList
= new ArrayList
<ITimeEvent
>(irqIntervals
.size());
597 long lastEndTime
= -1;
598 boolean lastIsNull
= true;
599 for (ITmfStateInterval irqInterval
: irqIntervals
) {
600 if (monitor
.isCanceled()) {
603 long time
= irqInterval
.getStartTime();
604 long duration
= irqInterval
.getEndTime() - time
+ 1;
605 if (!irqInterval
.getStateValue().isNull()) {
606 int cpu
= irqInterval
.getStateValue().unboxInt();
607 eventList
.add(new ResourcesEvent(entry
, time
, duration
, cpu
));
610 if (lastEndTime
!= time
&& lastEndTime
!= -1 && lastIsNull
) {
611 eventList
.add(new ResourcesEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
614 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
618 lastEndTime
= time
+ duration
;
620 } else if (entry
.getType().equals(Type
.SOFT_IRQ
)) {
621 List
<ITmfStateInterval
> softIrqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
622 eventList
= new ArrayList
<ITimeEvent
>(softIrqIntervals
.size());
623 long lastEndTime
= -1;
624 boolean lastIsNull
= true;
625 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
626 if (monitor
.isCanceled()) {
629 long time
= softIrqInterval
.getStartTime();
630 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
631 if (!softIrqInterval
.getStateValue().isNull()) {
632 int cpu
= softIrqInterval
.getStateValue().unboxInt();
633 eventList
.add(new ResourcesEvent(entry
, time
, duration
, cpu
));
635 if (lastEndTime
!= time
&& lastEndTime
!= -1 && lastIsNull
) {
636 eventList
.add(new ResourcesEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
639 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
643 lastEndTime
= time
+ duration
;
646 } catch (AttributeNotFoundException e
) {
648 } catch (TimeRangeException e
) {
650 } catch (StateValueTypeException e
) {
652 } catch (StateSystemDisposedException e
) {
658 private void refresh() {
659 Display
.getDefault().asyncExec(new Runnable() {
662 if (fTimeGraphViewer
.getControl().isDisposed()) {
665 ITimeGraphEntry
[] entries
= null;
666 synchronized (fEntryListMap
) {
667 fEntryList
= fEntryListMap
.get(fTrace
);
668 if (fEntryList
== null) {
669 fEntryList
= new ArrayList
<TraceEntry
>();
671 entries
= fEntryList
.toArray(new ITimeGraphEntry
[0]);
673 if (entries
!= null) {
674 Arrays
.sort(entries
, new TraceEntryComparator());
675 fTimeGraphViewer
.setInput(entries
);
676 fTimeGraphViewer
.setTimeBounds(fStartTime
, fEndTime
);
678 long timestamp
= fTrace
== null ?
0 : fTrace
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
679 long startTime
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
680 long endTime
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
681 startTime
= Math
.max(startTime
, fStartTime
);
682 endTime
= Math
.min(endTime
, fEndTime
);
683 fTimeGraphViewer
.setSelectedTime(timestamp
, false);
684 fTimeGraphViewer
.setStartFinishTime(startTime
, endTime
);
686 startZoomThread(startTime
, endTime
);
692 private void redraw() {
693 synchronized (fSyncObj
) {
694 if (fRedrawState
== State
.IDLE
) {
695 fRedrawState
= State
.BUSY
;
697 fRedrawState
= State
.PENDING
;
701 Display
.getDefault().asyncExec(new Runnable() {
704 if (fTimeGraphViewer
.getControl().isDisposed()) {
707 fTimeGraphViewer
.getControl().redraw();
708 fTimeGraphViewer
.getControl().update();
709 synchronized (fSyncObj
) {
710 if (fRedrawState
== State
.PENDING
) {
711 fRedrawState
= State
.IDLE
;
714 fRedrawState
= State
.IDLE
;
721 private void startZoomThread(long startTime
, long endTime
) {
722 if (fZoomThread
!= null) {
723 fZoomThread
.cancel();
725 fZoomThread
= new ZoomThread(fEntryList
, startTime
, endTime
);
729 private void makeActions() {
730 fPreviousResourceAction
= fTimeGraphViewer
.getPreviousItemAction();
731 fPreviousResourceAction
.setText(Messages
.ResourcesView_previousResourceActionNameText
);
732 fPreviousResourceAction
.setToolTipText(Messages
.ResourcesView_previousResourceActionToolTipText
);
733 fNextResourceAction
= fTimeGraphViewer
.getNextItemAction();
734 fNextResourceAction
.setText(Messages
.ResourcesView_nextResourceActionNameText
);
735 fNextResourceAction
.setToolTipText(Messages
.ResourcesView_previousResourceActionToolTipText
);
738 private void contributeToActionBars() {
739 IActionBars bars
= getViewSite().getActionBars();
740 fillLocalToolBar(bars
.getToolBarManager());
743 private void fillLocalToolBar(IToolBarManager manager
) {
744 manager
.add(fTimeGraphViewer
.getShowLegendAction());
745 manager
.add(new Separator());
746 manager
.add(fTimeGraphViewer
.getResetScaleAction());
747 manager
.add(fTimeGraphViewer
.getPreviousEventAction());
748 manager
.add(fTimeGraphViewer
.getNextEventAction());
749 manager
.add(fPreviousResourceAction
);
750 manager
.add(fNextResourceAction
);
751 manager
.add(fTimeGraphViewer
.getZoomInAction());
752 manager
.add(fTimeGraphViewer
.getZoomOutAction());
753 manager
.add(new Separator());