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; | |
a51b2b9f | 22 | import org.eclipse.linuxtools.lttng2.kernel.core.trace.CtfKernelTrace; |
be222f56 | 23 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; |
96345c5a | 24 | import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; |
be222f56 PT |
25 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; |
26 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; | |
27 | import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; | |
f1f86dfb | 28 | import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; |
be222f56 PT |
29 | import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; |
30 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem; | |
31 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider; | |
32 | import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent; | |
33 | import org.eclipse.swt.graphics.RGB; | |
34 | ||
35 | /** | |
36 | * Presentation provider for the control flow view | |
37 | */ | |
38 | public class ControlFlowPresentationProvider extends TimeGraphPresentationProvider { | |
39 | ||
40 | private enum State { | |
41 | UNKNOWN (new RGB(100, 100, 100)), | |
42 | WAIT (new RGB(200, 200, 0)), | |
43 | USERMODE (new RGB(0, 200, 0)), | |
44 | SYSCALL (new RGB(0, 0, 200)), | |
45 | INTERRUPTED (new RGB(200, 100, 100)); | |
46 | ||
47 | public final RGB rgb; | |
48 | ||
49 | private State (RGB rgb) { | |
50 | this.rgb = rgb; | |
51 | } | |
52 | } | |
53 | ||
54 | @Override | |
55 | public String getStateTypeName() { | |
56 | return Messages.ControlFlowView_stateTypeName; | |
57 | } | |
58 | ||
59 | @Override | |
60 | public StateItem[] getStateTable() { | |
61 | StateItem[] stateTable = new StateItem[State.values().length]; | |
62 | for (int i = 0; i < stateTable.length; i++) { | |
63 | State state = State.values()[i]; | |
64 | stateTable[i] = new StateItem(state.rgb, state.toString()); | |
65 | } | |
66 | return stateTable; | |
67 | } | |
68 | ||
69 | @Override | |
70 | public int getStateTableIndex(ITimeEvent event) { | |
71 | if (event instanceof ControlFlowEvent) { | |
72 | int status = ((ControlFlowEvent) event).getStatus(); | |
73 | if (status == StateValues.PROCESS_STATUS_WAIT) { | |
74 | return State.WAIT.ordinal(); | |
75 | } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) { | |
76 | return State.USERMODE.ordinal(); | |
77 | } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) { | |
78 | return State.SYSCALL.ordinal(); | |
79 | } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) { | |
80 | return State.INTERRUPTED.ordinal(); | |
81 | } | |
82 | } | |
83 | return State.UNKNOWN.ordinal(); | |
84 | } | |
85 | ||
86 | @Override | |
87 | public String getEventName(ITimeEvent event) { | |
88 | if (event instanceof ControlFlowEvent) { | |
89 | int status = ((ControlFlowEvent) event).getStatus(); | |
90 | if (status == StateValues.PROCESS_STATUS_WAIT) { | |
91 | return State.WAIT.toString(); | |
92 | } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) { | |
93 | return State.USERMODE.toString(); | |
94 | } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) { | |
95 | return State.SYSCALL.toString(); | |
96 | } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) { | |
97 | return State.INTERRUPTED.toString(); | |
98 | } | |
99 | } | |
100 | return State.UNKNOWN.toString(); | |
101 | } | |
102 | ||
103 | @Override | |
104 | public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) { | |
105 | Map<String, String> retMap = new LinkedHashMap<String, String>(); | |
106 | if (event instanceof ControlFlowEvent) { | |
107 | ControlFlowEntry entry = (ControlFlowEntry) event.getEntry(); | |
a51b2b9f | 108 | ITmfStateSystem ssq = entry.getTrace().getStateSystem(CtfKernelTrace.STATE_ID); |
be222f56 PT |
109 | int tid = entry.getThreadId(); |
110 | ||
111 | try { | |
112 | //Find every CPU first, then get the current thread | |
113 | int cpusQuark = ssq.getQuarkAbsolute(Attributes.CPUS); | |
114 | List<Integer> cpuQuarks = ssq.getSubAttributes(cpusQuark, false); | |
115 | for (Integer cpuQuark : cpuQuarks) { | |
116 | int currentThreadQuark = ssq.getQuarkRelative(cpuQuark, Attributes.CURRENT_THREAD); | |
117 | ITmfStateInterval interval = ssq.querySingleState(event.getTime(), currentThreadQuark); | |
118 | if (!interval.getStateValue().isNull()) { | |
119 | ITmfStateValue state = interval.getStateValue(); | |
120 | int currentThreadId = state.unboxInt(); | |
121 | if (tid == currentThreadId) { | |
122 | retMap.put(Messages.ControlFlowView_attributeCpuName, ssq.getAttributeName(cpuQuark)); | |
123 | break; | |
124 | } | |
125 | } | |
126 | } | |
127 | ||
128 | } catch (AttributeNotFoundException e) { | |
129 | e.printStackTrace(); | |
130 | } catch (TimeRangeException e) { | |
131 | e.printStackTrace(); | |
132 | } catch (StateValueTypeException e) { | |
133 | e.printStackTrace(); | |
96345c5a AM |
134 | } catch (StateSystemDisposedException e) { |
135 | /* Ignored */ | |
be222f56 PT |
136 | } |
137 | int status = ((ControlFlowEvent) event).getStatus(); | |
138 | if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) { | |
139 | try { | |
140 | int syscallQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL); | |
141 | ITmfStateInterval value = ssq.querySingleState(event.getTime(), syscallQuark); | |
142 | if (!value.getStateValue().isNull()) { | |
143 | ITmfStateValue state = value.getStateValue(); | |
144 | retMap.put(Messages.ControlFlowView_attributeSyscallName, state.toString()); | |
145 | } | |
146 | ||
147 | } catch (AttributeNotFoundException e) { | |
148 | e.printStackTrace(); | |
149 | } catch (TimeRangeException e) { | |
150 | e.printStackTrace(); | |
96345c5a AM |
151 | } catch (StateSystemDisposedException e) { |
152 | /* Ignored */ | |
be222f56 PT |
153 | } |
154 | } | |
155 | } | |
156 | ||
157 | return retMap; | |
158 | } | |
159 | ||
160 | } |