1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 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
.Activator
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.kernel
.ui
.Messages
;
24 import org
.eclipse
.linuxtools
.lttng2
.kernel
.core
.analysis
.LttngKernelAnalysisModule
;
25 import org
.eclipse
.linuxtools
.statesystem
.core
.ITmfStateSystem
;
26 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
27 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.StateSystemDisposedException
;
28 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.StateValueTypeException
;
29 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.TimeRangeException
;
30 import org
.eclipse
.linuxtools
.statesystem
.core
.interval
.ITmfStateInterval
;
31 import org
.eclipse
.linuxtools
.statesystem
.core
.statevalue
.ITmfStateValue
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.widgets
.Utils
;
38 import org
.eclipse
.swt
.SWT
;
39 import org
.eclipse
.swt
.graphics
.GC
;
40 import org
.eclipse
.swt
.graphics
.RGB
;
41 import org
.eclipse
.swt
.graphics
.Rectangle
;
44 * Presentation provider for the control flow view
46 public class ControlFlowPresentationProvider
extends TimeGraphPresentationProvider
{
49 UNKNOWN (new RGB(100, 100, 100)),
50 WAIT_BLOCKED (new RGB(200, 200, 0)),
51 WAIT_FOR_CPU (new RGB(200, 100, 0)),
52 USERMODE (new RGB(0, 200, 0)),
53 SYSCALL (new RGB(0, 0, 200)),
54 INTERRUPTED (new RGB(200, 0, 100));
58 private State(RGB rgb
) {
67 public ControlFlowPresentationProvider() {
68 super(Messages
.ControlFlowView_stateTypeName
);
71 private static State
[] getStateValues() {
72 return State
.values();
76 public StateItem
[] getStateTable() {
77 State
[] states
= getStateValues();
78 StateItem
[] stateTable
= new StateItem
[states
.length
];
79 for (int i
= 0; i
< stateTable
.length
; i
++) {
80 State state
= states
[i
];
81 stateTable
[i
] = new StateItem(state
.rgb
, state
.toString());
87 public int getStateTableIndex(ITimeEvent event
) {
88 if (event
instanceof TimeEvent
&& ((TimeEvent
) event
).hasValue()) {
89 int status
= ((TimeEvent
) event
).getValue();
90 return getMatchingState(status
).ordinal();
96 public String
getEventName(ITimeEvent event
) {
97 if (event
instanceof TimeEvent
) {
98 TimeEvent ev
= (TimeEvent
) event
;
100 return getMatchingState(ev
.getValue()).toString();
103 return Messages
.ControlFlowView_multipleStates
;
106 private static State
getMatchingState(int status
) {
108 case StateValues
.PROCESS_STATUS_WAIT_BLOCKED
:
109 return State
.WAIT_BLOCKED
;
110 case StateValues
.PROCESS_STATUS_WAIT_FOR_CPU
:
111 return State
.WAIT_FOR_CPU
;
112 case StateValues
.PROCESS_STATUS_RUN_USERMODE
:
113 return State
.USERMODE
;
114 case StateValues
.PROCESS_STATUS_RUN_SYSCALL
:
115 return State
.SYSCALL
;
116 case StateValues
.PROCESS_STATUS_INTERRUPTED
:
117 return State
.INTERRUPTED
;
119 return State
.UNKNOWN
;
124 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
125 Map
<String
, String
> retMap
= new LinkedHashMap
<>();
126 if (!(event
instanceof TimeEvent
) || !((TimeEvent
) event
).hasValue() ||
127 !(event
.getEntry() instanceof ControlFlowEntry
)) {
130 ControlFlowEntry entry
= (ControlFlowEntry
) event
.getEntry();
131 ITmfStateSystem ssq
= TmfStateSystemAnalysisModule
.getStateSystem(entry
.getTrace(), LttngKernelAnalysisModule
.ID
);
135 int tid
= entry
.getThreadId();
138 // Find every CPU first, then get the current thread
139 int cpusQuark
= ssq
.getQuarkAbsolute(Attributes
.CPUS
);
140 List
<Integer
> cpuQuarks
= ssq
.getSubAttributes(cpusQuark
, false);
141 for (Integer cpuQuark
: cpuQuarks
) {
142 int currentThreadQuark
= ssq
.getQuarkRelative(cpuQuark
, Attributes
.CURRENT_THREAD
);
143 ITmfStateInterval interval
= ssq
.querySingleState(event
.getTime(), currentThreadQuark
);
144 if (!interval
.getStateValue().isNull()) {
145 ITmfStateValue state
= interval
.getStateValue();
146 int currentThreadId
= state
.unboxInt();
147 if (tid
== currentThreadId
) {
148 retMap
.put(Messages
.ControlFlowView_attributeCpuName
, ssq
.getAttributeName(cpuQuark
));
154 } catch (AttributeNotFoundException
| TimeRangeException
| StateValueTypeException e
) {
155 Activator
.getDefault().logError("Error in ControlFlowPresentationProvider", e
); //$NON-NLS-1$
156 } catch (StateSystemDisposedException e
) {
159 int status
= ((TimeEvent
) event
).getValue();
160 if (status
== StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
162 int syscallQuark
= ssq
.getQuarkRelative(entry
.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
| TimeRangeException e
) {
170 Activator
.getDefault().logError("Error in ControlFlowPresentationProvider", e
); //$NON-NLS-1$
171 } catch (StateSystemDisposedException e
) {
180 public void postDrawEvent(ITimeEvent event
, Rectangle bounds
, GC gc
) {
181 if (bounds
.width
<= gc
.getFontMetrics().getAverageCharWidth()) {
184 if (!(event
instanceof TimeEvent
)) {
187 ControlFlowEntry entry
= (ControlFlowEntry
) event
.getEntry();
188 ITmfStateSystem ss
= TmfStateSystemAnalysisModule
.getStateSystem(entry
.getTrace(), LttngKernelAnalysisModule
.ID
);
192 int status
= ((TimeEvent
) event
).getValue();
194 if (status
!= StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
198 int syscallQuark
= ss
.getQuarkRelative(entry
.getThreadQuark(), Attributes
.SYSTEM_CALL
);
199 ITmfStateInterval value
= ss
.querySingleState(event
.getTime(), syscallQuark
);
200 if (!value
.getStateValue().isNull()) {
201 ITmfStateValue state
= value
.getStateValue();
202 gc
.setForeground(gc
.getDevice().getSystemColor(SWT
.COLOR_WHITE
));
203 Utils
.drawText(gc
, state
.toString().substring(4), bounds
.x
, bounds
.y
- 2, bounds
.width
, true, true);
205 } catch (AttributeNotFoundException
| TimeRangeException e
) {
206 Activator
.getDefault().logError("Error in ControlFlowPresentationProvider", e
); //$NON-NLS-1$
207 } catch (StateSystemDisposedException e
) {