tmf: Add a StateSystemDisposedException
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / resources / ResourcesPresentationProvider.java
CommitLineData
dedc7dec
PT
1/*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;
14
15import java.util.LinkedHashMap;
16import java.util.List;
17import java.util.Map;
18
19import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
20import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;
21import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
22import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;
23import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
96345c5a 24import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
dedc7dec
PT
25import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
26import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
27import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
f1f86dfb 28import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
dedc7dec
PT
29import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
30import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
31import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
32import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
33import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;
34import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
35import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
36import org.eclipse.swt.graphics.RGB;
37
38/**
39 * Presentation provider for the Resource view, based on the generic TMF
40 * presentation provider.
41 *
42 * @author Patrick Tasse
43 */
44public class ResourcesPresentationProvider extends TimeGraphPresentationProvider {
45
46 private enum State {
47 UNKNOWN (new RGB(100, 100, 100)),
48 IDLE (new RGB(200, 200, 200)),
49 USERMODE (new RGB(0, 200, 0)),
50 SYSCALL (new RGB(0, 0, 200)),
51 IRQ (new RGB(200, 100, 100)),
52 SOFT_IRQ (new RGB(200, 150, 100)),
53 IRQ_ACTIVE (new RGB(200, 100, 100)),
54 SOFT_IRQ_RAISED (new RGB(200, 200, 0)),
55 SOFT_IRQ_ACTIVE (new RGB(200, 150, 100));
56
57 public final RGB rgb;
58
59 private State (RGB rgb) {
60 this.rgb = rgb;
61 }
62 }
63
64 @Override
65 public String getStateTypeName() {
66 return Messages.ResourcesView_stateTypeName;
67 }
68
69 @Override
70 public StateItem[] getStateTable() {
71 StateItem[] stateTable = new StateItem[State.values().length];
72 for (int i = 0; i < stateTable.length; i++) {
73 State state = State.values()[i];
74 stateTable[i] = new StateItem(state.rgb, state.toString());
75 }
76 return stateTable;
77 }
78
79 @Override
80 public int getStateTableIndex(ITimeEvent event) {
81 if (event instanceof ResourcesEvent) {
82 ResourcesEvent resourcesEvent = (ResourcesEvent) event;
83 if (resourcesEvent.getType() == Type.CPU) {
84 int status = resourcesEvent.getValue();
85 if (status == StateValues.CPU_STATUS_IDLE) {
86 return State.IDLE.ordinal();
87 } else if (status == StateValues.CPU_STATUS_RUN_USERMODE) {
88 return State.USERMODE.ordinal();
89 } else if (status == StateValues.CPU_STATUS_RUN_SYSCALL) {
90 return State.SYSCALL.ordinal();
91 } else if (status == StateValues.CPU_STATUS_IRQ) {
92 return State.IRQ.ordinal();
93 } else if (status == StateValues.CPU_STATUS_SOFTIRQ) {
94 return State.SOFT_IRQ.ordinal();
95 }
96 } else if (resourcesEvent.getType() == Type.IRQ) {
97 return State.IRQ_ACTIVE.ordinal();
98 } else if (resourcesEvent.getType() == Type.SOFT_IRQ) {
99 int cpu = resourcesEvent.getValue();
100 if (cpu == StateValues.SOFT_IRQ_RAISED) {
101 return State.SOFT_IRQ_RAISED.ordinal();
102 }
103 return State.SOFT_IRQ_ACTIVE.ordinal();
104 } else {
105 return -1; // NULL
106 }
107 }
108 return State.UNKNOWN.ordinal();
109 }
110
111 @Override
112 public String getEventName(ITimeEvent event) {
113 if (event instanceof ResourcesEvent) {
114 ResourcesEvent resourcesEvent = (ResourcesEvent) event;
115 if (resourcesEvent.getType() == Type.CPU) {
116 int status = resourcesEvent.getValue();
117 if (status == StateValues.CPU_STATUS_IDLE) {
118 return State.IDLE.toString();
119 } else if (status == StateValues.CPU_STATUS_RUN_USERMODE) {
120 return State.USERMODE.toString();
121 } else if (status == StateValues.CPU_STATUS_RUN_SYSCALL) {
122 return State.SYSCALL.toString();
123 } else if (status == StateValues.CPU_STATUS_IRQ) {
124 return State.IRQ.toString();
125 } else if (status == StateValues.CPU_STATUS_SOFTIRQ) {
126 return State.SOFT_IRQ.toString();
127 }
128 } else if (resourcesEvent.getType() == Type.IRQ) {
129 return State.IRQ_ACTIVE.toString();
130 } else if (resourcesEvent.getType() == Type.SOFT_IRQ) {
131 int cpu = resourcesEvent.getValue();
132 if (cpu == StateValues.SOFT_IRQ_RAISED) {
133 return State.SOFT_IRQ_RAISED.toString();
134 }
135 return State.SOFT_IRQ_ACTIVE.toString();
136 } else {
137 return null;
138 }
139 }
140 return State.UNKNOWN.toString();
141 }
142
143 @Override
144 public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event, long hoverTime) {
145
146 Map<String, String> retMap = new LinkedHashMap<String, String>();
147 if (event instanceof ResourcesEvent) {
148
149 ResourcesEvent resourcesEvent = (ResourcesEvent) event;
150
151 // Check for IRQ or Soft_IRQ type
152 if (resourcesEvent.getType().equals(Type.IRQ) || resourcesEvent.getType().equals(Type.SOFT_IRQ)) {
153
154 // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display
155 int cpu = resourcesEvent.getValue();
156 if (cpu >= 0) {
157 retMap.put(Messages.ResourcesView_attributeCpuName, String.valueOf(cpu));
158 }
159 }
160
161 // Check for type CPU
162 if (resourcesEvent.getType().equals(Type.CPU)) {
163 int status = resourcesEvent.getValue();
164
165 if (status == StateValues.CPU_STATUS_IRQ) {
166 // In IRQ state get the IRQ that caused the interruption
167 ResourcesEntry entry = (ResourcesEntry) event.getEntry();
f1f86dfb 168 ITmfStateSystem ssq = entry.getTrace().getStateSystem();
dedc7dec
PT
169 int cpu = entry.getId();
170
f1f86dfb 171 ITmfStateSystem ss = entry.getTrace().getStateSystem();
dedc7dec
PT
172 try {
173 List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());
174 List<Integer> irqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$
175
176 for (int irqQuark : irqQuarks) {
177 if (fullState.get(irqQuark).getStateValue().unboxInt() == cpu) {
178 ITmfStateInterval value = ssq.querySingleState(event.getTime(), irqQuark);
179 if (!value.getStateValue().isNull()) {
180 int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));
181 retMap.put(Messages.ResourcesView_attributeIrqName, String.valueOf(irq));
182 }
183 break;
184 }
185 }
186 } catch (AttributeNotFoundException e) {
187 e.printStackTrace();
188 } catch (TimeRangeException e) {
189 e.printStackTrace();
190 } catch (StateValueTypeException e) {
191 e.printStackTrace();
96345c5a
AM
192 } catch (StateSystemDisposedException e) {
193 /* Ignored */
dedc7dec
PT
194 }
195 } else if (status == StateValues.CPU_STATUS_SOFTIRQ) {
196 // In SOFT_IRQ state get the SOFT_IRQ that caused the interruption
197 ResourcesEntry entry = (ResourcesEntry) event.getEntry();
f1f86dfb 198 ITmfStateSystem ssq = entry.getTrace().getStateSystem();
dedc7dec
PT
199 int cpu = entry.getId();
200
f1f86dfb 201 ITmfStateSystem ss = entry.getTrace().getStateSystem();
dedc7dec
PT
202 try {
203 List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());
204 List<Integer> softIrqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$
205
206 for (int softIrqQuark : softIrqQuarks) {
207 if (fullState.get(softIrqQuark).getStateValue().unboxInt() == cpu) {
208 ITmfStateInterval value = ssq.querySingleState(event.getTime(), softIrqQuark);
209 if (!value.getStateValue().isNull()) {
210 int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));
211 retMap.put(Messages.ResourcesView_attributeSoftIrqName, String.valueOf(softIrq));
212 }
213 break;
214 }
215 }
216 } catch (AttributeNotFoundException e) {
217 e.printStackTrace();
218 } catch (TimeRangeException e) {
219 e.printStackTrace();
220 } catch (StateValueTypeException e) {
221 e.printStackTrace();
96345c5a
AM
222 } catch (StateSystemDisposedException e) {
223 /* Ignored */
dedc7dec
PT
224 }
225 } else if (status == StateValues.CPU_STATUS_RUN_USERMODE || status == StateValues.CPU_STATUS_RUN_SYSCALL){
226 // In running state get the current tid
227 ResourcesEntry entry = (ResourcesEntry) event.getEntry();
f1f86dfb 228 ITmfStateSystem ssq = entry.getTrace().getStateSystem();
dedc7dec
PT
229
230 try {
231 retMap.put(Messages.ResourcesView_attributeHoverTime, Utils.formatTime(hoverTime, TimeFormat.ABSOLUTE, Resolution.NANOSEC));
232 int cpuQuark = entry.getQuark();
233 int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD);
234 ITmfStateInterval interval = ssq.querySingleState(hoverTime, currentThreadQuark);
235 if (!interval.getStateValue().isNull()) {
236 ITmfStateValue value = interval.getStateValue();
237 int currentThreadId = value.unboxInt();
238 retMap.put(Messages.ResourcesView_attributeTidName, Integer.toString(currentThreadId));
239 int execNameQuark = ssq.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThreadId), Attributes.EXEC_NAME);
240 interval = ssq.querySingleState(hoverTime, execNameQuark);
241 if (!interval.getStateValue().isNull()) {
242 value = interval.getStateValue();
243 retMap.put(Messages.ResourcesView_attributeProcessName, value.unboxStr());
244 }
245 if (status == StateValues.CPU_STATUS_RUN_SYSCALL) {
246 int syscallQuark = ssq.getQuarkAbsolute(Attributes.THREADS, Integer.toString(currentThreadId), Attributes.SYSTEM_CALL);
247 interval = ssq.querySingleState(hoverTime, syscallQuark);
248 if (!interval.getStateValue().isNull()) {
249 value = interval.getStateValue();
250 retMap.put(Messages.ResourcesView_attributeSyscallName, value.unboxStr());
251 }
252 }
253 }
254 } catch (AttributeNotFoundException e) {
255 e.printStackTrace();
256 } catch (TimeRangeException e) {
257 e.printStackTrace();
258 } catch (StateValueTypeException e) {
259 e.printStackTrace();
96345c5a
AM
260 } catch (StateSystemDisposedException e) {
261 /* Ignored */
dedc7dec 262 }
96345c5a 263 }
dedc7dec
PT
264 }
265 }
266
267 return retMap;
268 }
269
270}
This page took 0.035112 seconds and 5 git commands to generate.