fa71123d540655decb6b5c4c018145aeec127366
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui / src / org / eclipse / tracecompass / internal / analysis / os / linux / ui / views / controlflow / ControlFlowView.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2016 Ericsson, École Polytechnique de Montréal 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 * Geneviève Bastien - Move code to provide base classes for time graph view
12 * Christian Mansky - Add check active / uncheck inactive buttons
13 * Mahdi Zolnouri & Samuel Gagnon - Add flat / hierarchical button
14 *******************************************************************************/
15
16 package org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow;
17
18 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
19
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.Comparator;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
30 import java.util.function.Function;
31 import java.util.function.Predicate;
32 import java.util.stream.Collectors;
33 import java.util.stream.Stream;
34
35 import org.eclipse.core.runtime.IProgressMonitor;
36 import org.eclipse.core.runtime.IStatus;
37 import org.eclipse.core.runtime.Status;
38 import org.eclipse.core.runtime.jobs.ISchedulingRule;
39 import org.eclipse.core.runtime.jobs.Job;
40 import org.eclipse.jdt.annotation.NonNull;
41 import org.eclipse.jdt.annotation.Nullable;
42 import org.eclipse.jface.action.Action;
43 import org.eclipse.jface.action.IAction;
44 import org.eclipse.jface.action.IMenuManager;
45 import org.eclipse.jface.action.IToolBarManager;
46 import org.eclipse.jface.action.MenuManager;
47 import org.eclipse.jface.action.Separator;
48 import org.eclipse.jface.dialogs.IDialogSettings;
49 import org.eclipse.jface.util.IPropertyChangeListener;
50 import org.eclipse.jface.util.PropertyChangeEvent;
51 import org.eclipse.jface.viewers.ISelection;
52 import org.eclipse.jface.viewers.StructuredSelection;
53 import org.eclipse.jface.viewers.ViewerFilter;
54 import org.eclipse.jface.window.Window;
55 import org.eclipse.swt.widgets.Composite;
56 import org.eclipse.swt.widgets.Event;
57 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
58 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelTidAspect;
59 import org.eclipse.tracecompass.common.core.StreamUtils.StreamFlattener;
60 import org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.Attributes;
61 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.Activator;
62 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.Messages;
63 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.actions.FollowThreadAction;
64 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow.filters.ActiveThreadsFilter;
65 import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow.filters.DynamicFilterDialog;
66 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
67 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
68 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
69 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
70 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
71 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
72 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
73 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
74 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
75 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
76 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
77 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
78 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
79 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
80 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
81 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
82 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
83 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
84 import org.eclipse.tracecompass.tmf.core.util.Pair;
85 import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractStateSystemTimeGraphView;
86 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
87 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
88 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
89 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
90 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
91 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
92 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeLinkEvent;
93 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphControl;
94 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
95 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
96 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
97 import org.eclipse.ui.PlatformUI;
98
99 import com.google.common.base.Objects;
100 import com.google.common.collect.ImmutableList;
101
102 /**
103 * The Control Flow view main object
104 *
105 */
106 public class ControlFlowView extends AbstractStateSystemTimeGraphView {
107
108 // ------------------------------------------------------------------------
109 // Constants
110 // ------------------------------------------------------------------------
111 /**
112 * View ID.
113 */
114 public static final @NonNull String ID = "org.eclipse.tracecompass.analysis.os.linux.views.controlflow"; //$NON-NLS-1$
115
116 private static final String ICONS_PATH = "icons/"; //$NON-NLS-1$
117 private static final String OPTIMIZE_ICON = ICONS_PATH + "elcl16/Optimization.png"; //$NON-NLS-1$
118
119 private static final String PROCESS_COLUMN = Messages.ControlFlowView_processColumn;
120 private static final String TID_COLUMN = Messages.ControlFlowView_tidColumn;
121 private static final String PTID_COLUMN = Messages.ControlFlowView_ptidColumn;
122 private static final String BIRTH_TIME_COLUMN = Messages.ControlFlowView_birthTimeColumn;
123 private static final String INVISIBLE_COLUMN = Messages.ControlFlowView_invisibleColumn;
124 private Action fOptimizationAction;
125
126 private static final String NEXT_EVENT_ICON_PATH = "icons/elcl16/shift_r_edit.gif"; //$NON-NLS-1$
127 private static final String PREV_EVENT_ICON_PATH = "icons/elcl16/shift_l_edit.gif"; //$NON-NLS-1$
128
129 private static final String[] COLUMN_NAMES = new String[] {
130 PROCESS_COLUMN,
131 TID_COLUMN,
132 PTID_COLUMN,
133 BIRTH_TIME_COLUMN
134 };
135
136 private static final String[] FILTER_COLUMN_NAMES = new String[] {
137 PROCESS_COLUMN,
138 TID_COLUMN
139 };
140
141 // Timeout between updates in the build thread in ms
142 private static final long BUILD_UPDATE_TIMEOUT = 500;
143
144 private static final Comparator<ITimeGraphEntry>[] COLUMN_COMPARATORS;
145
146 private final Function<Collection<ILinkEvent>, Map<Integer, Long>> UPDATE_SCHEDULING_COLUMN_ALGO = new NaiveOptimizationAlgorithm();
147
148 private static final int INITIAL_SORT_COLUMN_INDEX = 3;
149
150 static {
151 ImmutableList.Builder<Comparator<ITimeGraphEntry>> builder = ImmutableList.builder();
152 builder.add(ControlFlowColumnComparators.PROCESS_NAME_COLUMN_COMPARATOR)
153 .add(ControlFlowColumnComparators.TID_COLUMN_COMPARATOR)
154 .add(ControlFlowColumnComparators.PTID_COLUMN_COMPARATOR)
155 .add(ControlFlowColumnComparators.BIRTH_TIME_COLUMN_COMPARATOR);
156 List<Comparator<ITimeGraphEntry>> l = builder.build();
157 COLUMN_COMPARATORS = l.toArray(new Comparator[l.size()]);
158 }
159
160 /**
161 * Mutex rule for search action jobs, making sure they execute sequentially
162 */
163 private final ISchedulingRule fSearchActionMutexRule = new ISchedulingRule() {
164 @Override
165 public boolean isConflicting(ISchedulingRule rule) {
166 return (rule == this);
167 }
168
169 @Override
170 public boolean contains(ISchedulingRule rule) {
171 return (rule == this);
172 }
173 };
174
175 private final Set<ITmfTrace> fFlatTraces = new HashSet<>();
176
177 private IAction fFlatAction;
178
179 private IAction fHierarchicalAction;
180
181 private @NonNull ActiveThreadsFilter fActiveThreadsFilter = new ActiveThreadsFilter(null, false);
182
183 private final ActiveThreadsFilterAction fActiveThreadsRapidToggle = new ActiveThreadsFilterAction();
184
185 class ActiveThreadsFilterAction extends Action {
186 public ActiveThreadsFilterAction() {
187 super(PackageMessages.ControlFlowView_DynamicFiltersActiveThreadToggleLabel, IAction.AS_CHECK_BOX);
188 setToolTipText(PackageMessages.ControlFlowView_DynamicFiltersActiveThreadToggleToolTip);
189 addPropertyChangeListener(new IPropertyChangeListener() {
190 @Override
191 public void propertyChange(PropertyChangeEvent event) {
192 if (!(event.getNewValue() instanceof Boolean)) {
193 return;
194 }
195
196 Boolean enabled = (Boolean) event.getNewValue();
197
198 /* Always remove the previous Active Threads filter */
199 getTimeGraphCombo().removeFilter(fActiveThreadsFilter);
200
201 if (enabled) {
202 fActiveThreadsFilter.setEnabled(true);
203 getTimeGraphCombo().addFilter(fActiveThreadsFilter);
204
205 /* Use flat representation */
206 if (fFlatAction != null) {
207 applyFlatPresentation();
208 fFlatAction.setChecked(true);
209 fHierarchicalAction.setChecked(false);
210 }
211 } else {
212 fActiveThreadsFilter.setEnabled(false);
213 }
214
215 refresh();
216 }
217 });
218 }
219 }
220
221 // ------------------------------------------------------------------------
222 // Constructors
223 // ------------------------------------------------------------------------
224
225 /**
226 * Constructor
227 */
228 public ControlFlowView() {
229 super(ID, new ControlFlowPresentationProvider());
230 setTreeColumns(COLUMN_NAMES, COLUMN_COMPARATORS, INITIAL_SORT_COLUMN_INDEX);
231 setTreeLabelProvider(new ControlFlowTreeLabelProvider());
232 setFilterColumns(FILTER_COLUMN_NAMES);
233 setFilterLabelProvider(new ControlFlowFilterLabelProvider());
234 setEntryComparator(ControlFlowColumnComparators.BIRTH_TIME_COLUMN_COMPARATOR);
235 }
236
237 @Override
238 public void createPartControl(Composite parent) {
239 super.createPartControl(parent);
240 // add "Check active" Button to TimeGraphFilterDialog
241 super.getTimeGraphCombo().addTimeGraphFilterCheckActiveButton(
242 new ControlFlowCheckActiveProvider(Messages.ControlFlowView_checkActiveLabel, Messages.ControlFlowView_checkActiveToolTip));
243 // add "Uncheck inactive" Button to TimeGraphFilterDialog
244 super.getTimeGraphCombo().addTimeGraphFilterUncheckInactiveButton(
245 new ControlFlowCheckActiveProvider(Messages.ControlFlowView_uncheckInactiveLabel, Messages.ControlFlowView_uncheckInactiveToolTip));
246 }
247
248 /**
249 * @since 2.0
250 */
251 @Override
252 protected void fillTimeGraphEntryContextMenu(@NonNull IMenuManager menuManager) {
253 ISelection selection = getSite().getSelectionProvider().getSelection();
254 if (selection instanceof StructuredSelection) {
255 StructuredSelection sSel = (StructuredSelection) selection;
256 if (sSel.getFirstElement() instanceof ControlFlowEntry) {
257 ControlFlowEntry entry = (ControlFlowEntry) sSel.getFirstElement();
258 menuManager.add(new FollowThreadAction(ControlFlowView.this, entry.getName(), entry.getThreadId(), entry.getTrace()));
259 }
260 }
261 }
262
263 @Override
264 protected void fillLocalToolBar(IToolBarManager manager) {
265 // add "Optimization" Button to local tool bar of Controlflow
266 IAction optimizationAction = getOptimizationAction();
267 manager.add(optimizationAction);
268
269 // add a separator to local tool bar
270 manager.add(new Separator());
271
272 super.fillLocalToolBar(manager);
273 IDialogSettings settings = Activator.getDefault().getDialogSettings();
274 IDialogSettings section = settings.getSection(getClass().getName());
275 if (section == null) {
276 section = settings.addNewSection(getClass().getName());
277 }
278
279 IAction hideArrowsAction = getTimeGraphCombo().getTimeGraphViewer().getHideArrowsAction(section);
280 manager.add(hideArrowsAction);
281
282 IAction followArrowBwdAction = getTimeGraphCombo().getTimeGraphViewer().getFollowArrowBwdAction();
283 followArrowBwdAction.setText(Messages.ControlFlowView_followCPUBwdText);
284 followArrowBwdAction.setToolTipText(Messages.ControlFlowView_followCPUBwdText);
285 manager.add(followArrowBwdAction);
286
287 IAction followArrowFwdAction = getTimeGraphCombo().getTimeGraphViewer().getFollowArrowFwdAction();
288 followArrowFwdAction.setText(Messages.ControlFlowView_followCPUFwdText);
289 followArrowFwdAction.setToolTipText(Messages.ControlFlowView_followCPUFwdText);
290 manager.add(followArrowFwdAction);
291
292 IAction previousEventAction = new SearchEventAction(false, PackageMessages.ControlFlowView_PreviousEventJobName);
293 previousEventAction.setText(PackageMessages.ControlFlowView_PreviousEventActionName);
294 previousEventAction.setToolTipText(PackageMessages.ControlFlowView_PreviousEventActionTooltip);
295 previousEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(PREV_EVENT_ICON_PATH));
296 manager.add(previousEventAction);
297
298 IAction nextEventAction = new SearchEventAction(true, PackageMessages.ControlFlowView_NextEventJobName);
299 nextEventAction.setText(PackageMessages.ControlFlowView_NextEventActionName);
300 nextEventAction.setToolTipText(PackageMessages.ControlFlowView_NextEventActionTooltip);
301 nextEventAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(NEXT_EVENT_ICON_PATH));
302 manager.add(nextEventAction);
303 }
304
305 private IAction getOptimizationAction() {
306 if (fOptimizationAction == null) {
307 fOptimizationAction = new OptimizationAction();
308 fOptimizationAction.setImageDescriptor(Activator.getDefault().getImageDescripterFromPath(OPTIMIZE_ICON));
309 fOptimizationAction.setText(Messages.ControlFlowView_optimizeLabel);
310 fOptimizationAction.setToolTipText(Messages.ControlFlowView_optimizeToolTip);
311 }
312 return fOptimizationAction;
313 }
314
315 @Override
316 protected void fillLocalMenu(IMenuManager manager) {
317 super.fillLocalMenu(manager);
318
319 MenuManager item = new MenuManager(Messages.ControlFlowView_threadPresentation);
320 fFlatAction = createFlatAction();
321 item.add(fFlatAction);
322
323 fHierarchicalAction = createHierarchicalAction();
324 item.add(fHierarchicalAction);
325 manager.add(item);
326
327 item = new MenuManager(PackageMessages.ControlFlowView_DynamicFiltersMenuLabel);
328 item.add(fActiveThreadsRapidToggle);
329 item.add(new Separator());
330
331 IAction dynamicFiltersConfigureAction = createDynamicFilterConfigureAction();
332 item.add(dynamicFiltersConfigureAction);
333
334 manager.add(item);
335 }
336
337
338
339 /**
340 * Base Action for the "Go to Next/Previous Event for thread" actions
341 */
342 private class SearchEventAction extends Action {
343
344 private final boolean ifDirection;
345 private final String ifJobName;
346
347 /**
348 * Constructor
349 *
350 * @param direction
351 * The direction of the search, "true" for forwards and
352 * "false" for backwards.
353 * @param jobName
354 * The name of the job that will be spawned
355 */
356 public SearchEventAction(boolean direction, String jobName) {
357 ifDirection = direction;
358 ifJobName = jobName;
359 }
360
361 @Override
362 public void run() {
363 Job job = new Job(ifJobName) {
364 @Override
365 protected IStatus run(IProgressMonitor monitor) {
366 TimeGraphControl ctrl = getTimeGraphViewer().getTimeGraphControl();
367 ITimeGraphEntry traceEntry = ctrl.getSelectedTrace();
368
369 long ts = getTimeGraphViewer().getSelectionBegin();
370 ITimeEvent selectedState = Utils.findEvent(traceEntry, ts, 0);
371
372 if (selectedState == null) {
373 /* No selection currently in the view, do nothing */
374 return Status.OK_STATUS;
375 }
376 ITimeGraphEntry entry = selectedState.getEntry();
377 if (!(entry instanceof ControlFlowEntry)) {
378 return Status.OK_STATUS;
379 }
380 ControlFlowEntry cfEntry = (ControlFlowEntry) entry;
381 int tid = cfEntry.getThreadId();
382
383 ITmfTrace trace = cfEntry.getTrace();
384 ITmfContext ctx = trace.seekEvent(TmfTimestamp.fromNanos(ts));
385 long rank = ctx.getRank();
386 ctx.dispose();
387
388 Predicate<@NonNull ITmfEvent> predicate = event -> {
389 /*
390 * TODO Specific to the Control Flow View and kernel
391 * traces for now. Could be eventually generalized to
392 * anything represented by the time graph row.
393 */
394 Integer eventTid = KernelTidAspect.INSTANCE.resolve(event);
395 return (eventTid != null && eventTid.intValue() == tid);
396 };
397
398 ITmfEvent event = (ifDirection ?
399 TmfTraceUtils.getNextEventMatching(cfEntry.getTrace(), rank, predicate, monitor) :
400 TmfTraceUtils.getPreviousEventMatching(cfEntry.getTrace(), rank, predicate, monitor));
401 if (event != null) {
402 TmfSignalManager.dispatchSignal(new TmfSelectionRangeUpdatedSignal(this, event.getTimestamp()));
403 }
404 return Status.OK_STATUS;
405
406 }
407 };
408 /*
409 * Make subsequent jobs not run concurrently, but wait after one
410 * another.
411 */
412 job.setRule(fSearchActionMutexRule);
413 job.schedule();
414 }
415 }
416
417 private IAction createDynamicFilterConfigureAction() {
418 return new Action(PackageMessages.ControlFlowView_DynamicFiltersConfigureLabel, IAction.AS_PUSH_BUTTON) {
419 @Override
420 public void run() {
421 DynamicFilterDialog dialog = new DynamicFilterDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), fActiveThreadsFilter);
422 if (dialog.open() == Window.OK) {
423 /* Remove the previous Active Threads filter */
424 checkNotNull(getTimeGraphCombo()).removeFilter(fActiveThreadsFilter);
425
426 ActiveThreadsFilter newFilter = dialog.getActiveThreadsResult();
427 ActiveThreadsFilter previousFilter = fActiveThreadsFilter;
428
429 /* Set the filter to the view */
430 fActiveThreadsFilter = newFilter;
431
432 boolean enabled = fActiveThreadsFilter.isEnabled();
433 if (enabled) {
434 checkNotNull(getTimeGraphCombo()).addFilter(newFilter);
435 }
436
437 /*
438 * Prevent double refresh from change state of setChecked
439 * and ensure that a refresh is done if the mode of the
440 * filter is changed or options are changed
441 */
442 if (previousFilter.isEnabled() && newFilter.isEnabled()) {
443 boolean changed = !Objects.equal(previousFilter.getCpuRanges(), newFilter.getCpuRanges()) || previousFilter.isCpuRangesBased() != newFilter.isCpuRangesBased();
444 if (changed) {
445 refresh();
446 }
447 } else {
448 fActiveThreadsRapidToggle.setChecked(enabled);
449 }
450 }
451 }
452 };
453 }
454
455 private IAction createHierarchicalAction() {
456 IAction action = new Action(Messages.ControlFlowView_hierarchicalViewLabel, IAction.AS_RADIO_BUTTON) {
457 @Override
458 public void run() {
459 ITmfTrace parentTrace = getTrace();
460 synchronized (fFlatTraces) {
461 fFlatTraces.remove(parentTrace);
462 for (ITmfTrace trace : TmfTraceManager.getTraceSet(parentTrace)) {
463 final ITmfStateSystem ss = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
464 for (TimeGraphEntry traceEntry : getEntryList(ss)) {
465 List<ControlFlowEntry> currentRootList = traceEntry.getChildren().stream()
466 .filter(e -> e instanceof ControlFlowEntry)
467 .map(e -> (ControlFlowEntry) e)
468 .collect(Collectors.toList());
469 addEntriesToHierarchicalTree(currentRootList, traceEntry);
470 }
471 }
472 }
473 refresh();
474 }
475 };
476 action.setChecked(true);
477 action.setToolTipText(Messages.ControlFlowView_hierarchicalViewToolTip);
478 return action;
479 }
480
481 private IAction createFlatAction() {
482 IAction action = new Action(Messages.ControlFlowView_flatViewLabel, IAction.AS_RADIO_BUTTON) {
483 @Override
484 public void run() {
485 applyFlatPresentation();
486 refresh();
487 }
488 };
489 action.setChecked(true);
490 action.setToolTipText(Messages.ControlFlowView_flatViewToolTip);
491 return action;
492 }
493
494 private void applyFlatPresentation() {
495 ITmfTrace parentTrace = getTrace();
496 synchronized (fFlatTraces) {
497 fFlatTraces.add(parentTrace);
498 for (ITmfTrace trace : TmfTraceManager.getTraceSet(parentTrace)) {
499 final ITmfStateSystem ss = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
500 List<@NonNull TimeGraphEntry> entryList = getEntryList(ss);
501 if (entryList != null) {
502 for (TimeGraphEntry traceEntry : entryList) {
503 hierarchicalToFlatTree(traceEntry);
504 }
505 }
506 }
507 }
508 }
509
510 @Override
511 protected String getNextText() {
512 return Messages.ControlFlowView_nextProcessActionNameText;
513 }
514
515 @Override
516 protected String getNextTooltip() {
517 return Messages.ControlFlowView_nextProcessActionToolTipText;
518 }
519
520 @Override
521 protected String getPrevText() {
522 return Messages.ControlFlowView_previousProcessActionNameText;
523 }
524
525 @Override
526 protected String getPrevTooltip() {
527 return Messages.ControlFlowView_previousProcessActionToolTipText;
528 }
529
530 /**
531 * Get the optimization function for the scheduling column. In the base
532 * implementation, this optimizes by Line arrows, but can be overidden.
533 * <p>
534 * It takes a collection of link events, looking at the entries being
535 * linked, and returns a list of the proposed order. The list of indexes
536 * should be in ascending order. There can be duplicates, but the values and
537 * order should always be the same for the same input.
538 *
539 * @return the returned column order, where the integer is the tid of the
540 * entry, and the return value is the position, there can be
541 * duplicates.
542 */
543 public Function<Collection<ILinkEvent>, Map<Integer, Long>> getUpdatedSchedulingColumn() {
544 return UPDATE_SCHEDULING_COLUMN_ALGO;
545 }
546
547 /**
548 * This is an optimization action used to find cliques of entries due to
549 * links and put them closer together
550 *
551 * @author Samuel Gagnon
552 */
553 private final class OptimizationAction extends Action {
554
555 @Override
556 public void runWithEvent(Event event) {
557 ITmfTrace trace = getTrace();
558 if (trace == null) {
559 return;
560 }
561
562 createFlatAction().run();
563
564 /*
565 * This method only returns the arrows in the current time interval
566 * [a,b] of ControlFlowView. Thus, we only optimize for that time
567 * interval
568 */
569 List<ILinkEvent> arrows = getTimeGraphViewer().getTimeGraphControl().getArrows();
570 final ITmfStateSystem ss = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
571 List<TimeGraphEntry> currentList = getEntryList(ss);
572
573 Map<Integer, Long> orderedTidMap = getUpdatedSchedulingColumn().apply(arrows);
574
575 /*
576 * Now that we have our list of ordered tid, it's time to assign a
577 * position for each threads in the view. For this, we assign a
578 * value to an invisible column and sort according to the values in
579 * this column.
580 */
581 for (TimeGraphEntry entry : currentList) {
582 if (entry instanceof TraceEntry) {
583 for (TimeGraphEntry child : ((TraceEntry) entry).getChildren()) {
584 if (child instanceof ControlFlowEntry) {
585 ControlFlowEntry cEntry = (ControlFlowEntry) child;
586 /*
587 * If the thread is in our list, we give it a
588 * position. Otherwise, it means there's no activity
589 * in the current interval for that thread. We set
590 * its position to Long.MAX_VALUE so it goes to the
591 * bottom.
592 */
593 cEntry.setSchedulingPosition(orderedTidMap.getOrDefault(cEntry.getThreadId(), Long.MAX_VALUE));
594 }
595 }
596 }
597 }
598
599 setEntryComparator(ControlFlowColumnComparators.SCHEDULING_COLUMN_COMPARATOR);
600 refresh();
601 }
602
603 }
604
605 /**
606 * @author gbastien
607 *
608 */
609 protected static class ControlFlowTreeLabelProvider extends TreeLabelProvider {
610
611 @Override
612 public String getColumnText(Object element, int columnIndex) {
613 if (element instanceof TraceEntry) {
614 if (columnIndex == 0) {
615 return ((TraceEntry) element).getName();
616 }
617 return ""; //$NON-NLS-1$
618 }
619 ControlFlowEntry entry = (ControlFlowEntry) element;
620
621 if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_processColumn)) {
622 return entry.getName();
623 } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_tidColumn)) {
624 return Integer.toString(entry.getThreadId());
625 } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_ptidColumn)) {
626 if (entry.getParentThreadId() > 0) {
627 return Integer.toString(entry.getParentThreadId());
628 }
629 } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_birthTimeColumn)) {
630 return Utils.formatTime(entry.getStartTime(), TimeFormat.CALENDAR, Resolution.NANOSEC);
631 } else if (COLUMN_NAMES[columnIndex].equals(Messages.ControlFlowView_traceColumn)) {
632 return entry.getTrace().getName();
633 } else if (COLUMN_NAMES[columnIndex].equals(INVISIBLE_COLUMN)) {
634 return Long.toString(entry.getSchedulingPosition());
635 }
636 return ""; //$NON-NLS-1$
637 }
638
639 }
640
641 private static class ControlFlowFilterLabelProvider extends TreeLabelProvider {
642
643 @Override
644 public String getColumnText(Object element, int columnIndex) {
645 if (element instanceof TraceEntry) {
646 if (columnIndex == 0) {
647 return ((TraceEntry) element).getName();
648 }
649 return ""; //$NON-NLS-1$
650 }
651 ControlFlowEntry entry = (ControlFlowEntry) element;
652
653 if (columnIndex == 0) {
654 return entry.getName();
655 } else if (columnIndex == 1) {
656 return Integer.toString(entry.getThreadId());
657 }
658 return ""; //$NON-NLS-1$
659 }
660
661 }
662
663 private static class TraceEntry extends TimeGraphEntry {
664
665 public TraceEntry(String name, long startTime, long endTime) {
666 super(name, startTime, endTime);
667 }
668
669 @Override
670 public boolean hasTimeEvents() {
671 return false;
672 }
673 }
674
675 @TmfSignalHandler
676 @Override
677 public void traceClosed(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal signal) {
678 super.traceClosed(signal);
679 synchronized (fFlatTraces) {
680 fFlatTraces.remove(signal.getTrace());
681 }
682 }
683
684 @TmfSignalHandler
685 @Override
686 public void traceSelected(TmfTraceSelectedSignal signal) {
687 super.traceSelected(signal);
688
689 /* Update the Flat and Hierarchical actions */
690 synchronized (fFlatTraces) {
691 if (fFlatTraces.contains(signal.getTrace())) {
692 fHierarchicalAction.setChecked(false);
693 fFlatAction.setChecked(true);
694 } else {
695 fFlatAction.setChecked(false);
696 fHierarchicalAction.setChecked(true);
697 }
698 }
699
700 /* Update the Dynamic Filters related actions */
701 ViewerFilter activeThreadFilter = null;
702 ViewerFilter[] traceFilters = getFiltersMap().get(signal.getTrace());
703 if (traceFilters != null) {
704 activeThreadFilter = getActiveThreadsFilter(traceFilters);
705 }
706
707 if (activeThreadFilter == null) {
708 fActiveThreadsFilter = new ActiveThreadsFilter(null, false);
709 } else {
710 fActiveThreadsFilter = (@NonNull ActiveThreadsFilter) checkNotNull(activeThreadFilter);
711 }
712
713 fActiveThreadsRapidToggle.setChecked(fActiveThreadsFilter.isEnabled());
714 }
715
716 // ------------------------------------------------------------------------
717 // Internal
718 // ------------------------------------------------------------------------
719
720 @Override
721 protected void buildEntryList(final ITmfTrace trace, final ITmfTrace parentTrace, final IProgressMonitor monitor) {
722 final ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
723 if (ssq == null) {
724 return;
725 }
726
727 final List<ControlFlowEntry> entryList = new ArrayList<>();
728 /** Map of trace entries */
729 Map<ITmfTrace, TraceEntry> traceEntryMap = new HashMap<>();
730 /** Map of control flow entries, key is a pair [threadId, cpuId] */
731 final Map<Pair<Integer, Integer>, ControlFlowEntry> entryMap = new HashMap<>();
732
733 long start = ssq.getStartTime();
734 setStartTime(Math.min(getStartTime(), start));
735
736 boolean complete = false;
737 while (!complete) {
738 if (monitor.isCanceled()) {
739 return;
740 }
741 complete = ssq.waitUntilBuilt(BUILD_UPDATE_TIMEOUT);
742 if (ssq.isCancelled()) {
743 return;
744 }
745 long end = ssq.getCurrentEndTime();
746 if (start == end && !complete) { // when complete execute one last time regardless of end time
747 continue;
748 }
749
750 TraceEntry aTraceEntry = traceEntryMap.get(trace);
751 if (aTraceEntry == null) {
752 aTraceEntry = new TraceEntry(trace.getName(), start, end + 1);
753 traceEntryMap.put(trace, aTraceEntry);
754 addToEntryList(parentTrace, ssq, Collections.singletonList(aTraceEntry));
755 } else {
756 aTraceEntry.updateEndTime(end + 1);
757 }
758 final TraceEntry traceEntry = aTraceEntry;
759
760 final long resolution = Math.max(1, (end - ssq.getStartTime()) / getDisplayWidth());
761 setEndTime(Math.max(getEndTime(), end + 1));
762 final List<Integer> threadQuarks = ssq.getQuarks(Attributes.THREADS, "*"); //$NON-NLS-1$
763 queryFullStates(ssq, start, end, resolution, monitor, new IQueryHandler() {
764 @Override
765 public void handle(List<List<ITmfStateInterval>> fullStates, List<ITmfStateInterval> prevFullState) {
766 for (int threadQuark : threadQuarks) {
767 String threadAttributeName = ssq.getAttributeName(threadQuark);
768
769 Pair<Integer, Integer> entryKey = Attributes.parseThreadAttributeName(threadAttributeName);
770 int threadId = entryKey.getFirst();
771
772 if (threadId < 0) { // ignore the 'unknown' (-1) thread
773 continue;
774 }
775
776 int execNameQuark = ssq.optQuarkRelative(threadQuark, Attributes.EXEC_NAME);
777 int ppidQuark = ssq.optQuarkRelative(threadQuark, Attributes.PPID);
778 if (execNameQuark == ITmfStateSystem.INVALID_ATTRIBUTE) {
779 /* No information on this thread (yet?), skip it for now */
780 continue;
781 }
782 ITmfStateInterval lastExecNameInterval = prevFullState == null || execNameQuark >= prevFullState.size() ? null : prevFullState.get(execNameQuark);
783 long lastExecNameStartTime = lastExecNameInterval == null ? -1 : lastExecNameInterval.getStartTime();
784 long lastExecNameEndTime = lastExecNameInterval == null ? -1 : lastExecNameInterval.getEndTime() + 1;
785 long lastPpidStartTime = prevFullState == null || ppidQuark >= prevFullState.size() || ppidQuark == ITmfStateSystem.INVALID_ATTRIBUTE ? -1 : prevFullState.get(ppidQuark).getStartTime();
786 for (List<ITmfStateInterval> fullState : fullStates) {
787 if (monitor.isCanceled()) {
788 return;
789 }
790 if (execNameQuark >= fullState.size() || ppidQuark >= fullState.size()) {
791 /* No information on this thread (yet?), skip it for now */
792 continue;
793 }
794 ITmfStateInterval execNameInterval = fullState.get(execNameQuark);
795 ITmfStateInterval ppidInterval = ppidQuark == ITmfStateSystem.INVALID_ATTRIBUTE ? null : fullState.get(ppidQuark);
796 long startTime = execNameInterval.getStartTime();
797 long endTime = execNameInterval.getEndTime() + 1;
798 if (startTime == lastExecNameStartTime && ppidInterval != null && ppidInterval.getStartTime() == lastPpidStartTime) {
799 continue;
800 }
801 boolean isNull = execNameInterval.getStateValue().isNull();
802 if (isNull && lastExecNameEndTime < startTime && lastExecNameEndTime != -1) {
803 /*
804 * There was a non-null interval in between the
805 * full states, try to use it.
806 */
807 try {
808 execNameInterval = ssq.querySingleState(startTime - 1, execNameQuark);
809 ppidInterval = ppidQuark == ITmfStateSystem.INVALID_ATTRIBUTE ? null : ssq.querySingleState(startTime - 1, ppidQuark);
810 startTime = execNameInterval.getStartTime();
811 endTime = execNameInterval.getEndTime() + 1;
812 } catch (StateSystemDisposedException e) {
813 /* ignored */
814 }
815 }
816 if (!execNameInterval.getStateValue().isNull() &&
817 execNameInterval.getStateValue().getType() == ITmfStateValue.Type.STRING) {
818 String execName = execNameInterval.getStateValue().unboxStr();
819 int ppid = ppidInterval == null ? -1 : ppidInterval.getStateValue().unboxInt();
820 ControlFlowEntry entry = entryMap.get(entryKey);
821 if (entry == null) {
822 entry = new ControlFlowEntry(threadQuark, trace, execName, threadId, ppid, startTime, endTime);
823 entryList.add(entry);
824 entryMap.put(entryKey, entry);
825 } else {
826 /*
827 * Update the name of the entry to the
828 * latest execName and the parent thread id
829 * to the latest ppid.
830 */
831 entry.setName(execName);
832 entry.setParentThreadId(ppid);
833 entry.updateEndTime(endTime);
834 }
835 }
836 if (isNull) {
837 entryMap.remove(entryKey);
838 }
839 lastExecNameStartTime = startTime;
840 lastExecNameEndTime = endTime;
841 lastPpidStartTime = ppidInterval == null ? -1 : ppidInterval.getStartTime();
842 }
843 }
844 synchronized (fFlatTraces) {
845 if (fFlatTraces.contains(parentTrace)) {
846 addEntriesToFlatTree(entryList, traceEntry);
847 } else {
848 addEntriesToHierarchicalTree(entryList, traceEntry);
849 }
850 }
851 }
852 });
853
854 queryFullStates(ssq, ssq.getStartTime(), end, resolution, monitor, new IQueryHandler() {
855 @Override
856 public void handle(@NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState) {
857 for (final TimeGraphEntry entry : traceEntry.getChildren()) {
858 if (monitor.isCanceled()) {
859 return;
860 }
861 buildStatusEvents(trace, parentTrace, ssq, fullStates, prevFullState, (ControlFlowEntry) entry, monitor, ssq.getStartTime(), end);
862 }
863 }
864 });
865
866 if (parentTrace.equals(getTrace())) {
867 refresh();
868 }
869
870 start = end;
871 }
872 }
873
874 /**
875 * Add entries to the traces's child list in a flat fashion (no hierarchy).
876 * If one entry has children, we do a depth first search to add each child
877 * to the trace's child list and update the parent and child relations.
878 */
879 private static void hierarchicalToFlatTree(TimeGraphEntry traceEntry) {
880 List<@NonNull TimeGraphEntry> rootList = traceEntry.getChildren();
881 // We visit the children of every entry to add
882 StreamFlattener<TimeGraphEntry> sf = new StreamFlattener<>(entry -> entry.getChildren().stream());
883 Stream<TimeGraphEntry> allEntries = rootList.stream().flatMap(entry -> sf.flatten(entry));
884
885 // We add every entry that is missing from the trace's entry list
886 List<@NonNull TimeGraphEntry> rootListToAdd = allEntries
887 .filter(entry -> !rootList.contains(entry))
888 .collect(Collectors.toList());
889 rootList.forEach(entry -> {
890 entry.clearChildren();
891 });
892 rootListToAdd.forEach(entry -> {
893 traceEntry.addChild(entry);
894 entry.clearChildren();
895 });
896 }
897
898 /**
899 * Add entries to the traces's child list in a flat fashion (no hierarchy).
900 */
901 private static void addEntriesToFlatTree(List<@NonNull ControlFlowEntry> entryList, TimeGraphEntry traceEntry) {
902 List<TimeGraphEntry> rootList = traceEntry.getChildren();
903 for (ControlFlowEntry entry : entryList) {
904 if (!rootList.contains(entry)) {
905 traceEntry.addChild(entry);
906 }
907 }
908 }
909
910 /**
911 * Add entries to the trace's child list in a hierarchical fashion.
912 */
913 private static void addEntriesToHierarchicalTree(List<ControlFlowEntry> entryList, TimeGraphEntry traceEntry) {
914 List<TimeGraphEntry> rootList = traceEntry.getChildren();
915
916 for (ControlFlowEntry entry : entryList) {
917 boolean root = (entry.getParent() == null || entry.getParent() == traceEntry);
918 if (root && entry.getParentThreadId() > 0) {
919 for (ControlFlowEntry parent : entryList) {
920 /*
921 * Associate the parent entry only if their time overlap. A
922 * child entry may start before its parent, for example at
923 * the beginning of the trace if a parent has not yet
924 * appeared in the state system. We just want to make sure
925 * that the entry didn't start after the parent ended or
926 * ended before the parent started.
927 */
928 if (parent.getThreadId() == entry.getParentThreadId() &&
929 !(entry.getStartTime() > parent.getEndTime() ||
930 entry.getEndTime() < parent.getStartTime())) {
931 root = false;
932 if (rootList.contains(entry)) {
933 traceEntry.removeChild(entry);
934 }
935 parent.addChild(entry);
936 break;
937 }
938 }
939 }
940 if (root && (!rootList.contains(entry))) {
941 traceEntry.addChild(entry);
942 }
943 }
944 }
945
946 private void buildStatusEvents(ITmfTrace trace, ITmfTrace parentTrace, ITmfStateSystem ss, @NonNull List<List<ITmfStateInterval>> fullStates,
947 @Nullable List<ITmfStateInterval> prevFullState, ControlFlowEntry entry, @NonNull IProgressMonitor monitor, long start, long end) {
948 if (start < entry.getEndTime() && end > entry.getStartTime()) {
949 List<ITimeEvent> eventList = getEventList(entry, ss, fullStates, prevFullState, monitor);
950 if (eventList == null) {
951 return;
952 }
953 /* Start a new event list on first iteration, then append to it */
954 if (prevFullState == null) {
955 entry.setEventList(eventList);
956 } else {
957 for (ITimeEvent event : eventList) {
958 entry.addEvent(event);
959 }
960 }
961 if (parentTrace.equals(getTrace())) {
962 redraw();
963 }
964 }
965 for (ITimeGraphEntry child : entry.getChildren()) {
966 if (monitor.isCanceled()) {
967 return;
968 }
969 buildStatusEvents(trace, parentTrace, ss, fullStates, prevFullState, (ControlFlowEntry) child, monitor, start, end);
970 }
971 }
972
973 @Override
974 protected @Nullable List<ITimeEvent> getEventList(@NonNull TimeGraphEntry tgentry, ITmfStateSystem ss,
975 @NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull IProgressMonitor monitor) {
976 List<ITimeEvent> eventList = null;
977 if (!(tgentry instanceof ControlFlowEntry)) {
978 return eventList;
979 }
980 ControlFlowEntry entry = (ControlFlowEntry) tgentry;
981 try {
982 int statusQuark = entry.getThreadQuark();
983 eventList = new ArrayList<>(fullStates.size());
984 ITmfStateInterval lastInterval = prevFullState == null || statusQuark >= prevFullState.size() ? null : prevFullState.get(statusQuark);
985 long lastStartTime = lastInterval == null ? -1 : lastInterval.getStartTime();
986 long lastEndTime = lastInterval == null ? -1 : lastInterval.getEndTime() + 1;
987 for (List<ITmfStateInterval> fullState : fullStates) {
988 if (monitor.isCanceled()) {
989 return null;
990 }
991 if (statusQuark >= fullState.size()) {
992 /* No information on this thread (yet?), skip it for now */
993 continue;
994 }
995 ITmfStateInterval statusInterval = fullState.get(statusQuark);
996 long time = statusInterval.getStartTime();
997 if (time == lastStartTime) {
998 continue;
999 }
1000 long duration = statusInterval.getEndTime() - time + 1;
1001 int status = -1;
1002 try {
1003 status = statusInterval.getStateValue().unboxInt();
1004 } catch (StateValueTypeException e) {
1005 Activator.getDefault().logError(e.getMessage());
1006 }
1007 if (lastEndTime != time && lastEndTime != -1) {
1008 eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
1009 }
1010 if (!statusInterval.getStateValue().isNull()) {
1011 eventList.add(new TimeEvent(entry, time, duration, status));
1012 } else {
1013 eventList.add(new NullTimeEvent(entry, time, duration));
1014 }
1015 lastStartTime = time;
1016 lastEndTime = time + duration;
1017 }
1018 } catch (TimeRangeException e) {
1019 Activator.getDefault().logError(e.getMessage());
1020 }
1021 return eventList;
1022 }
1023
1024 /**
1025 * Returns a value corresponding to the selected entry.
1026 *
1027 * Used in conjunction with synchingToTime to change the selected entry. If
1028 * one of these methods is overridden in child class, then both should be.
1029 *
1030 * @param time
1031 * The currently selected time
1032 * @return a value identifying the entry
1033 */
1034 private int getSelectionValue(long time) {
1035 int thread = -1;
1036 for (ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) {
1037 if (thread > 0) {
1038 break;
1039 }
1040 ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
1041 if (ssq == null) {
1042 continue;
1043 }
1044 if (time >= ssq.getStartTime() && time <= ssq.getCurrentEndTime()) {
1045 List<Integer> currentThreadQuarks = ssq.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$
1046 for (int currentThreadQuark : currentThreadQuarks) {
1047 try {
1048 ITmfStateInterval currentThreadInterval = ssq.querySingleState(time, currentThreadQuark);
1049 int currentThread = currentThreadInterval.getStateValue().unboxInt();
1050 if (currentThread > 0) {
1051 int statusQuark = ssq.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThread));
1052 ITmfStateInterval statusInterval = ssq.querySingleState(time, statusQuark);
1053 if (statusInterval.getStartTime() == time) {
1054 thread = currentThread;
1055 break;
1056 }
1057 }
1058 } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) {
1059 Activator.getDefault().logError(e.getMessage());
1060 } catch (StateSystemDisposedException e) {
1061 /* Ignored */
1062 }
1063 }
1064 }
1065 }
1066 return thread;
1067 }
1068
1069 @Override
1070 protected void synchingToTime(long time) {
1071 int selected = getSelectionValue(time);
1072 if (selected > 0) {
1073 for (Object element : getTimeGraphViewer().getExpandedElements()) {
1074 if (element instanceof ControlFlowEntry) {
1075 ControlFlowEntry entry = (ControlFlowEntry) element;
1076 if (entry.getThreadId() == selected) {
1077 getTimeGraphCombo().setSelection(entry);
1078 break;
1079 }
1080 }
1081 }
1082 }
1083 }
1084
1085 @Override
1086 protected @NonNull List<ILinkEvent> getLinkList(ITmfStateSystem ss,
1087 @NonNull List<List<ITmfStateInterval>> fullStates, @Nullable List<ITmfStateInterval> prevFullState, @NonNull IProgressMonitor monitor) {
1088 List<ILinkEvent> list = new ArrayList<>();
1089 List<TimeGraphEntry> entryList = getEntryList(ss);
1090 if (entryList == null) {
1091 return list;
1092 }
1093 for (ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) {
1094 List<Integer> currentThreadQuarks = ss.getQuarks(Attributes.CPUS, "*", Attributes.CURRENT_THREAD); //$NON-NLS-1$
1095 for (int currentThreadQuark : currentThreadQuarks) {
1096 if (currentThreadQuark >= fullStates.get(0).size()) {
1097 /* No information on this cpu (yet?), skip it for now */
1098 continue;
1099 }
1100 List<ITmfStateInterval> currentThreadIntervals = new ArrayList<>(fullStates.size() + 2);
1101 try {
1102 /*
1103 * Add the previous interval if it is the first query
1104 * iteration and the first interval has currentThread=0. Add
1105 * the following interval if the last interval has
1106 * currentThread=0. These are diagonal arrows crossing the
1107 * query iteration range.
1108 */
1109 if (prevFullState == null) {
1110 ITmfStateInterval currentThreadInterval = fullStates.get(0).get(currentThreadQuark);
1111 if (currentThreadInterval.getStateValue().unboxInt() == 0) {
1112 long start = Math.max(currentThreadInterval.getStartTime() - 1, ss.getStartTime());
1113 currentThreadIntervals.add(ss.querySingleState(start, currentThreadQuark));
1114 }
1115 }
1116 for (List<ITmfStateInterval> fullState : fullStates) {
1117 currentThreadIntervals.add(fullState.get(currentThreadQuark));
1118 }
1119 ITmfStateInterval currentThreadInterval = fullStates.get(fullStates.size() - 1).get(currentThreadQuark);
1120 if (currentThreadInterval.getStateValue().unboxInt() == 0) {
1121 long end = Math.min(currentThreadInterval.getEndTime() + 1, ss.getCurrentEndTime());
1122 currentThreadIntervals.add(ss.querySingleState(end, currentThreadQuark));
1123 }
1124 } catch (StateSystemDisposedException e) {
1125 /* Ignored */
1126 return list;
1127 }
1128 int prevThread = 0;
1129 long prevEnd = 0;
1130 long lastEnd = 0;
1131 for (ITmfStateInterval currentThreadInterval : currentThreadIntervals) {
1132 if (monitor.isCanceled()) {
1133 return list;
1134 }
1135 if (currentThreadInterval.getEndTime() + 1 == lastEnd) {
1136 continue;
1137 }
1138 long time = currentThreadInterval.getStartTime();
1139 if (time != lastEnd) {
1140 // don't create links where there are gaps in intervals due to the resolution
1141 prevThread = 0;
1142 prevEnd = 0;
1143 }
1144 int thread = currentThreadInterval.getStateValue().unboxInt();
1145 if (thread > 0 && prevThread > 0) {
1146 ITimeGraphEntry prevEntry = findEntry(entryList, trace, prevThread);
1147 ITimeGraphEntry nextEntry = findEntry(entryList, trace, thread);
1148 list.add(new TimeLinkEvent(prevEntry, nextEntry, prevEnd, time - prevEnd, 0));
1149 }
1150 lastEnd = currentThreadInterval.getEndTime() + 1;
1151 if (thread != 0) {
1152 prevThread = thread;
1153 prevEnd = lastEnd;
1154 }
1155 }
1156 }
1157 }
1158 return list;
1159 }
1160
1161 private ControlFlowEntry findEntry(List<TimeGraphEntry> entryList, ITmfTrace trace, int threadId) {
1162 for (TimeGraphEntry entry : entryList) {
1163 if (entry instanceof ControlFlowEntry) {
1164 ControlFlowEntry controlFlowEntry = (ControlFlowEntry) entry;
1165 if (controlFlowEntry.getThreadId() == threadId && controlFlowEntry.getTrace() == trace) {
1166 return controlFlowEntry;
1167 }
1168 }
1169 if (entry.hasChildren()) {
1170 ControlFlowEntry controlFlowEntry = findEntry(entry.getChildren(), trace, threadId);
1171 if (controlFlowEntry != null) {
1172 return controlFlowEntry;
1173 }
1174 }
1175 }
1176 return null;
1177 }
1178
1179 private static ActiveThreadsFilter getActiveThreadsFilter(ViewerFilter[] filters) {
1180 return (ActiveThreadsFilter) Arrays.stream(filters).filter(filter -> filter instanceof ActiveThreadsFilter).findFirst().orElse(null);
1181 }
1182
1183 @Override
1184 protected void updateFilters() {
1185 super.updateFilters();
1186 fActiveThreadsFilter.updateData();
1187 }
1188
1189 }
This page took 0.102806 seconds and 5 git commands to generate.