1 /*******************************************************************************
2 * Copyright (c) 2012 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
.event
.ITmfTimestamp
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateSystemDisposedException
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfRangeSynchSignal
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
44 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
45 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
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
.editors
.ITmfTraceEditor
;
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
;
63 import org
.eclipse
.ui
.IEditorPart
;
66 * Main implementation for the LTTng 2.0 kernel Resource view
68 * @author Patrick Tasse
70 public class ResourcesView
extends TmfView
{
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 public static final String ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.views.resources"; //$NON-NLS-1$
82 private enum State
{ IDLE
, BUSY
, PENDING
}
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
88 // The time graph viewer
89 TimeGraphViewer fTimeGraphViewer
;
92 private ITmfTrace fTrace
;
94 // The time graph entry list
95 private ArrayList
<TraceEntry
> fEntryList
;
97 // The trace to entry list hash map
98 final private HashMap
<ITmfTrace
, ArrayList
<TraceEntry
>> fEntryListMap
= new HashMap
<ITmfTrace
, ArrayList
<TraceEntry
>>();
100 // The trace to build thread hash map
101 final private HashMap
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<ITmfTrace
, BuildThread
>();
104 private long fStartTime
;
107 private long fEndTime
;
110 private final int fDisplayWidth
;
112 // The next resource action
113 private Action fNextResourceAction
;
115 // The previous resource action
116 private Action fPreviousResourceAction
;
119 private ZoomThread fZoomThread
;
121 // The redraw state used to prevent unnecessary queuing of display runnables
122 private State fRedrawState
= State
.IDLE
;
124 // The redraw synchronization object
125 final private Object fSyncObj
= new Object();
127 // ------------------------------------------------------------------------
129 // ------------------------------------------------------------------------
131 private class TraceEntry
implements ITimeGraphEntry
{
133 private final CtfKernelTrace fKernelTrace
;
135 private final long fTraceStartTime
;
137 private final long fTraceEndTime
;
138 // The children of the entry
139 private final ArrayList
<ResourcesEntry
> fChildren
;
141 private final String fName
;
143 public TraceEntry(CtfKernelTrace trace
, String name
, long startTime
, long endTime
) {
144 fKernelTrace
= trace
;
145 fChildren
= new ArrayList
<ResourcesEntry
>();
147 fTraceStartTime
= startTime
;
148 fTraceEndTime
= endTime
;
152 public ITimeGraphEntry
getParent() {
157 public boolean hasChildren() {
158 return fChildren
!= null && fChildren
.size() > 0;
162 public List
<ResourcesEntry
> getChildren() {
167 public String
getName() {
172 public long getStartTime() {
173 return fTraceStartTime
;
177 public long getEndTime() {
178 return fTraceEndTime
;
182 public boolean hasTimeEvents() {
187 public Iterator
<ITimeEvent
> getTimeEventsIterator() {
192 public <T
extends ITimeEvent
> Iterator
<T
> getTimeEventsIterator(long startTime
, long stopTime
, long visibleDuration
) {
196 public CtfKernelTrace
getTrace() {
200 public void addChild(ResourcesEntry entry
) {
202 for (index
= 0; index
< fChildren
.size(); index
++) {
203 ResourcesEntry other
= fChildren
.get(index
);
204 if (entry
.getType().compareTo(other
.getType()) < 0) {
206 } else if (entry
.getType().equals(other
.getType())) {
207 if (entry
.getId() < other
.getId()) {
212 entry
.setParent(this);
213 fChildren
.add(index
, entry
);
217 private static class TraceEntryComparator
implements Comparator
<ITimeGraphEntry
> {
219 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
220 int result
= o1
.getStartTime() < o2
.getStartTime() ?
-1 : o1
.getStartTime() > o2
.getStartTime() ?
1 : 0;
222 result
= o1
.getName().compareTo(o2
.getName());
228 private class BuildThread
extends Thread
{
229 private final ITmfTrace fBuildTrace
;
230 private final IProgressMonitor fMonitor
;
232 public BuildThread(ITmfTrace trace
) {
233 super("ResourcesView build"); //$NON-NLS-1$
235 fMonitor
= new NullProgressMonitor();
240 buildEventList(fBuildTrace
, fMonitor
);
241 synchronized (fBuildThreadMap
) {
242 fBuildThreadMap
.remove(this);
246 public void cancel() {
247 fMonitor
.setCanceled(true);
251 private class ZoomThread
extends Thread
{
252 private final ArrayList
<TraceEntry
> fZoomEntryList
;
253 private final long fZoomStartTime
;
254 private final long fZoomEndTime
;
255 private final IProgressMonitor fMonitor
;
257 public ZoomThread(ArrayList
<TraceEntry
> entryList
, long startTime
, long endTime
) {
258 super("ResourcesView zoom"); //$NON-NLS-1$
259 fZoomEntryList
= entryList
;
260 fZoomStartTime
= startTime
;
261 fZoomEndTime
= endTime
;
262 fMonitor
= new NullProgressMonitor();
267 if (fZoomEntryList
== null) {
270 long resolution
= Math
.max(1, (fZoomEndTime
- fZoomStartTime
) / fDisplayWidth
);
271 for (TraceEntry traceEntry
: fZoomEntryList
) {
272 if (!traceEntry
.fKernelTrace
.getStateSystem(CtfKernelTrace
.STATE_ID
).waitUntilBuilt()) {
275 for (ITimeGraphEntry child
: traceEntry
.getChildren()) {
276 if (fMonitor
.isCanceled()) {
279 ResourcesEntry entry
= (ResourcesEntry
) child
;
280 if (fZoomStartTime
<= fStartTime
&& fZoomEndTime
>= fEndTime
) {
281 entry
.setZoomedEventList(null);
283 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, fZoomStartTime
, fZoomEndTime
, resolution
, true, fMonitor
);
284 if (zoomedEventList
!= null) {
285 entry
.setZoomedEventList(zoomedEventList
);
293 public void cancel() {
294 fMonitor
.setCanceled(true);
298 // ------------------------------------------------------------------------
300 // ------------------------------------------------------------------------
303 * Default constructor
305 public ResourcesView() {
307 fDisplayWidth
= Display
.getDefault().getBounds().width
;
310 // ------------------------------------------------------------------------
312 // ------------------------------------------------------------------------
315 * @see org.eclipse.linuxtools.tmf.ui.views.TmfView#createPartControl(org.eclipse.swt.widgets.Composite)
318 public void createPartControl(Composite parent
) {
319 fTimeGraphViewer
= new TimeGraphViewer(parent
, SWT
.NONE
);
321 fTimeGraphViewer
.setTimeGraphProvider(new ResourcesPresentationProvider(fTimeGraphViewer
));
323 fTimeGraphViewer
.setTimeFormat(TimeFormat
.CALENDAR
);
325 fTimeGraphViewer
.addRangeListener(new ITimeGraphRangeListener() {
327 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
328 long startTime
= event
.getStartTime();
329 long endTime
= event
.getEndTime();
330 TmfTimeRange range
= new TmfTimeRange(new CtfTmfTimestamp(startTime
), new CtfTmfTimestamp(endTime
));
331 TmfTimestamp time
= new CtfTmfTimestamp(fTimeGraphViewer
.getSelectedTime());
332 broadcast(new TmfRangeSynchSignal(ResourcesView
.this, range
, time
));
333 startZoomThread(startTime
, endTime
);
337 fTimeGraphViewer
.addTimeListener(new ITimeGraphTimeListener() {
339 public void timeSelected(TimeGraphTimeEvent event
) {
340 long time
= event
.getTime();
341 broadcast(new TmfTimeSynchSignal(ResourcesView
.this, new CtfTmfTimestamp(time
)));
345 // View Action Handling
347 contributeToActionBars();
349 IEditorPart editor
= getSite().getPage().getActiveEditor();
350 if (editor
instanceof ITmfTraceEditor
) {
351 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
353 traceSelected(new TmfTraceSelectedSignal(this, trace
));
359 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
362 public void setFocus() {
363 fTimeGraphViewer
.setFocus();
366 // ------------------------------------------------------------------------
368 // ------------------------------------------------------------------------
371 * Handler for the trace selected signal
374 * The incoming signal
377 public void traceSelected(final TmfTraceSelectedSignal signal
) {
378 if (signal
.getTrace() == fTrace
) {
381 fTrace
= signal
.getTrace();
383 synchronized (fEntryListMap
) {
384 fEntryList
= fEntryListMap
.get(fTrace
);
385 if (fEntryList
== null) {
386 synchronized (fBuildThreadMap
) {
387 BuildThread buildThread
= new BuildThread(fTrace
);
388 fBuildThreadMap
.put(fTrace
, buildThread
);
392 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
393 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
400 * Trace is disposed: clear the data structures and the view
402 * @param signal the signal received
405 public void traceClosed(final TmfTraceClosedSignal signal
) {
406 synchronized (fBuildThreadMap
) {
407 BuildThread buildThread
= fBuildThreadMap
.remove(signal
.getTrace());
408 if (buildThread
!= null) {
409 buildThread
.cancel();
412 synchronized (fEntryListMap
) {
413 fEntryListMap
.remove(signal
.getTrace());
415 if (signal
.getTrace() == fTrace
) {
419 if (fZoomThread
!= null) {
420 fZoomThread
.cancel();
427 * Handler for the TimeSynch signal
430 * The incoming signal
433 public void synchToTime(final TmfTimeSynchSignal signal
) {
434 if (signal
.getSource() == this || fTrace
== null) {
437 final long time
= signal
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
438 Display
.getDefault().asyncExec(new Runnable() {
441 if (fTimeGraphViewer
.getControl().isDisposed()) {
444 fTimeGraphViewer
.setSelectedTime(time
, true);
445 startZoomThread(fTimeGraphViewer
.getTime0(), fTimeGraphViewer
.getTime1());
451 * Handler for the RangeSynch signal
454 * The incoming signal
457 public void synchToRange(final TmfRangeSynchSignal signal
) {
458 if (signal
.getSource() == this || fTrace
== null) {
461 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
464 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
465 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
466 final long time
= signal
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
467 Display
.getDefault().asyncExec(new Runnable() {
470 if (fTimeGraphViewer
.getControl().isDisposed()) {
473 fTimeGraphViewer
.setStartFinishTime(startTime
, endTime
);
474 fTimeGraphViewer
.setSelectedTime(time
, false);
475 startZoomThread(startTime
, endTime
);
480 // ------------------------------------------------------------------------
482 // ------------------------------------------------------------------------
484 private void buildEventList(final ITmfTrace trace
, IProgressMonitor monitor
) {
485 fStartTime
= Long
.MAX_VALUE
;
486 fEndTime
= Long
.MIN_VALUE
;
488 if (trace
instanceof TmfExperiment
) {
489 TmfExperiment experiment
= (TmfExperiment
) trace
;
490 traces
= experiment
.getTraces();
492 traces
= new ITmfTrace
[] { trace
};
494 ArrayList
<TraceEntry
> entryList
= new ArrayList
<TraceEntry
>();
495 for (ITmfTrace aTrace
: traces
) {
496 if (monitor
.isCanceled()) {
499 if (aTrace
instanceof CtfKernelTrace
) {
500 CtfKernelTrace ctfKernelTrace
= (CtfKernelTrace
) aTrace
;
501 ITmfStateSystem ssq
= ctfKernelTrace
.getStateSystem(CtfKernelTrace
.STATE_ID
);
502 if (!ssq
.waitUntilBuilt()) {
505 long startTime
= ssq
.getStartTime();
506 long endTime
= ssq
.getCurrentEndTime() + 1;
507 TraceEntry groupEntry
= new TraceEntry(ctfKernelTrace
, aTrace
.getName(), startTime
, endTime
);
508 entryList
.add(groupEntry
);
509 fStartTime
= Math
.min(fStartTime
, startTime
);
510 fEndTime
= Math
.max(fEndTime
, endTime
);
511 List
<Integer
> cpuQuarks
= ssq
.getQuarks(Attributes
.CPUS
, "*"); //$NON-NLS-1$
512 ResourcesEntry
[] cpuEntries
= new ResourcesEntry
[cpuQuarks
.size()];
513 for (int i
= 0; i
< cpuQuarks
.size(); i
++) {
514 int cpuQuark
= cpuQuarks
.get(i
);
515 int cpu
= Integer
.parseInt(ssq
.getAttributeName(cpuQuark
));
516 ResourcesEntry entry
= new ResourcesEntry(cpuQuark
, ctfKernelTrace
, Type
.CPU
, cpu
);
517 groupEntry
.addChild(entry
);
518 cpuEntries
[i
] = entry
;
520 List
<Integer
> irqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
521 ResourcesEntry
[] irqEntries
= new ResourcesEntry
[irqQuarks
.size()];
522 for (int i
= 0; i
< irqQuarks
.size(); i
++) {
523 int irqQuark
= irqQuarks
.get(i
);
524 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
525 ResourcesEntry entry
= new ResourcesEntry(irqQuark
, ctfKernelTrace
, Type
.IRQ
, irq
);
526 groupEntry
.addChild(entry
);
527 irqEntries
[i
] = entry
;
529 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
530 ResourcesEntry
[] softIrqEntries
= new ResourcesEntry
[softIrqQuarks
.size()];
531 for (int i
= 0; i
< softIrqQuarks
.size(); i
++) {
532 int softIrqQuark
= softIrqQuarks
.get(i
);
533 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
534 ResourcesEntry entry
= new ResourcesEntry(softIrqQuark
, ctfKernelTrace
, Type
.SOFT_IRQ
, softIrq
);
535 groupEntry
.addChild(entry
);
536 softIrqEntries
[i
] = entry
;
540 synchronized (fEntryListMap
) {
541 fEntryListMap
.put(trace
, (ArrayList
<TraceEntry
>) entryList
.clone());
543 if (trace
== fTrace
) {
546 for (TraceEntry traceEntry
: entryList
) {
547 if (monitor
.isCanceled()) {
550 CtfKernelTrace ctfKernelTrace
= traceEntry
.getTrace();
551 ITmfStateSystem ssq
= ctfKernelTrace
.getStateSystem(CtfKernelTrace
.STATE_ID
);
552 long startTime
= ssq
.getStartTime();
553 long endTime
= ssq
.getCurrentEndTime() + 1;
554 long resolution
= (endTime
- startTime
) / fDisplayWidth
;
555 for (ResourcesEntry entry
: traceEntry
.getChildren()) {
556 List
<ITimeEvent
> eventList
= getEventList(entry
, startTime
, endTime
, resolution
, false, monitor
);
557 entry
.setEventList(eventList
);
563 private static List
<ITimeEvent
> getEventList(ResourcesEntry entry
,
564 long startTime
, long endTime
, long resolution
, boolean includeNull
,
565 IProgressMonitor monitor
) {
566 ITmfStateSystem ssq
= entry
.getTrace().getStateSystem(CtfKernelTrace
.STATE_ID
);
567 final long realStart
= Math
.max(startTime
, ssq
.getStartTime());
568 final long realEnd
= Math
.min(endTime
, ssq
.getCurrentEndTime() + 1);
569 if (realEnd
<= realStart
) {
572 List
<ITimeEvent
> eventList
= null;
573 int quark
= entry
.getQuark();
575 if (entry
.getType().equals(Type
.CPU
)) {
576 int statusQuark
= ssq
.getQuarkRelative(quark
, Attributes
.STATUS
);
577 List
<ITmfStateInterval
> statusIntervals
= ssq
.queryHistoryRange(statusQuark
, realStart
, realEnd
- 1, resolution
, monitor
);
578 eventList
= new ArrayList
<ITimeEvent
>(statusIntervals
.size());
579 long lastEndTime
= -1;
580 for (ITmfStateInterval statusInterval
: statusIntervals
) {
581 if (monitor
.isCanceled()) {
584 int status
= statusInterval
.getStateValue().unboxInt();
585 long time
= statusInterval
.getStartTime();
586 long duration
= statusInterval
.getEndTime() - time
+ 1;
587 if (!statusInterval
.getStateValue().isNull()) {
588 if (lastEndTime
!= time
&& lastEndTime
!= -1) {
589 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
591 eventList
.add(new ResourcesEvent(entry
, time
, duration
, status
));
592 lastEndTime
= time
+ duration
;
595 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
599 } else if (entry
.getType().equals(Type
.IRQ
)) {
600 List
<ITmfStateInterval
> irqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
601 eventList
= new ArrayList
<ITimeEvent
>(irqIntervals
.size());
602 long lastEndTime
= -1;
603 boolean lastIsNull
= true;
604 for (ITmfStateInterval irqInterval
: irqIntervals
) {
605 if (monitor
.isCanceled()) {
608 long time
= irqInterval
.getStartTime();
609 long duration
= irqInterval
.getEndTime() - time
+ 1;
610 if (!irqInterval
.getStateValue().isNull()) {
611 int cpu
= irqInterval
.getStateValue().unboxInt();
612 eventList
.add(new ResourcesEvent(entry
, time
, duration
, cpu
));
615 if (lastEndTime
!= time
&& lastEndTime
!= -1 && lastIsNull
) {
616 eventList
.add(new ResourcesEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
619 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
623 lastEndTime
= time
+ duration
;
625 } else if (entry
.getType().equals(Type
.SOFT_IRQ
)) {
626 List
<ITmfStateInterval
> softIrqIntervals
= ssq
.queryHistoryRange(quark
, realStart
, realEnd
- 1, resolution
, monitor
);
627 eventList
= new ArrayList
<ITimeEvent
>(softIrqIntervals
.size());
628 long lastEndTime
= -1;
629 boolean lastIsNull
= true;
630 for (ITmfStateInterval softIrqInterval
: softIrqIntervals
) {
631 if (monitor
.isCanceled()) {
634 long time
= softIrqInterval
.getStartTime();
635 long duration
= softIrqInterval
.getEndTime() - time
+ 1;
636 if (!softIrqInterval
.getStateValue().isNull()) {
637 int cpu
= softIrqInterval
.getStateValue().unboxInt();
638 eventList
.add(new ResourcesEvent(entry
, time
, duration
, cpu
));
640 if (lastEndTime
!= time
&& lastEndTime
!= -1 && lastIsNull
) {
641 eventList
.add(new ResourcesEvent(entry
, lastEndTime
, time
- lastEndTime
, -1));
644 eventList
.add(new ResourcesEvent(entry
, time
, duration
));
648 lastEndTime
= time
+ duration
;
651 } catch (AttributeNotFoundException e
) {
653 } catch (TimeRangeException e
) {
655 } catch (StateValueTypeException e
) {
657 } catch (StateSystemDisposedException e
) {
663 private void refresh() {
664 Display
.getDefault().asyncExec(new Runnable() {
667 if (fTimeGraphViewer
.getControl().isDisposed()) {
670 ITimeGraphEntry
[] entries
= null;
671 synchronized (fEntryListMap
) {
672 fEntryList
= fEntryListMap
.get(fTrace
);
673 if (fEntryList
== null) {
674 fEntryList
= new ArrayList
<TraceEntry
>();
676 entries
= fEntryList
.toArray(new ITimeGraphEntry
[0]);
678 if (entries
!= null) {
679 Arrays
.sort(entries
, new TraceEntryComparator());
680 fTimeGraphViewer
.setInput(entries
);
681 fTimeGraphViewer
.setTimeBounds(fStartTime
, fEndTime
);
683 long timestamp
= fTrace
== null ?
0 : fTrace
.getCurrentTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
684 long startTime
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
685 long endTime
= fTrace
== null ?
0 : fTrace
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
686 startTime
= Math
.max(startTime
, fStartTime
);
687 endTime
= Math
.min(endTime
, fEndTime
);
688 fTimeGraphViewer
.setSelectedTime(timestamp
, false);
689 fTimeGraphViewer
.setStartFinishTime(startTime
, endTime
);
691 startZoomThread(startTime
, endTime
);
697 private void redraw() {
698 synchronized (fSyncObj
) {
699 if (fRedrawState
== State
.IDLE
) {
700 fRedrawState
= State
.BUSY
;
702 fRedrawState
= State
.PENDING
;
706 Display
.getDefault().asyncExec(new Runnable() {
709 if (fTimeGraphViewer
.getControl().isDisposed()) {
712 fTimeGraphViewer
.getControl().redraw();
713 fTimeGraphViewer
.getControl().update();
714 synchronized (fSyncObj
) {
715 if (fRedrawState
== State
.PENDING
) {
716 fRedrawState
= State
.IDLE
;
719 fRedrawState
= State
.IDLE
;
726 private void startZoomThread(long startTime
, long endTime
) {
727 if (fZoomThread
!= null) {
728 fZoomThread
.cancel();
730 fZoomThread
= new ZoomThread(fEntryList
, startTime
, endTime
);
734 private void makeActions() {
735 fPreviousResourceAction
= fTimeGraphViewer
.getPreviousItemAction();
736 fPreviousResourceAction
.setText(Messages
.ResourcesView_previousResourceActionNameText
);
737 fPreviousResourceAction
.setToolTipText(Messages
.ResourcesView_previousResourceActionToolTipText
);
738 fNextResourceAction
= fTimeGraphViewer
.getNextItemAction();
739 fNextResourceAction
.setText(Messages
.ResourcesView_nextResourceActionNameText
);
740 fNextResourceAction
.setToolTipText(Messages
.ResourcesView_previousResourceActionToolTipText
);
743 private void contributeToActionBars() {
744 IActionBars bars
= getViewSite().getActionBars();
745 fillLocalToolBar(bars
.getToolBarManager());
748 private void fillLocalToolBar(IToolBarManager manager
) {
749 manager
.add(fTimeGraphViewer
.getShowLegendAction());
750 manager
.add(new Separator());
751 manager
.add(fTimeGraphViewer
.getResetScaleAction());
752 manager
.add(fTimeGraphViewer
.getPreviousEventAction());
753 manager
.add(fTimeGraphViewer
.getNextEventAction());
754 manager
.add(fPreviousResourceAction
);
755 manager
.add(fNextResourceAction
);
756 manager
.add(fTimeGraphViewer
.getZoomInAction());
757 manager
.add(fTimeGraphViewer
.getZoomOutAction());
758 manager
.add(new Separator());