e0f790de41c8fcbcf97c02c58d5e582655d98f77
[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 /**
32 * Presentation provider for the control flow view
33 */
34 public class ControlFlowPresentationProvider extends TimeGraphPresentationProvider {
35
36 private enum State {
37 UNKNOWN (new RGB(100, 100, 100)),
38 WAIT (new RGB(200, 200, 0)),
39 USERMODE (new RGB(0, 200, 0)),
40 SYSCALL (new RGB(0, 0, 200)),
41 INTERRUPTED (new RGB(200, 100, 100));
42
43 public final RGB rgb;
44
45 private State (RGB rgb) {
46 this.rgb = rgb;
47 }
48 }
49
50 @Override
51 public String getStateTypeName() {
52 return Messages.ControlFlowView_stateTypeName;
53 }
54
55 @Override
56 public StateItem[] getStateTable() {
57 StateItem[] stateTable = new StateItem[State.values().length];
58 for (int i = 0; i < stateTable.length; i++) {
59 State state = State.values()[i];
60 stateTable[i] = new StateItem(state.rgb, state.toString());
61 }
62 return stateTable;
63 }
64
65 @Override
66 public int getStateTableIndex(ITimeEvent event) {
67 if (event instanceof ControlFlowEvent) {
68 int status = ((ControlFlowEvent) event).getStatus();
69 if (status == StateValues.PROCESS_STATUS_WAIT) {
70 return State.WAIT.ordinal();
71 } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) {
72 return State.USERMODE.ordinal();
73 } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
74 return State.SYSCALL.ordinal();
75 } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {
76 return State.INTERRUPTED.ordinal();
77 }
78 }
79 return State.UNKNOWN.ordinal();
80 }
81
82 @Override
83 public String getEventName(ITimeEvent event) {
84 if (event instanceof ControlFlowEvent) {
85 int status = ((ControlFlowEvent) event).getStatus();
86 if (status == StateValues.PROCESS_STATUS_WAIT) {
87 return State.WAIT.toString();
88 } else if (status == StateValues.PROCESS_STATUS_RUN_USERMODE) {
89 return State.USERMODE.toString();
90 } else if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
91 return State.SYSCALL.toString();
92 } else if (status == StateValues.PROCESS_STATUS_INTERRUPTED) {
93 return State.INTERRUPTED.toString();
94 }
95 }
96 return State.UNKNOWN.toString();
97 }
98
99 @Override
100 public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event) {
101 Map<String, String> retMap = new HashMap<String, String>();
102 if (event instanceof ControlFlowEvent) {
103 int status = ((ControlFlowEvent) event).getStatus();
104 if (status == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
105 ControlFlowEntry entry = (ControlFlowEntry) event.getEntry();
106 IStateSystemQuerier ssq = entry.getTrace().getStateSystem();
107 try {
108 int syscallQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.SYSTEM_CALL);
109 ITmfStateInterval value = ssq.querySingleState(event.getTime(), syscallQuark);
110 if (!value.getStateValue().isNull()) {
111 ITmfStateValue state = value.getStateValue();
112 retMap.put(Messages.ControlFlowView_attributeSyscallName, state.toString());
113 }
114
115 } catch (AttributeNotFoundException e) {
116 e.printStackTrace();
117 } catch (TimeRangeException e) {
118 e.printStackTrace();
119 }
120 }
121 }
122
123 return retMap;
124 }
125
126 }
This page took 0.033479 seconds and 5 git commands to generate.