tmf: Split the state system in a separate plugin
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / callstack / CallStackPresentationProvider.java
CommitLineData
e8251298 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 Ericsson
e8251298
PT
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
13package org.eclipse.linuxtools.tmf.ui.views.callstack;
14
52974e38 15import org.eclipse.linuxtools.internal.tmf.ui.Activator;
bcec0116
AM
16import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
17import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException;
18import org.eclipse.linuxtools.statesystem.core.exceptions.StateSystemDisposedException;
19import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
20import org.eclipse.linuxtools.statesystem.core.statevalue.ITmfStateValue;
e8251298
PT
21import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.StateItem;
22import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
23import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;
24import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
25import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.NullTimeEvent;
26import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets.Utils;
27import org.eclipse.swt.SWT;
28import org.eclipse.swt.graphics.GC;
29import org.eclipse.swt.graphics.RGB;
30import org.eclipse.swt.graphics.Rectangle;
31
32/**
33 * Presentation provider for the Call Stack view, based on the generic TMF
34 * presentation provider.
35 *
36 * @author Patrick Tasse
37 * @since 2.0
38 */
39public class CallStackPresentationProvider extends TimeGraphPresentationProvider {
40
41 /** Number of colors used for call stack events */
42 public static final int NUM_COLORS = 360;
43
5da83da5
AM
44 private final CallStackView fView;
45
e8251298
PT
46 private enum State {
47 MULTIPLE (new RGB(100, 100, 100)),
48 EXEC (new RGB(0, 200, 0));
49
52974e38 50 private final RGB rgb;
e8251298
PT
51
52 private State (RGB rgb) {
53 this.rgb = rgb;
54 }
55 }
56
5da83da5
AM
57 /**
58 * Constructor
59 *
60 * @param view
61 * The callstack view that will contain the time events
c4767854 62 * @since 3.0
5da83da5
AM
63 */
64 public CallStackPresentationProvider(CallStackView view) {
65 fView = view;
66 }
67
e8251298
PT
68 @Override
69 public String getStateTypeName() {
70 // Empty string since no generic name
71 return ""; //$NON-NLS-1$
72 }
73
74 @Override
75 public String getStateTypeName(ITimeGraphEntry entry) {
76 return ""; //$NON-NLS-1$
77 }
78
79 @Override
80 public StateItem[] getStateTable() {
52974e38
PT
81 final float saturation = 0.6f;
82 final float brightness = 0.6f;
e8251298
PT
83 StateItem[] stateTable = new StateItem[NUM_COLORS + 1];
84 stateTable[0] = new StateItem(State.MULTIPLE.rgb, State.MULTIPLE.toString());
85 for (int i = 0; i < NUM_COLORS; i++) {
52974e38 86 RGB rgb = new RGB(i, saturation, brightness);
e8251298
PT
87 stateTable[i + 1] = new StateItem(rgb, State.EXEC.toString());
88 }
89 return stateTable;
90 }
91
92 @Override
93 public int getStateTableIndex(ITimeEvent event) {
94 if (event instanceof CallStackEvent) {
95 CallStackEvent callStackEvent = (CallStackEvent) event;
96 return callStackEvent.getValue() + 1;
97 } else if (event instanceof NullTimeEvent) {
98 return INVISIBLE;
99 }
100 return State.MULTIPLE.ordinal();
101 }
102
103 @Override
104 public String getEventName(ITimeEvent event) {
105 if (event instanceof CallStackEvent) {
106 CallStackEntry entry = (CallStackEntry) event.getEntry();
50659279
AM
107 ITmfStateSystem ss = CallStackView.getCallStackStateSystem(entry.getTrace());
108 if (ss == null) {
109 return null;
110 }
e8251298 111 try {
5da83da5
AM
112 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
113 if (!value.isNull()) {
114 String address = value.toString();
115 return fView.getFunctionName(address);
e8251298
PT
116 }
117 } catch (AttributeNotFoundException e) {
52974e38 118 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298 119 } catch (TimeRangeException e) {
52974e38 120 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298
PT
121 } catch (StateSystemDisposedException e) {
122 /* Ignored */
123 }
124 return null;
125 }
126 return State.MULTIPLE.toString();
127 }
128
129 @Override
130 public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) {
131 if (bounds.width <= gc.getFontMetrics().getAverageCharWidth()) {
132 return;
133 }
134 if (!(event instanceof CallStackEvent)) {
135 return;
136 }
137 CallStackEntry entry = (CallStackEntry) event.getEntry();
50659279
AM
138 ITmfStateSystem ss = CallStackView.getCallStackStateSystem(entry.getTrace());
139 if (ss == null) {
140 return;
141 }
e8251298 142 try {
5da83da5
AM
143 ITmfStateValue value = ss.querySingleState(event.getTime(), entry.getQuark()).getStateValue();
144 if (!value.isNull()) {
145 String address = value.toString();
146 String name = fView.getFunctionName(address);
e8251298 147 gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
5da83da5 148 Utils.drawText(gc, name, bounds.x, bounds.y - 2, bounds.width, true, true);
e8251298
PT
149 }
150 } catch (AttributeNotFoundException e) {
52974e38 151 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298 152 } catch (TimeRangeException e) {
52974e38 153 Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
e8251298
PT
154 } catch (StateSystemDisposedException e) {
155 /* Ignored */
156 }
157 }
158
159}
This page took 0.041293 seconds and 5 git commands to generate.