-
Notifications
You must be signed in to change notification settings - Fork 13
/
FlameChartView.java
712 lines (646 loc) · 34 KB
/
FlameChartView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
/*******************************************************************************
* Copyright (c) 2013, 2018 Ericsson and others.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tracecompass.incubator.internal.callstack.ui.views.flamechart;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tracecompass.analysis.os.linux.core.model.HostThread;
import org.eclipse.tracecompass.analysis.os.linux.core.model.OsStrings;
import org.eclipse.tracecompass.incubator.internal.callstack.core.instrumented.provider.FlameChartDataProvider;
import org.eclipse.tracecompass.incubator.internal.callstack.core.instrumented.provider.FlameChartEntryModel;
import org.eclipse.tracecompass.incubator.internal.callstack.core.instrumented.provider.FlameChartEntryModel.EntryType;
import org.eclipse.tracecompass.incubator.internal.callstack.ui.Activator;
import org.eclipse.tracecompass.internal.analysis.os.linux.ui.actions.FollowThreadAction;
import org.eclipse.tracecompass.internal.provisional.tmf.ui.widgets.timegraph.BaseDataProviderTimeGraphPresentationProvider;
import org.eclipse.tracecompass.internal.tmf.core.model.filters.FetchParametersUtils;
import org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderManager;
import org.eclipse.tracecompass.tmf.core.model.ICoreElementResolver;
import org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter;
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider;
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel;
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState;
import org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel;
import org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel;
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel;
import org.eclipse.tracecompass.tmf.core.response.TmfModelResponse;
import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.symbols.ISymbolProvider;
import org.eclipse.tracecompass.tmf.core.symbols.SymbolProviderManager;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.ui.editors.ITmfTraceEditor;
import org.eclipse.tracecompass.tmf.ui.symbols.ISymbolProviderPreferencePage;
import org.eclipse.tracecompass.tmf.ui.symbols.SymbolProviderConfigDialog;
import org.eclipse.tracecompass.tmf.ui.views.TmfViewFactory;
import org.eclipse.tracecompass.tmf.ui.views.timegraph.BaseDataProviderTimeGraphView;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NamedTimeEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
/**
* Main implementation for the Flame Chart view
*
* @author Patrick Tasse
* @author Geneviève Bastien
*/
public class FlameChartView extends BaseDataProviderTimeGraphView {
// ------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------
/** View ID. */
public static final @NonNull String ID = "org.eclipse.tracecompass.incubator.callstack.ui.views.flamechart"; //$NON-NLS-1$
private static final String[] COLUMN_NAMES = new String[] {
Messages.CallStackView_FunctionColumn,
Messages.CallStackView_DepthColumn,
Messages.CallStackView_EntryTimeColumn,
Messages.CallStackView_ExitTimeColumn,
Messages.CallStackView_DurationColumn
};
private static final Comparator<ITimeGraphEntry> DEPTH_COMPARATOR = (o1, o2) -> {
if (o1 instanceof TimeGraphEntry && o2 instanceof TimeGraphEntry) {
TimeGraphEntry t1 = (TimeGraphEntry) o1;
TimeGraphEntry t2 = (TimeGraphEntry) o2;
ITmfTreeDataModel model1 = t1.getEntryModel();
ITmfTreeDataModel model2 = t2.getEntryModel();
if (model1 instanceof FlameChartEntryModel && model2 instanceof FlameChartEntryModel) {
FlameChartEntryModel m1 = (FlameChartEntryModel) model1;
FlameChartEntryModel m2 = (FlameChartEntryModel) model2;
if (m1.getEntryType() == EntryType.FUNCTION && m2.getEntryType() == EntryType.FUNCTION) {
return Integer.compare(Integer.valueOf(m1.getName()), Integer.valueOf(m2.getName()));
}
return Integer.compare(m1.getEntryType().ordinal(), m2.getEntryType().ordinal());
}
}
return 0;
};
@SuppressWarnings("unchecked")
private static final Comparator<ITimeGraphEntry>[] COMPARATORS = new Comparator[] {
Comparator.comparing(ITimeGraphEntry::getName),
DEPTH_COMPARATOR,
Comparator.comparingLong(ITimeGraphEntry::getStartTime),
Comparator.comparingLong(ITimeGraphEntry::getEndTime)
};
private static final String[] FILTER_COLUMN_NAMES = new String[] {
Messages.CallStackView_ThreadColumn
};
private static final Image GROUP_IMAGE = Activator.getDefault().getImageFromPath("icons/obj16/thread_obj.gif"); //$NON-NLS-1$
private static final Image STACKFRAME_IMAGE = Activator.getDefault().getImageFromPath("icons/obj16/stckframe_obj.gif"); //$NON-NLS-1$
private static final String IMPORT_BINARY_ICON_PATH = "icons/obj16/binaries_obj.gif"; //$NON-NLS-1$
// ------------------------------------------------------------------------
// Fields
// ------------------------------------------------------------------------
// The next event action
private Action fNextEventAction;
// The previous event action
private Action fPrevEventAction;
// The action to import a binary file mapping */
private Action fConfigureSymbolsAction;
// When set to true, syncToTime() will select the first call stack entry
// whose current state start time exactly matches the sync time.
private boolean fSyncSelection = false;
private final Map<Long, ITimeGraphState> fFunctions = new HashMap<>();
// ------------------------------------------------------------------------
// Classes
// ------------------------------------------------------------------------
private class CallStackComparator implements Comparator<ITimeGraphEntry> {
@Override
public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
if (o1 instanceof TimeGraphEntry && o2 instanceof TimeGraphEntry) {
TimeGraphEntry t1 = (TimeGraphEntry) o1;
TimeGraphEntry t2 = (TimeGraphEntry) o2;
return DEPTH_COMPARATOR.compare(t1, t2);
}
return 0;
}
}
private class CallStackTreeLabelProvider extends TreeLabelProvider {
@Override
public Image getColumnImage(Object element, int columnIndex) {
if (columnIndex == 0 && (element instanceof TimeGraphEntry)) {
TimeGraphEntry entry = (TimeGraphEntry) element;
ITmfTreeDataModel entryModel = entry.getEntryModel();
if (entryModel instanceof FlameChartEntryModel) {
FlameChartEntryModel model = (FlameChartEntryModel) entryModel;
if (model.getEntryType() == EntryType.LEVEL) {
// Is this the symbol key image? then show the symbol
// key image, otherwise, just the group image
return GROUP_IMAGE;
}
if (model.getEntryType() == EntryType.FUNCTION && fFunctions.containsKey(entryModel.getId())) {
return STACKFRAME_IMAGE;
}
}
}
return null;
}
@Override
public String getColumnText(Object element, int columnIndex) {
if (element instanceof TraceEntry && columnIndex == 0) {
return ((TraceEntry) element).getName();
} else if (element instanceof TimeGraphEntry) {
TimeGraphEntry entry = (TimeGraphEntry) element;
ITmfTreeDataModel model = entry.getEntryModel();
ITimeGraphState function = fFunctions.get(model.getId());
if (columnIndex == 0 && (!(model instanceof FlameChartEntryModel) ||
(model instanceof FlameChartEntryModel && ((FlameChartEntryModel) model).getEntryType() != EntryType.FUNCTION))) {
// It is not a function entry
return entry.getName();
}
if (function != null) {
if (columnIndex == 0) {
// functions
return function.getLabel();
} else if (columnIndex == 1 && model instanceof FlameChartEntryModel) {
return entry.getName();
} else if (columnIndex == 2) {
return TmfTimestampFormat.getDefaulTimeFormat().format(function.getStartTime());
} else if (columnIndex == 3) {
return TmfTimestampFormat.getDefaulTimeFormat().format(function.getStartTime() + function.getDuration());
} else if (columnIndex == 4) {
return TmfTimestampFormat.getDefaulIntervalFormat().format(function.getDuration());
}
}
}
return ""; //$NON-NLS-1$
}
}
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
/**
* Default constructor
*/
public FlameChartView() {
this(ID, new BaseDataProviderTimeGraphPresentationProvider(), FlameChartDataProvider.ID);
}
/**
* Custom constructor, used for extending the callstack view with a custom
* presentation provider or data provider.
*
* @param id
* The ID of the view
* @param presentationProvider
* the presentation provider
* @param dataProviderID
* the data provider id
* @since 3.3
*/
public FlameChartView(String id, TimeGraphPresentationProvider presentationProvider, String dataProviderID) {
super(id, presentationProvider, dataProviderID);
setTreeColumns(COLUMN_NAMES, COMPARATORS, 0);
setTreeLabelProvider(new CallStackTreeLabelProvider());
setEntryComparator(new CallStackComparator());
setFilterColumns(FILTER_COLUMN_NAMES);
setFilterLabelProvider(new CallStackTreeLabelProvider());
}
// ------------------------------------------------------------------------
// ViewPart
// ------------------------------------------------------------------------
@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
getTimeGraphViewer().addTimeListener(event -> synchingToTime(event.getBeginTime()));
getTimeGraphViewer().getTimeGraphControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent event) {
ITimeGraphEntry selection = getTimeGraphViewer().getSelection();
if (!(selection instanceof TimeGraphEntry)) {
// also null checks
return;
}
ITimeGraphState function = fFunctions.get(((TimeGraphEntry) selection).getEntryModel().getId());
if (function != null) {
long entryTime = function.getStartTime();
long exitTime = entryTime + function.getDuration();
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(entryTime), TmfTimestamp.fromNanos(exitTime));
broadcast(new TmfWindowRangeUpdatedSignal(FlameChartView.this, range, getTrace()));
getTimeGraphViewer().setStartFinishTime(entryTime, exitTime);
startZoomThread(entryTime, exitTime);
}
}
});
getTimeGraphViewer().getTimeGraphControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
TimeGraphControl timeGraphControl = getTimeGraphViewer().getTimeGraphControl();
ISelection selection = timeGraphControl.getSelection();
if (selection instanceof IStructuredSelection) {
for (Object object : ((IStructuredSelection) selection).toList()) {
if (object instanceof NamedTimeEvent) {
NamedTimeEvent event = (NamedTimeEvent) object;
long startTime = event.getTime();
long endTime = startTime + event.getDuration();
TmfTimeRange range = new TmfTimeRange(TmfTimestamp.fromNanos(startTime), TmfTimestamp.fromNanos(endTime));
broadcast(new TmfWindowRangeUpdatedSignal(FlameChartView.this, range, getTrace()));
getTimeGraphViewer().setStartFinishTime(startTime, endTime);
startZoomThread(startTime, endTime);
break;
}
}
}
}
});
IEditorPart editor = getSite().getPage().getActiveEditor();
if (editor instanceof ITmfTraceEditor) {
ITmfTrace trace = ((ITmfTraceEditor) editor).getTrace();
if (trace != null) {
traceSelected(new TmfTraceSelectedSignal(this, trace));
}
}
}
/**
* Handler for the selection range signal.
*
* @param signal
* The incoming signal
* @since 1.0
*/
@Override
@TmfSignalHandler
public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal) {
fSyncSelection = true;
super.selectionRangeUpdated(signal);
}
/**
* @since 2.0
*/
@Override
@TmfSignalHandler
public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal) {
if (signal.getSource() == this) {
return;
}
super.windowRangeUpdated(signal);
}
// ------------------------------------------------------------------------
// Internal
// ------------------------------------------------------------------------
/**
* @since 2.0
*/
@Override
protected void rebuild() {
super.rebuild();
updateConfigureSymbolsAction();
}
@Override
protected String getProviderId() {
String secondaryId = this.getViewSite().getSecondaryId();
return (secondaryId == null) ? FlameChartDataProvider.ID :
FlameChartDataProvider.ID + ':' + secondaryId.split(TmfViewFactory.INTERNAL_SECONDARY_ID_SEPARATOR)[0]; //NOSONAR
}
@Override
protected void buildEntryList(final ITmfTrace trace, final ITmfTrace parentTrace, final IProgressMonitor monitor) {
FlameChartDataProvider provider = DataProviderManager
.getInstance().getOrCreateDataProvider(trace, getProviderId(), FlameChartDataProvider.class);
if (provider == null) {
addUnavailableEntry(trace, parentTrace);
return;
}
provider.resetFunctionNames(monitor);
super.buildEntryList(trace, parentTrace, monitor);
}
private void addUnavailableEntry(ITmfTrace trace, ITmfTrace parentTrace) {
String name = Messages.CallStackView_StackInfoNotAvailable + ' ' + '(' + trace.getName() + ')';
TimeGraphEntry unavailableEntry = new TimeGraphEntry(name, 0, 0) {
@Override
public boolean hasTimeEvents() {
return false;
}
};
addToEntryList(parentTrace, Collections.singletonList(unavailableEntry));
if (parentTrace == getTrace()) {
refresh();
}
}
/**
* @since 1.2
*/
@Override
protected void synchingToTime(final long time) {
List<TimeGraphEntry> traceEntries = getEntryList(getTrace());
if (traceEntries != null) {
for (TraceEntry traceEntry : Iterables.filter(traceEntries, TraceEntry.class)) {
if (traceEntry.getStartTime() >= time) {
continue;
}
// Do not query for kernel entries
Iterable<TimeGraphEntry> unfiltered = Utils.flatten(traceEntry);
Iterable<TimeGraphEntry> filtered = Iterables.filter(unfiltered, e -> {
ITmfTreeDataModel model = e.getEntryModel();
if (model instanceof FlameChartEntryModel) {
return !((FlameChartEntryModel) model).getEntryType().equals(EntryType.KERNEL);
}
return true;
});
Map<Long, TimeGraphEntry> map = Maps.uniqueIndex(filtered, e -> e.getEntryModel().getId());
// use time -1 as a lower bound for the end of Time events to be
// included.
SelectionTimeQueryFilter filter = new SelectionTimeQueryFilter(Math.max(traceEntry.getStartTime(), time - 1), time, 2, map.keySet());
TmfModelResponse<@NonNull TimeGraphModel> response = traceEntry.getProvider().fetchRowModel(FetchParametersUtils.selectionTimeQueryToMap(filter), null);
TimeGraphModel model = response.getModel();
if (model != null) {
for (ITimeGraphRowModel row : model.getRows()) {
syncToRow(row, time, map);
}
}
}
}
fSyncSelection = false;
if (Display.getCurrent() != null) {
getTimeGraphViewer().refresh();
}
}
private void syncToRow(ITimeGraphRowModel rowModel, long time, Map<Long, TimeGraphEntry> entryMap) {
long id = rowModel.getEntryID();
List<@NonNull ITimeGraphState> list = rowModel.getStates();
if (!list.isEmpty()) {
ITimeGraphState event = list.get(0);
if (event.getStartTime() + event.getDuration() <= time && list.size() > 1) {
/*
* get the second time graph state as passing time - 1 as a
* first argument to the filter will get the previous state, if
* time is the beginning of an event
*/
event = list.get(1);
}
if (event.getLabel() != null) {
fFunctions.put(id, event);
} else {
fFunctions.remove(id);
}
if (fSyncSelection && time == event.getStartTime()) {
TimeGraphEntry entry = entryMap.get(id);
if (entry != null) {
fSyncSelection = false;
Display.getDefault().asyncExec(() -> {
getTimeGraphViewer().setSelection(entry, true);
getTimeGraphViewer().getTimeGraphControl().fireSelectionChanged();
});
}
}
} else {
fFunctions.remove(id);
}
}
@Override
protected void fillLocalToolBar(IToolBarManager manager) {
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getConfigureSymbolsAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new Separator());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getTimeGraphViewer().getShowFilterDialogAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new Separator());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getTimeGraphViewer().getResetScaleAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getPreviousEventAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getNextEventAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new Separator());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getTimeGraphViewer().getToggleBookmarkAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getTimeGraphViewer().getPreviousMarkerAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getTimeGraphViewer().getNextMarkerAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new Separator());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getTimeGraphViewer().getPreviousItemAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getTimeGraphViewer().getNextItemAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getTimeGraphViewer().getZoomInAction());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, getTimeGraphViewer().getZoomOutAction());
}
/**
* Get the the next event action.
*
* @return The action object
*/
private Action getNextEventAction() {
if (fNextEventAction == null) {
Action nextAction = getTimeGraphViewer().getNextEventAction();
fNextEventAction = new Action() {
@Override
public void run() {
TimeGraphViewer viewer = getTimeGraphViewer();
ITimeGraphEntry entry = viewer.getSelection();
if (entry instanceof TimeGraphEntry) {
TimeGraphEntry callStackEntry = (TimeGraphEntry) entry;
ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider = getProvider(callStackEntry);
long selectionBegin = viewer.getSelectionBegin();
Map<@NonNull String, @NonNull Object> parameters = FetchParametersUtils.selectionTimeQueryToMap(new SelectionTimeQueryFilter(selectionBegin, Long.MAX_VALUE, 2, Collections.singleton(callStackEntry.getEntryModel().getId())));
TmfModelResponse<@NonNull TimeGraphModel> response = provider.fetchRowModel(parameters, null);
TimeGraphModel model = response.getModel();
if (model == null || model.getRows().size() != 1) {
return;
}
List<@NonNull ITimeGraphState> row = model.getRows().get(0).getStates();
if (row.size() != 1) {
return;
}
ITimeGraphState stackInterval = row.get(0);
if (stackInterval.getStartTime() <= selectionBegin && selectionBegin <= stackInterval.getStartTime() + stackInterval.getDuration()) {
viewer.setSelectedTimeNotify(stackInterval.getStartTime() + stackInterval.getDuration() + 1, true);
} else {
viewer.setSelectedTimeNotify(stackInterval.getStartTime(), true);
}
int stackLevel = stackInterval.getValue();
ITimeGraphEntry selectedEntry = callStackEntry.getParent().getChildren().get(Integer.max(0, stackLevel - 1));
viewer.setSelection(selectedEntry, true);
viewer.getTimeGraphControl().fireSelectionChanged();
startZoomThread(viewer.getTime0(), viewer.getTime1());
}
}
};
fNextEventAction.setText(nextAction.getText());
fNextEventAction.setToolTipText(nextAction.getToolTipText());
fNextEventAction.setImageDescriptor(nextAction.getImageDescriptor());
}
return fNextEventAction;
}
/**
* Get the previous event action.
*
* @return The Action object
*/
private Action getPreviousEventAction() {
if (fPrevEventAction == null) {
Action prevAction = getTimeGraphViewer().getPreviousEventAction();
fPrevEventAction = new Action() {
@Override
public void run() {
TimeGraphViewer viewer = getTimeGraphViewer();
ITimeGraphEntry entry = viewer.getSelection();
if (entry instanceof TimeGraphEntry) {
TimeGraphEntry callStackEntry = (TimeGraphEntry) entry;
ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider = getProvider(callStackEntry);
long selectionBegin = viewer.getSelectionBegin();
Map<@NonNull String, @NonNull Object> parameters = FetchParametersUtils
.selectionTimeQueryToMap(new SelectionTimeQueryFilter(Lists.newArrayList(Long.MIN_VALUE, selectionBegin), Collections.singleton(callStackEntry.getEntryModel().getId())));
TmfModelResponse<@NonNull TimeGraphModel> response = provider.fetchRowModel(parameters, null);
TimeGraphModel model = response.getModel();
if (model == null || model.getRows().size() != 1) {
return;
}
List<@NonNull ITimeGraphState> row = model.getRows().get(0).getStates();
if (row.size() != 1) {
return;
}
ITimeGraphState stackInterval = row.get(0);
viewer.setSelectedTimeNotify(stackInterval.getStartTime(), true);
int stackLevel = stackInterval.getValue();
ITimeGraphEntry selectedEntry = callStackEntry.getParent().getChildren().get(Integer.max(0, stackLevel - 1));
viewer.setSelection(selectedEntry, true);
viewer.getTimeGraphControl().fireSelectionChanged();
startZoomThread(viewer.getTime0(), viewer.getTime1());
}
}
};
fPrevEventAction.setText(prevAction.getText());
fPrevEventAction.setToolTipText(prevAction.getToolTipText());
fPrevEventAction.setImageDescriptor(prevAction.getImageDescriptor());
}
return fPrevEventAction;
}
/**
* @since 2.0
*/
@Override
protected void fillTimeGraphEntryContextMenu(@NonNull IMenuManager menuManager) {
ISelection selection = getSite().getSelectionProvider().getSelection();
if (selection instanceof StructuredSelection) {
StructuredSelection sSel = (StructuredSelection) selection;
if (sSel.getFirstElement() instanceof TimeGraphEntry) {
TimeGraphEntry entry = (TimeGraphEntry) sSel.getFirstElement();
ITmfTreeDataModel entryModel = entry.getEntryModel();
if (entryModel instanceof ICoreElementResolver) {
Multimap<@NonNull String, @NonNull Object> metadata = ((ICoreElementResolver) entryModel).getMetadata();
Collection<@NonNull Object> tids = metadata.get(OsStrings.tid());
if (tids.size() == 1) {
HostThread hostThread = new HostThread(getTrace(entry).getHostId(), (Integer) tids.iterator().next());
menuManager.add(new FollowThreadAction(FlameChartView.this, String.valueOf(hostThread.getTid()), hostThread));
}
}
}
}
}
// ------------------------------------------------------------------------
// Methods related to function name mapping
// ------------------------------------------------------------------------
private Action getConfigureSymbolsAction() {
if (fConfigureSymbolsAction != null) {
return fConfigureSymbolsAction;
}
fConfigureSymbolsAction = new Action(Messages.CallStackView_ConfigureSymbolProvidersText) {
@Override
public void run() {
SymbolProviderConfigDialog dialog = new SymbolProviderConfigDialog(getSite().getShell(), getProviderPages());
if (dialog.open() == IDialogConstants.OK_ID) {
List<TimeGraphEntry> traceEntries = getEntryList(getTrace());
if (traceEntries != null) {
for (TraceEntry traceEntry : Iterables.filter(traceEntries, TraceEntry.class)) {
ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider = traceEntry.getProvider();
if (provider instanceof FlameChartDataProvider) {
((FlameChartDataProvider) provider).resetFunctionNames(new NullProgressMonitor());
}
// reset full and zoomed events here
Iterable<TimeGraphEntry> flatten = Utils.flatten(traceEntry);
flatten.forEach(e -> e.setSampling(null));
// recompute full events
long start = traceEntry.getStartTime();
long end = traceEntry.getEndTime();
final long resolution = Long.max(1, (end - start) / getDisplayWidth());
zoomEntries(flatten, start, end, resolution, new NullProgressMonitor());
}
// zoomed events will be retriggered by refreshing
refresh();
}
synchingToTime(getTimeGraphViewer().getSelectionBegin());
}
}
};
fConfigureSymbolsAction.setToolTipText(Messages.CallStackView_ConfigureSymbolProvidersTooltip);
fConfigureSymbolsAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(IMPORT_BINARY_ICON_PATH));
/*
* The updateConfigureSymbolsAction() method (called by refresh()) will
* set the action to true if applicable after the symbol provider has
* been properly loaded.
*/
fConfigureSymbolsAction.setEnabled(false);
return fConfigureSymbolsAction;
}
/**
* @return an array of {@link ISymbolProviderPreferencePage} that will
* configure the current traces
*/
private ISymbolProviderPreferencePage[] getProviderPages() {
List<ISymbolProviderPreferencePage> pages = new ArrayList<>();
ITmfTrace trace = getTrace();
if (trace != null) {
for (ITmfTrace subTrace : getTracesToBuild(trace)) {
Collection<@NonNull ISymbolProvider> symbolProviders = SymbolProviderManager.getInstance().getSymbolProviders(subTrace);
for (org.eclipse.tracecompass.tmf.ui.symbols.ISymbolProvider provider : Iterables.filter(symbolProviders, org.eclipse.tracecompass.tmf.ui.symbols.ISymbolProvider.class)) {
ISymbolProviderPreferencePage page = provider.createPreferencePage();
if (page != null) {
pages.add(page);
}
}
}
}
return pages.toArray(new ISymbolProviderPreferencePage[pages.size()]);
}
/**
* Update the enable status of the configure symbols action
*/
private void updateConfigureSymbolsAction() {
ISymbolProviderPreferencePage[] providerPages = getProviderPages();
getConfigureSymbolsAction().setEnabled(providerPages.length > 0);
}
@TmfSignalHandler
@Override
public void traceClosed(TmfTraceClosedSignal signal) {
List<@NonNull TimeGraphEntry> traceEntries = getEntryList(signal.getTrace());
if (traceEntries != null) {
/*
* remove functions associated to the trace's entries.
*/
Iterable<TimeGraphEntry> all = Iterables.concat(Iterables.transform(traceEntries, Utils::flatten));
all.forEach(entry -> fFunctions.remove(entry.getEntryModel().getId()));
}
super.traceClosed(signal);
}
}