KernelAnalysis: Use Threads CoreAttributes to store "Status"
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.ui / src / org / eclipse / tracecompass / internal / analysis / os / linux / ui / views / controlflow / ControlFlowCheckActiveProvider.java
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.internal.analysis.os.linux.ui.views.controlflow;
14
15 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule;
16 import org.eclipse.tracecompass.analysis.os.linux.core.kernel.StateValues;
17 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
18 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
19 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
20 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
21 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
22 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
23 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext;
24 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
25 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.dialogs.ITimeGraphEntryActiveProvider;
26 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
27
28 /**
29 * Provides Functionality for check Active / uncheck inactive
30 *
31 * @noinstantiate This class is not intended to be instantiated by clients.
32 * @noextend This class is not intended to be subclassed by clients.
33 * @since 1.0
34 */
35 public class ControlFlowCheckActiveProvider implements ITimeGraphEntryActiveProvider {
36
37 String fLabel;
38 String fTooltip;
39
40 /**
41 * @param label
42 * Button label
43 * @param tooltip
44 * Button tooltip
45 */
46 public ControlFlowCheckActiveProvider(String label, String tooltip) {
47 fLabel = label;
48 fTooltip = tooltip;
49 }
50
51 @Override
52 public String getLabel() {
53 return fLabel;
54 }
55
56 @Override
57 public String getTooltip() {
58 return fTooltip;
59 }
60
61 @Override
62 public boolean isActive(ITimeGraphEntry element) {
63 if (element instanceof ControlFlowEntry) {
64 ControlFlowEntry cfe = (ControlFlowEntry) element;
65
66 TmfTraceManager traceManager = TmfTraceManager.getInstance();
67 TmfTraceContext traceContext = traceManager.getCurrentTraceContext();
68 TmfTimeRange winRange = traceContext.getWindowRange();
69 TmfTimeRange selRange = traceContext.getSelectionRange();
70
71 /* Take precedence of selection over window range. */
72 long beginTS = selRange.getStartTime().getValue();
73 long endTS = selRange.getEndTime().getValue();
74
75 /* No selection, take window range */
76 if (beginTS == endTS) {
77 beginTS = winRange.getStartTime().getValue();
78 endTS = winRange.getEndTime().getValue();
79 }
80
81 ITmfTrace trace = cfe.getTrace();
82 ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, KernelAnalysisModule.ID);
83 if (ssq != null) {
84 beginTS = Math.max(beginTS, ssq.getStartTime());
85 endTS = Math.min(endTS, ssq.getCurrentEndTime());
86 if (beginTS > endTS) {
87 return false;
88 }
89 try {
90 int statusQuark = cfe.getThreadQuark();
91
92 /* Get the initial state at beginTS */
93 ITmfStateInterval currentInterval = ssq.querySingleState(beginTS, statusQuark);
94 if (isIntervalInStateActive(currentInterval)) {
95 return true;
96 }
97
98 /* Get the following state changes */
99 long ts = currentInterval.getEndTime();
100 while (ts != -1 && ts < endTS) {
101 ts++; /* To "jump over" to the next state in the history */
102 currentInterval = ssq.querySingleState(ts, statusQuark);
103 if (isIntervalInStateActive(currentInterval)) {
104 return true;
105 }
106 ts = currentInterval.getEndTime();
107 }
108 } catch (StateSystemDisposedException e) {
109 /* Ignore ... */
110 }
111 }
112 }
113
114 return false;
115 }
116
117 private static boolean isIntervalInStateActive (ITmfStateInterval ival) {
118 int value = ival.getStateValue().unboxInt();
119 /* An entry is only active when running */
120 if (value == StateValues.PROCESS_STATUS_RUN_USERMODE || value == StateValues.PROCESS_STATUS_RUN_SYSCALL ||
121 value == StateValues.PROCESS_STATUS_INTERRUPTED) {
122 return true;
123 }
124
125 return false;
126 }
127
128 }
This page took 0.034948 seconds and 5 git commands to generate.