1 /*******************************************************************************
2 * Copyright (c) 2012 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
.tmf
.core
.exceptions
.AttributeNotFoundException
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.IStateSystemQuerier
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.ITmfStateValue
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.StateItem
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
31 import org
.eclipse
.swt
.graphics
.RGB
;
34 * Presentation provider for the control flow view
36 public class ControlFlowPresentationProvider
extends TimeGraphPresentationProvider
{
39 UNKNOWN (new RGB(100, 100, 100)),
40 WAIT (new RGB(200, 200, 0)),
41 USERMODE (new RGB(0, 200, 0)),
42 SYSCALL (new RGB(0, 0, 200)),
43 INTERRUPTED (new RGB(200, 100, 100));
47 private State (RGB rgb
) {
53 public String
getStateTypeName() {
54 return Messages
.ControlFlowView_stateTypeName
;
58 public StateItem
[] getStateTable() {
59 StateItem
[] stateTable
= new StateItem
[State
.values().length
];
60 for (int i
= 0; i
< stateTable
.length
; i
++) {
61 State state
= State
.values()[i
];
62 stateTable
[i
] = new StateItem(state
.rgb
, state
.toString());
68 public int getStateTableIndex(ITimeEvent event
) {
69 if (event
instanceof ControlFlowEvent
) {
70 int status
= ((ControlFlowEvent
) event
).getStatus();
71 if (status
== StateValues
.PROCESS_STATUS_WAIT
) {
72 return State
.WAIT
.ordinal();
73 } else if (status
== StateValues
.PROCESS_STATUS_RUN_USERMODE
) {
74 return State
.USERMODE
.ordinal();
75 } else if (status
== StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
76 return State
.SYSCALL
.ordinal();
77 } else if (status
== StateValues
.PROCESS_STATUS_INTERRUPTED
) {
78 return State
.INTERRUPTED
.ordinal();
81 return State
.UNKNOWN
.ordinal();
85 public String
getEventName(ITimeEvent event
) {
86 if (event
instanceof ControlFlowEvent
) {
87 int status
= ((ControlFlowEvent
) event
).getStatus();
88 if (status
== StateValues
.PROCESS_STATUS_WAIT
) {
89 return State
.WAIT
.toString();
90 } else if (status
== StateValues
.PROCESS_STATUS_RUN_USERMODE
) {
91 return State
.USERMODE
.toString();
92 } else if (status
== StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
93 return State
.SYSCALL
.toString();
94 } else if (status
== StateValues
.PROCESS_STATUS_INTERRUPTED
) {
95 return State
.INTERRUPTED
.toString();
98 return State
.UNKNOWN
.toString();
102 public Map
<String
, String
> getEventHoverToolTipInfo(ITimeEvent event
) {
103 Map
<String
, String
> retMap
= new LinkedHashMap
<String
, String
>();
104 if (event
instanceof ControlFlowEvent
) {
105 ControlFlowEntry entry
= (ControlFlowEntry
) event
.getEntry();
106 IStateSystemQuerier ssq
= entry
.getTrace().getStateSystem();
107 int tid
= entry
.getThreadId();
110 //Find every CPU first, then get the current thread
111 int cpusQuark
= ssq
.getQuarkAbsolute(Attributes
.CPUS
);
112 List
<Integer
> cpuQuarks
= ssq
.getSubAttributes(cpusQuark
, false);
113 for (Integer cpuQuark
: cpuQuarks
) {
114 int currentThreadQuark
= ssq
.getQuarkRelative(cpuQuark
, Attributes
.CURRENT_THREAD
);
115 ITmfStateInterval interval
= ssq
.querySingleState(event
.getTime(), currentThreadQuark
);
116 if (!interval
.getStateValue().isNull()) {
117 ITmfStateValue state
= interval
.getStateValue();
118 int currentThreadId
= state
.unboxInt();
119 if (tid
== currentThreadId
) {
120 retMap
.put(Messages
.ControlFlowView_attributeCpuName
, ssq
.getAttributeName(cpuQuark
));
126 } catch (AttributeNotFoundException e
) {
128 } catch (TimeRangeException e
) {
130 } catch (StateValueTypeException e
) {
133 int status
= ((ControlFlowEvent
) event
).getStatus();
134 if (status
== StateValues
.PROCESS_STATUS_RUN_SYSCALL
) {
136 int syscallQuark
= ssq
.getQuarkRelative(entry
.getThreadQuark(), Attributes
.SYSTEM_CALL
);
137 ITmfStateInterval value
= ssq
.querySingleState(event
.getTime(), syscallQuark
);
138 if (!value
.getStateValue().isNull()) {
139 ITmfStateValue state
= value
.getStateValue();
140 retMap
.put(Messages
.ControlFlowView_attributeSyscallName
, state
.toString());
143 } catch (AttributeNotFoundException e
) {
145 } catch (TimeRangeException e
) {