tmf: Add a StateSystemDisposedException
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / controlflow / ControlFlowPresentationProvider.java
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.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;
33
34 /**
35 * Presentation provider for the control flow view
36 */
37 public class ControlFlowPresentationProvider extends TimeGraphPresentationProvider {
38
39 private enum State {
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));
45
46 public final RGB rgb;
47
48 private State (RGB rgb) {
49 this.rgb = rgb;
50 }
51 }
52
53 @Override
54 public String getStateTypeName() {
55 return Messages.ControlFlowView_stateTypeName;
56 }
57
58 @Override
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());
64 }
65 return stateTable;
66 }
67
68 @Override
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();
80 }
81 }
82 return State.UNKNOWN.ordinal();
83 }
84
85 @Override
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();
97 }
98 }
99 return State.UNKNOWN.toString();
100 }
101
102 @Override
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();
109
110 try {
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));
122 break;
123 }
124 }
125 }
126
127 } catch (AttributeNotFoundException e) {
128 e.printStackTrace();
129 } catch (TimeRangeException e) {
130 e.printStackTrace();
131 } catch (StateValueTypeException e) {
132 e.printStackTrace();
133 } catch (StateSystemDisposedException e) {
134 /* Ignored */
135 }
136 int status = ((ControlFlowEvent) event).getStatus();
137 if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
138 try {
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());
144 }
145
146 } catch (AttributeNotFoundException e) {
147 e.printStackTrace();
148 } catch (TimeRangeException e) {
149 e.printStackTrace();
150 } catch (StateSystemDisposedException e) {
151 /* Ignored */
152 }
153 }
154 }
155
156 return retMap;
157 }
158
159 }
This page took 0.034663 seconds and 5 git commands to generate.