1 /*******************************************************************************
2 * Copyright (c) 2015 Keba AG
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Christian Mansky - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.analysis
.os
.linux
.ui
.views
.controlflow
;
15 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.Attributes
;
16 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.KernelAnalysisModule
;
17 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.StateValues
;
18 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
19 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
20 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceContext
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.dialogs
.ITimeGraphEntryActiveProvider
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
31 * Provides Functionality for check Active / uncheck inactive
33 * @noinstantiate This class is not intended to be instantiated by clients.
34 * @noextend This class is not intended to be subclassed by clients.
37 public class ControlFlowCheckActiveProvider
implements ITimeGraphEntryActiveProvider
{
48 public ControlFlowCheckActiveProvider(String label
, String tooltip
) {
54 public String
getLabel() {
59 public String
getTooltip() {
64 public boolean isActive(ITimeGraphEntry element
) {
65 if (element
instanceof ControlFlowEntry
) {
66 ControlFlowEntry cfe
= (ControlFlowEntry
) element
;
68 TmfTraceManager traceManager
= TmfTraceManager
.getInstance();
69 TmfTraceContext traceContext
= traceManager
.getCurrentTraceContext();
70 TmfTimeRange winRange
= traceContext
.getWindowRange();
71 TmfTimeRange selRange
= traceContext
.getSelectionRange();
73 /* Take precedence of selection over window range. */
74 long beginTS
= selRange
.getStartTime().getValue();
75 long endTS
= selRange
.getEndTime().getValue();
77 /* No selection, take window range */
78 if (beginTS
== endTS
) {
79 beginTS
= winRange
.getStartTime().getValue();
80 endTS
= winRange
.getEndTime().getValue();
83 ITmfTrace trace
= cfe
.getTrace();
84 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(trace
, KernelAnalysisModule
.ID
);
86 beginTS
= Math
.max(beginTS
, ssq
.getStartTime());
87 endTS
= Math
.min(endTS
, ssq
.getCurrentEndTime());
88 if (beginTS
> endTS
) {
92 int statusQuark
= ssq
.getQuarkRelative(cfe
.getThreadQuark(), Attributes
.STATUS
);
94 /* Get the initial state at beginTS */
95 ITmfStateInterval currentInterval
= ssq
.querySingleState(beginTS
, statusQuark
);
96 if (isIntervalInStateActive(currentInterval
)) {
100 /* Get the following state changes */
101 long ts
= currentInterval
.getEndTime();
102 while (ts
!= -1 && ts
< endTS
) {
103 ts
++; /* To "jump over" to the next state in the history */
104 currentInterval
= ssq
.querySingleState(ts
, statusQuark
);
105 if (isIntervalInStateActive(currentInterval
)) {
108 ts
= currentInterval
.getEndTime();
110 } catch (AttributeNotFoundException
| StateSystemDisposedException e
) {
119 private static boolean isIntervalInStateActive (ITmfStateInterval ival
) {
120 int value
= ival
.getStateValue().unboxInt();
121 /* An entry is only active when running */
122 if (value
== StateValues
.PROCESS_STATUS_RUN_USERMODE
|| value
== StateValues
.PROCESS_STATUS_RUN_SYSCALL
||
123 value
== StateValues
.PROCESS_STATUS_INTERRUPTED
) {