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
.ui
.Messages
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.resources
.ResourcesEntry
.Type
;
21 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.trace
.Attributes
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.IStateSystemQuerier
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
30 import org
.eclipse
.swt
.graphics
.RGB
;
32 public class ResourcesPresentationProvider
extends TimeGraphPresentationProvider
{
35 UNKNOWN (new RGB(100, 100, 100)),
36 IDLE (new RGB(200, 200, 200)),
37 BUSY (new RGB(0, 200, 0)),
38 INTERRUPTED (new RGB(200, 100, 100)),
39 RAISED (new RGB(200, 200, 0)),
40 ACTIVE (new RGB(200, 150, 100));
44 private State (RGB rgb
) {
50 public String
getStateTypeName() {
51 return Messages
.ResourcesView_stateTypeName
;
55 public StateItem
[] getStateTable() {
56 StateItem
[] stateTable
= new StateItem
[State
.values().length
];
57 for (int i
= 0; i
< stateTable
.length
; i
++) {
58 State state
= State
.values()[i
];
59 stateTable
[i
] = new StateItem(state
.rgb
, state
.toString());
65 public int getStateTableIndex(ITimeEvent event
) {
66 if (event
instanceof ResourcesEvent
) {
67 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
68 if (resourcesEvent
.getType() == Type
.CPU
) {
69 int status
= resourcesEvent
.getValue();
70 if (status
== Attributes
.CPU_STATUS_IDLE
) {
71 return State
.IDLE
.ordinal();
72 } else if (status
== Attributes
.CPU_STATUS_BUSY
) {
73 return State
.BUSY
.ordinal();
74 } else if (status
== Attributes
.CPU_STATUS_INTERRUPTED
) {
75 return State
.INTERRUPTED
.ordinal();
77 } else if (resourcesEvent
.getType() == Type
.IRQ
|| resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
78 int cpu
= resourcesEvent
.getValue();
79 if (cpu
== Attributes
.SOFT_IRQ_RAISED
) {
80 return State
.RAISED
.ordinal();
82 return State
.ACTIVE
.ordinal();
87 return State
.UNKNOWN
.ordinal();
91 public String
getEventName(ITimeEvent event
) {
92 if (event
instanceof ResourcesEvent
) {
93 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
94 if (resourcesEvent
.getType() == Type
.CPU
) {
95 int status
= resourcesEvent
.getValue();
96 if (status
== Attributes
.CPU_STATUS_IDLE
) {
97 return State
.IDLE
.toString();
98 } else if (status
== Attributes
.CPU_STATUS_BUSY
) {
99 return State
.BUSY
.toString();
100 } else if (status
== Attributes
.CPU_STATUS_INTERRUPTED
) {
101 return State
.INTERRUPTED
.toString();
103 } else if (resourcesEvent
.getType() == Type
.IRQ
|| resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
104 int cpu
= resourcesEvent
.getValue();
105 if (cpu
== Attributes
.SOFT_IRQ_RAISED
) {
106 return State
.RAISED
.toString();
108 return State
.ACTIVE
.toString();
113 return State
.UNKNOWN
.toString();
117 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
119 Map
<String
, String
> retMap
= new HashMap
<String
, String
>();
120 if (event
instanceof ResourcesEvent
) {
122 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
124 // Check for IRQ or Soft_IRQ type
125 if (resourcesEvent
.getType().equals(Type
.IRQ
) || resourcesEvent
.getType().equals(Type
.SOFT_IRQ
)) {
127 // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display
128 int cpu
= resourcesEvent
.getValue();
130 retMap
.put(Messages
.ResourcesView_attributeCpuName
, String
.valueOf(cpu
));
134 // Check for type CPU
135 if (resourcesEvent
.getType().equals(Type
.CPU
)) {
136 int status
= resourcesEvent
.getValue();
138 if (status
== Attributes
.CPU_STATUS_INTERRUPTED
) {
139 // In interrupted state get the IRQ or SOFT_IRQ that caused the interruption
140 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
141 IStateSystemQuerier ssq
= entry
.getTrace().getStateSystem();
142 int cpu
= entry
.getId();
144 IStateSystemQuerier ss
= entry
.getTrace().getStateSystem();
147 String attributeName
= null;
149 // First check for IRQ
150 List
<ITmfStateInterval
> fullState
= ss
.queryFullState(event
.getTime());
151 List
<Integer
> irqQuarks
= ss
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
153 for (int curQuark
: irqQuarks
) {
154 if (fullState
.get(curQuark
).getStateValue().unboxInt() == cpu
) {
155 resultQuark
= curQuark
;
156 attributeName
= Messages
.ResourcesView_attributeIrqName
;
161 // If not found check for SOFT_IRQ
162 if (attributeName
== null) {
163 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
164 for (int curQuark
: softIrqQuarks
) {
165 if (fullState
.get(curQuark
).getStateValue().unboxInt() == cpu
) {
166 resultQuark
= curQuark
;
167 attributeName
= Messages
.ResourcesView_attributeSoftIrqName
;
173 if (attributeName
!= null) {
174 // A IRQ or SOFT_IRQ was found
175 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), resultQuark
);
176 if (!value
.getStateValue().isNull()) {
177 int irq
= Integer
.parseInt(ssq
.getAttributeName(resultQuark
));
178 retMap
.put(attributeName
, String
.valueOf(irq
));
181 } catch (AttributeNotFoundException e
) {
183 } catch (TimeRangeException e
) {
185 } catch (StateValueTypeException e
) {