Fix for bug 389328: Provide hover time for time graph tool tip info.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / resources / ResourcesPresentationProvider.java
CommitLineData
ce99194e
PT
1/*******************************************************************************\r
2 * Copyright (c) 2012 Ericsson\r
27f3a03d 3 *\r
ce99194e
PT
4 * All rights reserved. This program and the accompanying materials are\r
5 * made available under the terms of the Eclipse Public License v1.0 which\r
6 * accompanies this distribution, and is available at\r
7 * http://www.eclipse.org/legal/epl-v10.html\r
27f3a03d 8 *\r
ce99194e
PT
9 * Contributors:\r
10 * Patrick Tasse - Initial API and implementation\r
11 *******************************************************************************/\r
12\r
72b5abb1
PT
13package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;\r
14\r
15import java.util.HashMap;\r
0c180b6b 16import java.util.List;\r
72b5abb1
PT
17import java.util.Map;\r
18\r
3e97fbfa
AM
19import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;\r
20import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;\r
72b5abb1
PT
21import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;\r
22import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;\r
0c180b6b
BH
23import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;\r
24import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;\r
25import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;\r
26import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;\r
27import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;\r
72b5abb1
PT
28import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;\r
29import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;\r
30import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
31import org.eclipse.swt.graphics.RGB;\r
32\r
27f3a03d
AM
33/**\r
34 * Presentation provider for the Resource view, based on the generic TMF\r
35 * presentation provider.\r
36 *\r
37 * @author Patrick Tasse\r
38 */\r
72b5abb1
PT
39public class ResourcesPresentationProvider extends TimeGraphPresentationProvider {\r
40\r
41 private enum State {\r
3d90c4ff
PT
42 UNKNOWN (new RGB(100, 100, 100)),\r
43 IDLE (new RGB(200, 200, 200)),\r
44 USERMODE (new RGB(0, 200, 0)),\r
45 SYSCALL (new RGB(0, 0, 200)),\r
46 IRQ (new RGB(200, 100, 100)),\r
47 SOFT_IRQ (new RGB(200, 150, 100)),\r
48 IRQ_ACTIVE (new RGB(200, 100, 100)),\r
49 SOFT_IRQ_RAISED (new RGB(200, 200, 0)),\r
50 SOFT_IRQ_ACTIVE (new RGB(200, 150, 100));\r
72b5abb1
PT
51\r
52 public final RGB rgb;\r
53\r
54 private State (RGB rgb) {\r
55 this.rgb = rgb;\r
56 }\r
57 }\r
58\r
27f3a03d 59 @Override\r
72b5abb1
PT
60 public String getStateTypeName() {\r
61 return Messages.ResourcesView_stateTypeName;\r
62 }\r
63\r
64 @Override\r
65 public StateItem[] getStateTable() {\r
66 StateItem[] stateTable = new StateItem[State.values().length];\r
67 for (int i = 0; i < stateTable.length; i++) {\r
68 State state = State.values()[i];\r
69 stateTable[i] = new StateItem(state.rgb, state.toString());\r
70 }\r
71 return stateTable;\r
72 }\r
73\r
74 @Override\r
75 public int getStateTableIndex(ITimeEvent event) {\r
76 if (event instanceof ResourcesEvent) {\r
77 ResourcesEvent resourcesEvent = (ResourcesEvent) event;\r
78 if (resourcesEvent.getType() == Type.CPU) {\r
79 int status = resourcesEvent.getValue();\r
3e97fbfa 80 if (status == StateValues.CPU_STATUS_IDLE) {\r
72b5abb1 81 return State.IDLE.ordinal();\r
a080bb93 82 } else if (status == StateValues.CPU_STATUS_RUN_USERMODE) {\r
3d90c4ff
PT
83 return State.USERMODE.ordinal();\r
84 } else if (status == StateValues.CPU_STATUS_RUN_SYSCALL) {\r
85 return State.SYSCALL.ordinal();\r
a080bb93 86 } else if (status == StateValues.CPU_STATUS_IRQ) {\r
3d90c4ff
PT
87 return State.IRQ.ordinal();\r
88 } else if (status == StateValues.CPU_STATUS_SOFTIRQ) {\r
89 return State.SOFT_IRQ.ordinal();\r
72b5abb1 90 }\r
3d90c4ff
PT
91 } else if (resourcesEvent.getType() == Type.IRQ) {\r
92 return State.IRQ_ACTIVE.ordinal();\r
93 } else if (resourcesEvent.getType() == Type.SOFT_IRQ) {\r
72b5abb1 94 int cpu = resourcesEvent.getValue();\r
3e97fbfa 95 if (cpu == StateValues.SOFT_IRQ_RAISED) {\r
3d90c4ff 96 return State.SOFT_IRQ_RAISED.ordinal();\r
72b5abb1 97 }\r
3d90c4ff 98 return State.SOFT_IRQ_ACTIVE.ordinal();\r
72b5abb1
PT
99 } else {\r
100 return -1; // NULL\r
101 }\r
102 }\r
103 return State.UNKNOWN.ordinal();\r
104 }\r
105\r
106 @Override\r
107 public String getEventName(ITimeEvent event) {\r
108 if (event instanceof ResourcesEvent) {\r
109 ResourcesEvent resourcesEvent = (ResourcesEvent) event;\r
110 if (resourcesEvent.getType() == Type.CPU) {\r
111 int status = resourcesEvent.getValue();\r
3e97fbfa 112 if (status == StateValues.CPU_STATUS_IDLE) {\r
72b5abb1 113 return State.IDLE.toString();\r
a080bb93 114 } else if (status == StateValues.CPU_STATUS_RUN_USERMODE) {\r
3d90c4ff
PT
115 return State.USERMODE.toString();\r
116 } else if (status == StateValues.CPU_STATUS_RUN_SYSCALL) {\r
117 return State.SYSCALL.toString();\r
a080bb93 118 } else if (status == StateValues.CPU_STATUS_IRQ) {\r
3d90c4ff
PT
119 return State.IRQ.toString();\r
120 } else if (status == StateValues.CPU_STATUS_SOFTIRQ) {\r
121 return State.SOFT_IRQ.toString();\r
72b5abb1 122 }\r
3d90c4ff
PT
123 } else if (resourcesEvent.getType() == Type.IRQ) {\r
124 return State.IRQ_ACTIVE.toString();\r
125 } else if (resourcesEvent.getType() == Type.SOFT_IRQ) {\r
72b5abb1 126 int cpu = resourcesEvent.getValue();\r
3e97fbfa 127 if (cpu == StateValues.SOFT_IRQ_RAISED) {\r
3d90c4ff 128 return State.SOFT_IRQ_RAISED.toString();\r
72b5abb1 129 }\r
3d90c4ff 130 return State.SOFT_IRQ_ACTIVE.toString();\r
72b5abb1
PT
131 } else {\r
132 return null;\r
133 }\r
134 }\r
135 return State.UNKNOWN.toString();\r
136 }\r
137\r
138 @Override\r
139 public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {\r
27f3a03d 140\r
72b5abb1
PT
141 Map<String, String> retMap = new HashMap<String, String>();\r
142 if (event instanceof ResourcesEvent) {\r
143\r
144 ResourcesEvent resourcesEvent = (ResourcesEvent) event;\r
145\r
0c180b6b 146 // Check for IRQ or Soft_IRQ type\r
72b5abb1 147 if (resourcesEvent.getType().equals(Type.IRQ) || resourcesEvent.getType().equals(Type.SOFT_IRQ)) {\r
27f3a03d 148\r
0c180b6b 149 // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display\r
72b5abb1
PT
150 int cpu = resourcesEvent.getValue();\r
151 if (cpu >= 0) {\r
152 retMap.put(Messages.ResourcesView_attributeCpuName, String.valueOf(cpu));\r
153 }\r
27f3a03d
AM
154 }\r
155\r
0c180b6b
BH
156 // Check for type CPU\r
157 if (resourcesEvent.getType().equals(Type.CPU)) {\r
158 int status = resourcesEvent.getValue();\r
159\r
a080bb93 160 if (status == StateValues.CPU_STATUS_IRQ) {\r
3d90c4ff 161 // In IRQ state get the IRQ that caused the interruption\r
0c180b6b
BH
162 ResourcesEntry entry = (ResourcesEntry) event.getEntry();\r
163 IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r
164 int cpu = entry.getId();\r
3d90c4ff 165\r
0c180b6b
BH
166 IStateSystemQuerier ss = entry.getTrace().getStateSystem();\r
167 try {\r
0c180b6b
BH
168 List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());\r
169 List<Integer> irqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$\r
170\r
3d90c4ff
PT
171 for (int irqQuark : irqQuarks) {\r
172 if (fullState.get(irqQuark).getStateValue().unboxInt() == cpu) {\r
173 ITmfStateInterval value = ssq.querySingleState(event.getTime(), irqQuark);\r
174 if (!value.getStateValue().isNull()) {\r
175 int irq = Integer.parseInt(ssq.getAttributeName(irqQuark));\r
176 retMap.put(Messages.ResourcesView_attributeIrqName, String.valueOf(irq));\r
177 }\r
0c180b6b
BH
178 break;\r
179 }\r
180 }\r
3d90c4ff
PT
181 } catch (AttributeNotFoundException e) {\r
182 e.printStackTrace();\r
183 } catch (TimeRangeException e) {\r
184 e.printStackTrace();\r
185 } catch (StateValueTypeException e) {\r
186 e.printStackTrace();\r
187 }\r
188 } else if (status == StateValues.CPU_STATUS_SOFTIRQ) {\r
189 // In SOFT_IRQ state get the SOFT_IRQ that caused the interruption\r
190 ResourcesEntry entry = (ResourcesEntry) event.getEntry();\r
191 IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r
192 int cpu = entry.getId();\r
0c180b6b 193\r
3d90c4ff
PT
194 IStateSystemQuerier ss = entry.getTrace().getStateSystem();\r
195 try {\r
196 List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());\r
197 List<Integer> softIrqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$\r
198\r
199 for (int softIrqQuark : softIrqQuarks) {\r
200 if (fullState.get(softIrqQuark).getStateValue().unboxInt() == cpu) {\r
201 ITmfStateInterval value = ssq.querySingleState(event.getTime(), softIrqQuark);\r
202 if (!value.getStateValue().isNull()) {\r
203 int softIrq = Integer.parseInt(ssq.getAttributeName(softIrqQuark));\r
204 retMap.put(Messages.ResourcesView_attributeSoftIrqName, String.valueOf(softIrq));\r
205 }\r
206 break;\r
0c180b6b
BH
207 }\r
208 }\r
209 } catch (AttributeNotFoundException e) {\r
210 e.printStackTrace();\r
211 } catch (TimeRangeException e) {\r
212 e.printStackTrace();\r
213 } catch (StateValueTypeException e) {\r
214 e.printStackTrace();\r
215 }\r
216 }\r
72b5abb1
PT
217 }\r
218 }\r
219\r
220 return retMap;\r
221 }\r
222\r
223}\r
This page took 0.052086 seconds and 5 git commands to generate.