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