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