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
.HashMap
;
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
.IStateSystemQuerier
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
31 import org
.eclipse
.swt
.graphics
.RGB
;
34 * Presentation provider for the Resource view, based on the generic TMF
35 * presentation provider.
37 * @author Patrick Tasse
39 public class ResourcesPresentationProvider
extends TimeGraphPresentationProvider
{
42 UNKNOWN (new RGB(100, 100, 100)),
43 IDLE (new RGB(200, 200, 200)),
44 USERMODE (new RGB(0, 200, 0)),
45 SYSCALL (new RGB(0, 0, 200)),
46 IRQ (new RGB(200, 100, 100)),
47 SOFT_IRQ (new RGB(200, 150, 100)),
48 IRQ_ACTIVE (new RGB(200, 100, 100)),
49 SOFT_IRQ_RAISED (new RGB(200, 200, 0)),
50 SOFT_IRQ_ACTIVE (new RGB(200, 150, 100));
54 private State (RGB rgb
) {
60 public String
getStateTypeName() {
61 return Messages
.ResourcesView_stateTypeName
;
65 public StateItem
[] getStateTable() {
66 StateItem
[] stateTable
= new StateItem
[State
.values().length
];
67 for (int i
= 0; i
< stateTable
.length
; i
++) {
68 State state
= State
.values()[i
];
69 stateTable
[i
] = new StateItem(state
.rgb
, state
.toString());
75 public int getStateTableIndex(ITimeEvent event
) {
76 if (event
instanceof ResourcesEvent
) {
77 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
78 if (resourcesEvent
.getType() == Type
.CPU
) {
79 int status
= resourcesEvent
.getValue();
80 if (status
== StateValues
.CPU_STATUS_IDLE
) {
81 return State
.IDLE
.ordinal();
82 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
) {
83 return State
.USERMODE
.ordinal();
84 } else if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
85 return State
.SYSCALL
.ordinal();
86 } else if (status
== StateValues
.CPU_STATUS_IRQ
) {
87 return State
.IRQ
.ordinal();
88 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
89 return State
.SOFT_IRQ
.ordinal();
91 } else if (resourcesEvent
.getType() == Type
.IRQ
) {
92 return State
.IRQ_ACTIVE
.ordinal();
93 } else if (resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
94 int cpu
= resourcesEvent
.getValue();
95 if (cpu
== StateValues
.SOFT_IRQ_RAISED
) {
96 return State
.SOFT_IRQ_RAISED
.ordinal();
98 return State
.SOFT_IRQ_ACTIVE
.ordinal();
103 return State
.UNKNOWN
.ordinal();
107 public String
getEventName(ITimeEvent event
) {
108 if (event
instanceof ResourcesEvent
) {
109 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
110 if (resourcesEvent
.getType() == Type
.CPU
) {
111 int status
= resourcesEvent
.getValue();
112 if (status
== StateValues
.CPU_STATUS_IDLE
) {
113 return State
.IDLE
.toString();
114 } else if (status
== StateValues
.CPU_STATUS_RUN_USERMODE
) {
115 return State
.USERMODE
.toString();
116 } else if (status
== StateValues
.CPU_STATUS_RUN_SYSCALL
) {
117 return State
.SYSCALL
.toString();
118 } else if (status
== StateValues
.CPU_STATUS_IRQ
) {
119 return State
.IRQ
.toString();
120 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
121 return State
.SOFT_IRQ
.toString();
123 } else if (resourcesEvent
.getType() == Type
.IRQ
) {
124 return State
.IRQ_ACTIVE
.toString();
125 } else if (resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
126 int cpu
= resourcesEvent
.getValue();
127 if (cpu
== StateValues
.SOFT_IRQ_RAISED
) {
128 return State
.SOFT_IRQ_RAISED
.toString();
130 return State
.SOFT_IRQ_ACTIVE
.toString();
135 return State
.UNKNOWN
.toString();
139 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
141 Map
<String
, String
> retMap
= new HashMap
<String
, String
>();
142 if (event
instanceof ResourcesEvent
) {
144 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
146 // Check for IRQ or Soft_IRQ type
147 if (resourcesEvent
.getType().equals(Type
.IRQ
) || resourcesEvent
.getType().equals(Type
.SOFT_IRQ
)) {
149 // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display
150 int cpu
= resourcesEvent
.getValue();
152 retMap
.put(Messages
.ResourcesView_attributeCpuName
, String
.valueOf(cpu
));
156 // Check for type CPU
157 if (resourcesEvent
.getType().equals(Type
.CPU
)) {
158 int status
= resourcesEvent
.getValue();
160 if (status
== StateValues
.CPU_STATUS_IRQ
) {
161 // In IRQ state get the IRQ that caused the interruption
162 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
163 IStateSystemQuerier ssq
= entry
.getTrace().getStateSystem();
164 int cpu
= entry
.getId();
166 IStateSystemQuerier ss
= entry
.getTrace().getStateSystem();
168 List
<ITmfStateInterval
> fullState
= ss
.queryFullState(event
.getTime());
169 List
<Integer
> irqQuarks
= ss
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
171 for (int irqQuark
: irqQuarks
) {
172 if (fullState
.get(irqQuark
).getStateValue().unboxInt() == cpu
) {
173 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), irqQuark
);
174 if (!value
.getStateValue().isNull()) {
175 int irq
= Integer
.parseInt(ssq
.getAttributeName(irqQuark
));
176 retMap
.put(Messages
.ResourcesView_attributeIrqName
, String
.valueOf(irq
));
181 } catch (AttributeNotFoundException e
) {
183 } catch (TimeRangeException e
) {
185 } catch (StateValueTypeException e
) {
188 } else if (status
== StateValues
.CPU_STATUS_SOFTIRQ
) {
189 // In SOFT_IRQ state get the SOFT_IRQ that caused the interruption
190 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
191 IStateSystemQuerier ssq
= entry
.getTrace().getStateSystem();
192 int cpu
= entry
.getId();
194 IStateSystemQuerier ss
= entry
.getTrace().getStateSystem();
196 List
<ITmfStateInterval
> fullState
= ss
.queryFullState(event
.getTime());
197 List
<Integer
> softIrqQuarks
= ss
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
199 for (int softIrqQuark
: softIrqQuarks
) {
200 if (fullState
.get(softIrqQuark
).getStateValue().unboxInt() == cpu
) {
201 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), softIrqQuark
);
202 if (!value
.getStateValue().isNull()) {
203 int softIrq
= Integer
.parseInt(ssq
.getAttributeName(softIrqQuark
));
204 retMap
.put(Messages
.ResourcesView_attributeSoftIrqName
, String
.valueOf(softIrq
));
209 } catch (AttributeNotFoundException e
) {
211 } catch (TimeRangeException e
) {
213 } catch (StateValueTypeException e
) {