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
.tmf
.core
.exceptions
.AttributeNotFoundException
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.ITmfStateValue
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.Resolution
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
35 import org
.eclipse
.swt
.graphics
.RGB
;
38 * Presentation provider for the Resource view, based on the generic TMF
39 * presentation provider.
41 * @author Patrick Tasse
43 public class ResourcesPresentationProvider
extends TimeGraphPresentationProvider
{
46 UNKNOWN (new RGB(100, 100, 100)),
47 IDLE (new RGB(200, 200, 200)),
48 USERMODE (new RGB(0, 200, 0)),
49 SYSCALL (new RGB(0, 0, 200)),
50 IRQ (new RGB(200, 100, 100)),
51 SOFT_IRQ (new RGB(200, 150, 100)),
52 IRQ_ACTIVE (new RGB(200, 100, 100)),
53 SOFT_IRQ_RAISED (new RGB(200, 200, 0)),
54 SOFT_IRQ_ACTIVE (new RGB(200, 150, 100));
58 private State (RGB rgb
) {
64 public String
getStateTypeName() {
65 return Messages
.ResourcesView_stateTypeName
;
69 public StateItem
[] getStateTable() {
70 StateItem
[] stateTable
= new StateItem
[State
.values().length
];
71 for (int i
= 0; i
< stateTable
.length
; i
++) {
72 State state
= State
.values()[i
];
73 stateTable
[i
] = new StateItem(state
.rgb
, state
.toString());
79 public int getStateTableIndex(ITimeEvent event
) {
80 if (event
instanceof ResourcesEvent
) {
81 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
82 if (resourcesEvent
.getType() == Type
.CPU
) {
83 int status
= resourcesEvent
.getValue();
84 if (status
== StateValues
.CPU_STATUS_IDLE
) {
85 return State
.IDLE
.ordinal();
86 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
) {
87 return State
.USERMODE
.ordinal();
88 } else if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
89 return State
.SYSCALL
.ordinal();
90 } else if (status
== StateValues
.CPU_STATUS_IRQ
) {
91 return State
.IRQ
.ordinal();
92 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
93 return State
.SOFT_IRQ
.ordinal();
95 } else if (resourcesEvent
.getType() == Type
.IRQ
) {
96 return State
.IRQ_ACTIVE
.ordinal();
97 } else if (resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
98 int cpu
= resourcesEvent
.getValue();
99 if (cpu
== StateValues
.SOFT_IRQ_RAISED
) {
100 return State
.SOFT_IRQ_RAISED
.ordinal();
102 return State
.SOFT_IRQ_ACTIVE
.ordinal();
107 return State
.UNKNOWN
.ordinal();
111 public String
getEventName(ITimeEvent event
) {
112 if (event
instanceof ResourcesEvent
) {
113 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
114 if (resourcesEvent
.getType() == Type
.CPU
) {
115 int status
= resourcesEvent
.getValue();
116 if (status
== StateValues
.CPU_STATUS_IDLE
) {
117 return State
.IDLE
.toString();
118 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
) {
119 return State
.USERMODE
.toString();
120 } else if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
121 return State
.SYSCALL
.toString();
122 } else if (status
== StateValues
.CPU_STATUS_IRQ
) {
123 return State
.IRQ
.toString();
124 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
125 return State
.SOFT_IRQ
.toString();
127 } else if (resourcesEvent
.getType() == Type
.IRQ
) {
128 return State
.IRQ_ACTIVE
.toString();
129 } else if (resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
130 int cpu
= resourcesEvent
.getValue();
131 if (cpu
== StateValues
.SOFT_IRQ_RAISED
) {
132 return State
.SOFT_IRQ_RAISED
.toString();
134 return State
.SOFT_IRQ_ACTIVE
.toString();
139 return State
.UNKNOWN
.toString();
143 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
, long hoverTime
) {
145 Map
<String
, String
> retMap
= new LinkedHashMap
<String
, String
>();
146 if (event
instanceof ResourcesEvent
) {
148 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
150 // Check for IRQ or Soft_IRQ type
151 if (resourcesEvent
.getType().equals(Type
.IRQ
) || resourcesEvent
.getType().equals(Type
.SOFT_IRQ
)) {
153 // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display
154 int cpu
= resourcesEvent
.getValue();
156 retMap
.put(Messages
.ResourcesView_attributeCpuName
, String
.valueOf(cpu
));
160 // Check for type CPU
161 if (resourcesEvent
.getType().equals(Type
.CPU
)) {
162 int status
= resourcesEvent
.getValue();
164 if (status
== StateValues
.CPU_STATUS_IRQ
) {
165 // In IRQ state get the IRQ that caused the interruption
166 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
167 ITmfStateSystem ssq
= entry
.getTrace().getStateSystem();
168 int cpu
= entry
.getId();
170 ITmfStateSystem ss
= entry
.getTrace().getStateSystem();
172 List
<ITmfStateInterval
> fullState
= ss
.queryFullState(event
.getTime());
173 List
<Integer
> irqQuarks
= ss
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
175 for (int irqQuark
: irqQuarks
) {
176 if (fullState
.get(irqQuark
).getStateValue().unboxInt() == cpu
) {
177 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), irqQuark
);
178 if (!value
.getStateValue().isNull()) {
179 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
180 retMap
.put(Messages
.ResourcesView_attributeIrqName
, String
.valueOf(irq
));
185 } catch (AttributeNotFoundException e
) {
187 } catch (TimeRangeException e
) {
189 } catch (StateValueTypeException e
) {
192 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
193 // In SOFT_IRQ state get the SOFT_IRQ that caused the interruption
194 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
195 ITmfStateSystem ssq
= entry
.getTrace().getStateSystem();
196 int cpu
= entry
.getId();
198 ITmfStateSystem ss
= entry
.getTrace().getStateSystem();
200 List
<ITmfStateInterval
> fullState
= ss
.queryFullState(event
.getTime());
201 List
<Integer
> softIrqQuarks
= ss
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
203 for (int softIrqQuark
: softIrqQuarks
) {
204 if (fullState
.get(softIrqQuark
).getStateValue().unboxInt() == cpu
) {
205 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), softIrqQuark
);
206 if (!value
.getStateValue().isNull()) {
207 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
208 retMap
.put(Messages
.ResourcesView_attributeSoftIrqName
, String
.valueOf(softIrq
));
213 } catch (AttributeNotFoundException e
) {
215 } catch (TimeRangeException e
) {
217 } catch (StateValueTypeException e
) {
220 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
|| status
== StateValues
.CPU_STATUS_RUN_SYSCALL
){
221 // In running state get the current tid
222 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
223 ITmfStateSystem ssq
= entry
.getTrace().getStateSystem();
226 retMap
.put(Messages
.ResourcesView_attributeHoverTime
, Utils
.formatTime(hoverTime
, TimeFormat
.ABSOLUTE
, Resolution
.NANOSEC
));
227 int cpuQuark
= entry
.getQuark();
228 int currentThreadQuark
= ssq
.getQuarkRelative(cpuQuark
, Attributes
.CURRENT_THREAD
);
229 ITmfStateInterval interval
= ssq
.querySingleState(hoverTime
, currentThreadQuark
);
230 if (!interval
.getStateValue().isNull()) {
231 ITmfStateValue value
= interval
.getStateValue();
232 int currentThreadId
= value
.unboxInt();
233 retMap
.put(Messages
.ResourcesView_attributeTidName
, Integer
.toString(currentThreadId
));
234 int execNameQuark
= ssq
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(currentThreadId
), Attributes
.EXEC_NAME
);
235 interval
= ssq
.querySingleState(hoverTime
, execNameQuark
);
236 if (!interval
.getStateValue().isNull()) {
237 value
= interval
.getStateValue();
238 retMap
.put(Messages
.ResourcesView_attributeProcessName
, value
.unboxStr());
240 if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
241 int syscallQuark
= ssq
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(currentThreadId
), Attributes
.SYSTEM_CALL
);
242 interval
= ssq
.querySingleState(hoverTime
, syscallQuark
);
243 if (!interval
.getStateValue().isNull()) {
244 value
= interval
.getStateValue();
245 retMap
.put(Messages
.ResourcesView_attributeSyscallName
, value
.unboxStr());
249 } catch (AttributeNotFoundException e
) {
251 } catch (TimeRangeException e
) {
253 } catch (StateValueTypeException e
) {