Commit | Line | Data |
---|---|---|
b97d61f0 CM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 Keba AG | |
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 | * Christian Mansky - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.analysis.os.linux.ui.views.controlflow; | |
14 | ||
0f7a12d3 AM |
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; | |
b97d61f0 CM |
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; | |
29 | ||
30 | /** | |
31 | * Provides Functionality for check Active / uncheck inactive | |
32 | * | |
33 | * @noinstantiate This class is not intended to be instantiated by clients. | |
34 | * @noextend This class is not intended to be subclassed by clients. | |
35 | * @since 1.0 | |
36 | */ | |
37 | public class ControlFlowCheckActiveProvider implements ITimeGraphEntryActiveProvider { | |
38 | ||
39 | String fLabel; | |
40 | String fTooltip; | |
41 | ||
42 | /** | |
43 | * @param label | |
44 | * Button label | |
45 | * @param tooltip | |
46 | * Button tooltip | |
47 | */ | |
48 | public ControlFlowCheckActiveProvider(String label, String tooltip) { | |
49 | fLabel = label; | |
50 | fTooltip = tooltip; | |
51 | } | |
52 | ||
53 | @Override | |
54 | public String getLabel() { | |
55 | return fLabel; | |
56 | } | |
57 | ||
58 | @Override | |
59 | public String getTooltip() { | |
60 | return fTooltip; | |
61 | } | |
62 | ||
63 | @Override | |
64 | public boolean isActive(ITimeGraphEntry element) { | |
65 | if (element instanceof ControlFlowEntry) { | |
66 | ControlFlowEntry cfe = (ControlFlowEntry) element; | |
67 | ||
68 | TmfTraceManager traceManager = TmfTraceManager.getInstance(); | |
69 | TmfTraceContext traceContext = traceManager.getCurrentTraceContext(); | |
70 | TmfTimeRange winRange = traceContext.getWindowRange(); | |
71 | TmfTimeRange selRange = traceContext.getSelectionRange(); | |
72 | ||
73 | /* Take precedence of selection over window range. */ | |
74 | long beginTS = selRange.getStartTime().getValue(); | |
75 | long endTS = selRange.getEndTime().getValue(); | |
76 | ||
77 | /* No selection, take window range */ | |
78 | if (beginTS == endTS) { | |
79 | beginTS = winRange.getStartTime().getValue(); | |
80 | endTS = winRange.getEndTime().getValue(); | |
81 | } | |
82 | ||
83 | ITmfTrace trace = cfe.getTrace(); | |
6d16f5a9 | 84 | ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID); |
b97d61f0 CM |
85 | if (ssq != null) { |
86 | beginTS = Math.max(beginTS, ssq.getStartTime()); | |
87 | endTS = Math.min(endTS, ssq.getCurrentEndTime()); | |
88 | if (beginTS > endTS) { | |
89 | return false; | |
90 | } | |
91 | try { | |
92 | int statusQuark = ssq.getQuarkRelative(cfe.getThreadQuark(), Attributes.STATUS); | |
93 | ||
94 | /* Get the initial state at beginTS */ | |
95 | ITmfStateInterval currentInterval = ssq.querySingleState(beginTS, statusQuark); | |
96 | if (isIntervalInStateActive(currentInterval)) { | |
97 | return true; | |
98 | } | |
99 | ||
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)) { | |
106 | return true; | |
107 | } | |
108 | ts = currentInterval.getEndTime(); | |
109 | } | |
110 | } catch (AttributeNotFoundException | StateSystemDisposedException e) { | |
111 | /* Ignore ... */ | |
112 | } | |
113 | } | |
114 | } | |
115 | ||
116 | return false; | |
117 | } | |
118 | ||
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) { | |
124 | return true; | |
125 | } | |
126 | ||
127 | return false; | |
128 | } | |
129 | ||
130 | } |