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
.model
.TimeGraphEntry
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
37 import org
.eclipse
.swt
.SWT
;
38 import org
.eclipse
.swt
.graphics
.GC
;
39 import org
.eclipse
.swt
.graphics
.RGB
;
40 import org
.eclipse
.swt
.graphics
.Rectangle
;
43 * Presentation provider for the control flow view
45 public class ControlFlowPresentationProvider
extends TimeGraphPresentationProvider
{
48 UNKNOWN (new RGB(100, 100, 100)),
49 WAIT_BLOCKED (new RGB(200, 200, 0)),
50 WAIT_FOR_CPU (new RGB(200, 100, 0)),
51 USERMODE (new RGB(0, 200, 0)),
52 SYSCALL (new RGB(0, 0, 200)),
53 INTERRUPTED (new RGB(200, 0, 100));
57 private State(RGB rgb
) {
66 public ControlFlowPresentationProvider() {
67 super(Messages
.ControlFlowView_stateTypeName
);
70 private static State
[] getStateValues() {
71 return State
.values();
75 public StateItem
[] getStateTable() {
76 State
[] states
= getStateValues();
77 StateItem
[] stateTable
= new StateItem
[states
.length
];
78 for (int i
= 0; i
< stateTable
.length
; i
++) {
79 State state
= states
[i
];
80 stateTable
[i
] = new StateItem(state
.rgb
, state
.toString());
86 public int getStateTableIndex(ITimeEvent event
) {
87 if (event
instanceof TimeEvent
&& ((TimeEvent
) event
).hasValue()) {
88 int status
= ((TimeEvent
) event
).getValue();
89 return getMatchingState(status
).ordinal();
95 public String
getEventName(ITimeEvent event
) {
96 if (event
instanceof TimeEvent
) {
97 TimeEvent ev
= (TimeEvent
) event
;
99 return getMatchingState(ev
.getValue()).toString();
102 return Messages
.ControlFlowView_multipleStates
;
105 private static State
getMatchingState(int status
) {
107 case StateValues
.PROCESS_STATUS_WAIT_BLOCKED
:
108 return State
.WAIT_BLOCKED
;
109 case StateValues
.PROCESS_STATUS_WAIT_FOR_CPU
:
110 return State
.WAIT_FOR_CPU
;
111 case StateValues
.PROCESS_STATUS_RUN_USERMODE
:
112 return State
.USERMODE
;
113 case StateValues
.PROCESS_STATUS_RUN_SYSCALL
:
114 return State
.SYSCALL
;
115 case StateValues
.PROCESS_STATUS_INTERRUPTED
:
116 return State
.INTERRUPTED
;
118 return State
.UNKNOWN
;
123 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
124 Map
<String
, String
> retMap
= new LinkedHashMap
<String
, String
>();
126 if (event
instanceof TimeEvent
&& ((TimeEvent
) event
).hasValue()) {
127 TimeGraphEntry entry
= (TimeGraphEntry
) event
.getEntry();
128 ITmfStateSystem ssq
= entry
.getTrace().getStateSystems().get(LttngKernelTrace
.STATE_ID
);
129 if (entry
instanceof ControlFlowEntry
) {
130 ControlFlowEntry entry2
= (ControlFlowEntry
) entry
;
131 int tid
= entry2
.getThreadId();
134 // Find every CPU first, then get the current thread
135 int cpusQuark
= ssq
.getQuarkAbsolute(Attributes
.CPUS
);
136 List
<Integer
> cpuQuarks
= ssq
.getSubAttributes(cpusQuark
, false);
137 for (Integer cpuQuark
: cpuQuarks
) {
138 int currentThreadQuark
= ssq
.getQuarkRelative(cpuQuark
, Attributes
.CURRENT_THREAD
);
139 ITmfStateInterval interval
= ssq
.querySingleState(event
.getTime(), currentThreadQuark
);
140 if (!interval
.getStateValue().isNull()) {
141 ITmfStateValue state
= interval
.getStateValue();
142 int currentThreadId
= state
.unboxInt();
143 if (tid
== currentThreadId
) {
144 retMap
.put(Messages
.ControlFlowView_attributeCpuName
, ssq
.getAttributeName(cpuQuark
));
150 } catch (AttributeNotFoundException e
) {
152 } catch (TimeRangeException e
) {
154 } catch (StateValueTypeException e
) {
156 } catch (StateSystemDisposedException e
) {
159 int status
= ((TimeEvent
) event
).getValue();
160 if (status
== StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
162 int syscallQuark
= ssq
.getQuarkRelative(entry2
.getThreadQuark(), Attributes
.SYSTEM_CALL
);
163 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), syscallQuark
);
164 if (!value
.getStateValue().isNull()) {
165 ITmfStateValue state
= value
.getStateValue();
166 retMap
.put(Messages
.ControlFlowView_attributeSyscallName
, state
.toString());
169 } catch (AttributeNotFoundException e
) {
171 } catch (TimeRangeException e
) {
173 } catch (StateSystemDisposedException e
) {
184 public void postDrawEvent(ITimeEvent event
, Rectangle bounds
, GC gc
) {
185 if (bounds
.width
<= gc
.getFontMetrics().getAverageCharWidth()) {
188 if (!(event
instanceof TimeEvent
)) {
191 ControlFlowEntry entry
= (ControlFlowEntry
) event
.getEntry();
192 ITmfStateSystem ss
= entry
.getTrace().getStateSystems().get(LttngKernelTrace
.STATE_ID
);
193 int status
= ((TimeEvent
) event
).getValue();
195 if (status
!= StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
199 int syscallQuark
= ss
.getQuarkRelative(entry
.getThreadQuark(), Attributes
.SYSTEM_CALL
);
200 ITmfStateInterval value
= ss
.querySingleState(event
.getTime(), syscallQuark
);
201 if (!value
.getStateValue().isNull()) {
202 ITmfStateValue state
= value
.getStateValue();
203 gc
.setForeground(gc
.getDevice().getSystemColor(SWT
.COLOR_WHITE
));
204 Utils
.drawText(gc
, state
.toString().substring(4), bounds
.x
, bounds
.y
- 2, bounds
.width
, true, true);
206 } catch (AttributeNotFoundException e
) {
208 } catch (TimeRangeException e
) {
210 } catch (StateSystemDisposedException e
) {