1 /*******************************************************************************
2 * Copyright (c) 2012 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
;
15 import java
.util
.LinkedHashMap
;
16 import java
.util
.List
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.Attributes
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.StateValues
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.Messages
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
.ResourcesEntry
.Type
;
23 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.trace
.CtfKernelTrace
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateSystemDisposedException
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.ITmfStateValue
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.Resolution
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
37 import org
.eclipse
.swt
.graphics
.RGB
;
40 * Presentation provider for the Resource view, based on the generic TMF
41 * presentation provider.
43 * @author Patrick Tasse
45 public class ResourcesPresentationProvider
extends TimeGraphPresentationProvider
{
48 UNKNOWN (new RGB(100, 100, 100)),
49 IDLE (new RGB(200, 200, 200)),
50 USERMODE (new RGB(0, 200, 0)),
51 SYSCALL (new RGB(0, 0, 200)),
52 IRQ (new RGB(200, 100, 100)),
53 SOFT_IRQ (new RGB(200, 150, 100)),
54 IRQ_ACTIVE (new RGB(200, 100, 100)),
55 SOFT_IRQ_RAISED (new RGB(200, 200, 0)),
56 SOFT_IRQ_ACTIVE (new RGB(200, 150, 100));
60 private State (RGB rgb
) {
66 public String
getStateTypeName() {
67 return Messages
.ResourcesView_stateTypeName
;
71 public StateItem
[] getStateTable() {
72 StateItem
[] stateTable
= new StateItem
[State
.values().length
];
73 for (int i
= 0; i
< stateTable
.length
; i
++) {
74 State state
= State
.values()[i
];
75 stateTable
[i
] = new StateItem(state
.rgb
, state
.toString());
81 public int getStateTableIndex(ITimeEvent event
) {
82 if (event
instanceof ResourcesEvent
) {
83 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
84 if (resourcesEvent
.getType() == Type
.CPU
) {
85 int status
= resourcesEvent
.getValue();
86 if (status
== StateValues
.CPU_STATUS_IDLE
) {
87 return State
.IDLE
.ordinal();
88 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
) {
89 return State
.USERMODE
.ordinal();
90 } else if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
91 return State
.SYSCALL
.ordinal();
92 } else if (status
== StateValues
.CPU_STATUS_IRQ
) {
93 return State
.IRQ
.ordinal();
94 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
95 return State
.SOFT_IRQ
.ordinal();
97 } else if (resourcesEvent
.getType() == Type
.IRQ
) {
98 return State
.IRQ_ACTIVE
.ordinal();
99 } else if (resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
100 int cpu
= resourcesEvent
.getValue();
101 if (cpu
== StateValues
.SOFT_IRQ_RAISED
) {
102 return State
.SOFT_IRQ_RAISED
.ordinal();
104 return State
.SOFT_IRQ_ACTIVE
.ordinal();
109 return State
.UNKNOWN
.ordinal();
113 public String
getEventName(ITimeEvent event
) {
114 if (event
instanceof ResourcesEvent
) {
115 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
116 if (resourcesEvent
.getType() == Type
.CPU
) {
117 int status
= resourcesEvent
.getValue();
118 if (status
== StateValues
.CPU_STATUS_IDLE
) {
119 return State
.IDLE
.toString();
120 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
) {
121 return State
.USERMODE
.toString();
122 } else if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
123 return State
.SYSCALL
.toString();
124 } else if (status
== StateValues
.CPU_STATUS_IRQ
) {
125 return State
.IRQ
.toString();
126 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
127 return State
.SOFT_IRQ
.toString();
129 } else if (resourcesEvent
.getType() == Type
.IRQ
) {
130 return State
.IRQ_ACTIVE
.toString();
131 } else if (resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
132 int cpu
= resourcesEvent
.getValue();
133 if (cpu
== StateValues
.SOFT_IRQ_RAISED
) {
134 return State
.SOFT_IRQ_RAISED
.toString();
136 return State
.SOFT_IRQ_ACTIVE
.toString();
141 return State
.UNKNOWN
.toString();
145 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
, long hoverTime
) {
147 Map
<String
, String
> retMap
= new LinkedHashMap
<String
, String
>();
148 if (event
instanceof ResourcesEvent
) {
150 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
152 // Check for IRQ or Soft_IRQ type
153 if (resourcesEvent
.getType().equals(Type
.IRQ
) || resourcesEvent
.getType().equals(Type
.SOFT_IRQ
)) {
155 // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display
156 int cpu
= resourcesEvent
.getValue();
158 retMap
.put(Messages
.ResourcesView_attributeCpuName
, String
.valueOf(cpu
));
162 // Check for type CPU
163 if (resourcesEvent
.getType().equals(Type
.CPU
)) {
164 int status
= resourcesEvent
.getValue();
166 if (status
== StateValues
.CPU_STATUS_IRQ
) {
167 // In IRQ state get the IRQ that caused the interruption
168 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
169 ITmfStateSystem ss
= entry
.getTrace().getStateSystem(CtfKernelTrace
.STATE_ID
);
170 int cpu
= entry
.getId();
173 List
<ITmfStateInterval
> fullState
= ss
.queryFullState(event
.getTime());
174 List
<Integer
> irqQuarks
= ss
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
176 for (int irqQuark
: irqQuarks
) {
177 if (fullState
.get(irqQuark
).getStateValue().unboxInt() == cpu
) {
178 ITmfStateInterval value
= ss
.querySingleState(event
.getTime(), irqQuark
);
179 if (!value
.getStateValue().isNull()) {
180 int irq
= Integer
.parseInt(ss
.getAttributeName(irqQuark
));
181 retMap
.put(Messages
.ResourcesView_attributeIrqName
, String
.valueOf(irq
));
186 } catch (AttributeNotFoundException e
) {
188 } catch (TimeRangeException e
) {
190 } catch (StateValueTypeException e
) {
192 } catch (StateSystemDisposedException e
) {
195 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
196 // In SOFT_IRQ state get the SOFT_IRQ that caused the interruption
197 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
198 ITmfStateSystem ss
= entry
.getTrace().getStateSystem(CtfKernelTrace
.STATE_ID
);
199 int cpu
= entry
.getId();
202 List
<ITmfStateInterval
> fullState
= ss
.queryFullState(event
.getTime());
203 List
<Integer
> softIrqQuarks
= ss
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
205 for (int softIrqQuark
: softIrqQuarks
) {
206 if (fullState
.get(softIrqQuark
).getStateValue().unboxInt() == cpu
) {
207 ITmfStateInterval value
= ss
.querySingleState(event
.getTime(), softIrqQuark
);
208 if (!value
.getStateValue().isNull()) {
209 int softIrq
= Integer
.parseInt(ss
.getAttributeName(softIrqQuark
));
210 retMap
.put(Messages
.ResourcesView_attributeSoftIrqName
, String
.valueOf(softIrq
));
215 } catch (AttributeNotFoundException e
) {
217 } catch (TimeRangeException e
) {
219 } catch (StateValueTypeException e
) {
221 } catch (StateSystemDisposedException e
) {
224 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
|| status
== StateValues
.CPU_STATUS_RUN_SYSCALL
){
225 // In running state get the current tid
226 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
227 ITmfStateSystem ssq
= entry
.getTrace().getStateSystem(CtfKernelTrace
.STATE_ID
);
230 retMap
.put(Messages
.ResourcesView_attributeHoverTime
, Utils
.formatTime(hoverTime
, TimeFormat
.ABSOLUTE
, Resolution
.NANOSEC
));
231 int cpuQuark
= entry
.getQuark();
232 int currentThreadQuark
= ssq
.getQuarkRelative(cpuQuark
, Attributes
.CURRENT_THREAD
);
233 ITmfStateInterval interval
= ssq
.querySingleState(hoverTime
, currentThreadQuark
);
234 if (!interval
.getStateValue().isNull()) {
235 ITmfStateValue value
= interval
.getStateValue();
236 int currentThreadId
= value
.unboxInt();
237 retMap
.put(Messages
.ResourcesView_attributeTidName
, Integer
.toString(currentThreadId
));
238 int execNameQuark
= ssq
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(currentThreadId
), Attributes
.EXEC_NAME
);
239 interval
= ssq
.querySingleState(hoverTime
, execNameQuark
);
240 if (!interval
.getStateValue().isNull()) {
241 value
= interval
.getStateValue();
242 retMap
.put(Messages
.ResourcesView_attributeProcessName
, value
.unboxStr());
244 if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
245 int syscallQuark
= ssq
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(currentThreadId
), Attributes
.SYSTEM_CALL
);
246 interval
= ssq
.querySingleState(hoverTime
, syscallQuark
);
247 if (!interval
.getStateValue().isNull()) {
248 value
= interval
.getStateValue();
249 retMap
.put(Messages
.ResourcesView_attributeSyscallName
, value
.unboxStr());
253 } catch (AttributeNotFoundException e
) {
255 } catch (TimeRangeException e
) {
257 } catch (StateValueTypeException e
) {
259 } catch (StateSystemDisposedException e
) {