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