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