1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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
.controlflow
;
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
.lttng2
.kernel
.core
.trace
.CtfKernelTrace
;
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
.swt
.SWT
;
35 import org
.eclipse
.swt
.graphics
.GC
;
36 import org
.eclipse
.swt
.graphics
.RGB
;
37 import org
.eclipse
.swt
.graphics
.Rectangle
;
40 * Presentation provider for the control flow view
42 public class ControlFlowPresentationProvider
extends TimeGraphPresentationProvider
{
45 UNKNOWN (new RGB(100, 100, 100)),
46 WAIT_BLOCKED (new RGB(200, 200, 0)),
47 WAIT_FOR_CPU (new RGB(200, 100, 0)),
48 USERMODE (new RGB( 0, 200, 0)),
49 SYSCALL (new RGB( 0, 0, 200)),
50 INTERRUPTED (new RGB(200, 0, 100));
54 private State (RGB rgb
) {
60 public String
getStateTypeName() {
61 return Messages
.ControlFlowView_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 ControlFlowEvent
) {
77 int status
= ((ControlFlowEvent
) event
).getStatus();
78 return getMatchingState(status
).ordinal();
84 public String
getEventName(ITimeEvent event
) {
85 if (event
instanceof ControlFlowEvent
) {
86 int status
= ((ControlFlowEvent
) event
).getStatus();
87 return getMatchingState(status
).toString();
89 return Messages
.ControlFlowView_multipleStates
;
92 private static State
getMatchingState(int status
) {
94 case StateValues
.PROCESS_STATUS_WAIT_BLOCKED
:
95 return State
.WAIT_BLOCKED
;
96 case StateValues
.PROCESS_STATUS_WAIT_FOR_CPU
:
97 return State
.WAIT_FOR_CPU
;
98 case StateValues
.PROCESS_STATUS_RUN_USERMODE
:
99 return State
.USERMODE
;
100 case StateValues
.PROCESS_STATUS_RUN_SYSCALL
:
101 return State
.SYSCALL
;
102 case StateValues
.PROCESS_STATUS_INTERRUPTED
:
103 return State
.INTERRUPTED
;
105 return State
.UNKNOWN
;
110 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
111 Map
<String
, String
> retMap
= new LinkedHashMap
<String
, String
>();
112 if (event
instanceof ControlFlowEvent
) {
113 ControlFlowEntry entry
= (ControlFlowEntry
) event
.getEntry();
114 ITmfStateSystem ssq
= entry
.getTrace().getStateSystems().get(CtfKernelTrace
.STATE_ID
);
115 int tid
= entry
.getThreadId();
118 //Find every CPU first, then get the current thread
119 int cpusQuark
= ssq
.getQuarkAbsolute(Attributes
.CPUS
);
120 List
<Integer
> cpuQuarks
= ssq
.getSubAttributes(cpusQuark
, false);
121 for (Integer cpuQuark
: cpuQuarks
) {
122 int currentThreadQuark
= ssq
.getQuarkRelative(cpuQuark
, Attributes
.CURRENT_THREAD
);
123 ITmfStateInterval interval
= ssq
.querySingleState(event
.getTime(), currentThreadQuark
);
124 if (!interval
.getStateValue().isNull()) {
125 ITmfStateValue state
= interval
.getStateValue();
126 int currentThreadId
= state
.unboxInt();
127 if (tid
== currentThreadId
) {
128 retMap
.put(Messages
.ControlFlowView_attributeCpuName
, ssq
.getAttributeName(cpuQuark
));
134 } catch (AttributeNotFoundException e
) {
136 } catch (TimeRangeException e
) {
138 } catch (StateValueTypeException e
) {
140 } catch (StateSystemDisposedException e
) {
143 int status
= ((ControlFlowEvent
) event
).getStatus();
144 if (status
== StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
146 int syscallQuark
= ssq
.getQuarkRelative(entry
.getThreadQuark(), Attributes
.SYSTEM_CALL
);
147 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), syscallQuark
);
148 if (!value
.getStateValue().isNull()) {
149 ITmfStateValue state
= value
.getStateValue();
150 retMap
.put(Messages
.ControlFlowView_attributeSyscallName
, state
.toString());
153 } catch (AttributeNotFoundException e
) {
155 } catch (TimeRangeException e
) {
157 } catch (StateSystemDisposedException e
) {
167 public void postDrawEvent(ITimeEvent event
, Rectangle bounds
, GC gc
) {
168 if (bounds
.width
<= gc
.getFontMetrics().getAverageCharWidth()) {
171 if (!(event
instanceof ControlFlowEvent
)) {
174 ControlFlowEntry entry
= (ControlFlowEntry
) event
.getEntry();
175 ITmfStateSystem ss
= entry
.getTrace().getStateSystems().get(CtfKernelTrace
.STATE_ID
);
176 int status
= ((ControlFlowEvent
) event
).getStatus();
177 if (status
!= StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
181 int syscallQuark
= ss
.getQuarkRelative(entry
.getThreadQuark(), Attributes
.SYSTEM_CALL
);
182 ITmfStateInterval value
= ss
.querySingleState(event
.getTime(), syscallQuark
);
183 if (!value
.getStateValue().isNull()) {
184 ITmfStateValue state
= value
.getStateValue();
185 gc
.setForeground(gc
.getDevice().getSystemColor(SWT
.COLOR_WHITE
));
186 Utils
.drawText(gc
, state
.toString().substring(4), bounds
.x
, bounds
.y
- 2, bounds
.width
, true, true);
188 } catch (AttributeNotFoundException e
) {
190 } catch (TimeRangeException e
) {
192 } catch (StateSystemDisposedException e
) {