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
.StateSystemDisposedException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.ITmfStateValue
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.Resolution
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
.TimeFormat
;
36 import org
.eclipse
.swt
.graphics
.RGB
;
39 * Presentation provider for the Resource view, based on the generic TMF
40 * presentation provider.
42 * @author Patrick Tasse
44 public class ResourcesPresentationProvider
extends TimeGraphPresentationProvider
{
47 UNKNOWN (new RGB(100, 100, 100)),
48 IDLE (new RGB(200, 200, 200)),
49 USERMODE (new RGB(0, 200, 0)),
50 SYSCALL (new RGB(0, 0, 200)),
51 IRQ (new RGB(200, 100, 100)),
52 SOFT_IRQ (new RGB(200, 150, 100)),
53 IRQ_ACTIVE (new RGB(200, 100, 100)),
54 SOFT_IRQ_RAISED (new RGB(200, 200, 0)),
55 SOFT_IRQ_ACTIVE (new RGB(200, 150, 100));
59 private State (RGB rgb
) {
65 public String
getStateTypeName() {
66 return Messages
.ResourcesView_stateTypeName
;
70 public StateItem
[] getStateTable() {
71 StateItem
[] stateTable
= new StateItem
[State
.values().length
];
72 for (int i
= 0; i
< stateTable
.length
; i
++) {
73 State state
= State
.values()[i
];
74 stateTable
[i
] = new StateItem(state
.rgb
, state
.toString());
80 public int getStateTableIndex(ITimeEvent event
) {
81 if (event
instanceof ResourcesEvent
) {
82 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
83 if (resourcesEvent
.getType() == Type
.CPU
) {
84 int status
= resourcesEvent
.getValue();
85 if (status
== StateValues
.CPU_STATUS_IDLE
) {
86 return State
.IDLE
.ordinal();
87 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
) {
88 return State
.USERMODE
.ordinal();
89 } else if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
90 return State
.SYSCALL
.ordinal();
91 } else if (status
== StateValues
.CPU_STATUS_IRQ
) {
92 return State
.IRQ
.ordinal();
93 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
94 return State
.SOFT_IRQ
.ordinal();
96 } else if (resourcesEvent
.getType() == Type
.IRQ
) {
97 return State
.IRQ_ACTIVE
.ordinal();
98 } else if (resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
99 int cpu
= resourcesEvent
.getValue();
100 if (cpu
== StateValues
.SOFT_IRQ_RAISED
) {
101 return State
.SOFT_IRQ_RAISED
.ordinal();
103 return State
.SOFT_IRQ_ACTIVE
.ordinal();
108 return State
.UNKNOWN
.ordinal();
112 public String
getEventName(ITimeEvent event
) {
113 if (event
instanceof ResourcesEvent
) {
114 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
115 if (resourcesEvent
.getType() == Type
.CPU
) {
116 int status
= resourcesEvent
.getValue();
117 if (status
== StateValues
.CPU_STATUS_IDLE
) {
118 return State
.IDLE
.toString();
119 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
) {
120 return State
.USERMODE
.toString();
121 } else if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
122 return State
.SYSCALL
.toString();
123 } else if (status
== StateValues
.CPU_STATUS_IRQ
) {
124 return State
.IRQ
.toString();
125 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
126 return State
.SOFT_IRQ
.toString();
128 } else if (resourcesEvent
.getType() == Type
.IRQ
) {
129 return State
.IRQ_ACTIVE
.toString();
130 } else if (resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
131 int cpu
= resourcesEvent
.getValue();
132 if (cpu
== StateValues
.SOFT_IRQ_RAISED
) {
133 return State
.SOFT_IRQ_RAISED
.toString();
135 return State
.SOFT_IRQ_ACTIVE
.toString();
140 return State
.UNKNOWN
.toString();
144 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
, long hoverTime
) {
146 Map
<String
, String
> retMap
= new LinkedHashMap
<String
, String
>();
147 if (event
instanceof ResourcesEvent
) {
149 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
151 // Check for IRQ or Soft_IRQ type
152 if (resourcesEvent
.getType().equals(Type
.IRQ
) || resourcesEvent
.getType().equals(Type
.SOFT_IRQ
)) {
154 // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display
155 int cpu
= resourcesEvent
.getValue();
157 retMap
.put(Messages
.ResourcesView_attributeCpuName
, String
.valueOf(cpu
));
161 // Check for type CPU
162 if (resourcesEvent
.getType().equals(Type
.CPU
)) {
163 int status
= resourcesEvent
.getValue();
165 if (status
== StateValues
.CPU_STATUS_IRQ
) {
166 // In IRQ state get the IRQ that caused the interruption
167 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
168 ITmfStateSystem ssq
= entry
.getTrace().getStateSystem();
169 int cpu
= entry
.getId();
171 ITmfStateSystem ss
= entry
.getTrace().getStateSystem();
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
= ssq
.querySingleState(event
.getTime(), irqQuark
);
179 if (!value
.getStateValue().isNull()) {
180 int irq
= Integer
.parseInt(ssq
.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 ssq
= entry
.getTrace().getStateSystem();
199 int cpu
= entry
.getId();
201 ITmfStateSystem ss
= entry
.getTrace().getStateSystem();
203 List
<ITmfStateInterval
> fullState
= ss
.queryFullState(event
.getTime());
204 List
<Integer
> softIrqQuarks
= ss
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
206 for (int softIrqQuark
: softIrqQuarks
) {
207 if (fullState
.get(softIrqQuark
).getStateValue().unboxInt() == cpu
) {
208 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), softIrqQuark
);
209 if (!value
.getStateValue().isNull()) {
210 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
211 retMap
.put(Messages
.ResourcesView_attributeSoftIrqName
, String
.valueOf(softIrq
));
216 } catch (AttributeNotFoundException e
) {
218 } catch (TimeRangeException e
) {
220 } catch (StateValueTypeException e
) {
222 } catch (StateSystemDisposedException e
) {
225 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
|| status
== StateValues
.CPU_STATUS_RUN_SYSCALL
){
226 // In running state get the current tid
227 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
228 ITmfStateSystem ssq
= entry
.getTrace().getStateSystem();
231 retMap
.put(Messages
.ResourcesView_attributeHoverTime
, Utils
.formatTime(hoverTime
, TimeFormat
.ABSOLUTE
, Resolution
.NANOSEC
));
232 int cpuQuark
= entry
.getQuark();
233 int currentThreadQuark
= ssq
.getQuarkRelative(cpuQuark
, Attributes
.CURRENT_THREAD
);
234 ITmfStateInterval interval
= ssq
.querySingleState(hoverTime
, currentThreadQuark
);
235 if (!interval
.getStateValue().isNull()) {
236 ITmfStateValue value
= interval
.getStateValue();
237 int currentThreadId
= value
.unboxInt();
238 retMap
.put(Messages
.ResourcesView_attributeTidName
, Integer
.toString(currentThreadId
));
239 int execNameQuark
= ssq
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(currentThreadId
), Attributes
.EXEC_NAME
);
240 interval
= ssq
.querySingleState(hoverTime
, execNameQuark
);
241 if (!interval
.getStateValue().isNull()) {
242 value
= interval
.getStateValue();
243 retMap
.put(Messages
.ResourcesView_attributeProcessName
, value
.unboxStr());
245 if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
246 int syscallQuark
= ssq
.getQuarkAbsolute(Attributes
.THREADS
, Integer
.toString(currentThreadId
), Attributes
.SYSTEM_CALL
);
247 interval
= ssq
.querySingleState(hoverTime
, syscallQuark
);
248 if (!interval
.getStateValue().isNull()) {
249 value
= interval
.getStateValue();
250 retMap
.put(Messages
.ResourcesView_attributeSyscallName
, value
.unboxStr());
254 } catch (AttributeNotFoundException e
) {
256 } catch (TimeRangeException e
) {
258 } catch (StateValueTypeException e
) {
260 } catch (StateSystemDisposedException e
) {