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
.TmfTraceOpenedSignal
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
46 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
47 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
48 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
49 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
50 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
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
.TimeGraphTimeEvent
;
54 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
55 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
56 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
57 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
58 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
59 import org
.eclipse
.swt
.SWT
;
60 import org
.eclipse
.swt
.widgets
.Composite
;
61 import org
.eclipse
.swt
.widgets
.Display
;
62 import org
.eclipse
.ui
.IActionBars
;
65 * Main implementation for the LTTng 2.0 kernel Resource view
67 * @author Patrick Tasse
69 public class ResourcesView
extends TmfView
{
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
76 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
81 private enum State
{ IDLE
, BUSY
, PENDING
}
83 // ------------------------------------------------------------------------
85 // ------------------------------------------------------------------------
87 // The time graph viewer
88 TimeGraphViewer fTimeGraphViewer
;
91 private ITmfTrace fTrace
;
93 // The time graph entry list
94 private ArrayList
<TraceEntry
> fEntryList
;
96 // The trace to entry list hash map
97 final private HashMap
<ITmfTrace
, ArrayList
<TraceEntry
>> fEntryListMap
= new HashMap
<ITmfTrace
, ArrayList
<TraceEntry
>>();
99 // The trace to build thread hash map
100 final private HashMap
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<ITmfTrace
, BuildThread
>();
103 private long fStartTime
;
106 private long fEndTime
;
109 private final int fDisplayWidth
;
111 // The next resource action
112 private Action fNextResourceAction
;
114 // The previous resource action
115 private Action fPreviousResourceAction
;
118 private ZoomThread fZoomThread
;
120 // The redraw state used to prevent unnecessary queuing of display runnables
121 private State fRedrawState
= State
.IDLE
;
123 // The redraw synchronization object
124 final private Object fSyncObj
= new Object();
126 // ------------------------------------------------------------------------
128 // ------------------------------------------------------------------------
130 private class TraceEntry
implements ITimeGraphEntry
{
132 private final LttngKernelTrace fKernelTrace
;
134 private final long fTraceStartTime
;
136 private final long fTraceEndTime
;
137 // The children of the entry
138 private final ArrayList
<ResourcesEntry
> fChildren
;
140 private final String fName
;
142 public TraceEntry(LttngKernelTrace trace
, String name
, long startTime
, long endTime
) {
143 fKernelTrace
= trace
;
144 fChildren
= new ArrayList
<ResourcesEntry
>();
146 fTraceStartTime
= startTime
;
147 fTraceEndTime
= endTime
;
151 public ITimeGraphEntry
getParent() {
156 public boolean hasChildren() {
157 return fChildren
!= null && fChildren
.size() > 0;
161 public List
<ResourcesEntry
> getChildren() {
166 public String
getName() {
171 public long getStartTime() {
172 return fTraceStartTime
;
176 public long getEndTime() {
177 return fTraceEndTime
;
181 public boolean hasTimeEvents() {
186 public Iterator
<ITimeEvent
> getTimeEventsIterator() {
191 public <T
extends ITimeEvent
> Iterator
<T
> getTimeEventsIterator(long startTime
, long stopTime
, long visibleDuration
) {
195 public LttngKernelTrace
getTrace() {
199 public void addChild(ResourcesEntry entry
) {
201 for (index
= 0; index
< fChildren
.size(); index
++) {
202 ResourcesEntry other
= fChildren
.get(index
);
203 if (entry
.getType().compareTo(other
.getType()) < 0) {
205 } else if (entry
.getType().equals(other
.getType())) {
206 if (entry
.getId() < other
.getId()) {
211 entry
.setParent(this);
212 fChildren
.add(index
, entry
);
216 private static class TraceEntryComparator
implements Comparator
<ITimeGraphEntry
> {
218 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
219 int result
= o1
.getStartTime() < o2
.getStartTime() ?
-1 : o1
.getStartTime() > o2
.getStartTime() ?
1 : 0;
221 result
= o1
.getName().compareTo(o2
.getName());
227 private class BuildThread
extends Thread
{
228 private final ITmfTrace fBuildTrace
;
229 private final IProgressMonitor fMonitor
;
231 public BuildThread(ITmfTrace trace
) {
232 super("ResourcesView build"); //$NON-NLS-1$
234 fMonitor
= new NullProgressMonitor();
239 buildEventList(fBuildTrace
, fMonitor
);
240 synchronized (fBuildThreadMap
) {
241 fBuildThreadMap
.remove(this);
245 public void cancel() {
246 fMonitor
.setCanceled(true);
250 private class ZoomThread
extends Thread
{
251 private final ArrayList
<TraceEntry
> fZoomEntryList
;
252 private final long fZoomStartTime
;
253 private final long fZoomEndTime
;
254 private final IProgressMonitor fMonitor
;
256 public ZoomThread(ArrayList
<TraceEntry
> entryList
, long startTime
, long endTime
) {
257 super("ResourcesView zoom"); //$NON-NLS-1$
258 fZoomEntryList
= entryList
;
259 fZoomStartTime
= startTime
;
260 fZoomEndTime
= endTime
;
261 fMonitor
= new NullProgressMonitor();
266 if (fZoomEntryList
== null) {
269 long resolution
= Math
.max(1, (fZoomEndTime
- fZoomStartTime
) / fDisplayWidth
);
270 for (TraceEntry traceEntry
: fZoomEntryList
) {
271 if (!traceEntry
.fKernelTrace
.getStateSystems().get(LttngKernelTrace
.STATE_ID
).waitUntilBuilt()) {
274 for (ITimeGraphEntry child
: traceEntry
.getChildren()) {
275 if (fMonitor
.isCanceled()) {
278 ResourcesEntry entry
= (ResourcesEntry
) child
;
279 if (fZoomStartTime
<= fStartTime
&& fZoomEndTime
>= fEndTime
) {
280 entry
.setZoomedEventList(null);
282 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, fZoomStartTime
, fZoomEndTime
, resolution
, true, fMonitor
);
283 if (zoomedEventList
!= null) {
284 entry
.setZoomedEventList(zoomedEventList
);
292 public void cancel() {
293 fMonitor
.setCanceled(true);
297 // ------------------------------------------------------------------------
299 // ------------------------------------------------------------------------
302 * Default constructor
304 public ResourcesView() {
306 fDisplayWidth
= Display
.getDefault().getBounds().width
;
309 // ------------------------------------------------------------------------
311 // ------------------------------------------------------------------------
314 public void createPartControl(Composite parent
) {
315 fTimeGraphViewer
= new TimeGraphViewer(parent
, SWT
.NONE
);
317 fTimeGraphViewer
.setTimeGraphProvider(new ResourcesPresentationProvider(fTimeGraphViewer
));
319 fTimeGraphViewer
.setTimeFormat(TimeFormat
.CALENDAR
);
321 fTimeGraphViewer
.addRangeListener(new ITimeGraphRangeListener() {
323 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
324 long startTime
= event
.getStartTime();
325 long endTime
= event
.getEndTime();
326 TmfTimeRange range
= new TmfTimeRange(new CtfTmfTimestamp(startTime
), new CtfTmfTimestamp(endTime
));
327 TmfTimestamp time
= new CtfTmfTimestamp(fTimeGraphViewer
.getSelectedTime());
328 broadcast(new TmfRangeSynchSignal(ResourcesView
.this, range
, time
));
329 startZoomThread(startTime
, endTime
);
333 fTimeGraphViewer
.addTimeListener(new ITimeGraphTimeListener() {
335 public void timeSelected(TimeGraphTimeEvent event
) {
336 long time
= event
.getTime();
337 broadcast(new TmfTimeSynchSignal(ResourcesView
.this, new CtfTmfTimestamp(time
)));
341 // View Action Handling
343 contributeToActionBars();
345 ITmfTrace trace
= getActiveTrace();
347 traceSelected(new TmfTraceSelectedSignal(this, trace
));
352 public void setFocus() {
353 fTimeGraphViewer
.setFocus();
356 // ------------------------------------------------------------------------
358 // ------------------------------------------------------------------------
361 * Handler for the trace opened signal.
362 * @param signal the trace selected signal
366 public void traceOpened(TmfTraceOpenedSignal signal
) {
367 fTrace
= signal
.getTrace();
372 * Handler for the trace selected signal
375 * The incoming signal
378 public void traceSelected(final TmfTraceSelectedSignal signal
) {
379 if (signal
.getTrace() == fTrace
) {
382 fTrace
= signal
.getTrace();
387 * Trace is disposed: clear the data structures and the view
389 * @param signal the signal received
392 public void traceClosed(final TmfTraceClosedSignal signal
) {
393 synchronized (fBuildThreadMap
) {
394 BuildThread buildThread
= fBuildThreadMap
.remove(signal
.getTrace());
395 if (buildThread
!= null) {
396 buildThread
.cancel();
399 synchronized (fEntryListMap
) {
400 fEntryListMap
.remove(signal
.getTrace());
402 if (signal
.getTrace() == fTrace
) {
406 if (fZoomThread
!= null) {
407 fZoomThread
.cancel();
414 * Handler for the TimeSynch signal
417 * The incoming signal
420 public void synchToTime(final TmfTimeSynchSignal signal
) {
421 if (signal
.getSource() == this || fTrace
== null) {
424 final long time
= signal
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
425 Display
.getDefault().asyncExec(new Runnable() {
428 if (fTimeGraphViewer
.getControl().isDisposed()) {
431 fTimeGraphViewer
.setSelectedTime(time
, true);
432 startZoomThread(fTimeGraphViewer
.getTime0(), fTimeGraphViewer
.getTime1());
438 * Handler for the RangeSynch signal
441 * The incoming signal
444 public void synchToRange(final TmfRangeSynchSignal signal
) {
445 if (signal
.getSource() == this || fTrace
== null) {
448 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
451 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
452 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
453 final long time
= signal
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
454 Display
.getDefault().asyncExec(new Runnable() {
457 if (fTimeGraphViewer
.getControl().isDisposed()) {
460 fTimeGraphViewer
.setStartFinishTime(startTime
, endTime
);
461 fTimeGraphViewer
.setSelectedTime(time
, false);
462 startZoomThread(startTime
, endTime
);
467 // ------------------------------------------------------------------------
469 // ------------------------------------------------------------------------
471 private void loadTrace() {
472 synchronized (fEntryListMap
) {
473 fEntryList
= fEntryListMap
.get(fTrace
);
474 if (fEntryList
== null) {
475 synchronized (fBuildThreadMap
) {
476 BuildThread buildThread
= new BuildThread(fTrace
);
477 fBuildThreadMap
.put(fTrace
, buildThread
);
481 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
482 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
488 private void buildEventList(final ITmfTrace trace
, IProgressMonitor monitor
) {
489 fStartTime
= Long
.MAX_VALUE
;
490 fEndTime
= Long
.MIN_VALUE
;
491 ArrayList
<TraceEntry
> entryList
= new ArrayList
<TraceEntry
>();
492 for (ITmfTrace aTrace
: TmfTraceManager
.getTraceSet(trace
)) {
493 if (monitor
.isCanceled()) {
496 if (aTrace
instanceof LttngKernelTrace
) {
497 LttngKernelTrace ctfKernelTrace
= (LttngKernelTrace
) aTrace
;
498 ITmfStateSystem ssq
= ctfKernelTrace
.getStateSystems().get(LttngKernelTrace
.STATE_ID
);
499 if (!ssq
.waitUntilBuilt()) {
502 long startTime
= ssq
.getStartTime();
503 long endTime
= ssq
.getCurrentEndTime() + 1;
504 TraceEntry groupEntry
= new TraceEntry(ctfKernelTrace
, aTrace
.getName(), startTime
, endTime
);
505 entryList
.add(groupEntry
);
506 fStartTime
= Math
.min(fStartTime
, startTime
);
507 fEndTime
= Math
.max(fEndTime
, endTime
);
508 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
509 ResourcesEntry
[] cpuEntries
= new ResourcesEntry
[cpuQuarks
.size()];
510 for (int i
= 0; i
< cpuQuarks
.size(); i
++) {
511 int cpuQuark
= cpuQuarks
.get(i
);
512 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
513 ResourcesEntry entry
= new ResourcesEntry(cpuQuark
, ctfKernelTrace
, Type
.CPU
, cpu
);
514 groupEntry
.addChild(entry
);
515 cpuEntries
[i
] = entry
;
517 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
518 ResourcesEntry
[] irqEntries
= new ResourcesEntry
[irqQuarks
.size()];
519 for (int i
= 0; i
< irqQuarks
.size(); i
++) {
520 int irqQuark
= irqQuarks
.get(i
);
521 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
522 ResourcesEntry entry
= new ResourcesEntry(irqQuark
, ctfKernelTrace
, Type
.IRQ
, irq
);
523 groupEntry
.addChild(entry
);
524 irqEntries
[i
] = entry
;
526 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
527 ResourcesEntry
[] softIrqEntries
= new ResourcesEntry
[softIrqQuarks
.size()];
528 for (int i
= 0; i
< softIrqQuarks
.size(); i
++) {
529 int softIrqQuark
= softIrqQuarks
.get(i
);
530 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
531 ResourcesEntry entry
= new ResourcesEntry(softIrqQuark
, ctfKernelTrace
, Type
.SOFT_IRQ
, softIrq
);
532 groupEntry
.addChild(entry
);
533 softIrqEntries
[i
] = entry
;
537 synchronized (fEntryListMap
) {
538 fEntryListMap
.put(trace
, (ArrayList
<TraceEntry
>) entryList
.clone());
540 if (trace
== fTrace
) {
543 for (TraceEntry traceEntry
: entryList
) {
544 if (monitor
.isCanceled()) {
547 LttngKernelTrace ctfKernelTrace
= traceEntry
.getTrace();
548 ITmfStateSystem ssq
= ctfKernelTrace
.getStateSystems().get(LttngKernelTrace
.STATE_ID
);
549 long startTime
= ssq
.getStartTime();
550 long endTime
= ssq
.getCurrentEndTime() + 1;
551 long resolution
= (endTime
- startTime
) / fDisplayWidth
;
552 for (ResourcesEntry entry
: traceEntry
.getChildren()) {
553 List
<ITimeEvent
> eventList
= getEventList(entry
, startTime
, endTime
, resolution
, false, monitor
);
554 entry
.setEventList(eventList
);
560 private static List
<ITimeEvent
> getEventList(ResourcesEntry entry
,
561 long startTime
, long endTime
, long resolution
, boolean includeNull
,
562 IProgressMonitor monitor
) {
563 ITmfStateSystem ssq
= entry
.getTrace().getStateSystems().get(LttngKernelTrace
.STATE_ID
);
564 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
565 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
566 if (realEnd
<= realStart
) {
569 List
<ITimeEvent
> eventList
= null;
570 int quark
= entry
.getQuark();
572 if (entry
.getType().equals(Type
.CPU
)) {
573 int statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
574 List
<ITmfStateInterval
> statusIntervals
= ssq
.queryHistoryRange(statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
575 eventList
= new ArrayList
<ITimeEvent
>(statusIntervals
.size());
576 long lastEndTime
= -1;
577 for (ITmfStateInterval statusInterval
: statusIntervals
) {
578 if (monitor
.isCanceled()) {
581 int status
= statusInterval
.getStateValue().unboxInt();
582 long time
= statusInterval
.getStartTime();
583 long duration
= statusInterval
.getEndTime() - time
+ 1;
584 if (!statusInterval
.getStateValue().isNull()) {
585 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
586 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
588 eventList
.add(new ResourcesEvent(entry
, time
, duration
, status
));
589 lastEndTime
= time
+ duration
;
592 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
596 } else if (entry
.getType().equals(Type
.IRQ
)) {
597 List
<ITmfStateInterval
> irqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
598 eventList
= new ArrayList
<ITimeEvent
>(irqIntervals
.size());
599 long lastEndTime
= -1;
600 boolean lastIsNull
= true;
601 for (ITmfStateInterval irqInterval
: irqIntervals
) {
602 if (monitor
.isCanceled()) {
605 long time
= irqInterval
.getStartTime();
606 long duration
= irqInterval
.getEndTime() - time
+ 1;
607 if (!irqInterval
.getStateValue().isNull()) {
608 int cpu
= irqInterval
.getStateValue().unboxInt();
609 eventList
.add(new ResourcesEvent(entry
, time
, duration
, cpu
));
612 if (lastEndTime
!= time
&& lastEndTime
!= -1 && lastIsNull
) {
613 eventList
.add(new ResourcesEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
616 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
620 lastEndTime
= time
+ duration
;
622 } else if (entry
.getType().equals(Type
.SOFT_IRQ
)) {
623 List
<ITmfStateInterval
> softIrqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
624 eventList
= new ArrayList
<ITimeEvent
>(softIrqIntervals
.size());
625 long lastEndTime
= -1;
626 boolean lastIsNull
= true;
627 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
628 if (monitor
.isCanceled()) {
631 long time
= softIrqInterval
.getStartTime();
632 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
633 if (!softIrqInterval
.getStateValue().isNull()) {
634 int cpu
= softIrqInterval
.getStateValue().unboxInt();
635 eventList
.add(new ResourcesEvent(entry
, time
, duration
, cpu
));
637 if (lastEndTime
!= time
&& lastEndTime
!= -1 && lastIsNull
) {
638 eventList
.add(new ResourcesEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
641 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
645 lastEndTime
= time
+ duration
;
648 } catch (AttributeNotFoundException e
) {
650 } catch (TimeRangeException e
) {
652 } catch (StateValueTypeException e
) {
654 } catch (StateSystemDisposedException e
) {
660 private void refresh() {
661 Display
.getDefault().asyncExec(new Runnable() {
664 if (fTimeGraphViewer
.getControl().isDisposed()) {
667 ITimeGraphEntry
[] entries
= null;
668 synchronized (fEntryListMap
) {
669 fEntryList
= fEntryListMap
.get(fTrace
);
670 if (fEntryList
== null) {
671 fEntryList
= new ArrayList
<TraceEntry
>();
673 entries
= fEntryList
.toArray(new ITimeGraphEntry
[0]);
675 if (entries
!= null) {
676 Arrays
.sort(entries
, new TraceEntryComparator());
677 fTimeGraphViewer
.setInput(entries
);
678 fTimeGraphViewer
.setTimeBounds(fStartTime
, fEndTime
);
680 long timestamp
= fTrace
== null ?
0 : fTraceManager
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
681 long startTime
= fTrace
== null ?
0 : fTraceManager
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
682 long endTime
= fTrace
== null ?
0 : fTraceManager
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
683 startTime
= Math
.max(startTime
, fStartTime
);
684 endTime
= Math
.min(endTime
, fEndTime
);
685 fTimeGraphViewer
.setSelectedTime(timestamp
, false);
686 fTimeGraphViewer
.setStartFinishTime(startTime
, endTime
);
688 startZoomThread(startTime
, endTime
);
694 private void redraw() {
695 synchronized (fSyncObj
) {
696 if (fRedrawState
== State
.IDLE
) {
697 fRedrawState
= State
.BUSY
;
699 fRedrawState
= State
.PENDING
;
703 Display
.getDefault().asyncExec(new Runnable() {
706 if (fTimeGraphViewer
.getControl().isDisposed()) {
709 fTimeGraphViewer
.getControl().redraw();
710 fTimeGraphViewer
.getControl().update();
711 synchronized (fSyncObj
) {
712 if (fRedrawState
== State
.PENDING
) {
713 fRedrawState
= State
.IDLE
;
716 fRedrawState
= State
.IDLE
;
723 private void startZoomThread(long startTime
, long endTime
) {
724 if (fZoomThread
!= null) {
725 fZoomThread
.cancel();
727 fZoomThread
= new ZoomThread(fEntryList
, startTime
, endTime
);
731 private void makeActions() {
732 fPreviousResourceAction
= fTimeGraphViewer
.getPreviousItemAction();
733 fPreviousResourceAction
.setText(Messages
.ResourcesView_previousResourceActionNameText
);
734 fPreviousResourceAction
.setToolTipText(Messages
.ResourcesView_previousResourceActionToolTipText
);
735 fNextResourceAction
= fTimeGraphViewer
.getNextItemAction();
736 fNextResourceAction
.setText(Messages
.ResourcesView_nextResourceActionNameText
);
737 fNextResourceAction
.setToolTipText(Messages
.ResourcesView_previousResourceActionToolTipText
);
740 private void contributeToActionBars() {
741 IActionBars bars
= getViewSite().getActionBars();
742 fillLocalToolBar(bars
.getToolBarManager());
745 private void fillLocalToolBar(IToolBarManager manager
) {
746 manager
.add(fTimeGraphViewer
.getShowLegendAction());
747 manager
.add(new Separator());
748 manager
.add(fTimeGraphViewer
.getResetScaleAction());
749 manager
.add(fTimeGraphViewer
.getPreviousEventAction());
750 manager
.add(fTimeGraphViewer
.getNextEventAction());
751 manager
.add(fPreviousResourceAction
);
752 manager
.add(fNextResourceAction
);
753 manager
.add(fTimeGraphViewer
.getZoomInAction());
754 manager
.add(fTimeGraphViewer
.getZoomOutAction());
755 manager
.add(new Separator());