1 /*******************************************************************************
2 * Copyright (c) 2013, 2016 Ericsson and others.
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
;
17 import java
.util
.ArrayList
;
18 import java
.util
.Collections
;
19 import java
.util
.Comparator
;
20 import java
.util
.HashMap
;
21 import java
.util
.Iterator
;
22 import java
.util
.List
;
24 import java
.util
.function
.Consumer
;
26 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
27 import org
.eclipse
.jdt
.annotation
.NonNull
;
28 import org
.eclipse
.jdt
.annotation
.Nullable
;
29 import org
.eclipse
.jface
.action
.Action
;
30 import org
.eclipse
.jface
.action
.GroupMarker
;
31 import org
.eclipse
.jface
.action
.IAction
;
32 import org
.eclipse
.jface
.action
.IMenuManager
;
33 import org
.eclipse
.jface
.action
.IToolBarManager
;
34 import org
.eclipse
.jface
.action
.Separator
;
35 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
36 import org
.eclipse
.jface
.dialogs
.IDialogSettings
;
37 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
38 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
39 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
40 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
41 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
42 import org
.eclipse
.jface
.viewers
.ISelection
;
43 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
44 import org
.eclipse
.swt
.SWT
;
45 import org
.eclipse
.swt
.events
.MouseAdapter
;
46 import org
.eclipse
.swt
.events
.MouseEvent
;
47 import org
.eclipse
.swt
.graphics
.Image
;
48 import org
.eclipse
.swt
.widgets
.Composite
;
49 import org
.eclipse
.swt
.widgets
.Display
;
50 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Activator
;
51 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.ITmfImageConstants
;
52 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.Messages
;
53 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
54 import org
.eclipse
.tracecompass
.statesystem
.core
.StateSystemUtils
;
55 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
56 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
57 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
58 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
59 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
60 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
61 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
.Type
;
62 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
63 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
64 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
65 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
66 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
67 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
68 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
69 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
70 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestampDelta
;
71 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
72 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.ITmfTraceEditor
;
74 import org
.eclipse
.tracecompass
.tmf
.ui
.symbols
.ISymbolProvider
;
75 import org
.eclipse
.tracecompass
.tmf
.ui
.symbols
.ISymbolProviderPreferencePage
;
76 import org
.eclipse
.tracecompass
.tmf
.ui
.symbols
.SymbolProviderConfigDialog
;
77 import org
.eclipse
.tracecompass
.tmf
.ui
.symbols
.SymbolProviderManager
;
78 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.timegraph
.AbstractTimeGraphView
;
79 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.ITimeGraphTimeListener
;
80 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphContentProvider
;
81 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphTimeEvent
;
82 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
83 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
84 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
85 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
86 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
87 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeGraphEntry
;
88 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphControl
;
89 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.widgets
.TimeGraphSelection
;
90 import org
.eclipse
.ui
.IEditorPart
;
91 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
94 * Main implementation for the Call Stack view
96 * @author Patrick Tasse
98 public class CallStackView
extends AbstractTimeGraphView
{
100 // ------------------------------------------------------------------------
102 // ------------------------------------------------------------------------
105 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.callstack"; //$NON-NLS-1$
107 private static final String
[] COLUMN_NAMES
= new String
[] {
108 Messages
.CallStackView_FunctionColumn
,
109 Messages
.CallStackView_DepthColumn
,
110 Messages
.CallStackView_EntryTimeColumn
,
111 Messages
.CallStackView_ExitTimeColumn
,
112 Messages
.CallStackView_DurationColumn
115 private static final String
[] FILTER_COLUMN_NAMES
= new String
[] {
116 Messages
.CallStackView_ThreadColumn
119 /** Timeout between updates in the build thread in ms */
120 private static final long BUILD_UPDATE_TIMEOUT
= 500;
122 // Fraction of a function duration to be added as spacing
123 private static final double SPACING_RATIO
= 0.01;
125 private static final Image PROCESS_IMAGE
= Activator
.getDefault().getImageFromPath("icons/obj16/process_obj.gif"); //$NON-NLS-1$
126 private static final Image THREAD_IMAGE
= Activator
.getDefault().getImageFromPath("icons/obj16/thread_obj.gif"); //$NON-NLS-1$
127 private static final Image STACKFRAME_IMAGE
= Activator
.getDefault().getImageFromPath("icons/obj16/stckframe_obj.gif"); //$NON-NLS-1$
129 private static final String IMPORT_BINARY_ICON_PATH
= "icons/obj16/binaries_obj.gif"; //$NON-NLS-1$
131 private static final ImageDescriptor SORT_BY_NAME_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_alpha.gif"); //$NON-NLS-1$
132 private static final ImageDescriptor SORT_BY_NAME_REV_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_alpha_rev.gif"); //$NON-NLS-1$
133 private static final ImageDescriptor SORT_BY_ID_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_num.gif"); //$NON-NLS-1$
134 private static final ImageDescriptor SORT_BY_ID_REV_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_num_rev.gif"); //$NON-NLS-1$
135 private static final ImageDescriptor SORT_BY_TIME_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_time.gif"); //$NON-NLS-1$
136 private static final ImageDescriptor SORT_BY_TIME_REV_ICON
= Activator
.getDefault().getImageDescripterFromPath("icons/etool16/sort_time_rev.gif"); //$NON-NLS-1$
137 private static final String SORT_OPTION_KEY
= "sort.option"; //$NON-NLS-1$
139 private enum SortOption
{
140 BY_NAME
, BY_NAME_REV
, BY_ID
, BY_ID_REV
, BY_TIME
, BY_TIME_REV
143 private @NonNull SortOption fSortOption
= SortOption
.BY_NAME
;
144 private @NonNull Comparator
<ITimeGraphEntry
> fThreadComparator
= new ThreadNameComparator(false);
145 private Action fSortByNameAction
;
146 private Action fSortByIdAction
;
147 private Action fSortByTimeAction
;
149 // ------------------------------------------------------------------------
151 // ------------------------------------------------------------------------
153 private final Map
<ITmfTrace
, ISymbolProvider
> fSymbolProviders
= new HashMap
<>();
155 // The next event action
156 private Action fNextEventAction
;
158 // The previous event action
159 private Action fPrevEventAction
;
161 // The next item action
162 private Action fNextItemAction
;
164 // The previous item action
165 private Action fPreviousItemAction
;
167 // The action to import a binary file mapping */
168 private Action fConfigureSymbolsAction
;
170 // The saved time sync. signal used when switching off the pinning of a view
171 private TmfSelectionRangeUpdatedSignal fSavedTimeSyncSignal
;
173 // The saved window range signal used when switching off the pinning of
175 private TmfWindowRangeUpdatedSignal fSavedRangeSyncSignal
;
177 // When set to true, syncToTime() will select the first call stack entry
178 // whose current state start time exactly matches the sync time.
179 private boolean fSyncSelection
= false;
181 // ------------------------------------------------------------------------
183 // ------------------------------------------------------------------------
185 private static class TraceEntry
extends TimeGraphEntry
{
186 public TraceEntry(String name
, long startTime
, long endTime
) {
187 super(name
, startTime
, endTime
);
191 public boolean hasTimeEvents() {
196 private static class ProcessEntry
extends TimeGraphEntry
{
198 private final int fProcessId
;
200 public ProcessEntry(String name
, int processId
, long startTime
, long endTime
) {
201 super(name
, startTime
, endTime
);
202 fProcessId
= processId
;
206 public boolean hasTimeEvents() {
211 private static class ThreadEntry
extends TimeGraphEntry
{
213 private final long fThreadId
;
215 public ThreadEntry(String name
, long threadId
, long startTime
, long endTime
) {
216 super(name
, startTime
, endTime
);
217 fThreadId
= threadId
;
221 public boolean hasTimeEvents() {
225 public long getThreadId() {
230 private class CallStackComparator
implements Comparator
<ITimeGraphEntry
> {
232 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
233 if (o1
instanceof ThreadEntry
&& o2
instanceof ThreadEntry
) {
234 return fThreadComparator
.compare(o1
, o2
);
235 } else if (o1
instanceof ProcessEntry
&& o2
instanceof ProcessEntry
) {
236 return Integer
.compare(((ProcessEntry
) o1
).fProcessId
, ((ProcessEntry
) o2
).fProcessId
);
242 private static class ThreadNameComparator
implements Comparator
<ITimeGraphEntry
> {
243 private boolean reverse
;
245 public ThreadNameComparator(boolean reverse
) {
246 this.reverse
= reverse
;
250 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
251 return reverse ? o2
.getName().compareTo(o1
.getName()) :
252 o1
.getName().compareTo(o2
.getName());
256 private static class ThreadIdComparator
implements Comparator
<ITimeGraphEntry
> {
257 private boolean reverse
;
259 public ThreadIdComparator(boolean reverse
) {
260 this.reverse
= reverse
;
264 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
265 if (o1
instanceof ThreadEntry
&& o2
instanceof ThreadEntry
) {
266 ThreadEntry t1
= (ThreadEntry
) o1
;
267 ThreadEntry t2
= (ThreadEntry
) o2
;
268 return reverse ? Long
.compare(t2
.getThreadId(), t1
.getThreadId()) :
269 Long
.compare(t1
.getThreadId(), t2
.getThreadId());
275 private static class ThreadTimeComparator
implements Comparator
<ITimeGraphEntry
> {
276 private boolean reverse
;
278 public ThreadTimeComparator(boolean reverse
) {
279 this.reverse
= reverse
;
283 public int compare(ITimeGraphEntry o1
, ITimeGraphEntry o2
) {
284 return reverse ? Long
.compare(o2
.getStartTime(), o1
.getStartTime()) :
285 Long
.compare(o1
.getStartTime(), o2
.getStartTime());
289 private static class CallStackTreeLabelProvider
extends TreeLabelProvider
{
292 public Image
getColumnImage(Object element
, int columnIndex
) {
293 if (columnIndex
== 0) {
294 if (element
instanceof ProcessEntry
) {
295 return PROCESS_IMAGE
;
296 } else if (element
instanceof ThreadEntry
) {
298 } else if (element
instanceof CallStackEntry
) {
299 CallStackEntry entry
= (CallStackEntry
) element
;
300 if (entry
.getFunctionName().length() > 0) {
301 return STACKFRAME_IMAGE
;
309 public String
getColumnText(Object element
, int columnIndex
) {
310 if (element
instanceof CallStackEntry
) {
311 CallStackEntry entry
= (CallStackEntry
) element
;
312 if (columnIndex
== 0) {
313 return entry
.getFunctionName();
314 } else if (columnIndex
== 1 && entry
.getFunctionName().length() > 0) {
315 int depth
= entry
.getStackLevel();
316 return Integer
.toString(depth
);
317 } else if (columnIndex
== 2 && entry
.getFunctionName().length() > 0) {
318 ITmfTimestamp ts
= TmfTimestamp
.fromNanos(entry
.getFunctionEntryTime());
319 return ts
.toString();
320 } else if (columnIndex
== 3 && entry
.getFunctionName().length() > 0) {
321 ITmfTimestamp ts
= TmfTimestamp
.fromNanos(entry
.getFunctionExitTime());
322 return ts
.toString();
323 } else if (columnIndex
== 4 && entry
.getFunctionName().length() > 0) {
324 ITmfTimestamp ts
= new TmfTimestampDelta(entry
.getFunctionExitTime() - entry
.getFunctionEntryTime(), ITmfTimestamp
.NANOSECOND_SCALE
);
325 return ts
.toString();
327 } else if (element
instanceof ITimeGraphEntry
) {
328 if (columnIndex
== 0) {
329 return ((ITimeGraphEntry
) element
).getName();
332 return ""; //$NON-NLS-1$
337 private class CallStackFilterContentProvider
extends TimeGraphContentProvider
{
339 public boolean hasChildren(Object element
) {
340 if (element
instanceof TraceEntry
) {
341 return super.hasChildren(element
);
347 public ITimeGraphEntry
[] getChildren(Object parentElement
) {
348 if (parentElement
instanceof TraceEntry
) {
349 return super.getChildren(parentElement
);
351 return new ITimeGraphEntry
[0];
355 // ------------------------------------------------------------------------
357 // ------------------------------------------------------------------------
360 * Default constructor
362 public CallStackView() {
363 super(ID
, new CallStackPresentationProvider());
364 ((CallStackPresentationProvider
) getPresentationProvider()).setCallStackView(this);
365 setTreeColumns(COLUMN_NAMES
);
366 setTreeLabelProvider(new CallStackTreeLabelProvider());
367 setEntryComparator(new CallStackComparator());
368 setFilterColumns(FILTER_COLUMN_NAMES
);
369 setFilterContentProvider(new CallStackFilterContentProvider());
370 setFilterLabelProvider(new CallStackTreeLabelProvider());
373 // ------------------------------------------------------------------------
375 // ------------------------------------------------------------------------
378 public void createPartControl(Composite parent
) {
379 super.createPartControl(parent
);
381 getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
383 public void timeSelected(TimeGraphTimeEvent event
) {
384 synchingToTime(event
.getBeginTime());
388 getTimeGraphCombo().getTreeViewer().addDoubleClickListener(new IDoubleClickListener() {
390 public void doubleClick(DoubleClickEvent event
) {
391 Object selection
= ((IStructuredSelection
) event
.getSelection()).getFirstElement();
392 if (selection
instanceof CallStackEntry
) {
393 CallStackEntry entry
= (CallStackEntry
) selection
;
394 if (entry
.getFunctionName().length() > 0) {
395 long entryTime
= entry
.getFunctionEntryTime();
396 long exitTime
= entry
.getFunctionExitTime();
397 long spacingTime
= (long) ((exitTime
- entryTime
) * SPACING_RATIO
);
398 entryTime
-= spacingTime
;
399 exitTime
+= spacingTime
;
400 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.fromNanos(entryTime
), TmfTimestamp
.fromNanos(exitTime
));
401 broadcast(new TmfWindowRangeUpdatedSignal(CallStackView
.this, range
));
402 getTimeGraphViewer().setStartFinishTime(entryTime
, exitTime
);
403 startZoomThread(entryTime
, exitTime
);
409 getTimeGraphViewer().getTimeGraphControl().addMouseListener(new MouseAdapter() {
411 public void mouseDoubleClick(MouseEvent e
) {
412 TimeGraphControl timeGraphControl
= getTimeGraphViewer().getTimeGraphControl();
413 ISelection selection
= timeGraphControl
.getSelection();
414 if (selection
instanceof TimeGraphSelection
) {
415 Object o
= ((TimeGraphSelection
) selection
).getFirstElement();
416 if (o
instanceof CallStackEvent
) {
417 CallStackEvent event
= (CallStackEvent
) o
;
418 long startTime
= event
.getTime();
419 long endTime
= startTime
+ event
.getDuration();
420 long spacingTime
= (long) ((endTime
- startTime
) * SPACING_RATIO
);
421 startTime
-= spacingTime
;
422 endTime
+= spacingTime
;
423 TmfTimeRange range
= new TmfTimeRange(TmfTimestamp
.fromNanos(startTime
), TmfTimestamp
.fromNanos(endTime
));
424 broadcast(new TmfWindowRangeUpdatedSignal(CallStackView
.this, range
));
425 getTimeGraphViewer().setStartFinishTime(startTime
, endTime
);
426 startZoomThread(startTime
, endTime
);
432 contributeToActionBars();
435 IEditorPart editor
= getSite().getPage().getActiveEditor();
436 if (editor
instanceof ITmfTraceEditor
) {
437 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
439 traceSelected(new TmfTraceSelectedSignal(this, trace
));
445 * Handler for the selection range signal.
448 * The incoming signal
453 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
455 fSavedTimeSyncSignal
= isPinned() ?
new TmfSelectionRangeUpdatedSignal(signal
.getSource(), signal
.getBeginTime(), signal
.getEndTime()) : null;
457 if (signal
.getSource() == this || getTrace() == null || isPinned()) {
460 final long beginTime
= signal
.getBeginTime().toNanos();
461 final long endTime
= signal
.getEndTime().toNanos();
462 Display
.getDefault().asyncExec(new Runnable() {
465 if (getTimeGraphCombo().isDisposed()) {
468 if (beginTime
== endTime
) {
469 getTimeGraphViewer().setSelectedTime(beginTime
, true);
471 getTimeGraphViewer().setSelectionRange(beginTime
, endTime
, true);
473 fSyncSelection
= true;
474 synchingToTime(beginTime
);
475 fSyncSelection
= false;
476 startZoomThread(getTimeGraphViewer().getTime0(), getTimeGraphViewer().getTime1());
487 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal
) {
490 fSavedRangeSyncSignal
= new TmfWindowRangeUpdatedSignal(signal
.getSource(), signal
.getCurrentRange());
491 fSavedTimeSyncSignal
= null;
494 if ((signal
.getSource() == this) || isPinned()) {
497 super.windowRangeUpdated(signal
);
500 // ------------------------------------------------------------------------
502 // ------------------------------------------------------------------------
506 public void traceClosed(TmfTraceClosedSignal signal
) {
507 super.traceClosed(signal
);
508 synchronized(fSymbolProviders
){
509 for(ITmfTrace trace
: getTracesToBuild(signal
.getTrace())){
510 fSymbolProviders
.remove(trace
);
519 protected void refresh() {
521 updateConfigureSymbolsAction();
525 protected void buildEntryList(final ITmfTrace trace
, final ITmfTrace parentTrace
, final IProgressMonitor monitor
) {
526 if (monitor
.isCanceled()) {
531 * Load the symbol provider for the current trace, even if it does not
532 * provide a call stack analysis module. See
533 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=494212
535 ISymbolProvider provider
= fSymbolProviders
.get(trace
);
536 if (provider
== null) {
537 provider
= SymbolProviderManager
.getInstance().getSymbolProvider(trace
);
538 provider
.loadConfiguration(null);
539 fSymbolProviders
.put(trace
, provider
);
542 /* Continue with the call stack view specific operations */
543 AbstractCallStackAnalysis module
= getCallStackModule(trace
);
544 if (module
== null) {
545 addUnavailableEntry(trace
, parentTrace
);
548 ITmfStateSystem ss
= module
.getStateSystem();
550 addUnavailableEntry(trace
, parentTrace
);
554 Map
<ITmfTrace
, TraceEntry
> traceEntryMap
= new HashMap
<>();
555 Map
<Integer
, ProcessEntry
> processEntryMap
= new HashMap
<>();
556 Map
<Integer
, ThreadEntry
> threadEntryMap
= new HashMap
<>();
558 long start
= ss
.getStartTime();
560 boolean complete
= false;
562 if (monitor
.isCanceled()) {
565 complete
= ss
.waitUntilBuilt(BUILD_UPDATE_TIMEOUT
);
566 if (ss
.isCancelled()) {
569 long end
= ss
.getCurrentEndTime();
570 if (start
== end
&& !complete
) { // when complete execute one last time regardless of end time
574 TraceEntry traceEntry
= traceEntryMap
.get(trace
);
575 if (traceEntry
== null) {
576 traceEntry
= new TraceEntry(trace
.getName(), start
, end
+ 1);
577 traceEntryMap
.put(trace
, traceEntry
);
578 traceEntry
.sortChildren(fThreadComparator
);
579 addToEntryList(parentTrace
, Collections
.singletonList(traceEntry
));
581 traceEntry
.updateEndTime(end
);
585 List
<ITmfStateInterval
> endStates
= ss
.queryFullState(ss
.getCurrentEndTime());
587 List
<Integer
> processQuarks
= ss
.getQuarks(module
.getProcessesPattern());
588 for (int processQuark
: processQuarks
) {
591 * Default to trace entry, overwrite if a process entry exists.
593 TimeGraphEntry threadParent
= traceEntry
;
595 if (processQuark
!= ITmfStateSystem
.ROOT_ATTRIBUTE
) {
596 /* Create the entry for the process */
597 ProcessEntry processEntry
= processEntryMap
.get(processQuark
);
598 if (processEntry
== null) {
599 String processName
= ss
.getAttributeName(processQuark
);
600 ITmfStateValue processStateValue
= endStates
.get(processQuark
).getStateValue();
601 if (processStateValue
.getType() == Type
.INTEGER
) {
602 processId
= processStateValue
.unboxInt();
605 processId
= Integer
.parseInt(processName
);
606 } catch (NumberFormatException e
) {
607 /* use default processId */
610 processEntry
= new ProcessEntry(processName
, processId
, start
, end
);
611 processEntryMap
.put(processQuark
, processEntry
);
612 traceEntry
.addChild(processEntry
);
614 processEntry
.updateEndTime(end
);
616 /* The parent of the thread entries will be a process */
617 threadParent
= processEntry
;
620 /* Create the threads under the process */
621 List
<Integer
> threadQuarks
= ss
.getQuarks(processQuark
, module
.getThreadsPattern());
624 * Only query startStates if necessary (threadEntry == null)
626 List
<ITmfStateInterval
> startStates
= null;
627 for (int threadQuark
: threadQuarks
) {
628 if (monitor
.isCanceled()) {
632 String
[] callStackPath
= module
.getCallStackPath();
633 int callStackQuark
= ss
.getQuarkRelative(threadQuark
, callStackPath
);
634 String threadName
= ss
.getAttributeName(threadQuark
);
635 long threadEnd
= end
+ 1;
636 ITmfStateInterval endInterval
= endStates
.get(callStackQuark
);
637 if (endInterval
.getStateValue().isNull() && endInterval
.getStartTime() != ss
.getStartTime()) {
638 threadEnd
= endInterval
.getStartTime();
641 * Default to process/trace entry, overwrite if a thread entry exists.
643 TimeGraphEntry callStackParent
= threadParent
;
644 if (threadQuark
!= processQuark
) {
645 ThreadEntry threadEntry
= threadEntryMap
.get(threadQuark
);
646 if (threadEntry
== null) {
647 if (startStates
== null) {
648 startStates
= ss
.queryFullState(ss
.getStartTime());
651 ITmfStateValue threadStateValue
= endStates
.get(threadQuark
).getStateValue();
652 if (threadStateValue
.getType() == Type
.LONG
|| threadStateValue
.getType() == Type
.INTEGER
) {
653 threadId
= threadStateValue
.unboxLong();
656 threadId
= Long
.parseLong(threadName
);
657 } catch (NumberFormatException e
) {
658 /* use default threadId */
661 long threadStart
= start
;
662 ITmfStateInterval startInterval
= startStates
.get(callStackQuark
);
663 if (startInterval
.getStateValue().isNull()) {
664 threadStart
= Math
.min(startInterval
.getEndTime() + 1, end
+ 1);
666 threadEntry
= new ThreadEntry(threadName
, threadId
, threadStart
, threadEnd
);
667 threadEntryMap
.put(threadQuark
, threadEntry
);
668 threadParent
.addChild(threadEntry
);
670 threadEntry
.updateEndTime(threadEnd
);
672 /* The parent of the call stack entries will be a thread */
673 callStackParent
= threadEntry
;
676 for (int stackLevelQuark
: ss
.getSubAttributes(callStackQuark
, false)) {
677 if (level
> callStackParent
.getChildren().size()) {
678 CallStackEntry callStackEntry
= new CallStackEntry(threadName
, stackLevelQuark
, level
, processId
, trace
, ss
);
679 callStackParent
.addChild(callStackEntry
);
685 } catch (AttributeNotFoundException e
) {
686 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
687 } catch (StateSystemDisposedException e
) {
691 if (parentTrace
== getTrace()) {
692 synchronized (this) {
693 setStartTime(getStartTime() == SWT
.DEFAULT ? start
: Math
.min(getStartTime(), start
));
694 setEndTime(getEndTime() == SWT
.DEFAULT ? end
+ 1 : Math
.max(getEndTime(), end
+ 1));
696 synchingToTime(getTimeGraphViewer().getSelectionBegin());
700 Consumer
<TimeGraphEntry
> consumer
= new Consumer
<TimeGraphEntry
>() {
702 public void accept(TimeGraphEntry entry
) {
703 if (monitor
.isCanceled()) {
706 if (entry
instanceof CallStackEntry
) {
707 buildStatusEvents(parentTrace
, (CallStackEntry
) entry
, monitor
, ss
.getStartTime(), end
);
710 entry
.getChildren().forEach(this);
713 traceEntry
.getChildren().forEach(consumer
);
719 private void addUnavailableEntry(ITmfTrace trace
, ITmfTrace parentTrace
) {
720 String name
= Messages
.CallStackView_StackInfoNotAvailable
+ ' ' + '(' + trace
.getName() + ')';
721 TraceEntry unavailableEntry
= new TraceEntry(name
, 0, 0);
722 addToEntryList(parentTrace
, Collections
.singletonList(unavailableEntry
));
723 if (parentTrace
== getTrace()) {
728 private void buildStatusEvents(ITmfTrace trace
, CallStackEntry entry
, @NonNull IProgressMonitor monitor
, long start
, long end
) {
729 ITmfStateSystem ss
= entry
.getStateSystem();
730 long resolution
= Math
.max(1, (end
- ss
.getStartTime()) / getDisplayWidth());
731 List
<ITimeEvent
> eventList
= getEventList(entry
, start
, end
+ 1, resolution
, monitor
);
732 if (eventList
!= null) {
733 entry
.setEventList(eventList
);
735 if (trace
== getTrace()) {
744 protected final List
<ITimeEvent
> getEventList(TimeGraphEntry tgentry
, long startTime
, long endTime
, long resolution
, IProgressMonitor monitor
) {
745 if (!(tgentry
instanceof CallStackEntry
)) {
748 CallStackEntry entry
= (CallStackEntry
) tgentry
;
749 ITmfStateSystem ss
= entry
.getStateSystem();
750 long start
= Math
.max(startTime
, ss
.getStartTime());
751 long end
= Math
.min(endTime
, ss
.getCurrentEndTime() + 1);
755 boolean isZoomThread
= Thread
.currentThread() instanceof ZoomThread
;
756 List
<ITimeEvent
> eventList
= null;
758 List
<ITmfStateInterval
> stackIntervals
= StateSystemUtils
.queryHistoryRange(ss
, entry
.getQuark(), start
, end
- 1, resolution
, monitor
);
759 eventList
= new ArrayList
<>(stackIntervals
.size());
760 long lastEndTime
= -1;
761 boolean lastIsNull
= false;
762 for (ITmfStateInterval statusInterval
: stackIntervals
) {
763 if (monitor
.isCanceled()) {
766 long time
= statusInterval
.getStartTime();
767 long duration
= statusInterval
.getEndTime() - time
+ 1;
768 if (!statusInterval
.getStateValue().isNull()) {
769 final int modulo
= CallStackPresentationProvider
.NUM_COLORS
/ 2;
770 int value
= statusInterval
.getStateValue().toString().hashCode() % modulo
+ modulo
;
771 eventList
.add(new CallStackEvent(entry
, time
, duration
, value
));
774 if (lastEndTime
== -1 && isZoomThread
) {
775 // add null event if it intersects the start time
776 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
778 if (lastEndTime
!= time
&& lastIsNull
) {
779 // add unknown event if between two null states
780 eventList
.add(new TimeEvent(entry
, lastEndTime
, time
- lastEndTime
));
782 if (time
+ duration
>= endTime
&& isZoomThread
) {
783 // add null event if it intersects the end time
784 eventList
.add(new NullTimeEvent(entry
, time
, duration
));
789 lastEndTime
= time
+ duration
;
791 } catch (AttributeNotFoundException e
) {
792 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
793 } catch (TimeRangeException e
) {
794 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
795 } catch (StateSystemDisposedException e
) {
805 protected void synchingToTime(final long time
) {
806 List
<TimeGraphEntry
> traceEntries
= getEntryList(getTrace());
807 Map
<ITmfStateSystem
, List
<ITmfStateInterval
>> fullStateMap
= new HashMap
<>();
808 if (traceEntries
== null) {
811 Consumer
<TimeGraphEntry
> consumer
= new Consumer
<TimeGraphEntry
>() {
813 public void accept(TimeGraphEntry entry
) {
814 if (entry
instanceof CallStackEntry
) {
815 CallStackEntry callStackEntry
= (CallStackEntry
) entry
;
816 ITmfStateSystem ss
= callStackEntry
.getStateSystem();
817 if (time
< ss
.getStartTime() || time
> ss
.getCurrentEndTime()) {
820 ITmfTrace trace
= callStackEntry
.getTrace();
822 List
<ITmfStateInterval
> fullState
= getFullState(ss
);
823 ITmfStateInterval stackLevelInterval
= fullState
.get(callStackEntry
.getQuark());
824 ITmfStateValue nameValue
= stackLevelInterval
.getStateValue();
826 String name
= getFunctionName(trace
, callStackEntry
.getProcessId(), time
, nameValue
);
827 callStackEntry
.setFunctionName(name
);
828 if (!name
.isEmpty()) {
829 callStackEntry
.setFunctionEntryTime(stackLevelInterval
.getStartTime());
830 callStackEntry
.setFunctionExitTime(stackLevelInterval
.getEndTime() + 1);
832 if (fSyncSelection
) {
833 int callStackQuark
= ss
.getParentAttributeQuark(callStackEntry
.getQuark());
834 ITmfStateInterval stackInterval
= fullState
.get(callStackQuark
);
835 if (time
== stackInterval
.getStartTime()) {
836 ITmfStateValue stackLevelState
= stackInterval
.getStateValue();
837 if (stackLevelState
.unboxInt() == callStackEntry
.getStackLevel() || stackLevelState
.isNull()) {
838 Display
.getDefault().asyncExec(() -> {
839 getTimeGraphCombo().setSelection(callStackEntry
);
840 getTimeGraphViewer().getTimeGraphControl().fireSelectionChanged();
841 fSyncSelection
= false;
846 } catch (StateSystemDisposedException e
) {
851 entry
.getChildren().forEach(this);
854 private List
<ITmfStateInterval
> getFullState(ITmfStateSystem ss
) throws StateSystemDisposedException
{
855 List
<ITmfStateInterval
> fullState
= fullStateMap
.get(ss
);
856 if (fullState
== null) {
857 fullState
= ss
.queryFullState(time
);
858 fullStateMap
.put(ss
, fullState
);
863 traceEntries
.forEach(consumer
);
864 if (Display
.getCurrent() != null) {
865 getTimeGraphCombo().refresh();
869 String
getFunctionName(ITmfTrace trace
, int processId
, long timestamp
, ITmfStateValue nameValue
) {
870 long address
= Long
.MAX_VALUE
;
871 String name
= ""; //$NON-NLS-1$
873 if (nameValue
.getType() == Type
.STRING
) {
874 name
= nameValue
.unboxStr();
876 address
= Long
.parseLong(name
, 16);
877 } catch (NumberFormatException e
) {
880 } else if (nameValue
.getType() == Type
.INTEGER
) {
881 name
= "0x" + Integer
.toUnsignedString(nameValue
.unboxInt(), 16); //$NON-NLS-1$
882 address
= nameValue
.unboxInt();
883 } else if (nameValue
.getType() == Type
.LONG
) {
884 name
= "0x" + Long
.toUnsignedString(nameValue
.unboxLong(), 16); //$NON-NLS-1$
885 address
= nameValue
.unboxLong();
887 } catch (StateValueTypeException e
) {
889 if (address
!= Long
.MAX_VALUE
) {
890 ISymbolProvider provider
= fSymbolProviders
.get(trace
);
891 if (provider
!= null) {
892 String symbol
= provider
.getSymbolText(processId
, timestamp
, address
);
893 if (symbol
!= null) {
901 private void makeActions() {
902 fPreviousItemAction
= getTimeGraphViewer().getPreviousItemAction();
903 fPreviousItemAction
.setText(Messages
.TmfTimeGraphViewer_PreviousItemActionNameText
);
904 fPreviousItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousItemActionToolTipText
);
905 fNextItemAction
= getTimeGraphViewer().getNextItemAction();
906 fNextItemAction
.setText(Messages
.TmfTimeGraphViewer_NextItemActionNameText
);
907 fNextItemAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextItemActionToolTipText
);
910 private void contributeToActionBars() {
912 contributePinActionToToolBar();
913 fPinAction
.addPropertyChangeListener(new IPropertyChangeListener() {
915 public void propertyChange(PropertyChangeEvent event
) {
916 if (IAction
.CHECKED
.equals(event
.getProperty()) && !isPinned()) {
917 if (fSavedRangeSyncSignal
!= null) {
918 windowRangeUpdated(fSavedRangeSyncSignal
);
919 fSavedRangeSyncSignal
= null;
922 if (fSavedTimeSyncSignal
!= null) {
923 selectionRangeUpdated(fSavedTimeSyncSignal
);
924 fSavedTimeSyncSignal
= null;
935 protected void fillLocalToolBar(IToolBarManager manager
) {
937 manager
.add(getConfigureSymbolsAction());
938 manager
.add(new Separator());
939 manager
.add(getSortByNameAction());
940 manager
.add(getSortByIdAction());
941 manager
.add(getSortByTimeAction());
942 manager
.add(new Separator());
943 manager
.add(getTimeGraphCombo().getShowFilterDialogAction());
944 manager
.add(new Separator());
945 manager
.add(getTimeGraphViewer().getResetScaleAction());
946 manager
.add(getPreviousEventAction());
947 manager
.add(getNextEventAction());
948 manager
.add(new Separator());
949 manager
.add(getTimeGraphViewer().getToggleBookmarkAction());
950 manager
.add(getTimeGraphViewer().getPreviousMarkerAction());
951 manager
.add(getTimeGraphViewer().getNextMarkerAction());
952 manager
.add(new Separator());
953 manager
.add(fPreviousItemAction
);
954 manager
.add(fNextItemAction
);
955 manager
.add(getTimeGraphViewer().getZoomInAction());
956 manager
.add(getTimeGraphViewer().getZoomOutAction());
963 protected void fillTimeGraphEntryContextMenu(IMenuManager contextMenu
) {
964 contextMenu
.add(new GroupMarker(IWorkbenchActionConstants
.GROUP_REORGANIZE
));
965 contextMenu
.add(getSortByNameAction());
966 contextMenu
.add(getSortByIdAction());
967 contextMenu
.add(getSortByTimeAction());
971 * Get the the next event action.
973 * @return The action object
975 private Action
getNextEventAction() {
976 if (fNextEventAction
== null) {
977 fNextEventAction
= new Action() {
980 TimeGraphViewer viewer
= getTimeGraphViewer();
981 ITimeGraphEntry entry
= viewer
.getSelection();
982 if (entry
instanceof CallStackEntry
) {
984 CallStackEntry callStackEntry
= (CallStackEntry
) entry
;
985 ITmfStateSystem ss
= callStackEntry
.getStateSystem();
986 long time
= Math
.max(ss
.getStartTime(), Math
.min(ss
.getCurrentEndTime(), viewer
.getSelectionBegin()));
987 ThreadEntry threadEntry
= (ThreadEntry
) callStackEntry
.getParent();
988 int quark
= ss
.getParentAttributeQuark(callStackEntry
.getQuark());
989 ITmfStateInterval stackInterval
= ss
.querySingleState(time
, quark
);
990 long newTime
= stackInterval
.getEndTime() + 1;
991 viewer
.setSelectedTimeNotify(newTime
, true);
992 stackInterval
= ss
.querySingleState(Math
.min(ss
.getCurrentEndTime(), newTime
), quark
);
993 int stackLevel
= stackInterval
.getStateValue().unboxInt();
994 ITimeGraphEntry selectedEntry
= threadEntry
.getChildren().get(Math
.max(0, stackLevel
- 1));
995 getTimeGraphCombo().setSelection(selectedEntry
);
996 viewer
.getTimeGraphControl().fireSelectionChanged();
997 startZoomThread(viewer
.getTime0(), viewer
.getTime1());
999 } catch (TimeRangeException
| StateSystemDisposedException
| StateValueTypeException e
) {
1000 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
1006 fNextEventAction
.setText(Messages
.TmfTimeGraphViewer_NextStateChangeActionNameText
);
1007 fNextEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_NextStateChangeActionToolTipText
);
1008 fNextEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_NEXT_STATE_CHANGE
));
1011 return fNextEventAction
;
1015 * Get the previous event action.
1017 * @return The Action object
1019 private Action
getPreviousEventAction() {
1020 if (fPrevEventAction
== null) {
1021 fPrevEventAction
= new Action() {
1024 TimeGraphViewer viewer
= getTimeGraphCombo().getTimeGraphViewer();
1025 ITimeGraphEntry entry
= viewer
.getSelection();
1026 if (entry
instanceof CallStackEntry
) {
1028 CallStackEntry callStackEntry
= (CallStackEntry
) entry
;
1029 ITmfStateSystem ss
= callStackEntry
.getStateSystem();
1030 long time
= Math
.max(ss
.getStartTime(), Math
.min(ss
.getCurrentEndTime(), viewer
.getSelectionBegin()));
1031 ThreadEntry threadEntry
= (ThreadEntry
) callStackEntry
.getParent();
1032 int quark
= ss
.getParentAttributeQuark(callStackEntry
.getQuark());
1033 ITmfStateInterval stackInterval
= ss
.querySingleState(time
, quark
);
1034 if (stackInterval
.getStartTime() == time
&& time
> ss
.getStartTime()) {
1035 stackInterval
= ss
.querySingleState(time
- 1, quark
);
1037 viewer
.setSelectedTimeNotify(stackInterval
.getStartTime(), true);
1038 int stackLevel
= stackInterval
.getStateValue().unboxInt();
1039 ITimeGraphEntry selectedEntry
= threadEntry
.getChildren().get(Math
.max(0, stackLevel
- 1));
1040 getTimeGraphCombo().setSelection(selectedEntry
);
1041 viewer
.getTimeGraphControl().fireSelectionChanged();
1042 startZoomThread(viewer
.getTime0(), viewer
.getTime1());
1044 } catch (TimeRangeException
| StateSystemDisposedException
| StateValueTypeException e
) {
1045 Activator
.getDefault().logError("Error querying state system", e
); //$NON-NLS-1$
1051 fPrevEventAction
.setText(Messages
.TmfTimeGraphViewer_PreviousStateChangeActionNameText
);
1052 fPrevEventAction
.setToolTipText(Messages
.TmfTimeGraphViewer_PreviousStateChangeActionToolTipText
);
1053 fPrevEventAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(ITmfImageConstants
.IMG_UI_PREV_STATE_CHANGE
));
1056 return fPrevEventAction
;
1059 private static @Nullable AbstractCallStackAnalysis
getCallStackModule(@NonNull ITmfTrace trace
) {
1061 * Since we cannot know the exact analysis ID (in separate plugins), we
1062 * will search using the analysis type.
1064 Iterable
<AbstractCallStackAnalysis
> modules
=
1065 TmfTraceUtils
.getAnalysisModulesOfClass(trace
, AbstractCallStackAnalysis
.class);
1066 Iterator
<AbstractCallStackAnalysis
> it
= modules
.iterator();
1067 if (!it
.hasNext()) {
1068 /* This trace does not provide a call-stack analysis */
1073 * We only look at the first module we find.
1075 * TODO Handle the advanced case where one trace provides more than one
1076 * call-stack analysis.
1078 AbstractCallStackAnalysis module
= it
.next();
1079 /* This analysis is not automatic, we need to schedule it on-demand */
1081 if (!module
.waitForInitialization()) {
1082 /* The initialization did not succeed */
1088 // ------------------------------------------------------------------------
1089 // Methods related to function name mapping
1090 // ------------------------------------------------------------------------
1092 private Action
getSortByNameAction() {
1093 if (fSortByNameAction
== null) {
1094 fSortByNameAction
= new Action(Messages
.CallStackView_SortByThreadName
, IAction
.AS_CHECK_BOX
) {
1097 if (fSortOption
== SortOption
.BY_NAME
) {
1098 saveSortOption(SortOption
.BY_NAME_REV
);
1100 saveSortOption(SortOption
.BY_NAME
);
1104 fSortByNameAction
.setToolTipText(Messages
.CallStackView_SortByThreadName
);
1105 fSortByNameAction
.setImageDescriptor(SORT_BY_NAME_ICON
);
1107 return fSortByNameAction
;
1110 private Action
getSortByIdAction() {
1111 if (fSortByIdAction
== null) {
1112 fSortByIdAction
= new Action(Messages
.CallStackView_SortByThreadId
, IAction
.AS_CHECK_BOX
) {
1115 if (fSortOption
== SortOption
.BY_ID
) {
1116 saveSortOption(SortOption
.BY_ID_REV
);
1118 saveSortOption(SortOption
.BY_ID
);
1122 fSortByIdAction
.setToolTipText(Messages
.CallStackView_SortByThreadId
);
1123 fSortByIdAction
.setImageDescriptor(SORT_BY_ID_ICON
);
1125 return fSortByIdAction
;
1128 private Action
getSortByTimeAction() {
1129 if (fSortByTimeAction
== null) {
1130 fSortByTimeAction
= new Action(Messages
.CallStackView_SortByThreadTime
, IAction
.AS_CHECK_BOX
) {
1133 if (fSortOption
== SortOption
.BY_TIME
) {
1134 saveSortOption(SortOption
.BY_TIME_REV
);
1136 saveSortOption(SortOption
.BY_TIME
);
1140 fSortByTimeAction
.setToolTipText(Messages
.CallStackView_SortByThreadTime
);
1141 fSortByTimeAction
.setImageDescriptor(SORT_BY_TIME_ICON
);
1143 return fSortByTimeAction
;
1146 private void loadSortOption() {
1147 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
1148 IDialogSettings section
= settings
.getSection(getClass().getName());
1149 if (section
== null) {
1152 String sortOption
= section
.get(SORT_OPTION_KEY
);
1153 if (sortOption
== null) {
1158 getSortByNameAction().setChecked(false);
1159 getSortByNameAction().setImageDescriptor(SORT_BY_NAME_ICON
);
1160 getSortByIdAction().setChecked(false);
1161 getSortByIdAction().setImageDescriptor(SORT_BY_ID_ICON
);
1162 getSortByTimeAction().setChecked(false);
1163 getSortByTimeAction().setImageDescriptor(SORT_BY_TIME_ICON
);
1165 if (sortOption
.equals(SortOption
.BY_NAME
.name())) {
1166 fSortOption
= SortOption
.BY_NAME
;
1167 fThreadComparator
= new ThreadNameComparator(false);
1168 getSortByNameAction().setChecked(true);
1169 } else if (sortOption
.equals(SortOption
.BY_NAME_REV
.name())) {
1170 fSortOption
= SortOption
.BY_NAME_REV
;
1171 fThreadComparator
= new ThreadNameComparator(true);
1172 getSortByNameAction().setChecked(true);
1173 getSortByNameAction().setImageDescriptor(SORT_BY_NAME_REV_ICON
);
1174 } else if (sortOption
.equals(SortOption
.BY_ID
.name())) {
1175 fSortOption
= SortOption
.BY_ID
;
1176 fThreadComparator
= new ThreadIdComparator(false);
1177 getSortByIdAction().setChecked(true);
1178 } else if (sortOption
.equals(SortOption
.BY_ID_REV
.name())) {
1179 fSortOption
= SortOption
.BY_ID_REV
;
1180 fThreadComparator
= new ThreadIdComparator(true);
1181 getSortByIdAction().setChecked(true);
1182 getSortByIdAction().setImageDescriptor(SORT_BY_ID_REV_ICON
);
1183 } else if (sortOption
.equals(SortOption
.BY_TIME
.name())) {
1184 fSortOption
= SortOption
.BY_TIME
;
1185 fThreadComparator
= new ThreadTimeComparator(false);
1186 getSortByTimeAction().setChecked(true);
1187 } else if (sortOption
.equals(SortOption
.BY_TIME_REV
.name())) {
1188 fSortOption
= SortOption
.BY_TIME_REV
;
1189 fThreadComparator
= new ThreadTimeComparator(true);
1190 getSortByTimeAction().setChecked(true);
1191 getSortByTimeAction().setImageDescriptor(SORT_BY_TIME_REV_ICON
);
1195 private void saveSortOption(SortOption sortOption
) {
1196 IDialogSettings settings
= Activator
.getDefault().getDialogSettings();
1197 IDialogSettings section
= settings
.getSection(getClass().getName());
1198 if (section
== null) {
1199 section
= settings
.addNewSection(getClass().getName());
1201 section
.put(SORT_OPTION_KEY
, sortOption
.name());
1203 List
<TimeGraphEntry
> entryList
= getEntryList(getTrace());
1204 if (entryList
== null) {
1207 for (TimeGraphEntry traceEntry
: entryList
) {
1208 traceEntry
.sortChildren(fThreadComparator
);
1213 private Action
getConfigureSymbolsAction() {
1214 if (fConfigureSymbolsAction
!= null) {
1215 return fConfigureSymbolsAction
;
1218 fConfigureSymbolsAction
= new Action(Messages
.CallStackView_ConfigureSymbolProvidersText
) {
1221 SymbolProviderConfigDialog dialog
= new SymbolProviderConfigDialog(getSite().getShell(), getProviderPages());
1222 if (dialog
.open() == IDialogConstants
.OK_ID
) {
1228 fConfigureSymbolsAction
.setToolTipText(Messages
.CallStackView_ConfigureSymbolProvidersTooltip
);
1229 fConfigureSymbolsAction
.setImageDescriptor(Activator
.getDefault().getImageDescripterFromPath(IMPORT_BINARY_ICON_PATH
));
1232 * The updateConfigureSymbolsAction() method (called by refresh()) will
1233 * set the action to true if applicable after the symbol provider has
1234 * been properly loaded.
1236 fConfigureSymbolsAction
.setEnabled(false);
1238 return fConfigureSymbolsAction
;
1242 * @return an array of {@link ISymbolProviderPreferencePage} that will
1243 * configure the current traces
1245 private ISymbolProviderPreferencePage
[] getProviderPages() {
1246 List
<ISymbolProviderPreferencePage
> pages
= new ArrayList
<>();
1247 ITmfTrace trace
= getTrace();
1248 if (trace
!= null) {
1249 for (ITmfTrace subTrace
: getTracesToBuild(trace
)) {
1250 ISymbolProvider provider
= fSymbolProviders
.get(subTrace
);
1251 if (provider
!= null) {
1252 ISymbolProviderPreferencePage page
= provider
.createPreferencePage();
1259 return pages
.toArray(new ISymbolProviderPreferencePage
[pages
.size()]);
1263 * Update the enable status of the configure symbols action
1265 private void updateConfigureSymbolsAction() {
1266 ISymbolProviderPreferencePage
[] providerPages
= getProviderPages();
1267 getConfigureSymbolsAction().setEnabled(providerPages
.length
> 0);