Commit | Line | Data |
---|---|---|
e8251298 | 1 | /******************************************************************************* |
d2fb9e0f | 2 | * Copyright (c) 2013, 2016 Ericsson and others. |
e8251298 PT |
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 | |
fec1ac0b | 11 | * Bernd Hufmann - Updated signal handling |
41d9ce5b | 12 | * Marc-Andre Laperle - Map from binary file |
e8251298 PT |
13 | *******************************************************************************/ |
14 | ||
2bdf0193 | 15 | package org.eclipse.tracecompass.tmf.ui.views.callstack; |
e8251298 PT |
16 | |
17 | import java.util.ArrayList; | |
26c33ee2 | 18 | import java.util.Collections; |
46cc1ade | 19 | import java.util.Comparator; |
e8251298 PT |
20 | import java.util.HashMap; |
21 | import java.util.Iterator; | |
22 | import java.util.List; | |
52974e38 | 23 | import java.util.Map; |
1302015b | 24 | import java.util.function.Consumer; |
e8251298 PT |
25 | |
26 | import org.eclipse.core.runtime.IProgressMonitor; | |
1d83ed07 | 27 | import org.eclipse.jdt.annotation.NonNull; |
50659279 | 28 | import org.eclipse.jdt.annotation.Nullable; |
e8251298 | 29 | import org.eclipse.jface.action.Action; |
d2fb9e0f | 30 | import org.eclipse.jface.action.GroupMarker; |
e8251298 | 31 | import org.eclipse.jface.action.IAction; |
90bb3a0c | 32 | import org.eclipse.jface.action.IMenuManager; |
e8251298 PT |
33 | import org.eclipse.jface.action.IToolBarManager; |
34 | import org.eclipse.jface.action.Separator; | |
d90ae2a5 | 35 | import org.eclipse.jface.dialogs.IDialogConstants; |
46cc1ade PT |
36 | import org.eclipse.jface.dialogs.IDialogSettings; |
37 | import org.eclipse.jface.resource.ImageDescriptor; | |
e8251298 PT |
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; | |
e8251298 PT |
42 | import org.eclipse.jface.viewers.ISelection; |
43 | import org.eclipse.jface.viewers.IStructuredSelection; | |
e8251298 | 44 | import org.eclipse.swt.SWT; |
e8251298 PT |
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; | |
2bdf0193 AM |
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; | |
e894a508 | 53 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem; |
1dd75589 | 54 | import org.eclipse.tracecompass.statesystem.core.StateSystemUtils; |
e894a508 AM |
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; | |
97c71024 | 62 | import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; |
17a54620 | 63 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; |
d90ae2a5 | 64 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal; |
2bdf0193 | 65 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal; |
17a54620 | 66 | import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal; |
2bdf0193 | 67 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
2bdf0193 | 68 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; |
b2c971ec | 69 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; |
e4bbed4b | 70 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampDelta; |
2bdf0193 | 71 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
b8585c7c | 72 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; |
2bdf0193 | 73 | import org.eclipse.tracecompass.tmf.ui.editors.ITmfTraceEditor; |
d90ae2a5 RK |
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; | |
ade0a3c5 | 78 | import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView; |
2bdf0193 | 79 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphTimeListener; |
d8a230f8 | 80 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphContentProvider; |
2bdf0193 AM |
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; | |
e8251298 | 90 | import org.eclipse.ui.IEditorPart; |
d2fb9e0f | 91 | import org.eclipse.ui.IWorkbenchActionConstants; |
e8251298 PT |
92 | |
93 | /** | |
94 | * Main implementation for the Call Stack view | |
95 | * | |
96 | * @author Patrick Tasse | |
e8251298 | 97 | */ |
ade0a3c5 | 98 | public class CallStackView extends AbstractTimeGraphView { |
e8251298 PT |
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 | ||
ade0a3c5 | 107 | private static final String[] COLUMN_NAMES = new String[] { |
e8251298 PT |
108 | Messages.CallStackView_FunctionColumn, |
109 | Messages.CallStackView_DepthColumn, | |
110 | Messages.CallStackView_EntryTimeColumn, | |
111 | Messages.CallStackView_ExitTimeColumn, | |
112 | Messages.CallStackView_DurationColumn | |
113 | }; | |
114 | ||
ade0a3c5 PT |
115 | private static final String[] FILTER_COLUMN_NAMES = new String[] { |
116 | Messages.CallStackView_ThreadColumn | |
52974e38 PT |
117 | }; |
118 | ||
26c33ee2 PT |
119 | /** Timeout between updates in the build thread in ms */ |
120 | private static final long BUILD_UPDATE_TIMEOUT = 500; | |
121 | ||
52974e38 PT |
122 | // Fraction of a function duration to be added as spacing |
123 | private static final double SPACING_RATIO = 0.01; | |
124 | ||
1302015b | 125 | private static final Image PROCESS_IMAGE = Activator.getDefault().getImageFromPath("icons/obj16/process_obj.gif"); //$NON-NLS-1$ |
e8251298 PT |
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 | ||
41d9ce5b | 129 | private static final String IMPORT_BINARY_ICON_PATH = "icons/obj16/binaries_obj.gif"; //$NON-NLS-1$ |
5da83da5 | 130 | |
46cc1ade PT |
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$ | |
bac9c0df MK |
138 | |
139 | private enum SortOption { | |
140 | BY_NAME, BY_NAME_REV, BY_ID, BY_ID_REV, BY_TIME, BY_TIME_REV | |
141 | } | |
142 | ||
ade0a3c5 PT |
143 | private @NonNull SortOption fSortOption = SortOption.BY_NAME; |
144 | private @NonNull Comparator<ITimeGraphEntry> fThreadComparator = new ThreadNameComparator(false); | |
46cc1ade PT |
145 | private Action fSortByNameAction; |
146 | private Action fSortByIdAction; | |
147 | private Action fSortByTimeAction; | |
148 | ||
e8251298 PT |
149 | // ------------------------------------------------------------------------ |
150 | // Fields | |
151 | // ------------------------------------------------------------------------ | |
152 | ||
d90ae2a5 | 153 | private final Map<ITmfTrace, ISymbolProvider> fSymbolProviders = new HashMap<>(); |
5da83da5 | 154 | |
e8251298 PT |
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 | ||
41d9ce5b | 167 | // The action to import a binary file mapping */ |
d90ae2a5 | 168 | private Action fConfigureSymbolsAction; |
41d9ce5b | 169 | |
e8251298 | 170 | // The saved time sync. signal used when switching off the pinning of a view |
97c71024 | 171 | private TmfSelectionRangeUpdatedSignal fSavedTimeSyncSignal; |
e8251298 | 172 | |
97c71024 | 173 | // The saved window range signal used when switching off the pinning of |
bac9c0df | 174 | // a view |
97c71024 | 175 | private TmfWindowRangeUpdatedSignal fSavedRangeSyncSignal; |
e8251298 | 176 | |
1302015b PT |
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 | ||
e8251298 PT |
181 | // ------------------------------------------------------------------------ |
182 | // Classes | |
183 | // ------------------------------------------------------------------------ | |
184 | ||
658e0268 | 185 | private static class TraceEntry extends TimeGraphEntry { |
60b4d44c PT |
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 | ||
7f86b721 AM |
196 | private static class ProcessEntry extends TimeGraphEntry { |
197 | ||
4ce4d8af AM |
198 | private final int fProcessId; |
199 | ||
200 | public ProcessEntry(String name, int processId, long startTime, long endTime) { | |
7f86b721 | 201 | super(name, startTime, endTime); |
4ce4d8af AM |
202 | fProcessId = processId; |
203 | } | |
204 | ||
7f86b721 AM |
205 | @Override |
206 | public boolean hasTimeEvents() { | |
207 | return false; | |
208 | } | |
209 | } | |
210 | ||
658e0268 | 211 | private static class ThreadEntry extends TimeGraphEntry { |
46cc1ade PT |
212 | // The thread id |
213 | private final long fThreadId; | |
e8251298 | 214 | |
1302015b | 215 | public ThreadEntry(String name, long threadId, long startTime, long endTime) { |
60b4d44c | 216 | super(name, startTime, endTime); |
46cc1ade | 217 | fThreadId = threadId; |
e8251298 PT |
218 | } |
219 | ||
e8251298 PT |
220 | @Override |
221 | public boolean hasTimeEvents() { | |
222 | return false; | |
223 | } | |
224 | ||
46cc1ade PT |
225 | public long getThreadId() { |
226 | return fThreadId; | |
227 | } | |
e8251298 PT |
228 | } |
229 | ||
ade0a3c5 PT |
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); | |
4ce4d8af AM |
235 | } else if (o1 instanceof ProcessEntry && o2 instanceof ProcessEntry) { |
236 | return Integer.compare(((ProcessEntry) o1).fProcessId, ((ProcessEntry) o2).fProcessId); | |
ade0a3c5 PT |
237 | } |
238 | return 0; | |
239 | } | |
240 | } | |
241 | ||
658e0268 | 242 | private static class ThreadNameComparator implements Comparator<ITimeGraphEntry> { |
46cc1ade | 243 | private boolean reverse; |
bac9c0df | 244 | |
46cc1ade PT |
245 | public ThreadNameComparator(boolean reverse) { |
246 | this.reverse = reverse; | |
247 | } | |
bac9c0df | 248 | |
46cc1ade PT |
249 | @Override |
250 | public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) { | |
251 | return reverse ? o2.getName().compareTo(o1.getName()) : | |
bac9c0df | 252 | o1.getName().compareTo(o2.getName()); |
46cc1ade PT |
253 | } |
254 | } | |
255 | ||
658e0268 | 256 | private static class ThreadIdComparator implements Comparator<ITimeGraphEntry> { |
46cc1ade | 257 | private boolean reverse; |
bac9c0df | 258 | |
46cc1ade PT |
259 | public ThreadIdComparator(boolean reverse) { |
260 | this.reverse = reverse; | |
261 | } | |
bac9c0df | 262 | |
46cc1ade PT |
263 | @Override |
264 | public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) { | |
7e0d06ba PT |
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()) : | |
bac9c0df | 269 | Long.compare(t1.getThreadId(), t2.getThreadId()); |
7e0d06ba PT |
270 | } |
271 | return 0; | |
46cc1ade PT |
272 | } |
273 | } | |
274 | ||
658e0268 | 275 | private static class ThreadTimeComparator implements Comparator<ITimeGraphEntry> { |
46cc1ade | 276 | private boolean reverse; |
bac9c0df | 277 | |
46cc1ade PT |
278 | public ThreadTimeComparator(boolean reverse) { |
279 | this.reverse = reverse; | |
280 | } | |
bac9c0df | 281 | |
46cc1ade PT |
282 | @Override |
283 | public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) { | |
284 | return reverse ? Long.compare(o2.getStartTime(), o1.getStartTime()) : | |
bac9c0df | 285 | Long.compare(o1.getStartTime(), o2.getStartTime()); |
46cc1ade PT |
286 | } |
287 | } | |
288 | ||
658e0268 | 289 | private static class CallStackTreeLabelProvider extends TreeLabelProvider { |
e8251298 PT |
290 | |
291 | @Override | |
292 | public Image getColumnImage(Object element, int columnIndex) { | |
293 | if (columnIndex == 0) { | |
1302015b PT |
294 | if (element instanceof ProcessEntry) { |
295 | return PROCESS_IMAGE; | |
296 | } else if (element instanceof ThreadEntry) { | |
e8251298 PT |
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) { | |
60b4d44c | 310 | if (element instanceof CallStackEntry) { |
e8251298 PT |
311 | CallStackEntry entry = (CallStackEntry) element; |
312 | if (columnIndex == 0) { | |
313 | return entry.getFunctionName(); | |
52974e38 PT |
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) { | |
b2c971ec | 318 | ITmfTimestamp ts = TmfTimestamp.fromNanos(entry.getFunctionEntryTime()); |
52974e38 PT |
319 | return ts.toString(); |
320 | } else if (columnIndex == 3 && entry.getFunctionName().length() > 0) { | |
b2c971ec | 321 | ITmfTimestamp ts = TmfTimestamp.fromNanos(entry.getFunctionExitTime()); |
52974e38 PT |
322 | return ts.toString(); |
323 | } else if (columnIndex == 4 && entry.getFunctionName().length() > 0) { | |
60b4d44c | 324 | ITmfTimestamp ts = new TmfTimestampDelta(entry.getFunctionExitTime() - entry.getFunctionEntryTime(), ITmfTimestamp.NANOSECOND_SCALE); |
52974e38 | 325 | return ts.toString(); |
e8251298 | 326 | } |
60b4d44c PT |
327 | } else if (element instanceof ITimeGraphEntry) { |
328 | if (columnIndex == 0) { | |
329 | return ((ITimeGraphEntry) element).getName(); | |
330 | } | |
e8251298 PT |
331 | } |
332 | return ""; //$NON-NLS-1$ | |
333 | } | |
334 | ||
335 | } | |
336 | ||
ade0a3c5 | 337 | private class CallStackFilterContentProvider extends TimeGraphContentProvider { |
e8251298 | 338 | @Override |
ade0a3c5 PT |
339 | public boolean hasChildren(Object element) { |
340 | if (element instanceof TraceEntry) { | |
341 | return super.hasChildren(element); | |
e8251298 | 342 | } |
ade0a3c5 | 343 | return false; |
e8251298 PT |
344 | } |
345 | ||
346 | @Override | |
ade0a3c5 PT |
347 | public ITimeGraphEntry[] getChildren(Object parentElement) { |
348 | if (parentElement instanceof TraceEntry) { | |
349 | return super.getChildren(parentElement); | |
e8251298 | 350 | } |
ade0a3c5 | 351 | return new ITimeGraphEntry[0]; |
e8251298 PT |
352 | } |
353 | } | |
354 | ||
355 | // ------------------------------------------------------------------------ | |
356 | // Constructors | |
357 | // ------------------------------------------------------------------------ | |
358 | ||
359 | /** | |
360 | * Default constructor | |
361 | */ | |
362 | public CallStackView() { | |
ade0a3c5 PT |
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()); | |
e8251298 PT |
371 | } |
372 | ||
373 | // ------------------------------------------------------------------------ | |
374 | // ViewPart | |
375 | // ------------------------------------------------------------------------ | |
376 | ||
377 | @Override | |
378 | public void createPartControl(Composite parent) { | |
d2e4afa7 | 379 | super.createPartControl(parent); |
e8251298 | 380 | |
ade0a3c5 | 381 | getTimeGraphViewer().addTimeListener(new ITimeGraphTimeListener() { |
e8251298 PT |
382 | @Override |
383 | public void timeSelected(TimeGraphTimeEvent event) { | |
ade0a3c5 | 384 | synchingToTime(event.getBeginTime()); |
e8251298 PT |
385 | } |
386 | }); | |
387 | ||
ade0a3c5 | 388 | getTimeGraphCombo().getTreeViewer().addDoubleClickListener(new IDoubleClickListener() { |
e8251298 PT |
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) { | |
60b4d44c PT |
395 | long entryTime = entry.getFunctionEntryTime(); |
396 | long exitTime = entry.getFunctionExitTime(); | |
397 | long spacingTime = (long) ((exitTime - entryTime) * SPACING_RATIO); | |
398 | entryTime -= spacingTime; | |
399 | exitTime += spacingTime; | |
b2c971ec | 400 | TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(entryTime), TmfTimestamp.fromNanos(exitTime)); |
97c71024 | 401 | broadcast(new TmfWindowRangeUpdatedSignal(CallStackView.this, range)); |
ade0a3c5 | 402 | getTimeGraphViewer().setStartFinishTime(entryTime, exitTime); |
60b4d44c | 403 | startZoomThread(entryTime, exitTime); |
e8251298 PT |
404 | } |
405 | } | |
406 | } | |
407 | }); | |
408 | ||
ade0a3c5 | 409 | getTimeGraphViewer().getTimeGraphControl().addMouseListener(new MouseAdapter() { |
e8251298 PT |
410 | @Override |
411 | public void mouseDoubleClick(MouseEvent e) { | |
ade0a3c5 | 412 | TimeGraphControl timeGraphControl = getTimeGraphViewer().getTimeGraphControl(); |
e8251298 PT |
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(); | |
52974e38 | 420 | long spacingTime = (long) ((endTime - startTime) * SPACING_RATIO); |
e8251298 PT |
421 | startTime -= spacingTime; |
422 | endTime += spacingTime; | |
b2c971ec | 423 | TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(startTime), TmfTimestamp.fromNanos(endTime)); |
97c71024 | 424 | broadcast(new TmfWindowRangeUpdatedSignal(CallStackView.this, range)); |
ade0a3c5 | 425 | getTimeGraphViewer().setStartFinishTime(startTime, endTime); |
e8251298 PT |
426 | startZoomThread(startTime, endTime); |
427 | } | |
428 | } | |
429 | } | |
430 | }); | |
431 | ||
e8251298 | 432 | contributeToActionBars(); |
46cc1ade | 433 | loadSortOption(); |
e8251298 PT |
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 | ||
e8251298 | 444 | /** |
97c71024 | 445 | * Handler for the selection range signal. |
e8251298 PT |
446 | * |
447 | * @param signal | |
448 | * The incoming signal | |
97c71024 | 449 | * @since 1.0 |
e8251298 | 450 | */ |
ade0a3c5 | 451 | @Override |
e8251298 | 452 | @TmfSignalHandler |
97c71024 | 453 | public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) { |
e8251298 | 454 | |
97c71024 | 455 | fSavedTimeSyncSignal = isPinned() ? new TmfSelectionRangeUpdatedSignal(signal.getSource(), signal.getBeginTime(), signal.getEndTime()) : null; |
e8251298 | 456 | |
ade0a3c5 | 457 | if (signal.getSource() == this || getTrace() == null || isPinned()) { |
e8251298 PT |
458 | return; |
459 | } | |
16801c72 MK |
460 | final long beginTime = signal.getBeginTime().toNanos(); |
461 | final long endTime = signal.getEndTime().toNanos(); | |
e8251298 PT |
462 | Display.getDefault().asyncExec(new Runnable() { |
463 | @Override | |
464 | public void run() { | |
ade0a3c5 | 465 | if (getTimeGraphCombo().isDisposed()) { |
e8251298 PT |
466 | return; |
467 | } | |
0fcf3b09 | 468 | if (beginTime == endTime) { |
ade0a3c5 | 469 | getTimeGraphViewer().setSelectedTime(beginTime, true); |
0fcf3b09 | 470 | } else { |
ade0a3c5 | 471 | getTimeGraphViewer().setSelectionRange(beginTime, endTime, true); |
0fcf3b09 | 472 | } |
1302015b | 473 | fSyncSelection = true; |
26c33ee2 | 474 | synchingToTime(beginTime); |
1302015b | 475 | fSyncSelection = false; |
ade0a3c5 | 476 | startZoomThread(getTimeGraphViewer().getTime0(), getTimeGraphViewer().getTime1()); |
e8251298 PT |
477 | } |
478 | }); | |
7f86b721 | 479 | |
e8251298 PT |
480 | } |
481 | ||
37838e00 BH |
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 | ||
e8251298 PT |
500 | // ------------------------------------------------------------------------ |
501 | // Internal | |
502 | // ------------------------------------------------------------------------ | |
5da83da5 | 503 | |
d90ae2a5 RK |
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 | ||
ade0a3c5 | 524 | @Override |
f8f46a52 | 525 | protected void buildEntryList(final ITmfTrace trace, final ITmfTrace parentTrace, final IProgressMonitor monitor) { |
26c33ee2 PT |
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<>(); | |
7f86b721 | 541 | Map<Integer, ProcessEntry> processEntryMap = new HashMap<>(); |
26c33ee2 | 542 | Map<Integer, ThreadEntry> threadEntryMap = new HashMap<>(); |
26c33ee2 PT |
543 | |
544 | long start = ss.getStartTime(); | |
545 | ||
546 | boolean complete = false; | |
547 | while (!complete) { | |
e8251298 PT |
548 | if (monitor.isCanceled()) { |
549 | return; | |
550 | } | |
26c33ee2 PT |
551 | complete = ss.waitUntilBuilt(BUILD_UPDATE_TIMEOUT); |
552 | if (ss.isCancelled()) { | |
da27e43a PT |
553 | return; |
554 | } | |
26c33ee2 PT |
555 | long end = ss.getCurrentEndTime(); |
556 | if (start == end && !complete) { // when complete execute one last time regardless of end time | |
e8251298 PT |
557 | continue; |
558 | } | |
d90ae2a5 RK |
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 | ||
7f86b721 | 569 | |
26c33ee2 PT |
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 | } | |
1a0ff02c | 579 | |
7f86b721 | 580 | List<Integer> processQuarks = ss.getQuarks(module.getProcessesPattern()); |
1302015b PT |
581 | for (int processQuark : processQuarks) { |
582 | ||
583 | /* | |
584 | * Default to trace entry, overwrite if a process entry exists. | |
585 | */ | |
586 | TimeGraphEntry threadParent = traceEntry; | |
587 | int processId = -1; | |
588 | if (processQuark != ITmfStateSystem.ROOT_ATTRIBUTE) { | |
589 | /* Create the entry for the process */ | |
590 | ProcessEntry processEntry = processEntryMap.get(processQuark); | |
591 | if (processEntry == null) { | |
592 | String name = ss.getAttributeName(processQuark); | |
593 | /* The attribute name should already be parseable to integer */ | |
594 | processId = Integer.parseInt(name); | |
595 | processEntry = new ProcessEntry(name, processId, start, end); | |
596 | processEntryMap.put(processQuark, processEntry); | |
597 | traceEntry.addChild(processEntry); | |
598 | } else { | |
599 | processEntry.updateEndTime(end); | |
600 | } | |
601 | /* The parent of the thread entries will be a process */ | |
602 | threadParent = processEntry; | |
603 | } | |
7f86b721 AM |
604 | |
605 | /* Create the threads under the process */ | |
606 | try { | |
1302015b | 607 | List<Integer> threadQuarks = ss.getQuarks(processQuark, module.getThreadsPattern()); |
7f86b721 AM |
608 | |
609 | /* | |
610 | * Only query startStates if necessary (threadEntry == null) | |
611 | */ | |
612 | List<ITmfStateInterval> startStates = null; | |
613 | List<ITmfStateInterval> endStates = ss.queryFullState(ss.getCurrentEndTime()); | |
1302015b | 614 | for (int threadQuark : threadQuarks) { |
7f86b721 AM |
615 | if (monitor.isCanceled()) { |
616 | return; | |
1a0ff02c | 617 | } |
7f86b721 | 618 | |
1302015b | 619 | String[] callStackPath = module.getCallStackPath(); |
7f86b721 AM |
620 | int callStackQuark = ss.getQuarkRelative(threadQuark, callStackPath); |
621 | String threadName = ss.getAttributeName(threadQuark); | |
622 | long threadEnd = end + 1; | |
623 | ITmfStateInterval endInterval = endStates.get(callStackQuark); | |
624 | if (endInterval.getStateValue().isNull() && endInterval.getStartTime() != ss.getStartTime()) { | |
625 | threadEnd = endInterval.getStartTime(); | |
26c33ee2 | 626 | } |
1302015b PT |
627 | /* |
628 | * Default to process/trace entry, overwrite if a thread entry exists. | |
629 | */ | |
630 | TimeGraphEntry callStackParent = threadParent; | |
631 | if (threadQuark != processQuark) { | |
632 | ThreadEntry threadEntry = threadEntryMap.get(threadQuark); | |
633 | if (threadEntry == null) { | |
634 | if (startStates == null) { | |
635 | startStates = ss.queryFullState(ss.getStartTime()); | |
636 | } | |
637 | long threadId = endStates.get(threadQuark).getStateValue().unboxLong(); | |
638 | long threadStart = start; | |
639 | ITmfStateInterval startInterval = startStates.get(callStackQuark); | |
640 | if (startInterval.getStateValue().isNull()) { | |
641 | threadStart = Math.min(startInterval.getEndTime() + 1, end + 1); | |
642 | } | |
643 | threadEntry = new ThreadEntry(threadName, threadId, threadStart, threadEnd); | |
644 | threadEntryMap.put(threadQuark, threadEntry); | |
645 | threadParent.addChild(threadEntry); | |
646 | } else { | |
647 | threadEntry.updateEndTime(threadEnd); | |
7f86b721 | 648 | } |
1302015b PT |
649 | /* The parent of the call stack entries will be a thread */ |
650 | callStackParent = threadEntry; | |
7f86b721 AM |
651 | } |
652 | int level = 1; | |
653 | for (int stackLevelQuark : ss.getSubAttributes(callStackQuark, false)) { | |
1302015b | 654 | if (level > callStackParent.getChildren().size()) { |
4ce4d8af | 655 | CallStackEntry callStackEntry = new CallStackEntry(threadName, stackLevelQuark, level, processId, trace, ss); |
1302015b | 656 | callStackParent.addChild(callStackEntry); |
7f86b721 AM |
657 | } |
658 | level++; | |
26c33ee2 | 659 | } |
e8251298 | 660 | } |
7f86b721 AM |
661 | } catch (AttributeNotFoundException e) { |
662 | Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$ | |
663 | } catch (StateSystemDisposedException e) { | |
664 | /* Ignored */ | |
e8251298 PT |
665 | } |
666 | } | |
7f86b721 | 667 | |
ade0a3c5 PT |
668 | if (parentTrace == getTrace()) { |
669 | synchronized (this) { | |
670 | setStartTime(getStartTime() == SWT.DEFAULT ? start : Math.min(getStartTime(), start)); | |
671 | setEndTime(getEndTime() == SWT.DEFAULT ? end + 1 : Math.max(getEndTime(), end + 1)); | |
26c33ee2 | 672 | } |
ade0a3c5 | 673 | synchingToTime(getTimeGraphViewer().getSelectionBegin()); |
26c33ee2 PT |
674 | refresh(); |
675 | } | |
7f86b721 AM |
676 | |
677 | for (ITimeGraphEntry processEntry : traceEntry.getChildren()) { | |
678 | for (ITimeGraphEntry threadEntry : processEntry.getChildren()) { | |
679 | for (ITimeGraphEntry callStackEntry : threadEntry.getChildren()) { | |
680 | if (monitor.isCanceled()) { | |
681 | return; | |
682 | } | |
683 | buildStatusEvents(parentTrace, (CallStackEntry) callStackEntry, monitor, ss.getStartTime(), end); | |
60b4d44c | 684 | } |
e8251298 | 685 | } |
e8251298 | 686 | } |
26c33ee2 | 687 | start = end; |
e8251298 PT |
688 | } |
689 | } | |
690 | ||
26c33ee2 | 691 | private void addUnavailableEntry(ITmfTrace trace, ITmfTrace parentTrace) { |
60b4d44c PT |
692 | String name = Messages.CallStackView_StackInfoNotAvailable + ' ' + '(' + trace.getName() + ')'; |
693 | TraceEntry unavailableEntry = new TraceEntry(name, 0, 0); | |
26c33ee2 | 694 | addToEntryList(parentTrace, Collections.singletonList(unavailableEntry)); |
ade0a3c5 | 695 | if (parentTrace == getTrace()) { |
26c33ee2 PT |
696 | refresh(); |
697 | } | |
2002c638 AM |
698 | } |
699 | ||
ade0a3c5 | 700 | private void buildStatusEvents(ITmfTrace trace, CallStackEntry entry, @NonNull IProgressMonitor monitor, long start, long end) { |
da27e43a | 701 | ITmfStateSystem ss = entry.getStateSystem(); |
ade0a3c5 | 702 | long resolution = Math.max(1, (end - ss.getStartTime()) / getDisplayWidth()); |
26c33ee2 PT |
703 | List<ITimeEvent> eventList = getEventList(entry, start, end + 1, resolution, monitor); |
704 | if (eventList != null) { | |
8d5d4aa4 | 705 | entry.setEventList(eventList); |
e8251298 | 706 | } |
ade0a3c5 | 707 | if (trace == getTrace()) { |
e8251298 PT |
708 | redraw(); |
709 | } | |
710 | } | |
711 | ||
ade0a3c5 PT |
712 | /** |
713 | * @since 2.0 | |
714 | */ | |
715 | @Override | |
716 | protected final List<ITimeEvent> getEventList(TimeGraphEntry tgentry, long startTime, long endTime, long resolution, IProgressMonitor monitor) { | |
717 | if (!(tgentry instanceof CallStackEntry)) { | |
718 | return null; | |
719 | } | |
720 | CallStackEntry entry = (CallStackEntry) tgentry; | |
da27e43a | 721 | ITmfStateSystem ss = entry.getStateSystem(); |
e8251298 PT |
722 | long start = Math.max(startTime, ss.getStartTime()); |
723 | long end = Math.min(endTime, ss.getCurrentEndTime() + 1); | |
724 | if (end <= start) { | |
725 | return null; | |
726 | } | |
8d5d4aa4 | 727 | boolean isZoomThread = Thread.currentThread() instanceof ZoomThread; |
e8251298 PT |
728 | List<ITimeEvent> eventList = null; |
729 | try { | |
1dd75589 | 730 | List<ITmfStateInterval> stackIntervals = StateSystemUtils.queryHistoryRange(ss, entry.getQuark(), start, end - 1, resolution, monitor); |
507b1336 | 731 | eventList = new ArrayList<>(stackIntervals.size()); |
e8251298 | 732 | long lastEndTime = -1; |
fb70173e | 733 | boolean lastIsNull = false; |
e8251298 PT |
734 | for (ITmfStateInterval statusInterval : stackIntervals) { |
735 | if (monitor.isCanceled()) { | |
736 | return null; | |
737 | } | |
738 | long time = statusInterval.getStartTime(); | |
739 | long duration = statusInterval.getEndTime() - time + 1; | |
740 | if (!statusInterval.getStateValue().isNull()) { | |
52974e38 PT |
741 | final int modulo = CallStackPresentationProvider.NUM_COLORS / 2; |
742 | int value = statusInterval.getStateValue().toString().hashCode() % modulo + modulo; | |
e8251298 PT |
743 | eventList.add(new CallStackEvent(entry, time, duration, value)); |
744 | lastIsNull = false; | |
745 | } else { | |
8d5d4aa4 | 746 | if (lastEndTime == -1 && isZoomThread) { |
beb1b921 PT |
747 | // add null event if it intersects the start time |
748 | eventList.add(new NullTimeEvent(entry, time, duration)); | |
749 | } else { | |
750 | if (lastEndTime != time && lastIsNull) { | |
751 | // add unknown event if between two null states | |
752 | eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime)); | |
753 | } | |
8d5d4aa4 | 754 | if (time + duration >= endTime && isZoomThread) { |
beb1b921 PT |
755 | // add null event if it intersects the end time |
756 | eventList.add(new NullTimeEvent(entry, time, duration)); | |
757 | } | |
e8251298 | 758 | } |
e8251298 PT |
759 | lastIsNull = true; |
760 | } | |
761 | lastEndTime = time + duration; | |
762 | } | |
763 | } catch (AttributeNotFoundException e) { | |
52974e38 | 764 | Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$ |
e8251298 | 765 | } catch (TimeRangeException e) { |
52974e38 | 766 | Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$ |
e8251298 PT |
767 | } catch (StateSystemDisposedException e) { |
768 | /* Ignored */ | |
769 | } | |
770 | return eventList; | |
771 | } | |
772 | ||
ade0a3c5 PT |
773 | /** |
774 | * @since 2.0 | |
775 | */ | |
776 | @Override | |
1302015b PT |
777 | protected void synchingToTime(final long time) { |
778 | List<TimeGraphEntry> traceEntries = getEntryList(getTrace()); | |
779 | Map<ITmfStateSystem, List<ITmfStateInterval>> fullStateMap = new HashMap<>(); | |
780 | if (traceEntries == null) { | |
e8251298 PT |
781 | return; |
782 | } | |
1302015b PT |
783 | Consumer<TimeGraphEntry> consumer = new Consumer<TimeGraphEntry>() { |
784 | @Override | |
785 | public void accept(TimeGraphEntry entry) { | |
786 | if (entry instanceof CallStackEntry) { | |
787 | CallStackEntry callStackEntry = (CallStackEntry) entry; | |
788 | ITmfStateSystem ss = callStackEntry.getStateSystem(); | |
7f86b721 | 789 | if (time < ss.getStartTime() || time > ss.getCurrentEndTime()) { |
1302015b | 790 | return; |
7f86b721 | 791 | } |
1302015b PT |
792 | ITmfTrace trace = callStackEntry.getTrace(); |
793 | try { | |
794 | List<ITmfStateInterval> fullState = getFullState(ss); | |
795 | ITmfStateInterval stackLevelInterval = fullState.get(callStackEntry.getQuark()); | |
796 | ITmfStateValue nameValue = stackLevelInterval.getStateValue(); | |
797 | ||
798 | String name = getFunctionName(trace, callStackEntry.getProcessId(), time, nameValue); | |
799 | callStackEntry.setFunctionName(name); | |
800 | if (!name.isEmpty()) { | |
801 | callStackEntry.setFunctionEntryTime(stackLevelInterval.getStartTime()); | |
802 | callStackEntry.setFunctionExitTime(stackLevelInterval.getEndTime() + 1); | |
803 | } | |
804 | if (fSyncSelection) { | |
805 | int callStackQuark = ss.getParentAttributeQuark(callStackEntry.getQuark()); | |
806 | ITmfStateInterval stackInterval = fullState.get(callStackQuark); | |
807 | if (time == stackInterval.getStartTime()) { | |
808 | ITmfStateValue stackLevelState = stackInterval.getStateValue(); | |
809 | if (stackLevelState.unboxInt() == callStackEntry.getStackLevel() || stackLevelState.isNull()) { | |
810 | Display.getDefault().asyncExec(() -> { | |
811 | getTimeGraphCombo().setSelection(callStackEntry); | |
812 | getTimeGraphViewer().getTimeGraphControl().fireSelectionChanged(); | |
813 | fSyncSelection = false; | |
814 | }); | |
815 | } | |
7f86b721 | 816 | } |
60b4d44c | 817 | } |
1302015b PT |
818 | } catch (StateSystemDisposedException e) { |
819 | /* Ignored */ | |
e8251298 | 820 | } |
1302015b | 821 | return; |
e8251298 | 822 | } |
1302015b | 823 | entry.getChildren().forEach(this); |
e8251298 | 824 | } |
1302015b PT |
825 | |
826 | private List<ITmfStateInterval> getFullState(ITmfStateSystem ss) throws StateSystemDisposedException { | |
827 | List<ITmfStateInterval> fullState = fullStateMap.get(ss); | |
828 | if (fullState == null) { | |
829 | fullState = ss.queryFullState(time); | |
830 | fullStateMap.put(ss, fullState); | |
831 | } | |
832 | return fullState; | |
833 | } | |
834 | }; | |
835 | traceEntries.forEach(consumer); | |
ade0a3c5 PT |
836 | if (Display.getCurrent() != null) { |
837 | getTimeGraphCombo().refresh(); | |
e8251298 | 838 | } |
e8251298 PT |
839 | } |
840 | ||
4ce4d8af | 841 | String getFunctionName(ITmfTrace trace, int processId, long timestamp, ITmfStateValue nameValue) { |
d90ae2a5 RK |
842 | long address = Long.MAX_VALUE; |
843 | String name = ""; //$NON-NLS-1$ | |
844 | try { | |
845 | if (nameValue.getType() == Type.STRING) { | |
846 | name = nameValue.unboxStr(); | |
847 | try { | |
848 | address = Long.parseLong(name, 16); | |
849 | } catch (NumberFormatException e) { | |
850 | // ignore | |
851 | } | |
852 | } else if (nameValue.getType() == Type.INTEGER) { | |
c3777c23 | 853 | name = "0x" + Integer.toUnsignedString(nameValue.unboxInt(), 16); //$NON-NLS-1$ |
d90ae2a5 RK |
854 | address = nameValue.unboxInt(); |
855 | } else if (nameValue.getType() == Type.LONG) { | |
c3777c23 | 856 | name = "0x" + Long.toUnsignedString(nameValue.unboxLong(), 16); //$NON-NLS-1$ |
d90ae2a5 RK |
857 | address = nameValue.unboxLong(); |
858 | } | |
859 | } catch (StateValueTypeException e) { | |
860 | } | |
861 | if (address != Long.MAX_VALUE) { | |
862 | ISymbolProvider provider = fSymbolProviders.get(trace); | |
863 | if (provider != null) { | |
4ce4d8af | 864 | String symbol = provider.getSymbolText(processId, timestamp, address); |
d90ae2a5 RK |
865 | if (symbol != null) { |
866 | name = symbol; | |
867 | } | |
868 | } | |
869 | } | |
870 | return name; | |
871 | } | |
872 | ||
e8251298 | 873 | private void makeActions() { |
ade0a3c5 | 874 | fPreviousItemAction = getTimeGraphViewer().getPreviousItemAction(); |
e8251298 PT |
875 | fPreviousItemAction.setText(Messages.TmfTimeGraphViewer_PreviousItemActionNameText); |
876 | fPreviousItemAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousItemActionToolTipText); | |
ade0a3c5 | 877 | fNextItemAction = getTimeGraphViewer().getNextItemAction(); |
e8251298 PT |
878 | fNextItemAction.setText(Messages.TmfTimeGraphViewer_NextItemActionNameText); |
879 | fNextItemAction.setToolTipText(Messages.TmfTimeGraphViewer_NextItemActionToolTipText); | |
880 | } | |
881 | ||
882 | private void contributeToActionBars() { | |
e8251298 PT |
883 | // Create pin action |
884 | contributePinActionToToolBar(); | |
bac9c0df | 885 | fPinAction.addPropertyChangeListener(new IPropertyChangeListener() { |
e8251298 PT |
886 | @Override |
887 | public void propertyChange(PropertyChangeEvent event) { | |
52974e38 PT |
888 | if (IAction.CHECKED.equals(event.getProperty()) && !isPinned()) { |
889 | if (fSavedRangeSyncSignal != null) { | |
97c71024 | 890 | windowRangeUpdated(fSavedRangeSyncSignal); |
52974e38 PT |
891 | fSavedRangeSyncSignal = null; |
892 | } | |
e8251298 | 893 | |
52974e38 | 894 | if (fSavedTimeSyncSignal != null) { |
97c71024 | 895 | selectionRangeUpdated(fSavedTimeSyncSignal); |
52974e38 | 896 | fSavedTimeSyncSignal = null; |
e8251298 PT |
897 | } |
898 | } | |
899 | } | |
900 | }); | |
901 | } | |
902 | ||
ade0a3c5 PT |
903 | /** |
904 | * @since 2.0 | |
905 | */ | |
906 | @Override | |
907 | protected void fillLocalToolBar(IToolBarManager manager) { | |
908 | makeActions(); | |
d90ae2a5 | 909 | manager.add(getConfigureSymbolsAction()); |
46cc1ade PT |
910 | manager.add(new Separator()); |
911 | manager.add(getSortByNameAction()); | |
912 | manager.add(getSortByIdAction()); | |
913 | manager.add(getSortByTimeAction()); | |
914 | manager.add(new Separator()); | |
ade0a3c5 PT |
915 | manager.add(getTimeGraphCombo().getShowFilterDialogAction()); |
916 | manager.add(new Separator()); | |
917 | manager.add(getTimeGraphViewer().getResetScaleAction()); | |
e8251298 PT |
918 | manager.add(getPreviousEventAction()); |
919 | manager.add(getNextEventAction()); | |
ade0a3c5 PT |
920 | manager.add(new Separator()); |
921 | manager.add(getTimeGraphViewer().getToggleBookmarkAction()); | |
922 | manager.add(getTimeGraphViewer().getPreviousMarkerAction()); | |
923 | manager.add(getTimeGraphViewer().getNextMarkerAction()); | |
924 | manager.add(new Separator()); | |
e8251298 PT |
925 | manager.add(fPreviousItemAction); |
926 | manager.add(fNextItemAction); | |
ade0a3c5 PT |
927 | manager.add(getTimeGraphViewer().getZoomInAction()); |
928 | manager.add(getTimeGraphViewer().getZoomOutAction()); | |
e8251298 PT |
929 | } |
930 | ||
90bb3a0c BH |
931 | /** |
932 | * @since 2.0 | |
933 | */ | |
934 | @Override | |
935 | protected void fillTimeGraphEntryContextMenu(IMenuManager contextMenu) { | |
d2fb9e0f | 936 | contextMenu.add(new GroupMarker(IWorkbenchActionConstants.GROUP_REORGANIZE)); |
46cc1ade PT |
937 | contextMenu.add(getSortByNameAction()); |
938 | contextMenu.add(getSortByIdAction()); | |
939 | contextMenu.add(getSortByTimeAction()); | |
46cc1ade PT |
940 | } |
941 | ||
e8251298 PT |
942 | /** |
943 | * Get the the next event action. | |
944 | * | |
945 | * @return The action object | |
946 | */ | |
947 | private Action getNextEventAction() { | |
948 | if (fNextEventAction == null) { | |
949 | fNextEventAction = new Action() { | |
950 | @Override | |
951 | public void run() { | |
ade0a3c5 | 952 | TimeGraphViewer viewer = getTimeGraphViewer(); |
e8251298 PT |
953 | ITimeGraphEntry entry = viewer.getSelection(); |
954 | if (entry instanceof CallStackEntry) { | |
955 | try { | |
956 | CallStackEntry callStackEntry = (CallStackEntry) entry; | |
da27e43a | 957 | ITmfStateSystem ss = callStackEntry.getStateSystem(); |
0fcf3b09 | 958 | long time = Math.max(ss.getStartTime(), Math.min(ss.getCurrentEndTime(), viewer.getSelectionBegin())); |
e8251298 | 959 | ThreadEntry threadEntry = (ThreadEntry) callStackEntry.getParent(); |
da27e43a | 960 | int quark = ss.getParentAttributeQuark(callStackEntry.getQuark()); |
e8251298 PT |
961 | ITmfStateInterval stackInterval = ss.querySingleState(time, quark); |
962 | long newTime = stackInterval.getEndTime() + 1; | |
963 | viewer.setSelectedTimeNotify(newTime, true); | |
964 | stackInterval = ss.querySingleState(Math.min(ss.getCurrentEndTime(), newTime), quark); | |
965 | int stackLevel = stackInterval.getStateValue().unboxInt(); | |
a3188982 | 966 | ITimeGraphEntry selectedEntry = threadEntry.getChildren().get(Math.max(0, stackLevel - 1)); |
ade0a3c5 | 967 | getTimeGraphCombo().setSelection(selectedEntry); |
e8251298 PT |
968 | viewer.getTimeGraphControl().fireSelectionChanged(); |
969 | startZoomThread(viewer.getTime0(), viewer.getTime1()); | |
50659279 | 970 | |
bac9c0df | 971 | } catch (AttributeNotFoundException | TimeRangeException | StateSystemDisposedException | StateValueTypeException e) { |
52974e38 | 972 | Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$ |
e8251298 PT |
973 | } |
974 | } | |
975 | } | |
976 | }; | |
977 | ||
978 | fNextEventAction.setText(Messages.TmfTimeGraphViewer_NextEventActionNameText); | |
979 | fNextEventAction.setToolTipText(Messages.TmfTimeGraphViewer_NextEventActionToolTipText); | |
980 | fNextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_NEXT_EVENT)); | |
981 | } | |
982 | ||
983 | return fNextEventAction; | |
984 | } | |
985 | ||
986 | /** | |
987 | * Get the previous event action. | |
988 | * | |
989 | * @return The Action object | |
990 | */ | |
991 | private Action getPreviousEventAction() { | |
992 | if (fPrevEventAction == null) { | |
993 | fPrevEventAction = new Action() { | |
994 | @Override | |
995 | public void run() { | |
ade0a3c5 | 996 | TimeGraphViewer viewer = getTimeGraphCombo().getTimeGraphViewer(); |
e8251298 PT |
997 | ITimeGraphEntry entry = viewer.getSelection(); |
998 | if (entry instanceof CallStackEntry) { | |
999 | try { | |
1000 | CallStackEntry callStackEntry = (CallStackEntry) entry; | |
da27e43a | 1001 | ITmfStateSystem ss = callStackEntry.getStateSystem(); |
0fcf3b09 | 1002 | long time = Math.max(ss.getStartTime(), Math.min(ss.getCurrentEndTime(), viewer.getSelectionBegin())); |
e8251298 | 1003 | ThreadEntry threadEntry = (ThreadEntry) callStackEntry.getParent(); |
da27e43a | 1004 | int quark = ss.getParentAttributeQuark(callStackEntry.getQuark()); |
e8251298 PT |
1005 | ITmfStateInterval stackInterval = ss.querySingleState(time, quark); |
1006 | if (stackInterval.getStartTime() == time && time > ss.getStartTime()) { | |
1007 | stackInterval = ss.querySingleState(time - 1, quark); | |
1008 | } | |
1009 | viewer.setSelectedTimeNotify(stackInterval.getStartTime(), true); | |
1010 | int stackLevel = stackInterval.getStateValue().unboxInt(); | |
a3188982 | 1011 | ITimeGraphEntry selectedEntry = threadEntry.getChildren().get(Math.max(0, stackLevel - 1)); |
ade0a3c5 | 1012 | getTimeGraphCombo().setSelection(selectedEntry); |
e8251298 PT |
1013 | viewer.getTimeGraphControl().fireSelectionChanged(); |
1014 | startZoomThread(viewer.getTime0(), viewer.getTime1()); | |
50659279 | 1015 | |
bac9c0df | 1016 | } catch (AttributeNotFoundException | TimeRangeException | StateSystemDisposedException | StateValueTypeException e) { |
52974e38 | 1017 | Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$ |
e8251298 PT |
1018 | } |
1019 | } | |
1020 | } | |
1021 | }; | |
1022 | ||
1023 | fPrevEventAction.setText(Messages.TmfTimeGraphViewer_PreviousEventActionNameText); | |
1024 | fPrevEventAction.setToolTipText(Messages.TmfTimeGraphViewer_PreviousEventActionToolTipText); | |
1025 | fPrevEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(ITmfImageConstants.IMG_UI_PREV_EVENT)); | |
1026 | } | |
1027 | ||
1028 | return fPrevEventAction; | |
1029 | } | |
1030 | ||
1d83ed07 | 1031 | private static @Nullable AbstractCallStackAnalysis getCallStackModule(@NonNull ITmfTrace trace) { |
50659279 AM |
1032 | /* |
1033 | * Since we cannot know the exact analysis ID (in separate plugins), we | |
1034 | * will search using the analysis type. | |
1035 | */ | |
1036 | Iterable<AbstractCallStackAnalysis> modules = | |
b8585c7c | 1037 | TmfTraceUtils.getAnalysisModulesOfClass(trace, AbstractCallStackAnalysis.class); |
50659279 AM |
1038 | Iterator<AbstractCallStackAnalysis> it = modules.iterator(); |
1039 | if (!it.hasNext()) { | |
1040 | /* This trace does not provide a call-stack analysis */ | |
1041 | return null; | |
1042 | } | |
1043 | ||
1044 | /* | |
1045 | * We only look at the first module we find. | |
1046 | * | |
1047 | * TODO Handle the advanced case where one trace provides more than one | |
1048 | * call-stack analysis. | |
1049 | */ | |
1050 | AbstractCallStackAnalysis module = it.next(); | |
1051 | /* This analysis is not automatic, we need to schedule it on-demand */ | |
1052 | module.schedule(); | |
c81ffdf2 JCK |
1053 | if (!module.waitForInitialization()) { |
1054 | /* The initialization did not succeed */ | |
1055 | return null; | |
1056 | } | |
da27e43a | 1057 | return module; |
50659279 AM |
1058 | } |
1059 | ||
5da83da5 AM |
1060 | // ------------------------------------------------------------------------ |
1061 | // Methods related to function name mapping | |
1062 | // ------------------------------------------------------------------------ | |
1063 | ||
46cc1ade PT |
1064 | private Action getSortByNameAction() { |
1065 | if (fSortByNameAction == null) { | |
1066 | fSortByNameAction = new Action(Messages.CallStackView_SortByThreadName, IAction.AS_CHECK_BOX) { | |
1067 | @Override | |
1068 | public void run() { | |
1069 | if (fSortOption == SortOption.BY_NAME) { | |
1070 | saveSortOption(SortOption.BY_NAME_REV); | |
1071 | } else { | |
1072 | saveSortOption(SortOption.BY_NAME); | |
1073 | } | |
1074 | } | |
1075 | }; | |
1076 | fSortByNameAction.setToolTipText(Messages.CallStackView_SortByThreadName); | |
6aea3caa | 1077 | fSortByNameAction.setImageDescriptor(SORT_BY_NAME_ICON); |
46cc1ade PT |
1078 | } |
1079 | return fSortByNameAction; | |
1080 | } | |
1081 | ||
1082 | private Action getSortByIdAction() { | |
1083 | if (fSortByIdAction == null) { | |
1084 | fSortByIdAction = new Action(Messages.CallStackView_SortByThreadId, IAction.AS_CHECK_BOX) { | |
1085 | @Override | |
1086 | public void run() { | |
1087 | if (fSortOption == SortOption.BY_ID) { | |
1088 | saveSortOption(SortOption.BY_ID_REV); | |
1089 | } else { | |
1090 | saveSortOption(SortOption.BY_ID); | |
1091 | } | |
1092 | } | |
1093 | }; | |
1094 | fSortByIdAction.setToolTipText(Messages.CallStackView_SortByThreadId); | |
6aea3caa | 1095 | fSortByIdAction.setImageDescriptor(SORT_BY_ID_ICON); |
46cc1ade PT |
1096 | } |
1097 | return fSortByIdAction; | |
1098 | } | |
1099 | ||
1100 | private Action getSortByTimeAction() { | |
1101 | if (fSortByTimeAction == null) { | |
1102 | fSortByTimeAction = new Action(Messages.CallStackView_SortByThreadTime, IAction.AS_CHECK_BOX) { | |
1103 | @Override | |
1104 | public void run() { | |
1105 | if (fSortOption == SortOption.BY_TIME) { | |
1106 | saveSortOption(SortOption.BY_TIME_REV); | |
1107 | } else { | |
1108 | saveSortOption(SortOption.BY_TIME); | |
1109 | } | |
1110 | } | |
1111 | }; | |
1112 | fSortByTimeAction.setToolTipText(Messages.CallStackView_SortByThreadTime); | |
6aea3caa | 1113 | fSortByTimeAction.setImageDescriptor(SORT_BY_TIME_ICON); |
46cc1ade PT |
1114 | } |
1115 | return fSortByTimeAction; | |
1116 | } | |
1117 | ||
1118 | private void loadSortOption() { | |
1119 | IDialogSettings settings = Activator.getDefault().getDialogSettings(); | |
1120 | IDialogSettings section = settings.getSection(getClass().getName()); | |
1121 | if (section == null) { | |
1122 | return; | |
1123 | } | |
1124 | String sortOption = section.get(SORT_OPTION_KEY); | |
6aea3caa PT |
1125 | if (sortOption == null) { |
1126 | return; | |
1127 | } | |
46cc1ade PT |
1128 | |
1129 | // reset defaults | |
1130 | getSortByNameAction().setChecked(false); | |
1131 | getSortByNameAction().setImageDescriptor(SORT_BY_NAME_ICON); | |
1132 | getSortByIdAction().setChecked(false); | |
1133 | getSortByIdAction().setImageDescriptor(SORT_BY_ID_ICON); | |
1134 | getSortByTimeAction().setChecked(false); | |
1135 | getSortByTimeAction().setImageDescriptor(SORT_BY_TIME_ICON); | |
1136 | ||
1137 | if (sortOption.equals(SortOption.BY_NAME.name())) { | |
1138 | fSortOption = SortOption.BY_NAME; | |
1139 | fThreadComparator = new ThreadNameComparator(false); | |
1140 | getSortByNameAction().setChecked(true); | |
1141 | } else if (sortOption.equals(SortOption.BY_NAME_REV.name())) { | |
1142 | fSortOption = SortOption.BY_NAME_REV; | |
1143 | fThreadComparator = new ThreadNameComparator(true); | |
1144 | getSortByNameAction().setChecked(true); | |
1145 | getSortByNameAction().setImageDescriptor(SORT_BY_NAME_REV_ICON); | |
1146 | } else if (sortOption.equals(SortOption.BY_ID.name())) { | |
1147 | fSortOption = SortOption.BY_ID; | |
1148 | fThreadComparator = new ThreadIdComparator(false); | |
1149 | getSortByIdAction().setChecked(true); | |
1150 | } else if (sortOption.equals(SortOption.BY_ID_REV.name())) { | |
1151 | fSortOption = SortOption.BY_ID_REV; | |
1152 | fThreadComparator = new ThreadIdComparator(true); | |
1153 | getSortByIdAction().setChecked(true); | |
1154 | getSortByIdAction().setImageDescriptor(SORT_BY_ID_REV_ICON); | |
1155 | } else if (sortOption.equals(SortOption.BY_TIME.name())) { | |
1156 | fSortOption = SortOption.BY_TIME; | |
1157 | fThreadComparator = new ThreadTimeComparator(false); | |
1158 | getSortByTimeAction().setChecked(true); | |
1159 | } else if (sortOption.equals(SortOption.BY_TIME_REV.name())) { | |
1160 | fSortOption = SortOption.BY_TIME_REV; | |
1161 | fThreadComparator = new ThreadTimeComparator(true); | |
1162 | getSortByTimeAction().setChecked(true); | |
1163 | getSortByTimeAction().setImageDescriptor(SORT_BY_TIME_REV_ICON); | |
1164 | } | |
1165 | } | |
1166 | ||
1167 | private void saveSortOption(SortOption sortOption) { | |
1168 | IDialogSettings settings = Activator.getDefault().getDialogSettings(); | |
1169 | IDialogSettings section = settings.getSection(getClass().getName()); | |
1170 | if (section == null) { | |
1171 | section = settings.addNewSection(getClass().getName()); | |
1172 | } | |
1173 | section.put(SORT_OPTION_KEY, sortOption.name()); | |
1174 | loadSortOption(); | |
ade0a3c5 PT |
1175 | List<TimeGraphEntry> entryList = getEntryList(getTrace()); |
1176 | if (entryList == null) { | |
46cc1ade PT |
1177 | return; |
1178 | } | |
ade0a3c5 | 1179 | for (TimeGraphEntry traceEntry : entryList) { |
46cc1ade PT |
1180 | traceEntry.sortChildren(fThreadComparator); |
1181 | } | |
1182 | refresh(); | |
1183 | } | |
1184 | ||
d90ae2a5 RK |
1185 | private Action getConfigureSymbolsAction() { |
1186 | if (fConfigureSymbolsAction != null) { | |
1187 | return fConfigureSymbolsAction; | |
5da83da5 AM |
1188 | } |
1189 | ||
d90ae2a5 | 1190 | fConfigureSymbolsAction = new Action(Messages.CallStackView_ConfigureSymbolProvidersText) { |
41d9ce5b | 1191 | @Override |
d90ae2a5 RK |
1192 | public void run() { |
1193 | SymbolProviderConfigDialog dialog = new SymbolProviderConfigDialog(getSite().getShell(), getProviderPages()); | |
1194 | if (dialog.open() == IDialogConstants.OK_ID) { | |
1195 | refresh(); | |
1196 | } | |
41d9ce5b MAL |
1197 | } |
1198 | }; | |
5da83da5 | 1199 | |
d90ae2a5 RK |
1200 | fConfigureSymbolsAction.setToolTipText(Messages.CallStackView_ConfigureSymbolProvidersTooltip); |
1201 | fConfigureSymbolsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(IMPORT_BINARY_ICON_PATH)); | |
1202 | fConfigureSymbolsAction.setEnabled(false); | |
5da83da5 | 1203 | |
d90ae2a5 | 1204 | return fConfigureSymbolsAction; |
5da83da5 AM |
1205 | } |
1206 | ||
d90ae2a5 RK |
1207 | /** |
1208 | * @return an array of {@link ISymbolProviderPreferencePage} that will | |
1209 | * configure the current traces | |
1210 | */ | |
1211 | private ISymbolProviderPreferencePage[] getProviderPages() { | |
1212 | List<ISymbolProviderPreferencePage> pages = new ArrayList<>(); | |
1213 | ITmfTrace trace = getTrace(); | |
1214 | if (trace != null) { | |
1215 | for (ITmfTrace subTrace : getTracesToBuild(trace)) { | |
1216 | ISymbolProvider provider = fSymbolProviders.get(subTrace); | |
1217 | if (provider != null) { | |
1218 | ISymbolProviderPreferencePage page = provider.createPreferencePage(); | |
1219 | if (page != null) { | |
1220 | pages.add(page); | |
1221 | } | |
1222 | } | |
1223 | } | |
5da83da5 | 1224 | } |
d90ae2a5 RK |
1225 | return pages.toArray(new ISymbolProviderPreferencePage[pages.size()]); |
1226 | } | |
1227 | ||
1228 | /** | |
1229 | * Update the enable status of the configure symbols action | |
1230 | */ | |
1231 | private void updateConfigureSymbolsAction() { | |
1232 | ISymbolProviderPreferencePage[] providerPages = getProviderPages(); | |
1233 | getConfigureSymbolsAction().setEnabled(providerPages.length > 0); | |
5da83da5 AM |
1234 | } |
1235 | ||
e8251298 | 1236 | } |