1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
;
14 import java
.util
.HashMap
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.BdevMode
;
19 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.CpuMode
;
20 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ExecutionMode
;
21 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.IRQMode
;
22 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ProcessStatus
;
23 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.SoftIRQMode
;
24 import org
.eclipse
.linuxtools
.lttng
.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
;
30 public class TimeRangeViewerProvider
extends TmfTimeAnalysisProvider
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
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);
43 private final ParamsUpdater fviewParameters
;
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
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
;
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
65 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider#getEventColor(org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent)
68 public StateColor
getEventColor(ITimeEvent event
) {
69 StateColor retColor
= null;
71 if (event
instanceof TimeRangeEvent
) {
72 TimeRangeEvent devent
= (TimeRangeEvent
) event
;
73 String stateMode
= devent
.getStateMode();
74 switch (devent
.getEventType()) {
76 retColor
= procStateToColor
.get(stateMode
);
79 retColor
= bdevStateToColor
.get(stateMode
);
82 retColor
= irqStateToColor
.get(stateMode
);
85 retColor
= softIrqStateToColor
.get(stateMode
);
88 retColor
= cpuStateToColor
.get(stateMode
);
91 retColor
= trapStateToColor
.get(stateMode
);
96 if (retColor
== null) {
97 return StateColor
.MAGENTA3
;
103 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider#getStateName(org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider.StateColor)
106 public String
getStateName(StateColor color
) {
107 // Override to multiple instances of the widget, the same color can have
109 return "Not mapped"; //$NON-NLS-1$
113 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider#getEventHoverToolTipInfo(org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent)
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
120 if (revent
instanceof TimeRangeComponent
) {
121 ITimeRangeComponent parent
= ((TimeRangeComponent
) revent
).getEventParent();
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$
132 long eventEnd
= revent
.getTime() + revent
.getDuration();
133 if (eventEnd
> fviewParameters
.getEndTime()) {
134 toolTipEventMsgs
.put(Messages
.TimeRangeViewerProvider_EndTime
, Messages
.TimeRangeViewerProvider_UndefinedEndTime
+ extraInfo
);
137 if (parent
!= null && parent
instanceof TimeRangeEventProcess
) {
138 TimeRangeEventProcess localProcess
= (TimeRangeEventProcess
) parent
;
139 toolTipEventMsgs
.put(Messages
.TimeRangeViewerProvider_ProcessType
, localProcess
.getProcessType());
143 return toolTipEventMsgs
;
147 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider#getEventName(org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITimeEvent, boolean, boolean)
150 public String
getEventName(ITimeEvent event
, boolean upper
, boolean extInfo
) {
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();
160 return "Unknown"; //$NON-NLS-1$
166 * @see org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeAnalysisProvider#getTraceClassName(org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.model.ITmfTimeAnalysisEntry)
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();
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
);
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
);
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
);
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
);
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
);
213 private void fillProcessStateToColor() {
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
);
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
);
232 protected String
findObject(StateColor Value
, Map
<String
, StateColor
> map
) {
233 Set
<String
> keys
= map
.keySet();
234 for (String key
: keys
) {
235 if (map
.get(key
).equals(Value
)) {
239 return "Not Found"; //$NON-NLS-1$