ss: Replace AttributeNotFoundException with IOOBE for quark parameters
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / callstack / CallStackView.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2016 Ericsson and others.
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 * Bernd Hufmann - Updated signal handling
12 * Marc-Andre Laperle - Map from binary file
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.tmf.ui.views.callstack;
16
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;
23 import java.util.Map;
24 import java.util.function.Consumer;
25
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;
92
93 /**
94 * Main implementation for the Call Stack view
95 *
96 * @author Patrick Tasse
97 */
98 public class CallStackView extends AbstractTimeGraphView {
99
100 // ------------------------------------------------------------------------
101 // Constants
102 // ------------------------------------------------------------------------
103
104 /** View ID. */
105 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.callstack"; //$NON-NLS-1$
106
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
113 };
114
115 private static final String[] FILTER_COLUMN_NAMES = new String[] {
116 Messages.CallStackView_ThreadColumn
117 };
118
119 /** Timeout between updates in the build thread in ms */
120 private static final long BUILD_UPDATE_TIMEOUT = 500;
121
122 // Fraction of a function duration to be added as spacing
123 private static final double SPACING_RATIO = 0.01;
124
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$
128
129 private static final String IMPORT_BINARY_ICON_PATH = "icons/obj16/binaries_obj.gif"; //$NON-NLS-1$
130
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$
138
139 private enum SortOption {
140 BY_NAME, BY_NAME_REV, BY_ID, BY_ID_REV, BY_TIME, BY_TIME_REV
141 }
142
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;
148
149 // ------------------------------------------------------------------------
150 // Fields
151 // ------------------------------------------------------------------------
152
153 private final Map<ITmfTrace, ISymbolProvider> fSymbolProviders = new HashMap<>();
154
155 // The next event action
156 private Action fNextEventAction;
157
158 // The previous event action
159 private Action fPrevEventAction;
160
161 // The next item action
162 private Action fNextItemAction;
163
164 // The previous item action
165 private Action fPreviousItemAction;
166
167 // The action to import a binary file mapping */
168 private Action fConfigureSymbolsAction;
169
170 // The saved time sync. signal used when switching off the pinning of a view
171 private TmfSelectionRangeUpdatedSignal fSavedTimeSyncSignal;
172
173 // The saved window range signal used when switching off the pinning of
174 // a view
175 private TmfWindowRangeUpdatedSignal fSavedRangeSyncSignal;
176
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;
180
181 // ------------------------------------------------------------------------
182 // Classes
183 // ------------------------------------------------------------------------
184
185 private static class TraceEntry extends TimeGraphEntry {
186 public TraceEntry(String name, long startTime, long endTime) {
187 super(name, startTime, endTime);
188 }
189
190 @Override
191 public boolean hasTimeEvents() {
192 return false;
193 }
194 }
195
196 private static class ProcessEntry extends TimeGraphEntry {
197
198 private final int fProcessId;
199
200 public ProcessEntry(String name, int processId, long startTime, long endTime) {
201 super(name, startTime, endTime);
202 fProcessId = processId;
203 }
204
205 @Override
206 public boolean hasTimeEvents() {
207 return false;
208 }
209 }
210
211 private static class ThreadEntry extends TimeGraphEntry {
212 // The thread id
213 private final long fThreadId;
214
215 public ThreadEntry(String name, long threadId, long startTime, long endTime) {
216 super(name, startTime, endTime);
217 fThreadId = threadId;
218 }
219
220 @Override
221 public boolean hasTimeEvents() {
222 return false;
223 }
224
225 public long getThreadId() {
226 return fThreadId;
227 }
228 }
229
230 private class CallStackComparator implements Comparator<ITimeGraphEntry> {
231 @Override
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);
237 }
238 return 0;
239 }
240 }
241
242 private static class ThreadNameComparator implements Comparator<ITimeGraphEntry> {
243 private boolean reverse;
244
245 public ThreadNameComparator(boolean reverse) {
246 this.reverse = reverse;
247 }
248
249 @Override
250 public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
251 return reverse ? o2.getName().compareTo(o1.getName()) :
252 o1.getName().compareTo(o2.getName());
253 }
254 }
255
256 private static class ThreadIdComparator implements Comparator<ITimeGraphEntry> {
257 private boolean reverse;
258
259 public ThreadIdComparator(boolean reverse) {
260 this.reverse = reverse;
261 }
262
263 @Override
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());
270 }
271 return 0;
272 }
273 }
274
275 private static class ThreadTimeComparator implements Comparator<ITimeGraphEntry> {
276 private boolean reverse;
277
278 public ThreadTimeComparator(boolean reverse) {
279 this.reverse = reverse;
280 }
281
282 @Override
283 public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
284 return reverse ? Long.compare(o2.getStartTime(), o1.getStartTime()) :
285 Long.compare(o1.getStartTime(), o2.getStartTime());
286 }
287 }
288
289 private static class CallStackTreeLabelProvider extends TreeLabelProvider {
290
291 @Override
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) {
297 return THREAD_IMAGE;
298 } else if (element instanceof CallStackEntry) {
299 CallStackEntry entry = (CallStackEntry) element;
300 if (entry.getFunctionName().length() > 0) {
301 return STACKFRAME_IMAGE;
302 }
303 }
304 }
305 return null;
306 }
307
308 @Override
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();
326 }
327 } else if (element instanceof ITimeGraphEntry) {
328 if (columnIndex == 0) {
329 return ((ITimeGraphEntry) element).getName();
330 }
331 }
332 return ""; //$NON-NLS-1$
333 }
334
335 }
336
337 private class CallStackFilterContentProvider extends TimeGraphContentProvider {
338 @Override
339 public boolean hasChildren(Object element) {
340 if (element instanceof TraceEntry) {
341 return super.hasChildren(element);
342 }
343 return false;
344 }
345
346 @Override
347 public ITimeGraphEntry[] getChildren(Object parentElement) {
348 if (parentElement instanceof TraceEntry) {
349 return super.getChildren(parentElement);
350 }
351 return new ITimeGraphEntry[0];
352 }
353 }
354
355 // ------------------------------------------------------------------------
356 // Constructors
357 // ------------------------------------------------------------------------
358
359 /**
360 * Default constructor
361 */
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());
371 }
372
373 // ------------------------------------------------------------------------
374 // ViewPart
375 // ------------------------------------------------------------------------
376
377 @Override
378 public void createPartControl(Composite parent) {
379 super.createPartControl(parent);
380
381 getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() {
382 @Override
383 public void timeSelected(TimeGraphTimeEvent event) {
384 synchingToTime(event.getBeginTime());
385 }
386 });
387
388 getTimeGraphCombo().getTreeViewer().addDoubleClickListener(new IDoubleClickListener() {
389 @Override
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);
404 }
405 }
406 }
407 });
408
409 getTimeGraphViewer().getTimeGraphControl().addMouseListener(new MouseAdapter() {
410 @Override
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);
427 }
428 }
429 }
430 });
431
432 contributeToActionBars();
433 loadSortOption();
434
435 IEditorPart editor = getSite().getPage().getActiveEditor();
436 if (editor instanceof ITmfTraceEditor) {
437 ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
438 if (trace != null) {
439 traceSelected(new TmfTraceSelectedSignal(this, trace));
440 }
441 }
442 }
443
444 /**
445 * Handler for the selection range signal.
446 *
447 * @param signal
448 * The incoming signal
449 * @since 1.0
450 */
451 @Override
452 @TmfSignalHandler
453 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) {
454
455 fSavedTimeSyncSignal = isPinned() ? new TmfSelectionRangeUpdatedSignal(signal.getSource(), signal.getBeginTime(), signal.getEndTime()) : null;
456
457 if (signal.getSource() == this || getTrace() == null || isPinned()) {
458 return;
459 }
460 final long beginTime = signal.getBeginTime().toNanos();
461 final long endTime = signal.getEndTime().toNanos();
462 Display.getDefault().asyncExec(new Runnable() {
463 @Override
464 public void run() {
465 if (getTimeGraphCombo().isDisposed()) {
466 return;
467 }
468 if (beginTime == endTime) {
469 getTimeGraphViewer().setSelectedTime(beginTime, true);
470 } else {
471 getTimeGraphViewer().setSelectionRange(beginTime, endTime, true);
472 }
473 fSyncSelection = true;
474 synchingToTime(beginTime);
475 fSyncSelection = false;
476 startZoomThread(getTimeGraphViewer().getTime0(), getTimeGraphViewer().getTime1());
477 }
478 });
479
480 }
481
482 /**
483 * @since 2.0
484 */
485 @Override
486 @TmfSignalHandler
487 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal) {
488
489 if (isPinned()) {
490 fSavedRangeSyncSignal = new TmfWindowRangeUpdatedSignal(signal.getSource(), signal.getCurrentRange());
491 fSavedTimeSyncSignal = null;
492 }
493
494 if ((signal.getSource() == this) || isPinned()) {
495 return;
496 }
497 super.windowRangeUpdated(signal);
498 }
499
500 // ------------------------------------------------------------------------
501 // Internal
502 // ------------------------------------------------------------------------
503
504 @Override
505 @TmfSignalHandler
506 public void traceClosed(TmfTraceClosedSignal signal) {
507 super.traceClosed(signal);
508 synchronized(fSymbolProviders){
509 for(ITmfTrace trace : getTracesToBuild(signal.getTrace())){
510 fSymbolProviders.remove(trace);
511 }
512 }
513 }
514
515 /**
516 * @since 2.0
517 */
518 @Override
519 protected void refresh() {
520 super.refresh();
521 updateConfigureSymbolsAction();
522 }
523
524 @Override
525 protected void buildEntryList(final ITmfTrace trace, final ITmfTrace parentTrace, final IProgressMonitor monitor) {
526 if (monitor.isCanceled()) {
527 return;
528 }
529 AbstractCallStackAnalysis module = getCallStackModule(trace);
530 if (module == null) {
531 addUnavailableEntry(trace, parentTrace);
532 return;
533 }
534 ITmfStateSystem ss = module.getStateSystem();
535 if (ss == null) {
536 addUnavailableEntry(trace, parentTrace);
537 return;
538 }
539
540 Map<ITmfTrace, TraceEntry> traceEntryMap = new HashMap<>();
541 Map<Integer, ProcessEntry> processEntryMap = new HashMap<>();
542 Map<Integer, ThreadEntry> threadEntryMap = new HashMap<>();
543
544 long start = ss.getStartTime();
545
546 boolean complete = false;
547 while (!complete) {
548 if (monitor.isCanceled()) {
549 return;
550 }
551 complete = ss.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
552 if (ss.isCancelled()) {
553 return;
554 }
555 long end = ss.getCurrentEndTime();
556 if (start == end && !complete) { // when complete execute one last time regardless of end time
557 continue;
558 }
559
560 ISymbolProvider provider = fSymbolProviders.get(trace);
561 if (provider == null) {
562 provider = SymbolProviderManager.getInstance().getSymbolProvider(trace);
563 provider.loadConfiguration(monitor);
564 fSymbolProviders.put(trace, provider);
565 }
566
567 getConfigureSymbolsAction().setEnabled(true);
568
569
570 TraceEntry traceEntry = traceEntryMap.get(trace);
571 if (traceEntry == null) {
572 traceEntry = new TraceEntry(trace.getName(), start, end + 1);
573 traceEntryMap.put(trace, traceEntry);
574 traceEntry.sortChildren(fThreadComparator);
575 addToEntryList(parentTrace, Collections.singletonList(traceEntry));
576 } else {
577 traceEntry.updateEndTime(end);
578 }
579
580 try {
581 List<ITmfStateInterval> endStates = ss.queryFullState(ss.getCurrentEndTime());
582
583 List<Integer> processQuarks = ss.getQuarks(module.getProcessesPattern());
584 for (int processQuark : processQuarks) {
585
586 /*
587 * Default to trace entry, overwrite if a process entry exists.
588 */
589 TimeGraphEntry threadParent = traceEntry;
590 int processId = -1;
591 if (processQuark != ITmfStateSystem.ROOT_ATTRIBUTE) {
592 /* Create the entry for the process */
593 ProcessEntry processEntry = processEntryMap.get(processQuark);
594 if (processEntry == null) {
595 String processName = ss.getAttributeName(processQuark);
596 ITmfStateValue processStateValue = endStates.get(processQuark).getStateValue();
597 if (processStateValue.getType() == Type.INTEGER) {
598 processId = processStateValue.unboxInt();
599 } else {
600 try {
601 processId = Integer.parseInt(processName);
602 } catch (NumberFormatException e) {
603 /* use default processId */
604 }
605 }
606 processEntry = new ProcessEntry(processName, processId, start, end);
607 processEntryMap.put(processQuark, processEntry);
608 traceEntry.addChild(processEntry);
609 } else {
610 processEntry.updateEndTime(end);
611 }
612 /* The parent of the thread entries will be a process */
613 threadParent = processEntry;
614 }
615
616 /* Create the threads under the process */
617 List<Integer> threadQuarks = ss.getQuarks(processQuark, module.getThreadsPattern());
618
619 /*
620 * Only query startStates if necessary (threadEntry == null)
621 */
622 List<ITmfStateInterval> startStates = null;
623 for (int threadQuark : threadQuarks) {
624 if (monitor.isCanceled()) {
625 return;
626 }
627
628 String[] callStackPath = module.getCallStackPath();
629 int callStackQuark = ss.getQuarkRelative(threadQuark, callStackPath);
630 String threadName = ss.getAttributeName(threadQuark);
631 long threadEnd = end + 1;
632 ITmfStateInterval endInterval = endStates.get(callStackQuark);
633 if (endInterval.getStateValue().isNull() && endInterval.getStartTime() != ss.getStartTime()) {
634 threadEnd = endInterval.getStartTime();
635 }
636 /*
637 * Default to process/trace entry, overwrite if a thread entry exists.
638 */
639 TimeGraphEntry callStackParent = threadParent;
640 if (threadQuark != processQuark) {
641 ThreadEntry threadEntry = threadEntryMap.get(threadQuark);
642 if (threadEntry == null) {
643 if (startStates == null) {
644 startStates = ss.queryFullState(ss.getStartTime());
645 }
646 long threadId = -1;
647 ITmfStateValue threadStateValue = endStates.get(threadQuark).getStateValue();
648 if (threadStateValue.getType() == Type.LONG || threadStateValue.getType() == Type.INTEGER) {
649 threadId = threadStateValue.unboxLong();
650 } else {
651 try {
652 threadId = Long.parseLong(threadName);
653 } catch (NumberFormatException e) {
654 /* use default threadId */
655 }
656 }
657 long threadStart = start;
658 ITmfStateInterval startInterval = startStates.get(callStackQuark);
659 if (startInterval.getStateValue().isNull()) {
660 threadStart = Math.min(startInterval.getEndTime() + 1, end + 1);
661 }
662 threadEntry = new ThreadEntry(threadName, threadId, threadStart, threadEnd);
663 threadEntryMap.put(threadQuark, threadEntry);
664 threadParent.addChild(threadEntry);
665 } else {
666 threadEntry.updateEndTime(threadEnd);
667 }
668 /* The parent of the call stack entries will be a thread */
669 callStackParent = threadEntry;
670 }
671 int level = 1;
672 for (int stackLevelQuark : ss.getSubAttributes(callStackQuark, false)) {
673 if (level > callStackParent.getChildren().size()) {
674 CallStackEntry callStackEntry = new CallStackEntry(threadName, stackLevelQuark, level, processId, trace, ss);
675 callStackParent.addChild(callStackEntry);
676 }
677 level++;
678 }
679 }
680 }
681 } catch (AttributeNotFoundException e) {
682 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
683 } catch (StateSystemDisposedException e) {
684 /* Ignored */
685 }
686
687 if (parentTrace == getTrace()) {
688 synchronized (this) {
689 setStartTime(getStartTime() == SWT.DEFAULT ? start : Math.min(getStartTime(), start));
690 setEndTime(getEndTime() == SWT.DEFAULT ? end + 1 : Math.max(getEndTime(), end + 1));
691 }
692 synchingToTime(getTimeGraphViewer().getSelectionBegin());
693 refresh();
694 }
695
696 for (ITimeGraphEntry processEntry : traceEntry.getChildren()) {
697 for (ITimeGraphEntry threadEntry : processEntry.getChildren()) {
698 for (ITimeGraphEntry callStackEntry : threadEntry.getChildren()) {
699 if (monitor.isCanceled()) {
700 return;
701 }
702 buildStatusEvents(parentTrace, (CallStackEntry) callStackEntry, monitor, ss.getStartTime(), end);
703 }
704 }
705 }
706 start = end;
707 }
708 }
709
710 private void addUnavailableEntry(ITmfTrace trace, ITmfTrace parentTrace) {
711 String name = Messages.CallStackView_StackInfoNotAvailable + ' ' + '(' + trace.getName() + ')';
712 TraceEntry unavailableEntry = new TraceEntry(name, 0, 0);
713 addToEntryList(parentTrace, Collections.singletonList(unavailableEntry));
714 if (parentTrace == getTrace()) {
715 refresh();
716 }
717 }
718
719 private void buildStatusEvents(ITmfTrace trace, CallStackEntry entry, @NonNull IProgressMonitor monitor, long start, long end) {
720 ITmfStateSystem ss = entry.getStateSystem();
721 long resolution = Math.max(1, (end - ss.getStartTime()) / getDisplayWidth());
722 List<ITimeEvent> eventList = getEventList(entry, start, end + 1, resolution, monitor);
723 if (eventList != null) {
724 entry.setEventList(eventList);
725 }
726 if (trace == getTrace()) {
727 redraw();
728 }
729 }
730
731 /**
732 * @since 1.2
733 */
734 @Override
735 protected final List<ITimeEvent> getEventList(TimeGraphEntry tgentry, long startTime, long endTime, long resolution, IProgressMonitor monitor) {
736 if (!(tgentry instanceof CallStackEntry)) {
737 return null;
738 }
739 CallStackEntry entry = (CallStackEntry) tgentry;
740 ITmfStateSystem ss = entry.getStateSystem();
741 long start = Math.max(startTime, ss.getStartTime());
742 long end = Math.min(endTime, ss.getCurrentEndTime() + 1);
743 if (end <= start) {
744 return null;
745 }
746 boolean isZoomThread = Thread.currentThread() instanceof ZoomThread;
747 List<ITimeEvent> eventList = null;
748 try {
749 List<ITmfStateInterval> stackIntervals = StateSystemUtils.queryHistoryRange(ss, entry.getQuark(), start, end - 1, resolution, monitor);
750 eventList = new ArrayList<>(stackIntervals.size());
751 long lastEndTime = -1;
752 boolean lastIsNull = false;
753 for (ITmfStateInterval statusInterval : stackIntervals) {
754 if (monitor.isCanceled()) {
755 return null;
756 }
757 long time = statusInterval.getStartTime();
758 long duration = statusInterval.getEndTime() - time + 1;
759 if (!statusInterval.getStateValue().isNull()) {
760 final int modulo = CallStackPresentationProvider.NUM_COLORS / 2;
761 int value = statusInterval.getStateValue().toString().hashCode() % modulo + modulo;
762 eventList.add(new CallStackEvent(entry, time, duration, value));
763 lastIsNull = false;
764 } else {
765 if (lastEndTime == -1 && isZoomThread) {
766 // add null event if it intersects the start time
767 eventList.add(new NullTimeEvent(entry, time, duration));
768 } else {
769 if (lastEndTime != time && lastIsNull) {
770 // add unknown event if between two null states
771 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
772 }
773 if (time + duration >= endTime && isZoomThread) {
774 // add null event if it intersects the end time
775 eventList.add(new NullTimeEvent(entry, time, duration));
776 }
777 }
778 lastIsNull = true;
779 }
780 lastEndTime = time + duration;
781 }
782 } catch (AttributeNotFoundException e) {
783 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
784 } catch (TimeRangeException e) {
785 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
786 } catch (StateSystemDisposedException e) {
787 /* Ignored */
788 }
789 return eventList;
790 }
791
792 /**
793 * @since 1.2
794 */
795 @Override
796 protected void synchingToTime(final long time) {
797 List<TimeGraphEntry> traceEntries = getEntryList(getTrace());
798 Map<ITmfStateSystem, List<ITmfStateInterval>> fullStateMap = new HashMap<>();
799 if (traceEntries == null) {
800 return;
801 }
802 Consumer<TimeGraphEntry> consumer = new Consumer<TimeGraphEntry>() {
803 @Override
804 public void accept(TimeGraphEntry entry) {
805 if (entry instanceof CallStackEntry) {
806 CallStackEntry callStackEntry = (CallStackEntry) entry;
807 ITmfStateSystem ss = callStackEntry.getStateSystem();
808 if (time < ss.getStartTime() || time > ss.getCurrentEndTime()) {
809 return;
810 }
811 ITmfTrace trace = callStackEntry.getTrace();
812 try {
813 List<ITmfStateInterval> fullState = getFullState(ss);
814 ITmfStateInterval stackLevelInterval = fullState.get(callStackEntry.getQuark());
815 ITmfStateValue nameValue = stackLevelInterval.getStateValue();
816
817 String name = getFunctionName(trace, callStackEntry.getProcessId(), time, nameValue);
818 callStackEntry.setFunctionName(name);
819 if (!name.isEmpty()) {
820 callStackEntry.setFunctionEntryTime(stackLevelInterval.getStartTime());
821 callStackEntry.setFunctionExitTime(stackLevelInterval.getEndTime() + 1);
822 }
823 if (fSyncSelection) {
824 int callStackQuark = ss.getParentAttributeQuark(callStackEntry.getQuark());
825 ITmfStateInterval stackInterval = fullState.get(callStackQuark);
826 if (time == stackInterval.getStartTime()) {
827 ITmfStateValue stackLevelState = stackInterval.getStateValue();
828 if (stackLevelState.unboxInt() == callStackEntry.getStackLevel() || stackLevelState.isNull()) {
829 Display.getDefault().asyncExec(() -> {
830 getTimeGraphCombo().setSelection(callStackEntry);
831 getTimeGraphViewer().getTimeGraphControl().fireSelectionChanged();
832 fSyncSelection = false;
833 });
834 }
835 }
836 }
837 } catch (StateSystemDisposedException e) {
838 /* Ignored */
839 }
840 return;
841 }
842 entry.getChildren().forEach(this);
843 }
844
845 private List<ITmfStateInterval> getFullState(ITmfStateSystem ss) throws StateSystemDisposedException {
846 List<ITmfStateInterval> fullState = fullStateMap.get(ss);
847 if (fullState == null) {
848 fullState = ss.queryFullState(time);
849 fullStateMap.put(ss, fullState);
850 }
851 return fullState;
852 }
853 };
854 traceEntries.forEach(consumer);
855 if (Display.getCurrent() != null) {
856 getTimeGraphCombo().refresh();
857 }
858 }
859
860 String getFunctionName(ITmfTrace trace, int processId, long timestamp, ITmfStateValue nameValue) {
861 long address = Long.MAX_VALUE;
862 String name = ""; //$NON-NLS-1$
863 try {
864 if (nameValue.getType() == Type.STRING) {
865 name = nameValue.unboxStr();
866 try {
867 address = Long.parseLong(name, 16);
868 } catch (NumberFormatException e) {
869 // ignore
870 }
871 } else if (nameValue.getType() == Type.INTEGER) {
872 name = "0x" + Integer.toUnsignedString(nameValue.unboxInt(), 16); //$NON-NLS-1$
873 address = nameValue.unboxInt();
874 } else if (nameValue.getType() == Type.LONG) {
875 name = "0x" + Long.toUnsignedString(nameValue.unboxLong(), 16); //$NON-NLS-1$
876 address = nameValue.unboxLong();
877 }
878 } catch (StateValueTypeException e) {
879 }
880 if (address != Long.MAX_VALUE) {
881 ISymbolProvider provider = fSymbolProviders.get(trace);
882 if (provider != null) {
883 String symbol = provider.getSymbolText(processId, timestamp, address);
884 if (symbol != null) {
885 name = symbol;
886 }
887 }
888 }
889 return name;
890 }
891
892 private void makeActions() {
893 fPreviousItemAction = getTimeGraphViewer().getPreviousItemAction();
894 fPreviousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText);
895 fPreviousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText);
896 fNextItemAction = getTimeGraphViewer().getNextItemAction();
897 fNextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText);
898 fNextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText);
899 }
900
901 private void contributeToActionBars() {
902 // Create pin action
903 contributePinActionToToolBar();
904 fPinAction.addPropertyChangeListener(new IPropertyChangeListener() {
905 @Override
906 public void propertyChange(PropertyChangeEvent event) {
907 if (IAction.CHECKED.equals(event.getProperty()) && !isPinned()) {
908 if (fSavedRangeSyncSignal != null) {
909 windowRangeUpdated(fSavedRangeSyncSignal);
910 fSavedRangeSyncSignal = null;
911 }
912
913 if (fSavedTimeSyncSignal != null) {
914 selectionRangeUpdated(fSavedTimeSyncSignal);
915 fSavedTimeSyncSignal = null;
916 }
917 }
918 }
919 });
920 }
921
922 /**
923 * @since 1.2
924 */
925 @Override
926 protected void fillLocalToolBar(IToolBarManager manager) {
927 makeActions();
928 manager.add(getConfigureSymbolsAction());
929 manager.add(new Separator());
930 manager.add(getSortByNameAction());
931 manager.add(getSortByIdAction());
932 manager.add(getSortByTimeAction());
933 manager.add(new Separator());
934 manager.add(getTimeGraphCombo().getShowFilterDialogAction());
935 manager.add(new Separator());
936 manager.add(getTimeGraphViewer().getResetScaleAction());
937 manager.add(getPreviousEventAction());
938 manager.add(getNextEventAction());
939 manager.add(new Separator());
940 manager.add(getTimeGraphViewer().getToggleBookmarkAction());
941 manager.add(getTimeGraphViewer().getPreviousMarkerAction());
942 manager.add(getTimeGraphViewer().getNextMarkerAction());
943 manager.add(new Separator());
944 manager.add(fPreviousItemAction);
945 manager.add(fNextItemAction);
946 manager.add(getTimeGraphViewer().getZoomInAction());
947 manager.add(getTimeGraphViewer().getZoomOutAction());
948 }
949
950 /**
951 * @since 2.0
952 */
953 @Override
954 protected void fillTimeGraphEntryContextMenu(IMenuManager contextMenu) {
955 contextMenu.add(new GroupMarker(IWorkbenchActionConstants.GROUP_REORGANIZE));
956 contextMenu.add(getSortByNameAction());
957 contextMenu.add(getSortByIdAction());
958 contextMenu.add(getSortByTimeAction());
959 }
960
961 /**
962 * Get the the next event action.
963 *
964 * @return The action object
965 */
966 private Action getNextEventAction() {
967 if (fNextEventAction == null) {
968 fNextEventAction = new Action() {
969 @Override
970 public void run() {
971 TimeGraphViewer viewer = getTimeGraphViewer();
972 ITimeGraphEntry entry = viewer.getSelection();
973 if (entry instanceof CallStackEntry) {
974 try {
975 CallStackEntry callStackEntry = (CallStackEntry) entry;
976 ITmfStateSystem ss = callStackEntry.getStateSystem();
977 long time = Math.max(ss.getStartTime(), Math.min(ss.getCurrentEndTime(), viewer.getSelectionBegin()));
978 ThreadEntry threadEntry = (ThreadEntry) callStackEntry.getParent();
979 int quark = ss.getParentAttributeQuark(callStackEntry.getQuark());
980 ITmfStateInterval stackInterval = ss.querySingleState(time, quark);
981 long newTime = stackInterval.getEndTime() + 1;
982 viewer.setSelectedTimeNotify(newTime, true);
983 stackInterval = ss.querySingleState(Math.min(ss.getCurrentEndTime(), newTime), quark);
984 int stackLevel = stackInterval.getStateValue().unboxInt();
985 ITimeGraphEntry selectedEntry = threadEntry.getChildren().get(Math.max(0, stackLevel - 1));
986 getTimeGraphCombo().setSelection(selectedEntry);
987 viewer.getTimeGraphControl().fireSelectionChanged();
988 startZoomThread(viewer.getTime0(), viewer.getTime1());
989
990 } catch (TimeRangeException | StateSystemDisposedException | StateValueTypeException e) {
991 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
992 }
993 }
994 }
995 };
996
997 fNextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText);
998 fNextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText);
999 fNextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT));
1000 }
1001
1002 return fNextEventAction;
1003 }
1004
1005 /**
1006 * Get the previous event action.
1007 *
1008 * @return The Action object
1009 */
1010 private Action getPreviousEventAction() {
1011 if (fPrevEventAction == null) {
1012 fPrevEventAction = new Action() {
1013 @Override
1014 public void run() {
1015 TimeGraphViewer viewer = getTimeGraphCombo().getTimeGraphViewer();
1016 ITimeGraphEntry entry = viewer.getSelection();
1017 if (entry instanceof CallStackEntry) {
1018 try {
1019 CallStackEntry callStackEntry = (CallStackEntry) entry;
1020 ITmfStateSystem ss = callStackEntry.getStateSystem();
1021 long time = Math.max(ss.getStartTime(), Math.min(ss.getCurrentEndTime(), viewer.getSelectionBegin()));
1022 ThreadEntry threadEntry = (ThreadEntry) callStackEntry.getParent();
1023 int quark = ss.getParentAttributeQuark(callStackEntry.getQuark());
1024 ITmfStateInterval stackInterval = ss.querySingleState(time, quark);
1025 if (stackInterval.getStartTime() == time && time > ss.getStartTime()) {
1026 stackInterval = ss.querySingleState(time - 1, quark);
1027 }
1028 viewer.setSelectedTimeNotify(stackInterval.getStartTime(), true);
1029 int stackLevel = stackInterval.getStateValue().unboxInt();
1030 ITimeGraphEntry selectedEntry = threadEntry.getChildren().get(Math.max(0, stackLevel - 1));
1031 getTimeGraphCombo().setSelection(selectedEntry);
1032 viewer.getTimeGraphControl().fireSelectionChanged();
1033 startZoomThread(viewer.getTime0(), viewer.getTime1());
1034
1035 } catch (TimeRangeException | StateSystemDisposedException | StateValueTypeException e) {
1036 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
1037 }
1038 }
1039 }
1040 };
1041
1042 fPrevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText);
1043 fPrevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText);
1044 fPrevEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT));
1045 }
1046
1047 return fPrevEventAction;
1048 }
1049
1050 private static @Nullable AbstractCallStackAnalysis getCallStackModule(@NonNull ITmfTrace trace) {
1051 /*
1052 * Since we cannot know the exact analysis ID (in separate plugins), we
1053 * will search using the analysis type.
1054 */
1055 Iterable<AbstractCallStackAnalysis> modules =
1056 TmfTraceUtils.getAnalysisModulesOfClass(trace, AbstractCallStackAnalysis.class);
1057 Iterator<AbstractCallStackAnalysis> it = modules.iterator();
1058 if (!it.hasNext()) {
1059 /* This trace does not provide a call-stack analysis */
1060 return null;
1061 }
1062
1063 /*
1064 * We only look at the first module we find.
1065 *
1066 * TODO Handle the advanced case where one trace provides more than one
1067 * call-stack analysis.
1068 */
1069 AbstractCallStackAnalysis module = it.next();
1070 /* This analysis is not automatic, we need to schedule it on-demand */
1071 module.schedule();
1072 if (!module.waitForInitialization()) {
1073 /* The initialization did not succeed */
1074 return null;
1075 }
1076 return module;
1077 }
1078
1079 // ------------------------------------------------------------------------
1080 // Methods related to function name mapping
1081 // ------------------------------------------------------------------------
1082
1083 private Action getSortByNameAction() {
1084 if (fSortByNameAction == null) {
1085 fSortByNameAction = new Action(Messages.CallStackView_SortByThreadName, IAction.AS_CHECK_BOX) {
1086 @Override
1087 public void run() {
1088 if (fSortOption == SortOption.BY_NAME) {
1089 saveSortOption(SortOption.BY_NAME_REV);
1090 } else {
1091 saveSortOption(SortOption.BY_NAME);
1092 }
1093 }
1094 };
1095 fSortByNameAction.setToolTipText(Messages.CallStackView_SortByThreadName);
1096 fSortByNameAction.setImageDescriptor(SORT_BY_NAME_ICON);
1097 }
1098 return fSortByNameAction;
1099 }
1100
1101 private Action getSortByIdAction() {
1102 if (fSortByIdAction == null) {
1103 fSortByIdAction = new Action(Messages.CallStackView_SortByThreadId, IAction.AS_CHECK_BOX) {
1104 @Override
1105 public void run() {
1106 if (fSortOption == SortOption.BY_ID) {
1107 saveSortOption(SortOption.BY_ID_REV);
1108 } else {
1109 saveSortOption(SortOption.BY_ID);
1110 }
1111 }
1112 };
1113 fSortByIdAction.setToolTipText(Messages.CallStackView_SortByThreadId);
1114 fSortByIdAction.setImageDescriptor(SORT_BY_ID_ICON);
1115 }
1116 return fSortByIdAction;
1117 }
1118
1119 private Action getSortByTimeAction() {
1120 if (fSortByTimeAction == null) {
1121 fSortByTimeAction = new Action(Messages.CallStackView_SortByThreadTime, IAction.AS_CHECK_BOX) {
1122 @Override
1123 public void run() {
1124 if (fSortOption == SortOption.BY_TIME) {
1125 saveSortOption(SortOption.BY_TIME_REV);
1126 } else {
1127 saveSortOption(SortOption.BY_TIME);
1128 }
1129 }
1130 };
1131 fSortByTimeAction.setToolTipText(Messages.CallStackView_SortByThreadTime);
1132 fSortByTimeAction.setImageDescriptor(SORT_BY_TIME_ICON);
1133 }
1134 return fSortByTimeAction;
1135 }
1136
1137 private void loadSortOption() {
1138 IDialogSettings settings = Activator.getDefault().getDialogSettings();
1139 IDialogSettings section = settings.getSection(getClass().getName());
1140 if (section == null) {
1141 return;
1142 }
1143 String sortOption = section.get(SORT_OPTION_KEY);
1144 if (sortOption == null) {
1145 return;
1146 }
1147
1148 // reset defaults
1149 getSortByNameAction().setChecked(false);
1150 getSortByNameAction().setImageDescriptor(SORT_BY_NAME_ICON);
1151 getSortByIdAction().setChecked(false);
1152 getSortByIdAction().setImageDescriptor(SORT_BY_ID_ICON);
1153 getSortByTimeAction().setChecked(false);
1154 getSortByTimeAction().setImageDescriptor(SORT_BY_TIME_ICON);
1155
1156 if (sortOption.equals(SortOption.BY_NAME.name())) {
1157 fSortOption = SortOption.BY_NAME;
1158 fThreadComparator = new ThreadNameComparator(false);
1159 getSortByNameAction().setChecked(true);
1160 } else if (sortOption.equals(SortOption.BY_NAME_REV.name())) {
1161 fSortOption = SortOption.BY_NAME_REV;
1162 fThreadComparator = new ThreadNameComparator(true);
1163 getSortByNameAction().setChecked(true);
1164 getSortByNameAction().setImageDescriptor(SORT_BY_NAME_REV_ICON);
1165 } else if (sortOption.equals(SortOption.BY_ID.name())) {
1166 fSortOption = SortOption.BY_ID;
1167 fThreadComparator = new ThreadIdComparator(false);
1168 getSortByIdAction().setChecked(true);
1169 } else if (sortOption.equals(SortOption.BY_ID_REV.name())) {
1170 fSortOption = SortOption.BY_ID_REV;
1171 fThreadComparator = new ThreadIdComparator(true);
1172 getSortByIdAction().setChecked(true);
1173 getSortByIdAction().setImageDescriptor(SORT_BY_ID_REV_ICON);
1174 } else if (sortOption.equals(SortOption.BY_TIME.name())) {
1175 fSortOption = SortOption.BY_TIME;
1176 fThreadComparator = new ThreadTimeComparator(false);
1177 getSortByTimeAction().setChecked(true);
1178 } else if (sortOption.equals(SortOption.BY_TIME_REV.name())) {
1179 fSortOption = SortOption.BY_TIME_REV;
1180 fThreadComparator = new ThreadTimeComparator(true);
1181 getSortByTimeAction().setChecked(true);
1182 getSortByTimeAction().setImageDescriptor(SORT_BY_TIME_REV_ICON);
1183 }
1184 }
1185
1186 private void saveSortOption(SortOption sortOption) {
1187 IDialogSettings settings = Activator.getDefault().getDialogSettings();
1188 IDialogSettings section = settings.getSection(getClass().getName());
1189 if (section == null) {
1190 section = settings.addNewSection(getClass().getName());
1191 }
1192 section.put(SORT_OPTION_KEY, sortOption.name());
1193 loadSortOption();
1194 List<TimeGraphEntry> entryList = getEntryList(getTrace());
1195 if (entryList == null) {
1196 return;
1197 }
1198 for (TimeGraphEntry traceEntry : entryList) {
1199 traceEntry.sortChildren(fThreadComparator);
1200 }
1201 refresh();
1202 }
1203
1204 private Action getConfigureSymbolsAction() {
1205 if (fConfigureSymbolsAction != null) {
1206 return fConfigureSymbolsAction;
1207 }
1208
1209 fConfigureSymbolsAction = new Action(Messages.CallStackView_ConfigureSymbolProvidersText) {
1210 @Override
1211 public void run() {
1212 SymbolProviderConfigDialog dialog = new SymbolProviderConfigDialog(getSite().getShell(), getProviderPages());
1213 if (dialog.open() == IDialogConstants.OK_ID) {
1214 refresh();
1215 }
1216 }
1217 };
1218
1219 fConfigureSymbolsAction.setToolTipText(Messages.CallStackView_ConfigureSymbolProvidersTooltip);
1220 fConfigureSymbolsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(IMPORT_BINARY_ICON_PATH));
1221 fConfigureSymbolsAction.setEnabled(false);
1222
1223 return fConfigureSymbolsAction;
1224 }
1225
1226 /**
1227 * @return an array of {@link ISymbolProviderPreferencePage} that will
1228 * configure the current traces
1229 */
1230 private ISymbolProviderPreferencePage[] getProviderPages() {
1231 List<ISymbolProviderPreferencePage> pages = new ArrayList<>();
1232 ITmfTrace trace = getTrace();
1233 if (trace != null) {
1234 for (ITmfTrace subTrace : getTracesToBuild(trace)) {
1235 ISymbolProvider provider = fSymbolProviders.get(subTrace);
1236 if (provider != null) {
1237 ISymbolProviderPreferencePage page = provider.createPreferencePage();
1238 if (page != null) {
1239 pages.add(page);
1240 }
1241 }
1242 }
1243 }
1244 return pages.toArray(new ISymbolProviderPreferencePage[pages.size()]);
1245 }
1246
1247 /**
1248 * Update the enable status of the configure symbols action
1249 */
1250 private void updateConfigureSymbolsAction() {
1251 ISymbolProviderPreferencePage[] providerPages = getProviderPages();
1252 getConfigureSymbolsAction().setEnabled(providerPages.length > 0);
1253 }
1254
1255 }
This page took 0.059416 seconds and 5 git commands to generate.