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