1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson, École Polytechnique de Montréal
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 * Geneviève Bastien - Move code to provide base classes for time graph view
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.views
.controlflow
;
16 import java
.util
.LinkedHashMap
;
17 import java
.util
.List
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.Attributes
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.core
.StateValues
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.Messages
;
23 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.trace
.LttngKernelTrace
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateSystemDisposedException
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystem
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.ITmfStateValue
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
36 import org
.eclipse
.swt
.SWT
;
37 import org
.eclipse
.swt
.graphics
.GC
;
38 import org
.eclipse
.swt
.graphics
.RGB
;
39 import org
.eclipse
.swt
.graphics
.Rectangle
;
42 * Presentation provider for the control flow view
44 public class ControlFlowPresentationProvider
extends TimeGraphPresentationProvider
{
47 UNKNOWN (new RGB(100, 100, 100)),
48 WAIT_BLOCKED (new RGB(200, 200, 0)),
49 WAIT_FOR_CPU (new RGB(200, 100, 0)),
50 USERMODE (new RGB(0, 200, 0)),
51 SYSCALL (new RGB(0, 0, 200)),
52 INTERRUPTED (new RGB(200, 0, 100));
56 private State(RGB rgb
) {
65 public ControlFlowPresentationProvider() {
66 super(Messages
.ControlFlowView_stateTypeName
);
69 private static State
[] getStateValues() {
70 return State
.values();
74 public StateItem
[] getStateTable() {
75 State
[] states
= getStateValues();
76 StateItem
[] stateTable
= new StateItem
[states
.length
];
77 for (int i
= 0; i
< stateTable
.length
; i
++) {
78 State state
= states
[i
];
79 stateTable
[i
] = new StateItem(state
.rgb
, state
.toString());
85 public int getStateTableIndex(ITimeEvent event
) {
86 if (event
instanceof TimeEvent
&& ((TimeEvent
) event
).hasValue()) {
87 int status
= ((TimeEvent
) event
).getValue();
88 return getMatchingState(status
).ordinal();
94 public String
getEventName(ITimeEvent event
) {
95 if (event
instanceof TimeEvent
) {
96 TimeEvent ev
= (TimeEvent
) event
;
98 return getMatchingState(ev
.getValue()).toString();
101 return Messages
.ControlFlowView_multipleStates
;
104 private static State
getMatchingState(int status
) {
106 case StateValues
.PROCESS_STATUS_WAIT_BLOCKED
:
107 return State
.WAIT_BLOCKED
;
108 case StateValues
.PROCESS_STATUS_WAIT_FOR_CPU
:
109 return State
.WAIT_FOR_CPU
;
110 case StateValues
.PROCESS_STATUS_RUN_USERMODE
:
111 return State
.USERMODE
;
112 case StateValues
.PROCESS_STATUS_RUN_SYSCALL
:
113 return State
.SYSCALL
;
114 case StateValues
.PROCESS_STATUS_INTERRUPTED
:
115 return State
.INTERRUPTED
;
117 return State
.UNKNOWN
;
122 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
123 Map
<String
, String
> retMap
= new LinkedHashMap
<String
, String
>();
124 if (!(event
instanceof TimeEvent
) || !((TimeEvent
) event
).hasValue() ||
125 !(event
.getEntry() instanceof ControlFlowEntry
)) {
128 ControlFlowEntry entry
= (ControlFlowEntry
) event
.getEntry();
129 ITmfStateSystem ssq
= entry
.getTrace().getStateSystems().get(LttngKernelTrace
.STATE_ID
);
130 int tid
= entry
.getThreadId();
133 // Find every CPU first, then get the current thread
134 int cpusQuark
= ssq
.getQuarkAbsolute(Attributes
.CPUS
);
135 List
<Integer
> cpuQuarks
= ssq
.getSubAttributes(cpusQuark
, false);
136 for (Integer cpuQuark
: cpuQuarks
) {
137 int currentThreadQuark
= ssq
.getQuarkRelative(cpuQuark
, Attributes
.CURRENT_THREAD
);
138 ITmfStateInterval interval
= ssq
.querySingleState(event
.getTime(), currentThreadQuark
);
139 if (!interval
.getStateValue().isNull()) {
140 ITmfStateValue state
= interval
.getStateValue();
141 int currentThreadId
= state
.unboxInt();
142 if (tid
== currentThreadId
) {
143 retMap
.put(Messages
.ControlFlowView_attributeCpuName
, ssq
.getAttributeName(cpuQuark
));
149 } catch (AttributeNotFoundException e
) {
151 } catch (TimeRangeException e
) {
153 } catch (StateValueTypeException e
) {
155 } catch (StateSystemDisposedException e
) {
158 int status
= ((TimeEvent
) event
).getValue();
159 if (status
== StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
161 int syscallQuark
= ssq
.getQuarkRelative(entry
.getThreadQuark(), Attributes
.SYSTEM_CALL
);
162 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), syscallQuark
);
163 if (!value
.getStateValue().isNull()) {
164 ITmfStateValue state
= value
.getStateValue();
165 retMap
.put(Messages
.ControlFlowView_attributeSyscallName
, state
.toString());
168 } catch (AttributeNotFoundException e
) {
170 } catch (TimeRangeException e
) {
172 } catch (StateSystemDisposedException e
) {
181 public void postDrawEvent(ITimeEvent event
, Rectangle bounds
, GC gc
) {
182 if (bounds
.width
<= gc
.getFontMetrics().getAverageCharWidth()) {
185 if (!(event
instanceof TimeEvent
)) {
188 ControlFlowEntry entry
= (ControlFlowEntry
) event
.getEntry();
189 ITmfStateSystem ss
= entry
.getTrace().getStateSystems().get(LttngKernelTrace
.STATE_ID
);
190 int status
= ((TimeEvent
) event
).getValue();
192 if (status
!= StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
196 int syscallQuark
= ss
.getQuarkRelative(entry
.getThreadQuark(), Attributes
.SYSTEM_CALL
);
197 ITmfStateInterval value
= ss
.querySingleState(event
.getTime(), syscallQuark
);
198 if (!value
.getStateValue().isNull()) {
199 ITmfStateValue state
= value
.getStateValue();
200 gc
.setForeground(gc
.getDevice().getSystemColor(SWT
.COLOR_WHITE
));
201 Utils
.drawText(gc
, state
.toString().substring(4), bounds
.x
, bounds
.y
- 2, bounds
.width
, true, true);
203 } catch (AttributeNotFoundException e
) {
205 } catch (TimeRangeException e
) {
207 } catch (StateSystemDisposedException e
) {