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