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
;
33 public class ResourcesPresentationProvider
extends TimeGraphPresentationProvider
{
36 UNKNOWN (new RGB(100, 100, 100)),
37 IDLE (new RGB(200, 200, 200)),
38 BUSY (new RGB(0, 200, 0)),
39 INTERRUPTED (new RGB(200, 100, 100)),
40 RAISED (new RGB(200, 200, 0)),
41 ACTIVE (new RGB(200, 150, 100));
45 private State (RGB rgb
) {
51 public String
getStateTypeName() {
52 return Messages
.ResourcesView_stateTypeName
;
56 public StateItem
[] getStateTable() {
57 StateItem
[] stateTable
= new StateItem
[State
.values().length
];
58 for (int i
= 0; i
< stateTable
.length
; i
++) {
59 State state
= State
.values()[i
];
60 stateTable
[i
] = new StateItem(state
.rgb
, state
.toString());
66 public int getStateTableIndex(ITimeEvent event
) {
67 if (event
instanceof ResourcesEvent
) {
68 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
69 if (resourcesEvent
.getType() == Type
.CPU
) {
70 int status
= resourcesEvent
.getValue();
71 if (status
== StateValues
.CPU_STATUS_IDLE
) {
72 return State
.IDLE
.ordinal();
73 } else if (status
== StateValues
.CPU_STATUS_BUSY
) {
74 return State
.BUSY
.ordinal();
75 } else if (status
== StateValues
.CPU_STATUS_INTERRUPTED
) {
76 return State
.INTERRUPTED
.ordinal();
78 } else if (resourcesEvent
.getType() == Type
.IRQ
|| resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
79 int cpu
= resourcesEvent
.getValue();
80 if (cpu
== StateValues
.SOFT_IRQ_RAISED
) {
81 return State
.RAISED
.ordinal();
83 return State
.ACTIVE
.ordinal();
88 return State
.UNKNOWN
.ordinal();
92 public String
getEventName(ITimeEvent event
) {
93 if (event
instanceof ResourcesEvent
) {
94 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
95 if (resourcesEvent
.getType() == Type
.CPU
) {
96 int status
= resourcesEvent
.getValue();
97 if (status
== StateValues
.CPU_STATUS_IDLE
) {
98 return State
.IDLE
.toString();
99 } else if (status
== StateValues
.CPU_STATUS_BUSY
) {
100 return State
.BUSY
.toString();
101 } else if (status
== StateValues
.CPU_STATUS_INTERRUPTED
) {
102 return State
.INTERRUPTED
.toString();
104 } else if (resourcesEvent
.getType() == Type
.IRQ
|| resourcesEvent
.getType() == Type
.SOFT_IRQ
) {
105 int cpu
= resourcesEvent
.getValue();
106 if (cpu
== StateValues
.SOFT_IRQ_RAISED
) {
107 return State
.RAISED
.toString();
109 return State
.ACTIVE
.toString();
114 return State
.UNKNOWN
.toString();
118 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
120 Map
<String
, String
> retMap
= new HashMap
<String
, String
>();
121 if (event
instanceof ResourcesEvent
) {
123 ResourcesEvent resourcesEvent
= (ResourcesEvent
) event
;
125 // Check for IRQ or Soft_IRQ type
126 if (resourcesEvent
.getType().equals(Type
.IRQ
) || resourcesEvent
.getType().equals(Type
.SOFT_IRQ
)) {
128 // Get CPU of IRQ or SoftIRQ and provide it for the tooltip display
129 int cpu
= resourcesEvent
.getValue();
131 retMap
.put(Messages
.ResourcesView_attributeCpuName
, String
.valueOf(cpu
));
135 // Check for type CPU
136 if (resourcesEvent
.getType().equals(Type
.CPU
)) {
137 int status
= resourcesEvent
.getValue();
139 if (status
== StateValues
.CPU_STATUS_INTERRUPTED
) {
140 // In interrupted state get the IRQ or SOFT_IRQ that caused the interruption
141 ResourcesEntry entry
= (ResourcesEntry
) event
.getEntry();
142 IStateSystemQuerier ssq
= entry
.getTrace().getStateSystem();
143 int cpu
= entry
.getId();
145 IStateSystemQuerier ss
= entry
.getTrace().getStateSystem();
148 String attributeName
= null;
150 // First check for IRQ
151 List
<ITmfStateInterval
> fullState
= ss
.queryFullState(event
.getTime());
152 List
<Integer
> irqQuarks
= ss
.getQuarks(Attributes
.RESOURCES
, Attributes
.IRQS
, "*"); //$NON-NLS-1$
154 for (int curQuark
: irqQuarks
) {
155 if (fullState
.get(curQuark
).getStateValue().unboxInt() == cpu
) {
156 resultQuark
= curQuark
;
157 attributeName
= Messages
.ResourcesView_attributeIrqName
;
162 // If not found check for SOFT_IRQ
163 if (attributeName
== null) {
164 List
<Integer
> softIrqQuarks
= ssq
.getQuarks(Attributes
.RESOURCES
, Attributes
.SOFT_IRQS
, "*"); //$NON-NLS-1$
165 for (int curQuark
: softIrqQuarks
) {
166 if (fullState
.get(curQuark
).getStateValue().unboxInt() == cpu
) {
167 resultQuark
= curQuark
;
168 attributeName
= Messages
.ResourcesView_attributeSoftIrqName
;
174 if (attributeName
!= null) {
175 // A IRQ or SOFT_IRQ was found
176 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), resultQuark
);
177 if (!value
.getStateValue().isNull()) {
178 int irq
= Integer
.parseInt(ssq
.getAttributeName(resultQuark
));
179 retMap
.put(attributeName
, String
.valueOf(irq
));
182 } catch (AttributeNotFoundException e
) {
184 } catch (TimeRangeException e
) {
186 } catch (StateValueTypeException e
) {