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