Commit | Line | Data |
---|---|---|
6e512b93 ASL |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2009 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 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | package org.eclipse.linuxtools.lttng.ui.model.trange;\r | |
13 | \r | |
14 | import java.util.HashMap;\r | |
15 | import java.util.Map;\r | |
c48abe58 | 16 | import java.util.Set;\r |
6e512b93 | 17 | \r |
6c13869b FC |
18 | import org.eclipse.linuxtools.lttng.core.state.StateStrings.BdevMode;\r |
19 | import org.eclipse.linuxtools.lttng.core.state.StateStrings.CpuMode;\r | |
20 | import org.eclipse.linuxtools.lttng.core.state.StateStrings.ExecutionMode;\r | |
21 | import org.eclipse.linuxtools.lttng.core.state.StateStrings.IRQMode;\r | |
22 | import org.eclipse.linuxtools.lttng.core.state.StateStrings.ProcessStatus;\r | |
23 | import org.eclipse.linuxtools.lttng.core.state.StateStrings.SoftIRQMode;\r | |
24 | import org.eclipse.linuxtools.lttng.core.state.StateStrings.TrapMode;\r | |
a72a38d9 | 25 | import org.eclipse.linuxtools.lttng.ui.views.common.ParamsUpdater;\r |
6e512b93 | 26 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider;\r |
dfaf8391 | 27 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent;\r |
63eecb47 | 28 | import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry;\r |
6e512b93 ASL |
29 | \r |
30 | public class TimeRangeViewerProvider extends TmfTimeAnalysisProvider {\r | |
6e512b93 | 31 | \r |
a2e53983 FC |
32 | // ------------------------------------------------------------------------\r |
33 | // Data\r | |
34 | // ------------------------------------------------------------------------\r | |
35 | \r | |
c48abe58 FC |
36 | protected Map<String, StateColor> procStateToColor = new HashMap<String, StateColor>(16);\r |
37 | protected Map<String, StateColor> bdevStateToColor = new HashMap<String, StateColor>(4);\r | |
38 | protected Map<String, StateColor> softIrqStateToColor = new HashMap<String, StateColor>(4);\r | |
39 | protected Map<String, StateColor> trapStateToColor = new HashMap<String, StateColor>(4);\r | |
40 | protected Map<String, StateColor> irqStateToColor = new HashMap<String, StateColor>(4);\r | |
41 | protected Map<String, StateColor> cpuStateToColor = new HashMap<String, StateColor>(8);\r | |
a2e53983 FC |
42 | \r |
43 | private final ParamsUpdater fviewParameters;\r | |
44 | \r | |
45 | // ------------------------------------------------------------------------\r | |
46 | // Constructors\r | |
47 | // ------------------------------------------------------------------------\r | |
48 | \r | |
49 | public TimeRangeViewerProvider(ParamsUpdater paramsUpdater) {\r | |
50 | // Fill the state mode to color maps\r | |
51 | fillProcessStateToColor();\r | |
52 | fillBdevStateToColor();\r | |
53 | fillSoftIRQStateToColor();\r | |
54 | fillTrapStateToColor();\r | |
55 | fillIrqStateToColor();\r | |
56 | fillCpuStateToColor();\r | |
57 | fviewParameters = paramsUpdater;\r | |
58 | }\r | |
59 | \r | |
60 | // ------------------------------------------------------------------------\r | |
61 | // Methods\r | |
62 | // ------------------------------------------------------------------------\r | |
63 | \r | |
64 | /* (non-Javadoc)\r | |
65 | * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider#getEventColor(org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent)\r | |
66 | */\r | |
67 | @Override\r | |
68 | public StateColor getEventColor(ITimeEvent event) {\r | |
69 | StateColor retColor = null;\r | |
70 | \r | |
71 | if (event instanceof TimeRangeEvent) {\r | |
72 | TimeRangeEvent devent = (TimeRangeEvent) event;\r | |
73 | String stateMode = devent.getStateMode();\r | |
74 | switch (devent.getEventType()) {\r | |
75 | case PROCESS_MODE:\r | |
76 | retColor = procStateToColor.get(stateMode);\r | |
77 | break;\r | |
78 | case BDEV_MODE:\r | |
79 | retColor = bdevStateToColor.get(stateMode);\r | |
80 | break;\r | |
81 | case IRQ_MODE:\r | |
82 | retColor = irqStateToColor.get(stateMode);\r | |
83 | break;\r | |
84 | case SOFT_IRQ_MODE:\r | |
85 | retColor = softIrqStateToColor.get(stateMode);\r | |
86 | break;\r | |
87 | case CPU_MODE:\r | |
88 | retColor = cpuStateToColor.get(stateMode);\r | |
89 | break;\r | |
90 | case TRAP_MODE:\r | |
91 | retColor = trapStateToColor.get(stateMode);\r | |
92 | break;\r | |
93 | }\r | |
6e512b93 ASL |
94 | }\r |
95 | \r | |
a2e53983 FC |
96 | if (retColor == null) {\r |
97 | return StateColor.MAGENTA3;\r | |
6e512b93 | 98 | }\r |
a2e53983 FC |
99 | return retColor;\r |
100 | }\r | |
101 | \r | |
102 | /* (non-Javadoc)\r | |
103 | * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider#getStateName(org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider.StateColor)\r | |
104 | */\r | |
105 | @Override\r | |
106 | public String getStateName(StateColor color) {\r | |
107 | // Override to multiple instances of the widget, the same color can have\r | |
108 | // multiple meanings\r | |
109 | return "Not mapped"; //$NON-NLS-1$\r | |
110 | }\r | |
111 | \r | |
112 | /* (non-Javadoc)\r | |
113 | * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider#getEventHoverToolTipInfo(org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent)\r | |
114 | */\r | |
115 | @Override\r | |
116 | public Map<String, String> getEventHoverToolTipInfo(ITimeEvent revent) {\r | |
117 | Map<String, String> toolTipEventMsgs = new HashMap<String, String>();\r | |
118 | // if the selected resource is a Process, add the Process type to the\r | |
119 | // tool tip\r | |
120 | if (revent instanceof TimeRangeComponent) {\r | |
121 | ITimeRangeComponent parent = ((TimeRangeComponent) revent).getEventParent();\r | |
122 | \r | |
123 | // if the event start time is unknown, indicate it to the user\r | |
124 | String extraInfo = "\n" + Messages.TimeRangeViewerProvider_BadRangeExtraInfo; //$NON-NLS-1$\r | |
125 | long eventStart = revent.getTime();\r | |
126 | if (eventStart < fviewParameters.getStartTime()) {\r | |
127 | toolTipEventMsgs.put(Messages.TimeRangeViewerProvider_StartTime, Messages.TimeRangeViewerProvider_UndefinedStartTime + extraInfo);\r | |
128 | // avoid repeated details\r | |
129 | extraInfo = ""; //$NON-NLS-1$\r | |
130 | }\r | |
131 | \r | |
132 | long eventEnd = revent.getTime() + revent.getDuration();\r | |
133 | if (eventEnd > fviewParameters.getEndTime()) {\r | |
134 | toolTipEventMsgs.put(Messages.TimeRangeViewerProvider_EndTime, Messages.TimeRangeViewerProvider_UndefinedEndTime + extraInfo);\r | |
135 | }\r | |
136 | \r | |
137 | if (parent != null && parent instanceof TimeRangeEventProcess) {\r | |
138 | TimeRangeEventProcess localProcess = (TimeRangeEventProcess) parent;\r | |
139 | toolTipEventMsgs.put(Messages.TimeRangeViewerProvider_ProcessType, localProcess.getProcessType());\r | |
140 | }\r | |
6e512b93 ASL |
141 | }\r |
142 | \r | |
a2e53983 FC |
143 | return toolTipEventMsgs;\r |
144 | }\r | |
145 | \r | |
146 | /* (non-Javadoc)\r | |
147 | * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider#getEventName(org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent, boolean, boolean)\r | |
148 | */\r | |
149 | @Override\r | |
150 | public String getEventName(ITimeEvent event, boolean upper, boolean extInfo) {\r | |
151 | String name = null;\r | |
152 | // The relevant event name for the time range is the actual state mode\r | |
153 | if (event instanceof TimeRangeEvent) {\r | |
154 | TimeRangeEvent devent = (TimeRangeEvent) event;\r | |
155 | StringBuilder sb = new StringBuilder(devent.getStateMode());\r | |
156 | name = sb.toString();\r | |
6e512b93 ASL |
157 | }\r |
158 | \r | |
a2e53983 FC |
159 | if (name == null) {\r |
160 | return "Unknown"; //$NON-NLS-1$\r | |
6e512b93 | 161 | }\r |
a2e53983 FC |
162 | return name;\r |
163 | }\r | |
164 | \r | |
165 | /* (non-Javadoc)\r | |
166 | * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider#getTraceClassName(org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry)\r | |
167 | */\r | |
168 | @Override\r | |
169 | public String getTraceClassName(ITmfTimeAnalysisEntry trace) {\r | |
170 | String name = ""; //$NON-NLS-1$\r | |
171 | if (trace instanceof TimeRangeComposite) {\r | |
172 | TimeRangeComposite dTrace = (TimeRangeComposite) trace;\r | |
173 | name = dTrace.getClassName();\r | |
6e512b93 | 174 | }\r |
a2e53983 FC |
175 | return name;\r |
176 | }\r | |
177 | \r | |
178 | private void fillCpuStateToColor() {\r | |
179 | cpuStateToColor.put(CpuMode.LTTV_CPU_UNKNOWN.getInName(), StateColor.BLACK);\r | |
180 | cpuStateToColor.put(CpuMode.LTTV_CPU_IDLE.getInName(), StateColor.GRAY);\r | |
181 | cpuStateToColor.put(CpuMode.LTTV_CPU_BUSY.getInName(), StateColor.LIGHT_BLUE);\r | |
182 | cpuStateToColor.put(CpuMode.LTTV_CPU_IRQ.getInName(), StateColor.ORANGE);\r | |
183 | cpuStateToColor.put(CpuMode.LTTV_CPU_SOFT_IRQ.getInName(), StateColor.PURPLE1);\r | |
184 | cpuStateToColor.put(CpuMode.LTTV_CPU_TRAP.getInName(), StateColor.GOLD);\r | |
185 | }\r | |
186 | \r | |
187 | private void fillIrqStateToColor() {\r | |
188 | irqStateToColor.put(IRQMode.LTTV_IRQ_UNKNOWN.getInName(), StateColor.BLACK);\r | |
189 | irqStateToColor.put(IRQMode.LTTV_IRQ_IDLE.getInName(), StateColor.GRAY);\r | |
190 | irqStateToColor.put(IRQMode.LTTV_IRQ_BUSY.getInName(), StateColor.ORANGE);\r | |
191 | }\r | |
192 | \r | |
193 | private void fillTrapStateToColor() {\r | |
194 | trapStateToColor.put(TrapMode.LTTV_TRAP_UNKNOWN.getInName(), StateColor.BLACK);\r | |
c48abe58 | 195 | trapStateToColor.put(TrapMode.LTTV_TRAP_IDLE.getInName(), StateColor.GRAY);\r |
a2e53983 FC |
196 | trapStateToColor.put(TrapMode.LTTV_TRAP_BUSY.getInName(), StateColor.GOLD);\r |
197 | }\r | |
198 | \r | |
199 | private void fillSoftIRQStateToColor() {\r | |
200 | softIrqStateToColor.put(SoftIRQMode.LTTV_SOFT_IRQ_UNKNOWN.getInName(), StateColor.BLACK);\r | |
c48abe58 | 201 | softIrqStateToColor.put(SoftIRQMode.LTTV_SOFT_IRQ_IDLE.getInName(), StateColor.GRAY);\r |
a2e53983 FC |
202 | softIrqStateToColor.put(SoftIRQMode.LTTV_SOFT_IRQ_PENDING.getInName(), StateColor.PINK1);\r |
203 | softIrqStateToColor.put(SoftIRQMode.LTTV_SOFT_IRQ_BUSY.getInName(), StateColor.PURPLE1);\r | |
204 | }\r | |
205 | \r | |
206 | private void fillBdevStateToColor() {\r | |
207 | softIrqStateToColor.put(BdevMode.LTTV_BDEV_UNKNOWN.getInName(), StateColor.BLACK);\r | |
c48abe58 | 208 | softIrqStateToColor.put(BdevMode.LTTV_BDEV_IDLE.getInName(), StateColor.GRAY);\r |
a2e53983 FC |
209 | softIrqStateToColor.put(BdevMode.LTTV_BDEV_BUSY_READING.getInName(), StateColor.DARK_BLUE);\r |
210 | softIrqStateToColor.put(BdevMode.LTTV_BDEV_BUSY_WRITING.getInName(), StateColor.RED);\r | |
211 | }\r | |
212 | \r | |
213 | private void fillProcessStateToColor() {\r | |
214 | // Process Status\r | |
215 | procStateToColor.put(ProcessStatus.LTTV_STATE_UNNAMED.getInName(), StateColor.GRAY);\r | |
216 | procStateToColor.put(ProcessStatus.LTTV_STATE_DEAD.getInName(), StateColor.BLACK);\r | |
217 | procStateToColor.put(ProcessStatus.LTTV_STATE_WAIT_FORK.getInName(), StateColor.DARK_GREEN);\r | |
218 | procStateToColor.put(ProcessStatus.LTTV_STATE_WAIT_CPU.getInName(), StateColor.DARK_YELLOW);\r | |
219 | procStateToColor.put(ProcessStatus.LTTV_STATE_EXIT.getInName(), StateColor.MAGENTA3);\r | |
220 | procStateToColor.put(ProcessStatus.LTTV_STATE_ZOMBIE.getInName(), StateColor.PURPLE1);\r | |
221 | procStateToColor.put(ProcessStatus.LTTV_STATE_WAIT.getInName(), StateColor.RED);\r | |
222 | \r | |
223 | // Execution Mode\r | |
224 | procStateToColor.put(ExecutionMode.LTTV_STATE_MODE_UNKNOWN.getInName(), StateColor.BLACK);\r | |
225 | procStateToColor.put(ExecutionMode.LTTV_STATE_USER_MODE.getInName(), StateColor.GREEN);\r | |
226 | procStateToColor.put(ExecutionMode.LTTV_STATE_SYSCALL.getInName(), StateColor.DARK_BLUE);\r | |
227 | procStateToColor.put(ExecutionMode.LTTV_STATE_TRAP.getInName(), StateColor.GOLD);\r | |
228 | procStateToColor.put(ExecutionMode.LTTV_STATE_IRQ.getInName(), StateColor.ORANGE);\r | |
229 | procStateToColor.put(ExecutionMode.LTTV_STATE_SOFT_IRQ.getInName(), StateColor.PINK1);\r | |
230 | }\r | |
c48abe58 FC |
231 | \r |
232 | protected String findObject(StateColor Value, Map<String, StateColor> map) {\r | |
233 | Set<String> keys = map.keySet();\r | |
234 | for (String key : keys) {\r | |
235 | if (map.get(key).equals(Value)) {\r | |
236 | return key;\r | |
237 | }\r | |
238 | }\r | |
e8d771d5 | 239 | return "Not Found"; //$NON-NLS-1$\r |
c48abe58 | 240 | }\r |
6e512b93 | 241 | }\r |