1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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 * Bernd Hufmann - Updated signal handling
12 * Marc-Andre Laperle - Map from binary file
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.callstack
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Collections
;
20 import java
.util
.Comparator
;
21 import java
.util
.HashMap
;
22 import java
.util
.Iterator
;
23 import java
.util
.List
;
25 import java
.util
.concurrent
.CopyOnWriteArrayList
;
27 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
28 import org
.eclipse
.core
.runtime
.IStatus
;
29 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
30 import org
.eclipse
.core
.runtime
.Status
;
31 import org
.eclipse
.core
.runtime
.jobs
.Job
;
32 import org
.eclipse
.jdt
.annotation
.Nullable
;
33 import org
.eclipse
.jface
.action
.Action
;
34 import org
.eclipse
.jface
.action
.IAction
;
35 import org
.eclipse
.jface
.action
.IStatusLineManager
;
36 import org
.eclipse
.jface
.action
.IToolBarManager
;
37 import org
.eclipse
.jface
.action
.MenuManager
;
38 import org
.eclipse
.jface
.action
.Separator
;
39 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
40 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
41 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
42 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
43 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
44 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
45 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
46 import org
.eclipse
.jface
.viewers
.ISelection
;
47 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
48 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
49 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
50 import org
.eclipse
.jface
.viewers
.Viewer
;
51 import org
.eclipse
.swt
.SWT
;
52 import org
.eclipse
.swt
.events
.ControlAdapter
;
53 import org
.eclipse
.swt
.events
.ControlEvent
;
54 import org
.eclipse
.swt
.events
.MouseAdapter
;
55 import org
.eclipse
.swt
.events
.MouseEvent
;
56 import org
.eclipse
.swt
.graphics
.Image
;
57 import org
.eclipse
.swt
.widgets
.Composite
;
58 import org
.eclipse
.swt
.widgets
.Display
;
59 import org
.eclipse
.swt
.widgets
.FileDialog
;
60 import org
.eclipse
.swt
.widgets
.Menu
;
61 import org
.eclipse
.swt
.widgets
.Tree
;
62 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
63 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.ITmfImageConstants
;
64 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
65 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
66 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
67 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
68 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
69 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
70 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
71 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
72 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
.Type
;
73 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfRangeSynchSignal
;
74 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
75 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
76 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
77 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
78 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
79 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
80 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
81 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
82 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
83 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestampDelta
;
84 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
85 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
86 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.ITmfTraceEditor
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
88 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphContentProvider
;
89 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphRangeListener
;
90 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
91 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphCombo
;
92 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphRangeUpdateEvent
;
93 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
94 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
95 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
96 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
97 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
98 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
99 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
100 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
101 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphSelection
;
102 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
103 import org
.eclipse
.ui
.IActionBars
;
104 import org
.eclipse
.ui
.IEditorPart
;
107 * Main implementation for the Call Stack view
109 * @author Patrick Tasse
112 public class CallStackView
extends TmfView
{
114 // ------------------------------------------------------------------------
116 // ------------------------------------------------------------------------
119 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.callstack"; //$NON-NLS-1$
128 private static final String
[] COLUMN_TIMES
= new String
[] {
129 Messages
.CallStackView_FunctionColumn
,
130 Messages
.CallStackView_DepthColumn
,
131 Messages
.CallStackView_EntryTimeColumn
,
132 Messages
.CallStackView_ExitTimeColumn
,
133 Messages
.CallStackView_DurationColumn
136 private static final int[] COLUMN_WIDTHS
= new int[] {
144 /** Timeout between updates in the build thread in ms */
145 private static final long BUILD_UPDATE_TIMEOUT
= 500;
147 // Fraction of a function duration to be added as spacing
148 private static final double SPACING_RATIO
= 0.01;
150 private static final Image THREAD_IMAGE
= Activator
.getDefault().getImageFromPath("icons/obj16/thread_obj.gif"); //$NON-NLS-1$
151 private static final Image STACKFRAME_IMAGE
= Activator
.getDefault().getImageFromPath("icons/obj16/stckframe_obj.gif"); //$NON-NLS-1$
153 private static final String IMPORT_MAPPING_ICON_PATH
= "icons/etool16/import.gif"; //$NON-NLS-1$
154 private static final String IMPORT_BINARY_ICON_PATH
= "icons/obj16/binaries_obj.gif"; //$NON-NLS-1$
156 private static final ImageDescriptor SORT_BY_NAME_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_alpha.gif"); //$NON-NLS-1$
157 private static final ImageDescriptor SORT_BY_NAME_REV_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_alpha_rev.gif"); //$NON-NLS-1$
158 private static final ImageDescriptor SORT_BY_ID_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_num.gif"); //$NON-NLS-1$
159 private static final ImageDescriptor SORT_BY_ID_REV_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_num_rev.gif"); //$NON-NLS-1$
160 private static final ImageDescriptor SORT_BY_TIME_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_time.gif"); //$NON-NLS-1$
161 private static final ImageDescriptor SORT_BY_TIME_REV_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_time_rev.gif"); //$NON-NLS-1$
162 private static final String SORT_OPTION_KEY
= "sort.option"; //$NON-NLS-1$
164 private enum SortOption
{
165 BY_NAME
, BY_NAME_REV
, BY_ID
, BY_ID_REV
, BY_TIME
, BY_TIME_REV
168 private SortOption fSortOption
;
169 private Comparator
<ITimeGraphEntry
> fThreadComparator
= null;
170 private Action fSortByNameAction
;
171 private Action fSortByIdAction
;
172 private Action fSortByTimeAction
;
174 // ------------------------------------------------------------------------
176 // ------------------------------------------------------------------------
178 // The time graph combo
179 private TimeGraphCombo fTimeGraphCombo
;
181 // The selected trace
182 private ITmfTrace fTrace
;
184 // The selected thread map
185 private final Map
<ITmfTrace
, String
> fSelectedThreadMap
= new HashMap
<>();
187 // The time graph entry list
188 private List
<TraceEntry
> fEntryList
;
190 // The trace to entry list hash map
191 private final Map
<ITmfTrace
, List
<TraceEntry
>> fEntryListMap
= new HashMap
<>();
193 // The trace to build thread hash map
194 private final Map
<ITmfTrace
, BuildThread
> fBuildThreadMap
= new HashMap
<>();
196 /** The map to map function addresses to function names */
197 private Map
<String
, String
> fNameMapping
;
200 private long fStartTime
;
203 private long fEndTime
;
206 private int fDisplayWidth
;
208 // The next event action
209 private Action fNextEventAction
;
211 // The previous event action
212 private Action fPrevEventAction
;
214 // The next item action
215 private Action fNextItemAction
;
217 // The previous item action
218 private Action fPreviousItemAction
;
220 // The action to import a function-name mapping file
221 private Action fImportMappingAction
;
223 // The action to import a binary file mapping */
224 private Action fImportBinaryFileMappingAction
;
227 private ZoomThread fZoomThread
;
229 // The redraw state used to prevent unnecessary queuing of display runnables
230 private State fRedrawState
= State
.IDLE
;
232 // The redraw synchronization object
233 private final Object fSyncObj
= new Object();
235 // The saved time sync. signal used when switching off the pinning of a view
236 private TmfTimeSynchSignal fSavedTimeSyncSignal
;
238 // The saved time range sync. signal used when switching off the pinning of
240 private TmfRangeSynchSignal fSavedRangeSyncSignal
;
242 // ------------------------------------------------------------------------
244 // ------------------------------------------------------------------------
246 private class TraceEntry
extends TimeGraphEntry
{
247 public TraceEntry(String name
, long startTime
, long endTime
) {
248 super(name
, startTime
, endTime
);
252 public boolean hasTimeEvents() {
257 private class ThreadEntry
extends TimeGraphEntry
{
258 // The call stack quark
259 private final int fCallStackQuark
;
260 // The state system from which this entry comes
261 private final ITmfStateSystem fSS
;
263 private final long fThreadId
;
265 public ThreadEntry(ITmfStateSystem ss
, String name
, long threadId
, int callStackQuark
, long startTime
, long endTime
) {
266 super(name
, startTime
, endTime
);
267 fCallStackQuark
= callStackQuark
;
268 fThreadId
= threadId
;
273 public boolean hasTimeEvents() {
277 public int getCallStackQuark() {
278 return fCallStackQuark
;
281 public long getThreadId() {
286 public ITmfStateSystem
getStateSystem() {
291 private class ThreadNameComparator
implements Comparator
<ITimeGraphEntry
> {
292 private boolean reverse
;
294 public ThreadNameComparator(boolean reverse
) {
295 this.reverse
= reverse
;
299 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
300 return reverse ? o2
.getName().compareTo(o1
.getName()) :
301 o1
.getName().compareTo(o2
.getName());
305 private class ThreadIdComparator
implements Comparator
<ITimeGraphEntry
> {
306 private boolean reverse
;
308 public ThreadIdComparator(boolean reverse
) {
309 this.reverse
= reverse
;
313 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
314 ThreadEntry t1
= (ThreadEntry
) o1
;
315 ThreadEntry t2
= (ThreadEntry
) o2
;
316 return reverse ? Long
.compare(t2
.getThreadId(), t1
.getThreadId()) :
317 Long
.compare(t1
.getThreadId(), t2
.getThreadId());
321 private class ThreadTimeComparator
implements Comparator
<ITimeGraphEntry
> {
322 private boolean reverse
;
324 public ThreadTimeComparator(boolean reverse
) {
325 this.reverse
= reverse
;
329 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
330 return reverse ? Long
.compare(o2
.getStartTime(), o1
.getStartTime()) :
331 Long
.compare(o1
.getStartTime(), o2
.getStartTime());
335 private class TreeContentProvider
implements ITreeContentProvider
{
338 public void dispose() {
342 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {
346 public Object
[] getElements(Object inputElement
) {
347 if (inputElement
!= null) {
349 return ((List
<?
>) inputElement
).toArray(new ITimeGraphEntry
[0]);
350 } catch (ClassCastException e
) {
353 return new ITimeGraphEntry
[0];
357 public Object
[] getChildren(Object parentElement
) {
358 ITimeGraphEntry entry
= (ITimeGraphEntry
) parentElement
;
359 return entry
.getChildren().toArray();
363 public Object
getParent(Object element
) {
364 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
365 return entry
.getParent();
369 public boolean hasChildren(Object element
) {
370 ITimeGraphEntry entry
= (ITimeGraphEntry
) element
;
371 return entry
.hasChildren();
376 private class TreeLabelProvider
implements ITableLabelProvider
{
379 public void addListener(ILabelProviderListener listener
) {
383 public void dispose() {
387 public boolean isLabelProperty(Object element
, String property
) {
392 public void removeListener(ILabelProviderListener listener
) {
396 public Image
getColumnImage(Object element
, int columnIndex
) {
397 if (columnIndex
== 0) {
398 if (element
instanceof ThreadEntry
) {
400 } else if (element
instanceof CallStackEntry
) {
401 CallStackEntry entry
= (CallStackEntry
) element
;
402 if (entry
.getFunctionName().length() > 0) {
403 return STACKFRAME_IMAGE
;
411 public String
getColumnText(Object element
, int columnIndex
) {
412 if (element
instanceof CallStackEntry
) {
413 CallStackEntry entry
= (CallStackEntry
) element
;
414 if (columnIndex
== 0) {
415 return entry
.getFunctionName();
416 } else if (columnIndex
== 1 && entry
.getFunctionName().length() > 0) {
417 int depth
= entry
.getStackLevel();
418 return Integer
.toString(depth
);
419 } else if (columnIndex
== 2 && entry
.getFunctionName().length() > 0) {
420 ITmfTimestamp ts
= new TmfTimestamp(entry
.getFunctionEntryTime(), ITmfTimestamp
.NANOSECOND_SCALE
);
421 return ts
.toString();
422 } else if (columnIndex
== 3 && entry
.getFunctionName().length() > 0) {
423 ITmfTimestamp ts
= new TmfTimestamp(entry
.getFunctionExitTime(), ITmfTimestamp
.NANOSECOND_SCALE
);
424 return ts
.toString();
425 } else if (columnIndex
== 4 && entry
.getFunctionName().length() > 0) {
426 ITmfTimestamp ts
= new TmfTimestampDelta(entry
.getFunctionExitTime() - entry
.getFunctionEntryTime(), ITmfTimestamp
.NANOSECOND_SCALE
);
427 return ts
.toString();
429 } else if (element
instanceof ITimeGraphEntry
) {
430 if (columnIndex
== 0) {
431 return ((ITimeGraphEntry
) element
).getName();
434 return ""; //$NON-NLS-1$
439 private class TimeGraphContentProvider
implements ITimeGraphContentProvider
{
442 public ITimeGraphEntry
[] getElements(Object inputElement
) {
443 if (inputElement
!= null) {
445 return ((List
<?
>) inputElement
).toArray(new ITimeGraphEntry
[0]);
446 } catch (ClassCastException e
) {
449 return new ITimeGraphEntry
[0];
454 private class BuildThread
extends Thread
{
455 private final ITmfTrace fBuildTrace
;
456 private final ITmfTrace fParentTrace
;
457 private final IProgressMonitor fMonitor
;
459 public BuildThread(ITmfTrace trace
, ITmfTrace parentTrace
) {
460 super("CallStackView build"); //$NON-NLS-1$
462 fParentTrace
= parentTrace
;
463 fMonitor
= new NullProgressMonitor();
468 buildThreadList(fBuildTrace
, fParentTrace
, fMonitor
);
469 synchronized (fBuildThreadMap
) {
470 fBuildThreadMap
.remove(fBuildTrace
);
474 public void cancel() {
475 fMonitor
.setCanceled(true);
479 private class ZoomThread
extends Thread
{
480 private final List
<TraceEntry
> fZoomEntryList
;
481 private final long fZoomStartTime
;
482 private final long fZoomEndTime
;
483 private final IProgressMonitor fMonitor
;
485 public ZoomThread(List
<TraceEntry
> entryList
, long startTime
, long endTime
) {
486 super("CallStackView zoom"); //$NON-NLS-1$
487 fZoomEntryList
= entryList
;
488 fZoomStartTime
= startTime
;
489 fZoomEndTime
= endTime
;
490 fMonitor
= new NullProgressMonitor();
495 if (fZoomEntryList
== null) {
498 long resolution
= Math
.max(1, (fZoomEndTime
- fZoomStartTime
) / fDisplayWidth
);
499 for (TraceEntry traceEntry
: fZoomEntryList
) {
500 for (ITimeGraphEntry threadEntry
: traceEntry
.getChildren()) {
501 ITmfStateSystem ss
= ((ThreadEntry
) threadEntry
).getStateSystem();
506 if (ss
.isCancelled()) {
509 for (ITimeGraphEntry child
: threadEntry
.getChildren()) {
510 if (fMonitor
.isCanceled()) {
513 CallStackEntry entry
= (CallStackEntry
) child
;
514 if (fZoomStartTime
<= fStartTime
&& fZoomEndTime
>= fEndTime
) {
515 entry
.setZoomedEventList(null);
517 List
<ITimeEvent
> zoomedEventList
= getEventList(entry
, fZoomStartTime
, fZoomEndTime
, resolution
, fMonitor
);
518 if (zoomedEventList
!= null) {
519 entry
.setZoomedEventList(zoomedEventList
);
528 public void cancel() {
529 fMonitor
.setCanceled(true);
533 // ------------------------------------------------------------------------
535 // ------------------------------------------------------------------------
538 * Default constructor
540 public CallStackView() {
542 fDisplayWidth
= Display
.getDefault().getBounds().width
;
545 // ------------------------------------------------------------------------
547 // ------------------------------------------------------------------------
550 public void createPartControl(Composite parent
) {
551 fTimeGraphCombo
= new TimeGraphCombo(parent
, SWT
.NONE
);
553 fTimeGraphCombo
.setTreeContentProvider(new TreeContentProvider());
555 fTimeGraphCombo
.setTreeLabelProvider(new TreeLabelProvider());
557 fTimeGraphCombo
.setTreeColumns(COLUMN_TIMES
);
559 fTimeGraphCombo
.getTreeViewer().getTree().getColumn(0).setWidth(COLUMN_WIDTHS
[0]);
560 fTimeGraphCombo
.getTreeViewer().getTree().getColumn(1).setWidth(COLUMN_WIDTHS
[1]);
561 fTimeGraphCombo
.getTreeViewer().getTree().getColumn(2).setWidth(COLUMN_WIDTHS
[2]);
562 fTimeGraphCombo
.getTreeViewer().getTree().getColumn(3).setWidth(COLUMN_WIDTHS
[3]);
563 fTimeGraphCombo
.getTreeViewer().getTree().getColumn(4).setWidth(COLUMN_WIDTHS
[4]);
565 fTimeGraphCombo
.setTimeGraphContentProvider(new TimeGraphContentProvider());
566 fTimeGraphCombo
.setTimeGraphProvider(new CallStackPresentationProvider(this));
567 fTimeGraphCombo
.getTimeGraphViewer().setTimeFormat(TimeFormat
.CALENDAR
);
569 fTimeGraphCombo
.getTimeGraphViewer().addRangeListener(new ITimeGraphRangeListener() {
571 public void timeRangeUpdated(TimeGraphRangeUpdateEvent event
) {
572 long startTime
= event
.getStartTime();
573 long endTime
= event
.getEndTime();
574 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
575 broadcast(new TmfRangeSynchSignal(CallStackView
.this, range
));
576 startZoomThread(startTime
, endTime
);
580 fTimeGraphCombo
.getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
582 public void timeSelected(TimeGraphTimeEvent event
) {
583 long beginTime
= event
.getBeginTime();
584 long endTime
= event
.getEndTime();
585 synchingToTime(beginTime
);
586 broadcast(new TmfTimeSynchSignal(CallStackView
.this, new TmfNanoTimestamp(beginTime
), new TmfNanoTimestamp(endTime
)));
590 fTimeGraphCombo
.getTimeGraphViewer().getControl().addControlListener(new ControlAdapter() {
592 public void controlResized(ControlEvent e
) {
593 fDisplayWidth
= fTimeGraphCombo
.getTimeGraphViewer().getControl().getSize().x
;
594 if (fEntryList
!= null) {
595 startZoomThread(fTimeGraphCombo
.getTimeGraphViewer().getTime0(), fTimeGraphCombo
.getTimeGraphViewer().getTime1());
600 fTimeGraphCombo
.getTreeViewer().addDoubleClickListener(new IDoubleClickListener() {
602 public void doubleClick(DoubleClickEvent event
) {
603 Object selection
= ((IStructuredSelection
) event
.getSelection()).getFirstElement();
604 if (selection
instanceof CallStackEntry
) {
605 CallStackEntry entry
= (CallStackEntry
) selection
;
606 if (entry
.getFunctionName().length() > 0) {
607 long entryTime
= entry
.getFunctionEntryTime();
608 long exitTime
= entry
.getFunctionExitTime();
609 long spacingTime
= (long) ((exitTime
- entryTime
) * SPACING_RATIO
);
610 entryTime
-= spacingTime
;
611 exitTime
+= spacingTime
;
612 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(entryTime
), new TmfNanoTimestamp(exitTime
));
613 broadcast(new TmfRangeSynchSignal(CallStackView
.this, range
));
614 fTimeGraphCombo
.getTimeGraphViewer().setStartFinishTime(entryTime
, exitTime
);
615 startZoomThread(entryTime
, exitTime
);
621 fTimeGraphCombo
.getTimeGraphViewer().getTimeGraphControl().addMouseListener(new MouseAdapter() {
623 public void mouseDoubleClick(MouseEvent e
) {
624 TimeGraphControl timeGraphControl
= fTimeGraphCombo
.getTimeGraphViewer().getTimeGraphControl();
625 ISelection selection
= timeGraphControl
.getSelection();
626 if (selection
instanceof TimeGraphSelection
) {
627 Object o
= ((TimeGraphSelection
) selection
).getFirstElement();
628 if (o
instanceof CallStackEvent
) {
629 CallStackEvent event
= (CallStackEvent
) o
;
630 long startTime
= event
.getTime();
631 long endTime
= startTime
+ event
.getDuration();
632 long spacingTime
= (long) ((endTime
- startTime
) * SPACING_RATIO
);
633 startTime
-= spacingTime
;
634 endTime
+= spacingTime
;
635 TmfTimeRange range
= new TmfTimeRange(new TmfNanoTimestamp(startTime
), new TmfNanoTimestamp(endTime
));
636 broadcast(new TmfRangeSynchSignal(CallStackView
.this, range
));
637 fTimeGraphCombo
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
638 startZoomThread(startTime
, endTime
);
644 IStatusLineManager statusLineManager
= getViewSite().getActionBars().getStatusLineManager();
645 fTimeGraphCombo
.getTimeGraphViewer().getTimeGraphControl().setStatusLineManager(statusLineManager
);
647 // View Action Handling
649 contributeToActionBars();
653 IEditorPart editor
= getSite().getPage().getActiveEditor();
654 if (editor
instanceof ITmfTraceEditor
) {
655 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
657 traceSelected(new TmfTraceSelectedSignal(this, trace
));
663 public void setFocus() {
664 fTimeGraphCombo
.setFocus();
667 // ------------------------------------------------------------------------
669 // ------------------------------------------------------------------------
671 * Handler for the trace opened signal.
674 * The incoming signal
678 public void traceOpened(TmfTraceOpenedSignal signal
) {
679 fTrace
= signal
.getTrace();
684 * Handler for the trace selected signal
687 * The incoming signal
690 public void traceSelected(final TmfTraceSelectedSignal signal
) {
691 if (signal
.getTrace() == fTrace
) {
694 fTrace
= signal
.getTrace();
699 * Trace is closed: clear the data structures and the view
702 * the signal received
705 public void traceClosed(final TmfTraceClosedSignal signal
) {
706 synchronized (fBuildThreadMap
) {
707 ITmfTrace
[] traces
= TmfTraceManager
.getTraceSet(signal
.getTrace());
708 for (ITmfTrace trace
: traces
) {
709 BuildThread buildThread
= fBuildThreadMap
.remove(trace
);
710 if (buildThread
!= null) {
711 buildThread
.cancel();
715 synchronized (fEntryListMap
) {
716 fEntryListMap
.remove(signal
.getTrace());
718 fSelectedThreadMap
.remove(signal
.getTrace());
719 if (signal
.getTrace() == fTrace
) {
728 * Handler for the TimeSynch signal
731 * The incoming signal
734 public void synchToTime(final TmfTimeSynchSignal signal
) {
736 fSavedTimeSyncSignal
= isPinned() ?
new TmfTimeSynchSignal(signal
.getSource(), signal
.getBeginTime(), signal
.getEndTime()) : null;
738 if (signal
.getSource() == this || fTrace
== null || isPinned()) {
741 final long beginTime
= signal
.getBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
742 final long endTime
= signal
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
743 Display
.getDefault().asyncExec(new Runnable() {
746 if (fTimeGraphCombo
.isDisposed()) {
749 if (beginTime
== endTime
) {
750 fTimeGraphCombo
.getTimeGraphViewer().setSelectedTime(beginTime
, true);
752 fTimeGraphCombo
.getTimeGraphViewer().setSelectionRange(beginTime
, endTime
);
754 synchingToTime(beginTime
);
755 startZoomThread(fTimeGraphCombo
.getTimeGraphViewer().getTime0(), fTimeGraphCombo
.getTimeGraphViewer().getTime1());
756 if (fEntryList
== null) {
759 TimeGraphViewer viewer
= fTimeGraphCombo
.getTimeGraphViewer();
760 for (TraceEntry traceEntry
: fEntryList
) {
761 for (ITimeGraphEntry child
: traceEntry
.getChildren()) {
762 ThreadEntry threadEntry
= (ThreadEntry
) child
;
763 ITmfStateSystem ss
= threadEntry
.getStateSystem();
764 if (ss
== null || beginTime
< ss
.getStartTime() || beginTime
> ss
.getCurrentEndTime()) {
768 int quark
= threadEntry
.getCallStackQuark();
769 ITmfStateInterval stackInterval
= ss
.querySingleState(beginTime
, quark
);
770 if (beginTime
== stackInterval
.getStartTime()) {
771 int stackLevel
= stackInterval
.getStateValue().unboxInt();
772 ITimeGraphEntry selectedEntry
= threadEntry
.getChildren().get(Math
.max(0, stackLevel
- 1));
773 fTimeGraphCombo
.setSelection(selectedEntry
);
774 viewer
.getTimeGraphControl().fireSelectionChanged();
777 } catch (AttributeNotFoundException
| TimeRangeException
| StateSystemDisposedException
| StateValueTypeException e
) {
778 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
787 * Handler for the RangeSynch signal
790 * The incoming signal
793 public void synchToRange(final TmfRangeSynchSignal signal
) {
796 fSavedRangeSyncSignal
=
797 new TmfRangeSynchSignal(signal
.getSource(), new TmfTimeRange(signal
.getCurrentRange().getStartTime(), signal
.getCurrentRange().getEndTime()));
799 fSavedTimeSyncSignal
= null;
802 if (signal
.getSource() == this || fTrace
== null || isPinned()) {
805 if (signal
.getCurrentRange().getIntersection(fTrace
.getTimeRange()) == null) {
808 final long startTime
= signal
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
809 final long endTime
= signal
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
810 Display
.getDefault().asyncExec(new Runnable() {
813 if (fTimeGraphCombo
.isDisposed()) {
816 fTimeGraphCombo
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
817 startZoomThread(startTime
, endTime
);
822 // ------------------------------------------------------------------------
824 // ------------------------------------------------------------------------
826 private void loadTrace() {
827 synchronized (fEntryListMap
) {
828 fEntryList
= fEntryListMap
.get(fTrace
);
829 if (fEntryList
== null) {
830 fStartTime
= Long
.MAX_VALUE
;
831 fEndTime
= Long
.MIN_VALUE
;
832 synchronized (fBuildThreadMap
) {
833 ITmfTrace
[] traces
= TmfTraceManager
.getTraceSet(fTrace
);
834 for (ITmfTrace trace
: traces
) {
835 BuildThread buildThread
= new BuildThread(trace
, fTrace
);
836 fBuildThreadMap
.put(trace
, buildThread
);
841 fStartTime
= fTrace
.getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
842 fEndTime
= fTrace
.getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
848 private void buildThreadList(final ITmfTrace trace
, final ITmfTrace parentTrace
, IProgressMonitor monitor
) {
849 if (monitor
.isCanceled()) {
852 AbstractCallStackAnalysis module
= getCallStackModule(trace
);
853 if (module
== null) {
854 addUnavailableEntry(trace
, parentTrace
);
857 ITmfStateSystem ss
= module
.getStateSystem();
859 addUnavailableEntry(trace
, parentTrace
);
863 Map
<ITmfTrace
, TraceEntry
> traceEntryMap
= new HashMap
<>();
864 Map
<Integer
, ThreadEntry
> threadEntryMap
= new HashMap
<>();
865 String
[] threadPaths
= module
.getThreadsPattern();
867 long start
= ss
.getStartTime();
869 boolean complete
= false;
871 if (monitor
.isCanceled()) {
874 complete
= ss
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
875 if (ss
.isCancelled()) {
878 long end
= ss
.getCurrentEndTime();
879 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
882 List
<Integer
> threadQuarks
= ss
.getQuarks(threadPaths
);
883 TraceEntry traceEntry
= traceEntryMap
.get(trace
);
884 if (traceEntry
== null) {
885 traceEntry
= new TraceEntry(trace
.getName(), start
, end
+ 1);
886 traceEntryMap
.put(trace
, traceEntry
);
887 traceEntry
.sortChildren(fThreadComparator
);
888 addToEntryList(parentTrace
, Collections
.singletonList(traceEntry
));
890 traceEntry
.updateEndTime(end
);
892 for (int i
= 0; i
< threadQuarks
.size(); i
++) {
893 if (monitor
.isCanceled()) {
896 int threadQuark
= threadQuarks
.get(i
);
898 String
[] callStackPath
= module
.getCallStackPath();
899 int callStackQuark
= ss
.getQuarkRelative(threadQuark
, callStackPath
);
900 String threadName
= ss
.getAttributeName(threadQuark
);
901 long threadEnd
= end
+ 1;
902 ITmfStateInterval endInterval
= ss
.querySingleState(ss
.getCurrentEndTime(), callStackQuark
);
903 if (endInterval
.getStateValue().isNull() && endInterval
.getStartTime() != ss
.getStartTime()) {
904 threadEnd
= endInterval
.getStartTime();
906 ThreadEntry threadEntry
= threadEntryMap
.get(threadQuark
);
907 if (threadEntry
== null) {
908 long threadId
= ss
.querySingleState(ss
.getCurrentEndTime(), threadQuark
).getStateValue().unboxLong();
909 long threadStart
= start
;
910 ITmfStateInterval startInterval
= ss
.querySingleState(start
, callStackQuark
);
911 if (startInterval
.getStateValue().isNull()) {
912 threadStart
= Math
.min(startInterval
.getEndTime() + 1, end
+ 1);
914 threadEntry
= new ThreadEntry(ss
, threadName
, threadId
, callStackQuark
, threadStart
, threadEnd
);
915 threadEntryMap
.put(threadQuark
, threadEntry
);
916 traceEntry
.addChild(threadEntry
);
918 threadEntry
.updateEndTime(threadEnd
);
921 for (int stackLevelQuark
: ss
.getSubAttributes(callStackQuark
, false)) {
922 if (level
> threadEntry
.getChildren().size()) {
923 CallStackEntry callStackEntry
= new CallStackEntry(threadName
, stackLevelQuark
, level
, trace
, ss
);
924 threadEntry
.addChild(callStackEntry
);
928 } catch (AttributeNotFoundException e
) {
929 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
930 } catch (StateSystemDisposedException e
) {
934 if (parentTrace
== fTrace
) {
935 synchronized (fEntryListMap
) {
936 fStartTime
= Math
.min(fStartTime
, start
);
937 fEndTime
= Math
.max(fEndTime
, end
+ 1);
941 for (ITimeGraphEntry threadEntry
: traceEntry
.getChildren()) {
942 for (ITimeGraphEntry callStackEntry
: threadEntry
.getChildren()) {
943 if (monitor
.isCanceled()) {
946 buildStatusEvents(parentTrace
, (CallStackEntry
) callStackEntry
, monitor
, start
, end
);
953 private void addToEntryList(ITmfTrace trace
, List
<TraceEntry
> list
) {
954 synchronized (fEntryListMap
) {
955 List
<TraceEntry
> entryList
= fEntryListMap
.get(trace
);
956 if (entryList
== null) {
957 fEntryListMap
.put(trace
, new CopyOnWriteArrayList
<>(list
));
959 entryList
.addAll(list
);
964 private void addUnavailableEntry(ITmfTrace trace
, ITmfTrace parentTrace
) {
965 String name
= Messages
.CallStackView_StackInfoNotAvailable
+ ' ' + '(' + trace
.getName() + ')';
966 TraceEntry unavailableEntry
= new TraceEntry(name
, 0, 0);
967 addToEntryList(parentTrace
, Collections
.singletonList(unavailableEntry
));
968 if (parentTrace
== fTrace
) {
973 private void buildStatusEvents(ITmfTrace trace
, CallStackEntry entry
, IProgressMonitor monitor
, long start
, long end
) {
974 ITmfStateSystem ss
= entry
.getStateSystem();
975 long resolution
= Math
.max(1, (end
- ss
.getStartTime()) / fDisplayWidth
);
976 List
<ITimeEvent
> eventList
= getEventList(entry
, start
, end
+ 1, resolution
, monitor
);
977 if (eventList
!= null) {
978 for (ITimeEvent event
: eventList
) {
979 entry
.addEvent(event
);
982 if (trace
== fTrace
) {
987 private static List
<ITimeEvent
> getEventList(CallStackEntry entry
,
988 long startTime
, long endTime
, long resolution
,
989 IProgressMonitor monitor
) {
990 ITmfStateSystem ss
= entry
.getStateSystem();
991 long start
= Math
.max(startTime
, ss
.getStartTime());
992 long end
= Math
.min(endTime
, ss
.getCurrentEndTime() + 1);
996 List
<ITimeEvent
> eventList
= null;
998 List
<ITmfStateInterval
> stackIntervals
= ss
.queryHistoryRange(entry
.getQuark(), start
, end
- 1, resolution
, monitor
);
999 eventList
= new ArrayList
<>(stackIntervals
.size());
1000 long lastEndTime
= -1;
1001 boolean lastIsNull
= true;
1002 for (ITmfStateInterval statusInterval
: stackIntervals
) {
1003 if (monitor
.isCanceled()) {
1006 long time
= statusInterval
.getStartTime();
1007 long duration
= statusInterval
.getEndTime() - time
+ 1;
1008 if (!statusInterval
.getStateValue().isNull()) {
1009 final int modulo
= CallStackPresentationProvider
.NUM_COLORS
/ 2;
1010 int value
= statusInterval
.getStateValue().toString().hashCode() % modulo
+ modulo
;
1011 eventList
.add(new CallStackEvent(entry
, time
, duration
, value
));
1014 if (lastEndTime
== -1) {
1015 // add null event if it intersects the start time
1016 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
1018 if (lastEndTime
!= time
&& lastIsNull
) {
1019 // add unknown event if between two null states
1020 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
1022 if (time
+ duration
>= endTime
) {
1023 // add null event if it intersects the end time
1024 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
1029 lastEndTime
= time
+ duration
;
1031 } catch (AttributeNotFoundException e
) {
1032 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
1033 } catch (TimeRangeException e
) {
1034 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
1035 } catch (StateSystemDisposedException e
) {
1041 private void synchingToTime(long time
) {
1042 if (fEntryList
== null) {
1045 for (TraceEntry traceEntry
: fEntryList
) {
1046 for (ITimeGraphEntry threadEntry
: traceEntry
.getChildren()) {
1047 ITmfStateSystem ss
= ((ThreadEntry
) threadEntry
).getStateSystem();
1051 if (ss
.isCancelled()) {
1054 if (time
< ss
.getStartTime() || time
> ss
.getCurrentEndTime()) {
1057 for (ITimeGraphEntry child
: threadEntry
.getChildren()) {
1058 CallStackEntry callStackEntry
= (CallStackEntry
) child
;
1060 ITmfStateInterval stackLevelInterval
= ss
.querySingleState(time
, callStackEntry
.getQuark());
1061 ITmfStateValue nameValue
= stackLevelInterval
.getStateValue();
1062 String name
= ""; //$NON-NLS-1$
1064 if (nameValue
.getType() == Type
.STRING
) {
1065 String address
= nameValue
.unboxStr();
1066 name
= getFunctionName(address
);
1067 } else if (nameValue
.getType() == Type
.INTEGER
) {
1068 name
= "0x" + Integer
.toHexString(nameValue
.unboxInt()); //$NON-NLS-1$
1069 } else if (nameValue
.getType() == Type
.LONG
) {
1070 name
= "0x" + Long
.toHexString(nameValue
.unboxLong()); //$NON-NLS-1$
1072 } catch (StateValueTypeException e
) {
1074 callStackEntry
.setFunctionName(name
);
1075 if (name
.length() > 0) {
1076 callStackEntry
.setFunctionEntryTime(stackLevelInterval
.getStartTime());
1077 callStackEntry
.setFunctionExitTime(stackLevelInterval
.getEndTime() + 1);
1079 } catch (AttributeNotFoundException e
) {
1080 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
1081 } catch (StateSystemDisposedException e
) {
1087 fTimeGraphCombo
.refresh();
1090 private void refresh() {
1091 Display
.getDefault().asyncExec(new Runnable() {
1094 if (fTimeGraphCombo
.isDisposed()) {
1097 synchronized (fEntryListMap
) {
1098 fEntryList
= fEntryListMap
.get(fTrace
);
1099 if (fEntryList
== null) {
1100 fEntryList
= new ArrayList
<>();
1102 for (TraceEntry traceEntry
: fEntryList
) {
1103 traceEntry
.sortChildren(fThreadComparator
);
1106 if (fEntryList
!= fTimeGraphCombo
.getInput()) {
1107 fTimeGraphCombo
.setInput(fEntryList
);
1109 fTimeGraphCombo
.refresh();
1111 fTimeGraphCombo
.getTimeGraphViewer().setTimeBounds(fStartTime
, fEndTime
);
1113 long selectionBeginTime
= fTrace
== null ?
0 : fTraceManager
.getSelectionBeginTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1114 long selectionEndTime
= fTrace
== null ?
0 : fTraceManager
.getSelectionEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1115 long startTime
= fTrace
== null ?
0 : fTraceManager
.getCurrentRange().getStartTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1116 long endTime
= fTrace
== null ?
0 : fTraceManager
.getCurrentRange().getEndTime().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
1117 startTime
= Math
.max(startTime
, fStartTime
);
1118 endTime
= Math
.min(endTime
, fEndTime
);
1119 fTimeGraphCombo
.getTimeGraphViewer().setSelectionRange(selectionBeginTime
, selectionEndTime
);
1120 synchingToTime(selectionBeginTime
);
1121 fTimeGraphCombo
.getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
1122 startZoomThread(startTime
, endTime
);
1127 private void redraw() {
1128 synchronized (fSyncObj
) {
1129 if (fRedrawState
== State
.IDLE
) {
1130 fRedrawState
= State
.BUSY
;
1132 fRedrawState
= State
.PENDING
;
1136 Display
.getDefault().asyncExec(new Runnable() {
1139 if (fTimeGraphCombo
.isDisposed()) {
1142 fTimeGraphCombo
.redraw();
1143 fTimeGraphCombo
.update();
1144 synchronized (fSyncObj
) {
1145 if (fRedrawState
== State
.PENDING
) {
1146 fRedrawState
= State
.IDLE
;
1149 fRedrawState
= State
.IDLE
;
1156 private void startZoomThread(long startTime
, long endTime
) {
1157 if (fZoomThread
!= null) {
1158 fZoomThread
.cancel();
1160 fZoomThread
= new ZoomThread(fEntryList
, startTime
, endTime
);
1161 fZoomThread
.start();
1164 private void makeActions() {
1165 fPreviousItemAction
= fTimeGraphCombo
.getTimeGraphViewer().getPreviousItemAction();
1166 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
1167 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
1168 fNextItemAction
= fTimeGraphCombo
.getTimeGraphViewer().getNextItemAction();
1169 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
1170 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
1173 private void contributeToActionBars() {
1174 IActionBars bars
= getViewSite().getActionBars();
1175 fillLocalToolBar(bars
.getToolBarManager());
1177 // Create pin action
1178 contributePinActionToToolBar();
1179 fPinAction
.addPropertyChangeListener(new IPropertyChangeListener() {
1181 public void propertyChange(PropertyChangeEvent event
) {
1182 if (IAction
.CHECKED
.equals(event
.getProperty()) && !isPinned()) {
1183 if (fSavedRangeSyncSignal
!= null) {
1184 synchToRange(fSavedRangeSyncSignal
);
1185 fSavedRangeSyncSignal
= null;
1188 if (fSavedTimeSyncSignal
!= null) {
1189 synchToTime(fSavedTimeSyncSignal
);
1190 fSavedTimeSyncSignal
= null;
1197 private void fillLocalToolBar(IToolBarManager manager
) {
1198 manager
.add(getImportBinaryAction());
1199 manager
.add(getImportMappingAction());
1200 manager
.add(new Separator());
1201 manager
.add(getSortByNameAction());
1202 manager
.add(getSortByIdAction());
1203 manager
.add(getSortByTimeAction());
1204 manager
.add(new Separator());
1205 manager
.add(fTimeGraphCombo
.getTimeGraphViewer().getResetScaleAction());
1206 manager
.add(getPreviousEventAction());
1207 manager
.add(getNextEventAction());
1208 manager
.add(fPreviousItemAction
);
1209 manager
.add(fNextItemAction
);
1210 manager
.add(fTimeGraphCombo
.getTimeGraphViewer().getZoomInAction());
1211 manager
.add(fTimeGraphCombo
.getTimeGraphViewer().getZoomOutAction());
1212 manager
.add(new Separator());
1215 private void createContextMenu() {
1216 final MenuManager contextMenu
= new MenuManager();
1217 contextMenu
.add(getSortByNameAction());
1218 contextMenu
.add(getSortByIdAction());
1219 contextMenu
.add(getSortByTimeAction());
1221 Tree tree
= fTimeGraphCombo
.getTreeViewer().getTree();
1222 Menu menu
= contextMenu
.createContextMenu(tree
);
1227 * Get the the next event action.
1229 * @return The action object
1231 private Action
getNextEventAction() {
1232 if (fNextEventAction
== null) {
1233 fNextEventAction
= new Action() {
1236 TimeGraphViewer viewer
= fTimeGraphCombo
.getTimeGraphViewer();
1237 ITimeGraphEntry entry
= viewer
.getSelection();
1238 if (entry
instanceof CallStackEntry
) {
1240 CallStackEntry callStackEntry
= (CallStackEntry
) entry
;
1241 ITmfStateSystem ss
= callStackEntry
.getStateSystem();
1242 long time
= Math
.max(ss
.getStartTime(), Math
.min(ss
.getCurrentEndTime(), viewer
.getSelectionBegin()));
1243 ThreadEntry threadEntry
= (ThreadEntry
) callStackEntry
.getParent();
1244 int quark
= ss
.getParentAttributeQuark(callStackEntry
.getQuark());
1245 ITmfStateInterval stackInterval
= ss
.querySingleState(time
, quark
);
1246 long newTime
= stackInterval
.getEndTime() + 1;
1247 viewer
.setSelectedTimeNotify(newTime
, true);
1248 stackInterval
= ss
.querySingleState(Math
.min(ss
.getCurrentEndTime(), newTime
), quark
);
1249 int stackLevel
= stackInterval
.getStateValue().unboxInt();
1250 ITimeGraphEntry selectedEntry
= threadEntry
.getChildren().get(Math
.max(0, stackLevel
- 1));
1251 fTimeGraphCombo
.setSelection(selectedEntry
);
1252 viewer
.getTimeGraphControl().fireSelectionChanged();
1253 startZoomThread(viewer
.getTime0(), viewer
.getTime1());
1255 } catch (AttributeNotFoundException
| TimeRangeException
| StateSystemDisposedException
| StateValueTypeException e
) {
1256 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
1262 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextEventActionNameText
);
1263 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextEventActionToolTipText
);
1264 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_EVENT
));
1267 return fNextEventAction
;
1271 * Get the previous event action.
1273 * @return The Action object
1275 private Action
getPreviousEventAction() {
1276 if (fPrevEventAction
== null) {
1277 fPrevEventAction
= new Action() {
1280 TimeGraphViewer viewer
= fTimeGraphCombo
.getTimeGraphViewer();
1281 ITimeGraphEntry entry
= viewer
.getSelection();
1282 if (entry
instanceof CallStackEntry
) {
1284 CallStackEntry callStackEntry
= (CallStackEntry
) entry
;
1285 ITmfStateSystem ss
= callStackEntry
.getStateSystem();
1286 long time
= Math
.max(ss
.getStartTime(), Math
.min(ss
.getCurrentEndTime(), viewer
.getSelectionBegin()));
1287 ThreadEntry threadEntry
= (ThreadEntry
) callStackEntry
.getParent();
1288 int quark
= ss
.getParentAttributeQuark(callStackEntry
.getQuark());
1289 ITmfStateInterval stackInterval
= ss
.querySingleState(time
, quark
);
1290 if (stackInterval
.getStartTime() == time
&& time
> ss
.getStartTime()) {
1291 stackInterval
= ss
.querySingleState(time
- 1, quark
);
1293 viewer
.setSelectedTimeNotify(stackInterval
.getStartTime(), true);
1294 int stackLevel
= stackInterval
.getStateValue().unboxInt();
1295 ITimeGraphEntry selectedEntry
= threadEntry
.getChildren().get(Math
.max(0, stackLevel
- 1));
1296 fTimeGraphCombo
.setSelection(selectedEntry
);
1297 viewer
.getTimeGraphControl().fireSelectionChanged();
1298 startZoomThread(viewer
.getTime0(), viewer
.getTime1());
1300 } catch (AttributeNotFoundException
| TimeRangeException
| StateSystemDisposedException
| StateValueTypeException e
) {
1301 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
1307 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousEventActionNameText
);
1308 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousEventActionToolTipText
);
1309 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_EVENT
));
1312 return fPrevEventAction
;
1315 private static @Nullable AbstractCallStackAnalysis
getCallStackModule(ITmfTrace trace
) {
1317 * Since we cannot know the exact analysis ID (in separate plugins), we
1318 * will search using the analysis type.
1320 Iterable
<AbstractCallStackAnalysis
> modules
=
1321 trace
.getAnalysisModulesOfClass(AbstractCallStackAnalysis
.class);
1322 Iterator
<AbstractCallStackAnalysis
> it
= modules
.iterator();
1323 if (!it
.hasNext()) {
1324 /* This trace does not provide a call-stack analysis */
1329 * We only look at the first module we find.
1331 * TODO Handle the advanced case where one trace provides more than one
1332 * call-stack analysis.
1334 AbstractCallStackAnalysis module
= it
.next();
1335 /* This analysis is not automatic, we need to schedule it on-demand */
1337 module
.waitForInitialization();
1341 // ------------------------------------------------------------------------
1342 // Methods related to function name mapping
1343 // ------------------------------------------------------------------------
1346 * Common code for all import file mapping actions
1348 private abstract class AbstractImportFileMappingAction
extends Action
{
1349 private final String fDialogTitle
;
1351 private AbstractImportFileMappingAction(String dialogTitle
) {
1352 fDialogTitle
= dialogTitle
;
1357 FileDialog dialog
= new FileDialog(getViewSite().getShell());
1358 dialog
.setText(fDialogTitle
);
1359 final String filePath
= dialog
.open();
1360 if (filePath
== null) {
1361 /* No file was selected, don't change anything */
1366 * Start the mapping import in a separate thread (we do not want to
1367 * UI thread to do this).
1369 Job job
= new Job(Messages
.CallStackView_ImportMappingJobName
) {
1371 public IStatus
run(IProgressMonitor monitor
) {
1372 fNameMapping
= doMapping(new File(filePath
));
1374 /* Refresh call stack entries and event labels */
1375 Display
.getDefault().asyncExec(new Runnable() {
1378 synchingToTime(fTimeGraphCombo
.getTimeGraphViewer().getSelectionBegin());
1381 return Status
.OK_STATUS
;
1387 abstract Map
<String
, String
> doMapping(File file
);
1391 * Toolbar icon to import the function address-to-name mapping file.
1393 private Action
getImportMappingAction() {
1394 if (fImportMappingAction
!= null) {
1395 return fImportMappingAction
;
1397 fImportMappingAction
= new AbstractImportFileMappingAction(Messages
.CallStackView_ImportMappingDialogTitle
) {
1399 Map
<String
, String
> doMapping(File file
) {
1400 return FunctionNameMapper
.mapFromNmTextFile(file
);
1404 fImportMappingAction
.setText(Messages
.CallStackView_ImportMappingButtonText
);
1405 fImportMappingAction
.setToolTipText(Messages
.CallStackView_ImportMappingButtonTooltip
);
1406 fImportMappingAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(IMPORT_MAPPING_ICON_PATH
));
1408 return fImportMappingAction
;
1411 private Action
getSortByNameAction() {
1412 if (fSortByNameAction
== null) {
1413 fSortByNameAction
= new Action(Messages
.CallStackView_SortByThreadName
, IAction
.AS_CHECK_BOX
) {
1416 if (fSortOption
== SortOption
.BY_NAME
) {
1417 saveSortOption(SortOption
.BY_NAME_REV
);
1419 saveSortOption(SortOption
.BY_NAME
);
1423 fSortByNameAction
.setToolTipText(Messages
.CallStackView_SortByThreadName
);
1424 fSortByNameAction
.setImageDescriptor(SORT_BY_NAME_ICON
);
1426 return fSortByNameAction
;
1429 private Action
getSortByIdAction() {
1430 if (fSortByIdAction
== null) {
1431 fSortByIdAction
= new Action(Messages
.CallStackView_SortByThreadId
, IAction
.AS_CHECK_BOX
) {
1434 if (fSortOption
== SortOption
.BY_ID
) {
1435 saveSortOption(SortOption
.BY_ID_REV
);
1437 saveSortOption(SortOption
.BY_ID
);
1441 fSortByIdAction
.setToolTipText(Messages
.CallStackView_SortByThreadId
);
1442 fSortByIdAction
.setImageDescriptor(SORT_BY_ID_ICON
);
1444 return fSortByIdAction
;
1447 private Action
getSortByTimeAction() {
1448 if (fSortByTimeAction
== null) {
1449 fSortByTimeAction
= new Action(Messages
.CallStackView_SortByThreadTime
, IAction
.AS_CHECK_BOX
) {
1452 if (fSortOption
== SortOption
.BY_TIME
) {
1453 saveSortOption(SortOption
.BY_TIME_REV
);
1455 saveSortOption(SortOption
.BY_TIME
);
1459 fSortByTimeAction
.setToolTipText(Messages
.CallStackView_SortByThreadTime
);
1460 fSortByTimeAction
.setImageDescriptor(SORT_BY_TIME_ICON
);
1462 return fSortByTimeAction
;
1465 private void loadSortOption() {
1466 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
1467 IDialogSettings section
= settings
.getSection(getClass().getName());
1468 if (section
== null) {
1471 String sortOption
= section
.get(SORT_OPTION_KEY
);
1472 if (sortOption
== null) {
1477 getSortByNameAction().setChecked(false);
1478 getSortByNameAction().setImageDescriptor(SORT_BY_NAME_ICON
);
1479 getSortByIdAction().setChecked(false);
1480 getSortByIdAction().setImageDescriptor(SORT_BY_ID_ICON
);
1481 getSortByTimeAction().setChecked(false);
1482 getSortByTimeAction().setImageDescriptor(SORT_BY_TIME_ICON
);
1484 if (sortOption
.equals(SortOption
.BY_NAME
.name())) {
1485 fSortOption
= SortOption
.BY_NAME
;
1486 fThreadComparator
= new ThreadNameComparator(false);
1487 getSortByNameAction().setChecked(true);
1488 } else if (sortOption
.equals(SortOption
.BY_NAME_REV
.name())) {
1489 fSortOption
= SortOption
.BY_NAME_REV
;
1490 fThreadComparator
= new ThreadNameComparator(true);
1491 getSortByNameAction().setChecked(true);
1492 getSortByNameAction().setImageDescriptor(SORT_BY_NAME_REV_ICON
);
1493 } else if (sortOption
.equals(SortOption
.BY_ID
.name())) {
1494 fSortOption
= SortOption
.BY_ID
;
1495 fThreadComparator
= new ThreadIdComparator(false);
1496 getSortByIdAction().setChecked(true);
1497 } else if (sortOption
.equals(SortOption
.BY_ID_REV
.name())) {
1498 fSortOption
= SortOption
.BY_ID_REV
;
1499 fThreadComparator
= new ThreadIdComparator(true);
1500 getSortByIdAction().setChecked(true);
1501 getSortByIdAction().setImageDescriptor(SORT_BY_ID_REV_ICON
);
1502 } else if (sortOption
.equals(SortOption
.BY_TIME
.name())) {
1503 fSortOption
= SortOption
.BY_TIME
;
1504 fThreadComparator
= new ThreadTimeComparator(false);
1505 getSortByTimeAction().setChecked(true);
1506 } else if (sortOption
.equals(SortOption
.BY_TIME_REV
.name())) {
1507 fSortOption
= SortOption
.BY_TIME_REV
;
1508 fThreadComparator
= new ThreadTimeComparator(true);
1509 getSortByTimeAction().setChecked(true);
1510 getSortByTimeAction().setImageDescriptor(SORT_BY_TIME_REV_ICON
);
1514 private void saveSortOption(SortOption sortOption
) {
1515 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
1516 IDialogSettings section
= settings
.getSection(getClass().getName());
1517 if (section
== null) {
1518 section
= settings
.addNewSection(getClass().getName());
1520 section
.put(SORT_OPTION_KEY
, sortOption
.name());
1522 if (fEntryList
== null) {
1525 for (TraceEntry traceEntry
: fEntryList
) {
1526 traceEntry
.sortChildren(fThreadComparator
);
1532 * Toolbar icon to import the function address-to-name mapping binary file.
1534 private Action
getImportBinaryAction() {
1535 if (fImportBinaryFileMappingAction
!= null) {
1536 return fImportBinaryFileMappingAction
;
1539 fImportBinaryFileMappingAction
= new AbstractImportFileMappingAction(Messages
.CallStackView_ImportBinaryFileDialogTitle
) {
1541 Map
<String
, String
> doMapping(File file
) {
1542 return FunctionNameMapper
.mapFromBinaryFile(file
);
1546 fImportBinaryFileMappingAction
.setText(Messages
.CallStackView_ImportBinaryFileButtonText
);
1547 fImportBinaryFileMappingAction
.setToolTipText(Messages
.CallStackView_ImportBinaryFileButtonTooltip
);
1548 fImportBinaryFileMappingAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(IMPORT_BINARY_ICON_PATH
));
1550 return fImportBinaryFileMappingAction
;
1553 String
getFunctionName(String address
) {
1554 if (fNameMapping
== null) {
1555 /* No mapping available, just print the addresses */
1558 String ret
= fNameMapping
.get(address
);
1561 * We didn't find this address in the mapping file, just use the