1 /*******************************************************************************
2 * Copyright (c) 2016 É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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.ui
.views
.vm
.vcpuview
;
12 import org
.eclipse
.jdt
.annotation
.Nullable
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.graphics
.Color
;
15 import org
.eclipse
.swt
.graphics
.GC
;
16 import org
.eclipse
.swt
.graphics
.RGB
;
17 import org
.eclipse
.swt
.graphics
.Rectangle
;
18 import org
.eclipse
.swt
.widgets
.Display
;
19 import org
.eclipse
.tracecompass
.analysis
.os
.linux
.core
.kernel
.StateValues
;
20 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.analysis
.vm
.VcpuStateValues
;
21 import org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.ui
.views
.vm
.vcpuview
.VirtualMachineCommon
.Type
;
22 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.StateItem
;
23 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
24 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
25 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
29 * Presentation provider for the Virtual Machine view, based on the generic TMF
30 * presentation provider.
32 * @author Mohamad Gebai
34 public class VirtualMachinePresentationProvider
extends TimeGraphPresentationProvider
{
36 private static final int ALPHA
= 70;
39 * TODO: Some of it is copy-pasted from the control flow presentation
40 * provider because it actually is the same data as from the control flow
41 * view. Ideally, we should reuse what is there instead of rewriting it here
44 UNKNOWN(new RGB(100, 100, 100)),
45 IDLE(new RGB(200, 200, 200)),
46 USERMODE(new RGB(0, 200, 0)),
47 WAIT_VMM(new RGB(200, 0, 0)),
48 VCPU_PREEMPTED(new RGB(120, 40, 90)),
49 THREAD_UNKNOWN(new RGB(100, 100, 100)),
50 THREAD_WAIT_BLOCKED(new RGB(200, 200, 0)),
51 THREAD_WAIT_FOR_CPU(new RGB(200, 100, 0)),
52 THREAD_USERMODE(new RGB(0, 200, 0)),
53 THREAD_SYSCALL(new RGB(0, 0, 200)),
54 THREAD_INTERRUPTED(new RGB(200, 0, 100));
56 private final RGB fRgb
;
58 private State(RGB rgb
) {
66 public VirtualMachinePresentationProvider() {
70 private static State
[] getStateValues() {
71 return State
.values();
74 private static State
getStateForVcpu(int value
) {
75 if ((value
& VcpuStateValues
.VCPU_PREEMPT
) > 0) {
76 return State
.VCPU_PREEMPTED
;
77 } else if ((value
& VcpuStateValues
.VCPU_VMM
) > 0) {
78 return State
.WAIT_VMM
;
79 } else if (value
== 2) {
80 return State
.USERMODE
;
81 } else if (value
== 1) {
88 private static @Nullable State
getStateForThread(int value
) {
89 if (value
== VcpuStateValues
.VCPU_PREEMPT
) {
93 case StateValues
.PROCESS_STATUS_RUN_USERMODE
:
94 return State
.THREAD_USERMODE
;
95 case StateValues
.PROCESS_STATUS_RUN_SYSCALL
:
96 return State
.THREAD_SYSCALL
;
97 case StateValues
.PROCESS_STATUS_WAIT_FOR_CPU
:
98 return State
.THREAD_WAIT_FOR_CPU
;
99 case StateValues
.PROCESS_STATUS_WAIT_BLOCKED
:
100 return State
.THREAD_WAIT_BLOCKED
;
101 case StateValues
.PROCESS_STATUS_INTERRUPTED
:
102 return State
.THREAD_INTERRUPTED
;
103 case StateValues
.PROCESS_STATUS_UNKNOWN
:
104 case StateValues
.PROCESS_STATUS_WAIT_UNKNOWN
:
105 return State
.THREAD_UNKNOWN
;
111 private static @Nullable State
getEventState(TimeEvent event
) {
112 if (event
.hasValue()) {
113 VirtualMachineViewEntry entry
= (VirtualMachineViewEntry
) event
.getEntry();
114 int value
= event
.getValue();
116 if (entry
.getType() == Type
.VCPU
) {
117 return getStateForVcpu(value
);
118 } else if (entry
.getType() == Type
.THREAD
) {
119 return getStateForThread(value
);
126 public int getStateTableIndex(@Nullable ITimeEvent event
) {
130 State state
= getEventState((TimeEvent
) event
);
132 return state
.ordinal();
134 if (event
instanceof NullTimeEvent
) {
141 public StateItem
[] getStateTable() {
142 State
[] states
= getStateValues();
143 StateItem
[] stateTable
= new StateItem
[states
.length
];
144 for (int i
= 0; i
< stateTable
.length
; i
++) {
145 State state
= states
[i
];
146 stateTable
[i
] = new StateItem(state
.fRgb
, state
.toString());
152 public @Nullable String
getEventName(@Nullable ITimeEvent event
) {
156 State state
= getEventState((TimeEvent
) event
);
158 return state
.toString();
160 if (event
instanceof NullTimeEvent
) {
163 return Messages
.VmView_multipleStates
;
167 public void postDrawEvent(@Nullable ITimeEvent event
, @Nullable Rectangle bounds
, @Nullable GC gc
) {
168 if (bounds
== null || gc
== null || !(event
instanceof TimeEvent
)) {
171 boolean visible
= bounds
.width
== 0 ?
false : true;
175 TimeEvent ev
= (TimeEvent
) event
;
177 * FIXME: There seems to be a bug when multiple events should be drawn
178 * under a alpha event. See FIXME comment in
179 * VirtualMachineView#getEventList
182 VirtualMachineViewEntry entry
= (VirtualMachineViewEntry
) event
.getEntry();
184 if (entry
.getType() == Type
.THREAD
) {
185 int value
= ev
.getValue();
186 if ((value
& VcpuStateValues
.VCPU_PREEMPT
) != 0) {
188 * If the status was preempted at this time, draw an alpha
191 Color alphaColor
= Display
.getDefault().getSystemColor(SWT
.COLOR_RED
);
193 int alpha
= gc
.getAlpha();
194 Color background
= gc
.getBackground();
195 // fill all rect area
196 gc
.setBackground(alphaColor
);
198 gc
.fillRectangle(bounds
);
200 gc
.setBackground(background
);