Commit | Line | Data |
---|---|---|
ce99194e PT |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2012 Ericsson\r | |
3 | * \r | |
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 | |
8 | * \r | |
9 | * Contributors:\r | |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
72b5abb1 PT |
13 | package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources;\r |
14 | \r | |
15 | import java.util.HashMap;\r | |
0c180b6b | 16 | import java.util.List;\r |
72b5abb1 PT |
17 | import java.util.Map;\r |
18 | \r | |
3e97fbfa AM |
19 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;\r |
20 | import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;\r | |
72b5abb1 PT |
21 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;\r |
22 | import org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.resources.ResourcesEntry.Type;\r | |
0c180b6b BH |
23 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;\r |
24 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;\r | |
25 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;\r | |
26 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;\r | |
27 | import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;\r | |
72b5abb1 PT |
28 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;\r |
29 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;\r | |
30 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r | |
31 | import org.eclipse.swt.graphics.RGB;\r | |
32 | \r | |
33 | public class ResourcesPresentationProvider extends TimeGraphPresentationProvider {\r | |
34 | \r | |
35 | private enum State {\r | |
36 | UNKNOWN (new RGB(100, 100, 100)),\r | |
37 | IDLE (new RGB(200, 200, 200)),\r | |
38 | BUSY (new RGB(0, 200, 0)),\r | |
39 | INTERRUPTED (new RGB(200, 100, 100)),\r | |
40 | RAISED (new RGB(200, 200, 0)),\r | |
41 | ACTIVE (new RGB(200, 150, 100));\r | |
42 | \r | |
43 | public final RGB rgb;\r | |
44 | \r | |
45 | private State (RGB rgb) {\r | |
46 | this.rgb = rgb;\r | |
47 | }\r | |
48 | }\r | |
49 | \r | |
50 | @Override \r | |
51 | public String getStateTypeName() {\r | |
52 | return Messages.ResourcesView_stateTypeName;\r | |
53 | }\r | |
54 | \r | |
55 | @Override\r | |
56 | public StateItem[] getStateTable() {\r | |
57 | StateItem[] stateTable = new StateItem[State.values().length];\r | |
58 | for (int i = 0; i < stateTable.length; i++) {\r | |
59 | State state = State.values()[i];\r | |
60 | stateTable[i] = new StateItem(state.rgb, state.toString());\r | |
61 | }\r | |
62 | return stateTable;\r | |
63 | }\r | |
64 | \r | |
65 | @Override\r | |
66 | public int getStateTableIndex(ITimeEvent event) {\r | |
67 | if (event instanceof ResourcesEvent) {\r | |
68 | ResourcesEvent resourcesEvent = (ResourcesEvent) event;\r | |
69 | if (resourcesEvent.getType() == Type.CPU) {\r | |
70 | int status = resourcesEvent.getValue();\r | |
3e97fbfa | 71 | if (status == StateValues.CPU_STATUS_IDLE) {\r |
72b5abb1 | 72 | return State.IDLE.ordinal();\r |
a080bb93 | 73 | } else if (status == StateValues.CPU_STATUS_RUN_USERMODE) {\r |
72b5abb1 | 74 | return State.BUSY.ordinal();\r |
a080bb93 | 75 | } else if (status == StateValues.CPU_STATUS_IRQ) {\r |
72b5abb1 PT |
76 | return State.INTERRUPTED.ordinal();\r |
77 | }\r | |
78 | } else if (resourcesEvent.getType() == Type.IRQ || resourcesEvent.getType() == Type.SOFT_IRQ) {\r | |
79 | int cpu = resourcesEvent.getValue();\r | |
3e97fbfa | 80 | if (cpu == StateValues.SOFT_IRQ_RAISED) {\r |
72b5abb1 PT |
81 | return State.RAISED.ordinal();\r |
82 | }\r | |
83 | return State.ACTIVE.ordinal();\r | |
84 | } else {\r | |
85 | return -1; // NULL\r | |
86 | }\r | |
87 | }\r | |
88 | return State.UNKNOWN.ordinal();\r | |
89 | }\r | |
90 | \r | |
91 | @Override\r | |
92 | public String getEventName(ITimeEvent event) {\r | |
93 | if (event instanceof ResourcesEvent) {\r | |
94 | ResourcesEvent resourcesEvent = (ResourcesEvent) event;\r | |
95 | if (resourcesEvent.getType() == Type.CPU) {\r | |
96 | int status = resourcesEvent.getValue();\r | |
3e97fbfa | 97 | if (status == StateValues.CPU_STATUS_IDLE) {\r |
72b5abb1 | 98 | return State.IDLE.toString();\r |
a080bb93 | 99 | } else if (status == StateValues.CPU_STATUS_RUN_USERMODE) {\r |
72b5abb1 | 100 | return State.BUSY.toString();\r |
a080bb93 | 101 | } else if (status == StateValues.CPU_STATUS_IRQ) {\r |
72b5abb1 PT |
102 | return State.INTERRUPTED.toString();\r |
103 | }\r | |
104 | } else if (resourcesEvent.getType() == Type.IRQ || resourcesEvent.getType() == Type.SOFT_IRQ) {\r | |
105 | int cpu = resourcesEvent.getValue();\r | |
3e97fbfa | 106 | if (cpu == StateValues.SOFT_IRQ_RAISED) {\r |
72b5abb1 PT |
107 | return State.RAISED.toString();\r |
108 | }\r | |
109 | return State.ACTIVE.toString();\r | |
110 | } else {\r | |
111 | return null;\r | |
112 | }\r | |
113 | }\r | |
114 | return State.UNKNOWN.toString();\r | |
115 | }\r | |
116 | \r | |
117 | @Override\r | |
118 | public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {\r | |
119 | \r | |
120 | Map<String, String> retMap = new HashMap<String, String>();\r | |
121 | if (event instanceof ResourcesEvent) {\r | |
122 | \r | |
123 | ResourcesEvent resourcesEvent = (ResourcesEvent) event;\r | |
124 | \r | |
0c180b6b | 125 | // Check for IRQ or Soft_IRQ type\r |
72b5abb1 | 126 | if (resourcesEvent.getType().equals(Type.IRQ) || resourcesEvent.getType().equals(Type.SOFT_IRQ)) {\r |
0c180b6b BH |
127 | \r |
128 | // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display\r | |
72b5abb1 PT |
129 | int cpu = resourcesEvent.getValue();\r |
130 | if (cpu >= 0) {\r | |
131 | retMap.put(Messages.ResourcesView_attributeCpuName, String.valueOf(cpu));\r | |
132 | }\r | |
0c180b6b BH |
133 | } \r |
134 | \r | |
135 | // Check for type CPU\r | |
136 | if (resourcesEvent.getType().equals(Type.CPU)) {\r | |
137 | int status = resourcesEvent.getValue();\r | |
138 | \r | |
a080bb93 | 139 | if (status == StateValues.CPU_STATUS_IRQ) {\r |
0c180b6b BH |
140 | // In interrupted state get the IRQ or SOFT_IRQ that caused the interruption\r |
141 | ResourcesEntry entry = (ResourcesEntry) event.getEntry();\r | |
142 | IStateSystemQuerier ssq = entry.getTrace().getStateSystem();\r | |
143 | int cpu = entry.getId();\r | |
144 | \r | |
145 | IStateSystemQuerier ss = entry.getTrace().getStateSystem();\r | |
146 | try {\r | |
147 | int resultQuark = 0;\r | |
148 | String attributeName = null;\r | |
149 | \r | |
150 | // First check for IRQ\r | |
151 | List<ITmfStateInterval> fullState = ss.queryFullState(event.getTime());\r | |
152 | List<Integer> irqQuarks = ss.getQuarks(Attributes.RESOURCES, Attributes.IRQS, "*"); //$NON-NLS-1$\r | |
153 | \r | |
154 | for (int curQuark : irqQuarks) {\r | |
155 | if (fullState.get(curQuark).getStateValue().unboxInt() == cpu) {\r | |
156 | resultQuark = curQuark;\r | |
157 | attributeName = Messages.ResourcesView_attributeIrqName;\r | |
158 | break;\r | |
159 | }\r | |
160 | }\r | |
161 | \r | |
162 | // If not found check for SOFT_IRQ\r | |
163 | if (attributeName == null) {\r | |
164 | List<Integer> softIrqQuarks = ssq.getQuarks(Attributes.RESOURCES, Attributes.SOFT_IRQS, "*"); //$NON-NLS-1$\r | |
165 | for (int curQuark : softIrqQuarks) {\r | |
166 | if (fullState.get(curQuark).getStateValue().unboxInt() == cpu) {\r | |
167 | resultQuark = curQuark;\r | |
168 | attributeName = Messages.ResourcesView_attributeSoftIrqName;\r | |
169 | break;\r | |
170 | }\r | |
171 | } \r | |
172 | }\r | |
173 | \r | |
174 | if (attributeName != null) {\r | |
175 | // A IRQ or SOFT_IRQ was found\r | |
176 | ITmfStateInterval value = ssq.querySingleState(event.getTime(), resultQuark);\r | |
177 | if (!value.getStateValue().isNull()) {\r | |
178 | int irq = Integer.parseInt(ssq.getAttributeName(resultQuark));\r | |
179 | retMap.put(attributeName, String.valueOf(irq));\r | |
180 | }\r | |
181 | }\r | |
182 | } catch (AttributeNotFoundException e) {\r | |
183 | e.printStackTrace();\r | |
184 | } catch (TimeRangeException e) {\r | |
185 | e.printStackTrace();\r | |
186 | } catch (StateValueTypeException e) {\r | |
187 | e.printStackTrace();\r | |
188 | }\r | |
189 | }\r | |
72b5abb1 PT |
190 | }\r |
191 | }\r | |
192 | \r | |
193 | return retMap;\r | |
194 | }\r | |
195 | \r | |
196 | }\r |