Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2012, 2014 Ericsson, École Polytechnique de Montréal |
be222f56 PT |
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 | |
4999a196 | 11 | * Geneviève Bastien - Move code to provide base classes for time graph view |
be222f56 PT |
12 | *******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow; | |
15 | ||
16 | import java.util.LinkedHashMap; | |
17 | import java.util.List; | |
18 | import java.util.Map; | |
19 | ||
20 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes; | |
21 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues; | |
4bc53929 | 22 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Activator; |
be222f56 | 23 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages; |
e3366401 | 24 | import org.eclipse.linuxtools.lttng2.kernel.core.analysis.LttngKernelAnalysisModule; |
bcec0116 AM |
25 | import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem; |
26 | import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException; | |
27 | import org.eclipse.linuxtools.statesystem.core.exceptions.StateSystemDisposedException; | |
28 | import org.eclipse.linuxtools.statesystem.core.exceptions.StateValueTypeException; | |
29 | import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException; | |
30 | import org.eclipse.linuxtools.statesystem.core.interval.ITmfStateInterval; | |
31 | import org.eclipse.linuxtools.statesystem.core.statevalue.ITmfStateValue; | |
713a70ae PT |
32 | import org.eclipse.swt.SWT; |
33 | import org.eclipse.swt.graphics.GC; | |
be222f56 | 34 | import org.eclipse.swt.graphics.RGB; |
713a70ae | 35 | import org.eclipse.swt.graphics.Rectangle; |
2bdf0193 AM |
36 | import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule; |
37 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem; | |
38 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; | |
39 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent; | |
40 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent; | |
41 | import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils; | |
be222f56 PT |
42 | |
43 | /** | |
44 | * Presentation provider for the control flow view | |
45 | */ | |
46 | public class ControlFlowPresentationProvider extends TimeGraphPresentationProvider { | |
47 | ||
48 | private enum State { | |
4999a196 GB |
49 | UNKNOWN (new RGB(100, 100, 100)), |
50 | WAIT_BLOCKED (new RGB(200, 200, 0)), | |
51 | WAIT_FOR_CPU (new RGB(200, 100, 0)), | |
52 | USERMODE (new RGB(0, 200, 0)), | |
53 | SYSCALL (new RGB(0, 0, 200)), | |
54 | INTERRUPTED (new RGB(200, 0, 100)); | |
be222f56 PT |
55 | |
56 | public final RGB rgb; | |
57 | ||
4999a196 | 58 | private State(RGB rgb) { |
be222f56 PT |
59 | this.rgb = rgb; |
60 | } | |
4999a196 | 61 | |
be222f56 PT |
62 | } |
63 | ||
4999a196 GB |
64 | /** |
65 | * Default constructor | |
66 | */ | |
67 | public ControlFlowPresentationProvider() { | |
68 | super(Messages.ControlFlowView_stateTypeName); | |
69 | } | |
70 | ||
71 | private static State[] getStateValues() { | |
72 | return State.values(); | |
be222f56 PT |
73 | } |
74 | ||
75 | @Override | |
76 | public StateItem[] getStateTable() { | |
4999a196 GB |
77 | State[] states = getStateValues(); |
78 | StateItem[] stateTable = new StateItem[states.length]; | |
be222f56 | 79 | for (int i = 0; i < stateTable.length; i++) { |
4999a196 | 80 | State state = states[i]; |
be222f56 PT |
81 | stateTable[i] = new StateItem(state.rgb, state.toString()); |
82 | } | |
83 | return stateTable; | |
84 | } | |
85 | ||
86 | @Override | |
87 | public int getStateTableIndex(ITimeEvent event) { | |
4999a196 GB |
88 | if (event instanceof TimeEvent && ((TimeEvent) event).hasValue()) { |
89 | int status = ((TimeEvent) event).getValue(); | |
f2338178 | 90 | return getMatchingState(status).ordinal(); |
be222f56 | 91 | } |
af10fe06 | 92 | return TRANSPARENT; |
be222f56 PT |
93 | } |
94 | ||
95 | @Override | |
96 | public String getEventName(ITimeEvent event) { | |
4999a196 GB |
97 | if (event instanceof TimeEvent) { |
98 | TimeEvent ev = (TimeEvent) event; | |
99 | if (ev.hasValue()) { | |
100 | return getMatchingState(ev.getValue()).toString(); | |
101 | } | |
be222f56 | 102 | } |
af10fe06 | 103 | return Messages.ControlFlowView_multipleStates; |
be222f56 | 104 | } |
f2338178 MD |
105 | |
106 | private static State getMatchingState(int status) { | |
107 | switch (status) { | |
108 | case StateValues.PROCESS_STATUS_WAIT_BLOCKED: | |
109 | return State.WAIT_BLOCKED; | |
110 | case StateValues.PROCESS_STATUS_WAIT_FOR_CPU: | |
111 | return State.WAIT_FOR_CPU; | |
112 | case StateValues.PROCESS_STATUS_RUN_USERMODE: | |
113 | return State.USERMODE; | |
114 | case StateValues.PROCESS_STATUS_RUN_SYSCALL: | |
115 | return State.SYSCALL; | |
116 | case StateValues.PROCESS_STATUS_INTERRUPTED: | |
117 | return State.INTERRUPTED; | |
118 | default: | |
119 | return State.UNKNOWN; | |
120 | } | |
121 | } | |
be222f56 PT |
122 | |
123 | @Override | |
124 | public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) { | |
e0838ca1 | 125 | Map<String, String> retMap = new LinkedHashMap<>(); |
1d46dc38 PT |
126 | if (!(event instanceof TimeEvent) || !((TimeEvent) event).hasValue() || |
127 | !(event.getEntry() instanceof ControlFlowEntry)) { | |
128 | return retMap; | |
129 | } | |
130 | ControlFlowEntry entry = (ControlFlowEntry) event.getEntry(); | |
72221aa4 | 131 | ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(entry.getTrace(), LttngKernelAnalysisModule.ID); |
4bc53929 GB |
132 | if (ssq == null) { |
133 | return retMap; | |
134 | } | |
1d46dc38 PT |
135 | int tid = entry.getThreadId(); |
136 | ||
137 | try { | |
138 | // Find every CPU first, then get the current thread | |
139 | int cpusQuark = ssq.getQuarkAbsolute(Attributes.CPUS); | |
140 | List<Integer> cpuQuarks = ssq.getSubAttributes(cpusQuark, false); | |
141 | for (Integer cpuQuark : cpuQuarks) { | |
142 | int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD); | |
143 | ITmfStateInterval interval = ssq.querySingleState(event.getTime(), currentThreadQuark); | |
144 | if (!interval.getStateValue().isNull()) { | |
145 | ITmfStateValue state = interval.getStateValue(); | |
146 | int currentThreadId = state.unboxInt(); | |
147 | if (tid == currentThreadId) { | |
148 | retMap.put(Messages.ControlFlowView_attributeCpuName, ssq.getAttributeName(cpuQuark)); | |
149 | break; | |
be222f56 | 150 | } |
be222f56 | 151 | } |
1d46dc38 PT |
152 | } |
153 | ||
4bc53929 GB |
154 | } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) { |
155 | Activator.getDefault().logError("Error in ControlFlowPresentationProvider", e); //$NON-NLS-1$ | |
1d46dc38 PT |
156 | } catch (StateSystemDisposedException e) { |
157 | /* Ignored */ | |
158 | } | |
159 | int status = ((TimeEvent) event).getValue(); | |
160 | if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) { | |
161 | try { | |
162 | int syscallQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL); | |
163 | ITmfStateInterval value = ssq.querySingleState(event.getTime(), syscallQuark); | |
164 | if (!value.getStateValue().isNull()) { | |
165 | ITmfStateValue state = value.getStateValue(); | |
166 | retMap.put(Messages.ControlFlowView_attributeSyscallName, state.toString()); | |
4999a196 | 167 | } |
1d46dc38 | 168 | |
4bc53929 GB |
169 | } catch (AttributeNotFoundException | TimeRangeException e) { |
170 | Activator.getDefault().logError("Error in ControlFlowPresentationProvider", e); //$NON-NLS-1$ | |
1d46dc38 PT |
171 | } catch (StateSystemDisposedException e) { |
172 | /* Ignored */ | |
be222f56 PT |
173 | } |
174 | } | |
175 | ||
176 | return retMap; | |
177 | } | |
178 | ||
713a70ae PT |
179 | @Override |
180 | public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) { | |
181 | if (bounds.width <= gc.getFontMetrics().getAverageCharWidth()) { | |
182 | return; | |
183 | } | |
4999a196 | 184 | if (!(event instanceof TimeEvent)) { |
713a70ae PT |
185 | return; |
186 | } | |
187 | ControlFlowEntry entry = (ControlFlowEntry) event.getEntry(); | |
72221aa4 | 188 | ITmfStateSystem ss = TmfStateSystemAnalysisModule.getStateSystem(entry.getTrace(), LttngKernelAnalysisModule.ID); |
4bc53929 GB |
189 | if (ss == null) { |
190 | return; | |
191 | } | |
4999a196 GB |
192 | int status = ((TimeEvent) event).getValue(); |
193 | ||
713a70ae PT |
194 | if (status != StateValues.PROCESS_STATUS_RUN_SYSCALL) { |
195 | return; | |
196 | } | |
197 | try { | |
198 | int syscallQuark = ss.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL); | |
199 | ITmfStateInterval value = ss.querySingleState(event.getTime(), syscallQuark); | |
200 | if (!value.getStateValue().isNull()) { | |
201 | ITmfStateValue state = value.getStateValue(); | |
202 | gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE)); | |
203 | Utils.drawText(gc, state.toString().substring(4), bounds.x, bounds.y - 2, bounds.width, true, true); | |
204 | } | |
4bc53929 GB |
205 | } catch (AttributeNotFoundException | TimeRangeException e) { |
206 | Activator.getDefault().logError("Error in ControlFlowPresentationProvider", e); //$NON-NLS-1$ | |
713a70ae PT |
207 | } catch (StateSystemDisposedException e) { |
208 | /* Ignored */ | |
209 | } | |
210 | } | |
be222f56 | 211 | } |