9ebc6f200ea32f610b9de9af3855af18aaa4c75d
[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.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
19 import org.eclipse.linuxtools.internal.lttng2.kernel.core.StateValues;
20 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
21 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
22 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
23 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
24 import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
25 import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
26 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
27 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
28 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
29 import org.eclipse.swt.graphics.RGB;
30
31 public class ControlFlowPresentationProvider extends TimeGraphPresentationProvider {
32
33 private enum State {
34 UNKNOWN (new RGB(100, 100, 100)),
35 WAIT (new RGB(200, 200, 0)),
36 USERMODE (new RGB(0, 200, 0)),
37 SYSCALL (new RGB(0, 0, 200)),
38 INTERRUPTED (new RGB(200, 100, 100));
39
40 public final RGB rgb;
41
42 private State (RGB rgb) {
43 this.rgb = rgb;
44 }
45 }
46
47 @Override
48 public String getStateTypeName() {
49 return Messages.ControlFlowView_stateTypeName;
50 }
51
52 @Override
53 public StateItem[] getStateTable() {
54 StateItem[] stateTable = new StateItem[State.values().length];
55 for (int i = 0; i < stateTable.length; i++) {
56 State state = State.values()[i];
57 stateTable[i] = new StateItem(state.rgb, state.toString());
58 }
59 return stateTable;
60 }
61
62 @Override
63 public int getStateTableIndex(ITimeEvent event) {
64 if (event instanceof ControlFlowEvent) {
65 int status = ((ControlFlowEvent) event).getStatus();
66 if (status == StateValues.PROCESS_STATUS_WAIT) {
67 return State.WAIT.ordinal();
68 } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) {
69 return State.USERMODE.ordinal();
70 } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
71 return State.SYSCALL.ordinal();
72 } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {
73 return State.INTERRUPTED.ordinal();
74 }
75 }
76 return State.UNKNOWN.ordinal();
77 }
78
79 @Override
80 public String getEventName(ITimeEvent event) {
81 if (event instanceof ControlFlowEvent) {
82 int status = ((ControlFlowEvent) event).getStatus();
83 if (status == StateValues.PROCESS_STATUS_WAIT) {
84 return State.WAIT.toString();
85 } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) {
86 return State.USERMODE.toString();
87 } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
88 return State.SYSCALL.toString();
89 } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {
90 return State.INTERRUPTED.toString();
91 }
92 }
93 return State.UNKNOWN.toString();
94 }
95
96 @Override
97 public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {
98 Map<String, String> retMap = new HashMap<String, String>();
99 if (event instanceof ControlFlowEvent) {
100 int status = ((ControlFlowEvent) event).getStatus();
101 if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
102 ControlFlowEntry entry = (ControlFlowEntry) event.getEntry();
103 IStateSystemQuerier ssq = entry.getTrace().getStateSystem();
104 try {
105 int syscallQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL);
106 ITmfStateInterval value = ssq.querySingleState(event.getTime(), syscallQuark);
107 if (!value.getStateValue().isNull()) {
108 ITmfStateValue state = value.getStateValue();
109 retMap.put(Messages.ControlFlowView_attributeSyscallName, state.toString());
110 }
111
112 } catch (AttributeNotFoundException e) {
113 e.printStackTrace();
114 } catch (TimeRangeException e) {
115 e.printStackTrace();
116 }
117 }
118 }
119
120 return retMap;
121 }
122
123 }
This page took 0.032673 seconds and 5 git commands to generate.