Commit | Line | Data |
---|---|---|
be222f56 PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 Ericsson | |
3 | * | |
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 | * | |
9 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.internal.lttng2.kernel.ui.views.controlflow; | |
14 | ||
15 | import java.util.LinkedHashMap; | |
16 | import java.util.List; | |
17 | import java.util.Map; | |
18 | ||
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; | |
32 | ||
33 | /** | |
34 | * Presentation provider for the control flow view | |
35 | */ | |
36 | public class ControlFlowPresentationProvider extends TimeGraphPresentationProvider { | |
37 | ||
38 | private enum State { | |
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)); | |
44 | ||
45 | public final RGB rgb; | |
46 | ||
47 | private State (RGB rgb) { | |
48 | this.rgb = rgb; | |
49 | } | |
50 | } | |
51 | ||
52 | @Override | |
53 | public String getStateTypeName() { | |
54 | return Messages.ControlFlowView_stateTypeName; | |
55 | } | |
56 | ||
57 | @Override | |
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()); | |
63 | } | |
64 | return stateTable; | |
65 | } | |
66 | ||
67 | @Override | |
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(); | |
79 | } | |
80 | } | |
81 | return State.UNKNOWN.ordinal(); | |
82 | } | |
83 | ||
84 | @Override | |
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(); | |
96 | } | |
97 | } | |
98 | return State.UNKNOWN.toString(); | |
99 | } | |
100 | ||
101 | @Override | |
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(); | |
108 | ||
109 | try { | |
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)); | |
121 | break; | |
122 | } | |
123 | } | |
124 | } | |
125 | ||
126 | } catch (AttributeNotFoundException e) { | |
127 | e.printStackTrace(); | |
128 | } catch (TimeRangeException e) { | |
129 | e.printStackTrace(); | |
130 | } catch (StateValueTypeException e) { | |
131 | e.printStackTrace(); | |
132 | } | |
133 | int status = ((ControlFlowEvent) event).getStatus(); | |
134 | if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) { | |
135 | try { | |
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()); | |
141 | } | |
142 | ||
143 | } catch (AttributeNotFoundException e) { | |
144 | e.printStackTrace(); | |
145 | } catch (TimeRangeException e) { | |
146 | e.printStackTrace(); | |
147 | } | |
148 | } | |
149 | } | |
150 | ||
151 | return retMap; | |
152 | } | |
153 | ||
154 | } |